1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef AUDIO_DEF_H
5 #define AUDIO_DEF_H
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #include <stdint.h>
12 
13 #define CODEC_FREQ_24M                      24000000
14 #define CODEC_FREQ_26M                      26000000
15 #define CODEC_FREQ_24P576M                  24576000
16 #define CODEC_FREQ_22P5792M                 22579200
17 
18 #define CODEC_FREQ_48K_SERIES               CODEC_FREQ_24P576M
19 #define CODEC_FREQ_44_1K_SERIES             CODEC_FREQ_22P5792M
20 
21 #if 0
22 #elif defined(CHIP_BEST3001) || defined(CHIP_BEST3003) || defined(CHIP_BEST3005)
23 
24 #define CODEC_FREQ_CRYSTAL                  CODEC_FREQ_24M
25 
26 #define CODEC_PLL_DIV                       36
27 #define CODEC_CMU_DIV                       9
28 #ifdef CHIP_BEST3001
29 #define CODEC_PLAYBACK_BIT_DEPTH            20
30 #else
31 #define CODEC_PLAYBACK_BIT_DEPTH            24
32 #endif
33 
34 #elif defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \
35     defined(CHIP_BEST2300) || defined(CHIP_BEST2300P)
36 
37 #define CODEC_FREQ_EXTRA_DIV                2
38 
39 #define CODEC_PLL_DIV                       16
40 #define CODEC_CMU_DIV                       8
41 #define CODEC_PLAYBACK_BIT_DEPTH            24
42 
43 #elif defined(CHIP_BEST1000)
44 
45 #if defined(__AUDIO_DIV_10___)
46 #define CODEC_PLL_DIV                       10
47 #elif defined(__AUDIO_DIV_9___)
48 #define CODEC_PLL_DIV                       9
49 #else
50 #define CODEC_PLL_DIV                       8
51 #endif
52 #define CODEC_PLAYBACK_BIT_DEPTH            18
53 
54 #elif defined(CHIP_BEST2000)
55 
56 #define CODEC_PLL_DIV                       32
57 #define CODEC_CMU_DIV                       8
58 #define CODEC_PLAYBACK_BIT_DEPTH            20
59 
60 #elif defined(CHIP_HAAS1000)
61 
62 #define CODEC_PLL_DIV                       38
63 #define CODEC_CMU_DIV                       8
64 #define CODEC_PLAYBACK_BIT_DEPTH            20
65 
66 #else
67 
68 #error "Please update audio definitions"
69 
70 #endif
71 
72 #ifndef CODEC_FREQ_CRYSTAL
73 #define CODEC_FREQ_CRYSTAL                  CODEC_FREQ_26M
74 #endif
75 #ifndef CODEC_FREQ_EXTRA_DIV
76 #define CODEC_FREQ_EXTRA_DIV                1
77 #endif
78 
79 #define CODEC_TX_PA_GAIN_DEFAULT            -1
80 
81 enum AUD_STREAM_USE_DEVICE_T{
82     AUD_STREAM_USE_DEVICE_NULL = 0,
83     AUD_STREAM_USE_EXT_CODEC,
84     AUD_STREAM_USE_I2S0_MASTER,
85     AUD_STREAM_USE_I2S0_SLAVE,
86     AUD_STREAM_USE_I2S1_MASTER,
87     AUD_STREAM_USE_I2S1_SLAVE,
88     AUD_STREAM_USE_TDM0_MASTER,
89     AUD_STREAM_USE_TDM0_SLAVE,
90     AUD_STREAM_USE_TDM1_MASTER,
91     AUD_STREAM_USE_TDM1_SLAVE,
92     AUD_STREAM_USE_INT_CODEC,
93     AUD_STREAM_USE_INT_SPDIF,
94     AUD_STREAM_USE_BT_PCM,
95     AUD_STREAM_USE_DPD_RX,
96     AUD_STREAM_USE_MC,
97 };
98 
99 enum AUD_SAMPRATE_T {
100     AUD_SAMPRATE_NULL = 0,
101     AUD_SAMPRATE_7350 = 7350,
102     AUD_SAMPRATE_8000 = 8000,
103     AUD_SAMPRATE_8463 = 8463,       // 26M / 512 / 6
104     AUD_SAMPRATE_14700 = 14700,
105     AUD_SAMPRATE_16000 = 16000,
106     AUD_SAMPRATE_16927 = 16927,     // 26M / 512 / 3
107     AUD_SAMPRATE_22050 = 22050,
108     AUD_SAMPRATE_24000 = 24000,
109     AUD_SAMPRATE_32000 = 32000,
110     AUD_SAMPRATE_44100 = 44100,
111     AUD_SAMPRATE_48000 = 48000,
112     AUD_SAMPRATE_64000 = 64000,
113     AUD_SAMPRATE_50781 = 50781,     // 26M / 512
114     AUD_SAMPRATE_88200 = 88200,
115     AUD_SAMPRATE_96000 = 96000,
116     AUD_SAMPRATE_128000 = 128000,
117     AUD_SAMPRATE_256000 = 256000,
118     AUD_SAMPRATE_176400 = 176400,
119     AUD_SAMPRATE_192000 = 192000,
120     AUD_SAMPRATE_352800 = 352800,
121     AUD_SAMPRATE_384000 = 384000,
122     AUD_SAMPRATE_512000 = 512000,
123     AUD_SAMPRATE_705600 = 705600,
124     AUD_SAMPRATE_768000 = 768000,
125     AUD_SAMPRATE_1024000 = 1024000,
126 };
127 
128 enum AUD_CHANNEL_NUM_T {
129     AUD_CHANNEL_NUM_NULL = 0,
130     AUD_CHANNEL_NUM_1 = 1,
131     AUD_CHANNEL_NUM_2 = 2,
132     AUD_CHANNEL_NUM_3 = 3,
133     AUD_CHANNEL_NUM_4 = 4,
134     AUD_CHANNEL_NUM_5 = 5,
135     AUD_CHANNEL_NUM_6 = 6,
136     AUD_CHANNEL_NUM_7 = 7,
137     AUD_CHANNEL_NUM_8 = 8,
138 };
139 
140 // For preprocess check
141 #define AUD_CHANNEL_MAP_CH0                 (1 << 0)
142 #define AUD_CHANNEL_MAP_CH1                 (1 << 1)
143 #define AUD_CHANNEL_MAP_CH2                 (1 << 2)
144 #define AUD_CHANNEL_MAP_CH3                 (1 << 3)
145 #define AUD_CHANNEL_MAP_CH4                 (1 << 4)
146 #define AUD_CHANNEL_MAP_CH5                 (1 << 5)
147 #define AUD_CHANNEL_MAP_CH6                 (1 << 6)
148 #define AUD_CHANNEL_MAP_CH7                 (1 << 7)
149 #define AUD_CHANNEL_MAP_DIGMIC_CH0          (1 << 8)
150 #define AUD_CHANNEL_MAP_DIGMIC_CH1          (1 << 9)
151 #define AUD_CHANNEL_MAP_DIGMIC_CH2          (1 << 10)
152 #define AUD_CHANNEL_MAP_DIGMIC_CH3          (1 << 11)
153 #define AUD_CHANNEL_MAP_DIGMIC_CH4          (1 << 12)
154 #define AUD_CHANNEL_MAP_DIGMIC_CH5          (1 << 13)
155 #define AUD_CHANNEL_MAP_DIGMIC_CH6          (1 << 14)
156 #define AUD_CHANNEL_MAP_DIGMIC_CH7          (1 << 15)
157 
158 #define AUD_CHANNEL_MAP_ANA_ALL             (0x00FF)
159 #define AUD_CHANNEL_MAP_DIGMIC_ALL          (0xFF00)
160 #define AUD_CHANNEL_MAP_ALL                 (0xFFFF)
161 
162 enum AUD_CHANNEL_MAP_T {
163     AUD_CHANNEL_MAP_END = AUD_CHANNEL_MAP_DIGMIC_CH7,
164 };
165 
166 enum AUD_VMIC_MAP_T {
167     AUD_VMIC_MAP_VMIC1 = (AUD_CHANNEL_MAP_END << 1),
168     AUD_VMIC_MAP_VMIC2 = (AUD_CHANNEL_MAP_END << 2),
169     AUD_VMIC_MAP_VMIC3 = (AUD_CHANNEL_MAP_END << 3),
170     AUD_VMIC_MAP_VMIC4 = (AUD_CHANNEL_MAP_END << 4),
171     AUD_VMIC_MAP_VMIC5 = (AUD_CHANNEL_MAP_END << 5),
172 };
173 
174 enum AUD_BITS_T {
175     AUD_BITS_NULL = 0,
176     AUD_BITS_8 = 8,
177     AUD_BITS_12 = 12,
178     AUD_BITS_16 = 16,
179     AUD_BITS_20 = 20,
180     AUD_BITS_24 = 24,
181     AUD_BITS_32 = 32,
182 };
183 
184 enum AUD_STREAM_ID_T {
185     AUD_STREAM_ID_0 = 0,
186     AUD_STREAM_ID_1,
187     AUD_STREAM_ID_2,
188 
189     AUD_STREAM_ID_NUM,
190 };
191 
192 enum AUD_STREAM_T {
193     AUD_STREAM_PLAYBACK = 0,
194     AUD_STREAM_CAPTURE,
195 
196     AUD_STREAM_NUM,
197 };
198 
199 // TODO: Need rename
200 enum AUD_IO_PATH_T {
201     AUD_IO_PATH_NULL = 0,
202 
203     // Input path
204     AUD_INPUT_PATH_MAINMIC,
205     AUD_INPUT_PATH_VADMIC,
206     AUD_INPUT_PATH_ASRMIC,
207     AUD_INPUT_PATH_LINEIN,
208     AUD_INPUT_PATH_NTMIC,
209     AUD_INPUT_PATH_ANC_WNR,
210     AUD_INPUT_PATH_USBAUDIO,
211 
212     // Output path
213     AUD_OUTPUT_PATH_SPEAKER,
214 };
215 
216 struct AUD_IO_PATH_CFG_T {
217     enum AUD_IO_PATH_T io_path;
218     unsigned int cfg;
219 };
220 
221 enum ANC_TYPE_T {
222     ANC_NOTYPE = 0,
223     ANC_FEEDFORWARD,
224     ANC_FEEDBACK,
225 #if defined(AUDIO_ANC_TT_HW)
226     ANC_TALKTHRU,
227 #endif
228 #if defined(AUDIO_ANC_FB_MC_HW)
229     ANC_MUSICCANCLE,
230 #endif
231 };
232 
233 struct CODEC_DAC_VOL_T {
234     signed char tx_pa_gain      :6;
235     unsigned char sdm_gain      :2;
236     signed char sdac_volume;
237 };
238 
239 typedef signed char CODEC_ADC_VOL_T;
240 
241 enum TGT_VOLUME_LEVEL_T {
242     TGT_VOLUME_LEVEL_WARNINGTONE = 0,
243 
244     TGT_VOLUME_LEVEL_MUTE,
245     TGT_VOLUME_LEVEL_0,
246     TGT_VOLUME_LEVEL_1,
247     TGT_VOLUME_LEVEL_2,
248     TGT_VOLUME_LEVEL_3,
249     TGT_VOLUME_LEVEL_4,
250     TGT_VOLUME_LEVEL_5,
251     TGT_VOLUME_LEVEL_6,
252     TGT_VOLUME_LEVEL_7,
253     TGT_VOLUME_LEVEL_8,
254     TGT_VOLUME_LEVEL_9,
255     TGT_VOLUME_LEVEL_10,
256     TGT_VOLUME_LEVEL_11,
257     TGT_VOLUME_LEVEL_12,
258     TGT_VOLUME_LEVEL_13,
259     TGT_VOLUME_LEVEL_14,
260     TGT_VOLUME_LEVEL_15,
261 
262     TGT_VOLUME_LEVEL_QTY
263 };
264 
265 enum TGT_ADC_VOL_LEVEL_T {
266     TGT_ADC_VOL_LEVEL_0,
267     TGT_ADC_VOL_LEVEL_1,
268     TGT_ADC_VOL_LEVEL_2,
269     TGT_ADC_VOL_LEVEL_3,
270     TGT_ADC_VOL_LEVEL_4,
271     TGT_ADC_VOL_LEVEL_5,
272     TGT_ADC_VOL_LEVEL_6,
273     TGT_ADC_VOL_LEVEL_7,
274     TGT_ADC_VOL_LEVEL_8,
275     TGT_ADC_VOL_LEVEL_9,
276     TGT_ADC_VOL_LEVEL_10,
277     TGT_ADC_VOL_LEVEL_11,
278     TGT_ADC_VOL_LEVEL_12,
279     TGT_ADC_VOL_LEVEL_13,
280     TGT_ADC_VOL_LEVEL_14,
281     TGT_ADC_VOL_LEVEL_15,
282 
283     TGT_ADC_VOL_LEVEL_QTY
284 };
285 
286 typedef void (*AUD_VAD_CALLBACK)(int found);
287 
288 enum AUD_VAD_TYPE_T {
289     AUD_VAD_TYPE_NONE = 0,
290     AUD_VAD_TYPE_MIX,
291     AUD_VAD_TYPE_DIG,
292     AUD_VAD_TYPE_ANA,
293 
294     AUD_VAD_TYPE_NUM,
295 };
296 
297 struct AUD_VAD_CONFIG_T {
298     enum AUD_VAD_TYPE_T type;
299     enum AUD_SAMPRATE_T sample_rate;
300     AUD_VAD_CALLBACK handler;
301 
302     uint8_t udc;
303     uint8_t upre;
304     uint8_t frame_len;
305     uint8_t mvad;
306 
307     uint8_t dig_mode;
308     uint8_t pre_gain;
309     uint8_t sth;
310     uint8_t dc_bypass;
311 
312     uint8_t ds_bypass;
313     uint8_t pre_bypass;
314     uint8_t adc_gain;
315 
316     uint16_t range[4];
317 
318     uint32_t frame_th[3];
319     uint32_t psd_th[2];
320 };
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 #endif /* AUDIO_DEF_H */
327