1 /*
2  * Copyright (C) 2013-2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef QCOM_AUDIO_PLATFORM_H
18 #define QCOM_AUDIO_PLATFORM_H
19 
20 enum {
21     FLUENCE_DISABLE,                  /* Target dosent support fluence */
22     FLUENCE_ENABLE      = 0x1,        /* Target supports fluence */
23     FLUENCE_PRO_ENABLE  = 0x2,        /* Target supports fluence pro */
24 };
25 
26 enum {
27     SOURCE_MONO_MIC  = 0x1,            /* Target contains 1 mic */
28     SOURCE_DUAL_MIC  = 0x2,            /* Target contains 2 mics */
29     SOURCE_THREE_MIC = 0x4,            /* Target contains 3 mics */
30     SOURCE_QUAD_MIC  = 0x8,            /* Target contains 4 mics */
31 };
32 
33 /*
34  * Below are the devices for which is back end is same, SLIMBUS_0_RX.
35  * All these devices are handled by the internal HW codec. We can
36  * enable any one of these devices at any time
37  */
38 #define AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND \
39     (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | \
40      AUDIO_DEVICE_OUT_SPEAKER_SAFE | \
41      AUDIO_DEVICE_OUT_WIRED_HEADSET | AUDIO_DEVICE_OUT_WIRED_HEADPHONE | \
42      AUDIO_DEVICE_OUT_LINE)
43 
44 /*
45  * Below are the input devices for which back end is same, SLIMBUS_0_TX.
46  * All these devices are handled by the internal HW codec. We can
47  * enable any one of these devices at any time
48  */
49 #define AUDIO_DEVICE_IN_ALL_CODEC_BACKEND \
50     (AUDIO_DEVICE_IN_BUILTIN_MIC | AUDIO_DEVICE_IN_BACK_MIC | \
51      AUDIO_DEVICE_IN_WIRED_HEADSET | AUDIO_DEVICE_IN_VOICE_CALL) & ~AUDIO_DEVICE_BIT_IN
52 
53 /* Sound devices specific to the platform
54  * The DEVICE_OUT_* and DEVICE_IN_* should be mapped to these sound
55  * devices to enable corresponding mixer paths
56  */
57 enum {
58     SND_DEVICE_NONE = 0,
59 
60     /* Playback devices */
61     SND_DEVICE_MIN,
62     SND_DEVICE_OUT_BEGIN = SND_DEVICE_MIN,
63     SND_DEVICE_OUT_HANDSET = SND_DEVICE_OUT_BEGIN,
64     SND_DEVICE_OUT_SPEAKER,
65     SND_DEVICE_OUT_SPEAKER_REVERSE,
66     SND_DEVICE_OUT_SPEAKER_SAFE,
67     SND_DEVICE_OUT_HEADPHONES,
68     SND_DEVICE_OUT_LINE,
69     SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES,
70     SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES,
71     SND_DEVICE_OUT_SPEAKER_AND_LINE,
72     SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE,
73     SND_DEVICE_OUT_VOICE_HANDSET,
74     SND_DEVICE_OUT_VOICE_SPEAKER,
75     SND_DEVICE_OUT_VOICE_HEADPHONES,
76     SND_DEVICE_OUT_VOICE_HEADSET,
77     SND_DEVICE_OUT_VOICE_LINE,
78     SND_DEVICE_OUT_HDMI,
79     SND_DEVICE_OUT_SPEAKER_AND_HDMI,
80     SND_DEVICE_OUT_BT_SCO,
81     SND_DEVICE_OUT_BT_SCO_WB,
82     SND_DEVICE_OUT_BT_A2DP,
83     SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP,
84     SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP,
85     SND_DEVICE_OUT_VOICE_HANDSET_TMUS,
86     SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES,
87     SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES,
88     SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET,
89     SND_DEVICE_OUT_VOICE_TTY_FULL_USB,
90     SND_DEVICE_OUT_VOICE_TTY_VCO_USB,
91     SND_DEVICE_OUT_VOICE_HAC_HANDSET,
92     SND_DEVICE_OUT_VOICE_TX,
93     SND_DEVICE_OUT_VOICE_MUSIC_TX,
94     SND_DEVICE_OUT_SPEAKER_PROTECTED,
95     SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED,
96     SND_DEVICE_OUT_VOICE_SPEAKER_HFP,
97     SND_DEVICE_OUT_SPEAKER_AND_BT_SCO,
98     SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO,
99     SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB,
100     SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB,
101     SND_DEVICE_OUT_USB_HEADSET,
102     SND_DEVICE_OUT_USB_HEADPHONES,
103     SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET,
104     SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET,
105     SND_DEVICE_OUT_VOICE_USB_HEADPHONES,
106     SND_DEVICE_OUT_VOICE_USB_HEADSET,
107     /* Specific snd_devices */
108     SND_DEVICE_OUT_USB_HEADSET_SPEC,
109     SND_DEVICE_OUT_VOICE_HEARING_AID,
110     SND_DEVICE_OUT_END,
111 
112     /*
113      * Note: IN_BEGIN should be same as OUT_END because total number of devices
114      * SND_DEVICES_MAX should not exceed MAX_RX + MAX_TX devices.
115      */
116     /* Capture devices */
117     SND_DEVICE_IN_BEGIN = SND_DEVICE_OUT_END,
118     SND_DEVICE_IN_HANDSET_MIC  = SND_DEVICE_IN_BEGIN,
119     SND_DEVICE_IN_HANDSET_MIC_AEC,
120     SND_DEVICE_IN_HANDSET_MIC_NS,
121     SND_DEVICE_IN_HANDSET_MIC_AEC_NS,
122     SND_DEVICE_IN_HANDSET_DMIC,
123     SND_DEVICE_IN_HANDSET_DMIC_AEC,
124     SND_DEVICE_IN_HANDSET_DMIC_NS,
125     SND_DEVICE_IN_HANDSET_DMIC_AEC_NS,
126     SND_DEVICE_IN_HANDSET_DMIC_STEREO,
127 
128     SND_DEVICE_IN_SPEAKER_MIC,
129     SND_DEVICE_IN_SPEAKER_MIC_AEC,
130     SND_DEVICE_IN_SPEAKER_MIC_NS,
131     SND_DEVICE_IN_SPEAKER_MIC_AEC_NS,
132     SND_DEVICE_IN_SPEAKER_DMIC,
133     SND_DEVICE_IN_SPEAKER_DMIC_AEC,
134     SND_DEVICE_IN_SPEAKER_DMIC_NS,
135     SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS,
136     SND_DEVICE_IN_SPEAKER_DMIC_STEREO,
137 
138     SND_DEVICE_IN_HEADSET_MIC,
139     SND_DEVICE_IN_HEADSET_MIC_AEC,
140 
141     SND_DEVICE_IN_HDMI_MIC,
142     SND_DEVICE_IN_BT_SCO_MIC,
143     SND_DEVICE_IN_BT_SCO_MIC_NREC,
144     SND_DEVICE_IN_BT_SCO_MIC_WB,
145     SND_DEVICE_IN_BT_SCO_MIC_WB_NREC,
146     SND_DEVICE_IN_CAMCORDER_LANDSCAPE,
147 
148     SND_DEVICE_IN_VOICE_DMIC,
149     SND_DEVICE_IN_VOICE_DMIC_TMUS,
150     SND_DEVICE_IN_VOICE_SPEAKER_MIC,
151     SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP,
152     SND_DEVICE_IN_VOICE_SPEAKER_DMIC,
153     SND_DEVICE_IN_VOICE_HEADSET_MIC,
154     SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC,
155     SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC,
156     SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC,
157     SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC,
158     SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC,
159 
160     SND_DEVICE_IN_VOICE_REC_MIC,
161     SND_DEVICE_IN_VOICE_REC_MIC_NS,
162     SND_DEVICE_IN_VOICE_REC_MIC_AEC,
163     SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS,
164     SND_DEVICE_IN_VOICE_REC_DMIC_STEREO,
165     SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE,
166     SND_DEVICE_IN_VOICE_REC_HEADSET_MIC,
167 
168     SND_DEVICE_IN_UNPROCESSED_MIC,
169     SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC,
170     SND_DEVICE_IN_UNPROCESSED_STEREO_MIC,
171     SND_DEVICE_IN_UNPROCESSED_THREE_MIC,
172     SND_DEVICE_IN_UNPROCESSED_QUAD_MIC,
173 
174     SND_DEVICE_IN_VOICE_RX,
175 
176     SND_DEVICE_IN_USB_HEADSET_MIC,
177     SND_DEVICE_IN_USB_HEADSET_MIC_AEC,
178     SND_DEVICE_IN_VOICE_USB_HEADSET_MIC,
179     SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC,
180     SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC,
181     SND_DEVICE_IN_THREE_MIC,
182     SND_DEVICE_IN_QUAD_MIC,
183     SND_DEVICE_IN_CAPTURE_VI_FEEDBACK,
184 
185     SND_DEVICE_IN_HANDSET_TMIC,
186     SND_DEVICE_IN_HANDSET_QMIC,
187     SND_DEVICE_IN_HANDSET_TMIC_AEC,
188     SND_DEVICE_IN_HANDSET_QMIC_AEC,
189     SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE,
190     SND_DEVICE_IN_CAMCORDER_PORTRAIT,
191     SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE,
192     SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE,
193     SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT,
194     SND_DEVICE_IN_SPEAKER_QMIC_NS,
195     SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS,
196     SND_DEVICE_IN_VOICE_HEARING_AID,
197     SND_DEVICE_IN_END,
198 
199     SND_DEVICE_MAX = SND_DEVICE_IN_END,
200     /* For legacy xml file parsing */
201     SND_DEVICE_IN_CAMCORDER_MIC = SND_DEVICE_IN_CAMCORDER_LANDSCAPE,
202 };
203 #define DEFAULT_OUTPUT_SAMPLING_RATE    48000
204 #define OUTPUT_SAMPLING_RATE_44100      44100
205 #define DEFAULT_INPUT_SAMPLING_RATE     48000
206 
207 enum {
208     DEFAULT_CODEC_BACKEND,
209     SLIMBUS_0_RX = DEFAULT_CODEC_BACKEND,
210     HEADPHONE_BACKEND,
211     SLIMBUS_6_RX = HEADPHONE_BACKEND,
212     HDMI_RX_BACKEND,
213     USB_AUDIO_RX_BACKEND,
214     MAX_RX_CODEC_BACKENDS = USB_AUDIO_RX_BACKEND,
215     /* TX BE follows RX BE */
216     SLIMBUS_0_TX,
217     DEFAULT_CODEC_TX_BACKEND = SLIMBUS_0_TX,
218     USB_AUDIO_TX_BACKEND,
219     BT_SCO_TX_BACKEND,
220     MAX_CODEC_BACKENDS
221 };
222 
223 #define DEVICE_NAME_MAX_SIZE   128
224 #define HW_INFO_ARRAY_MAX_SIZE 32
225 
226 #define ALL_SESSION_VSID                0xFFFFFFFF
227 #define DEFAULT_MUTE_RAMP_DURATION_MS   20
228 #define DEFAULT_VOLUME_RAMP_DURATION_MS 20
229 #define MIXER_PATH_MAX_LENGTH 100
230 
231 #define ACDB_ID_VOICE_SPEAKER 15
232 #define ACDB_ID_VOICE_HANDSET 7
233 #define ACDB_ID_VOICE_HANDSET_TMUS 88
234 #define ACDB_ID_VOICE_DMIC_EF_TMUS 89
235 #define ACDB_ID_HEADSET_MIC_AEC 8
236 #define ACDB_ID_VOICE_REC_MIC 62
237 
238 #define MAX_VOL_INDEX 5
239 #define MIN_VOL_INDEX 0
240 #define percent_to_index(val, min, max) \
241             ((val) * ((max) - (min)) * 0.01 + (min) + .5)
242 
243 /*
244  * tinyAlsa library interprets period size as number of frames
245  * one frame = channel_count * sizeof (pcm sample)
246  * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes
247  * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes
248  * We should take care of returning proper size when AudioFlinger queries for
249  * the buffer size of an input/output stream
250  */
251 
252 /* 1920 frames(40ms) at 2 buffers gives a good tradeoff between power and latency */
253 #define DEEP_BUFFER_OUTPUT_PERIOD_SIZE 1920
254 #define DEEP_BUFFER_OUTPUT_PERIOD_COUNT 2
255 
256 #define LOW_LATENCY_OUTPUT_PERIOD_SIZE 240
257 #define LOW_LATENCY_OUTPUT_PERIOD_COUNT 2
258 
259 #define HDMI_MULTI_PERIOD_SIZE  336
260 #define HDMI_MULTI_PERIOD_COUNT 8
261 #define HDMI_MULTI_DEFAULT_CHANNEL_COUNT 6
262 #define HDMI_MULTI_PERIOD_BYTES (HDMI_MULTI_PERIOD_SIZE * HDMI_MULTI_DEFAULT_CHANNEL_COUNT * 2)
263 
264 #define AUDIO_CAPTURE_PERIOD_DURATION_MSEC 20
265 #define AUDIO_CAPTURE_PERIOD_COUNT 2
266 
267 #define VOIP_CAPTURE_PERIOD_DURATION_MSEC 20
268 #define VOIP_CAPTURE_PERIOD_COUNT 2
269 
270 #define VOIP_PLAYBACK_PERIOD_DURATION_MSEC 20
271 #define VOIP_PLAYBACK_PERIOD_COUNT 2
272 
273 #define LOW_LATENCY_CAPTURE_SAMPLE_RATE 48000
274 #define LOW_LATENCY_CAPTURE_PERIOD_SIZE 240
275 #define LOW_LATENCY_CAPTURE_USE_CASE 1
276 
277 #define DEEP_BUFFER_PCM_DEVICE 0
278 #define AUDIO_RECORD_PCM_DEVICE 0
279 #define MULTIMEDIA2_PCM_DEVICE 1
280 
281 #define SPKR_PROT_CALIB_RX_PCM_DEVICE 5
282 #define SPKR_PROT_CALIB_TX_PCM_DEVICE 25
283 
284 #define MULTIMEDIA3_PCM_DEVICE 4
285 
286 #define MMAP_PLAYBACK_PCM_DEVICE 18
287 #define MMAP_RECORD_PCM_DEVICE 18
288 
289 #define QUAT_MI2S_PCM_DEVICE    44
290 #define PLAYBACK_OFFLOAD_DEVICE 9
291 #define LOWLATENCY_PCM_DEVICE 15
292 #define VOICE_VSID  0x10C01000
293 
294 #define AUDIO_HAPTICS_PCM_DEVICE 43
295 #define HAPTICS_PCM_DEVICE 44
296 
297 //needs verification
298 #define AUDIO_PLAYBACK_VOIP_PCM_DEVICE 5
299 #define AUDIO_RECORD_VOIP_PCM_DEVICE 6
300 
301 #ifdef PLATFORM_MSM8x26
302 #define VOICE_CALL_PCM_DEVICE 2
303 #define VOICE2_CALL_PCM_DEVICE 14
304 #define VOLTE_CALL_PCM_DEVICE 17
305 #define QCHAT_CALL_PCM_DEVICE 18
306 #define VOWLAN_CALL_PCM_DEVICE 30
307 #elif PLATFORM_MSM8084
308 #define VOICE_CALL_PCM_DEVICE 20
309 #define VOICE2_CALL_PCM_DEVICE 25
310 #define VOLTE_CALL_PCM_DEVICE 21
311 #define QCHAT_CALL_PCM_DEVICE 33
312 #define VOWLAN_CALL_PCM_DEVICE -1
313 #elif PLATFORM_MSM8996
314 #define VOICE_CALL_PCM_DEVICE 40
315 #define VOICE2_CALL_PCM_DEVICE 41
316 #define VOLTE_CALL_PCM_DEVICE 14
317 #define QCHAT_CALL_PCM_DEVICE 20
318 #define VOWLAN_CALL_PCM_DEVICE 33
319 #else
320 #define VOICE_CALL_PCM_DEVICE 2
321 #define VOICE2_CALL_PCM_DEVICE 22
322 #define VOLTE_CALL_PCM_DEVICE 14
323 #define QCHAT_CALL_PCM_DEVICE 20
324 #define VOWLAN_CALL_PCM_DEVICE 36
325 #endif
326 
327 #ifdef PLATFORM_MSM8996
328 #define VOICEMMODE1_CALL_PCM_DEVICE 2
329 #define VOICEMMODE2_CALL_PCM_DEVICE 22
330 #else
331 #define VOICEMMODE1_CALL_PCM_DEVICE 44
332 #define VOICEMMODE2_CALL_PCM_DEVICE 45
333 #endif
334 
335 #define AFE_PROXY_PLAYBACK_PCM_DEVICE 7
336 #define AFE_PROXY_RECORD_PCM_DEVICE 8
337 
338 #define INCALL_MUSIC_UPLINK_PCM_DEVICE 27
339 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 27
340 
341 #define HFP_PCM_RX 5
342 #ifdef PLATFORM_MSM8x26
343 #ifdef EXTERNAL_BT_SUPPORTED
344 #define HFP_SCO_RX 10 // AUXPCM Hostless
345 #else
346 #define HFP_SCO_RX 28 // INT_HFP_BT Hostless
347 #endif
348 #define HFP_ASM_RX_TX 29
349 #else
350 #define HFP_SCO_RX 23
351 #define HFP_ASM_RX_TX 24
352 #endif
353 
354 #define TX_VOICE_FLUENCE_PROV2 0x10F17
355 #define TX_VOICE_DM_FV5_BROADSIDE 0x10F18
356 #define TX_VOICE_FV5ECNS_SM 0x10F09
357 #define TX_VOICE_FV5ECNS_DM 0x10F0A
358 
359 #define LIB_CSD_CLIENT "libcsd-client.so"
360 #define LIB_MDM_DETECT "libmdmdetect.so"
361 
362 #define PLATFORM_CONFIG_KEY_SOUNDCARD_NAME "snd_card_name"
363 #define PLATFORM_CONFIG_KEY_MAX_MIC_COUNT "input_mic_max_count"
364 #define PLATFORM_DEFAULT_MIC_COUNT 2
365 
366 #define AUDIO_MAKE_STRING_FROM_ENUM(X)   { #X, X }
367 
368 /* CSD-CLIENT related functions */
369 typedef int (*init_t)(bool);
370 typedef int (*deinit_t)();
371 typedef int (*disable_device_t)();
372 typedef int (*enable_device_config_t)(int, int);
373 typedef int (*enable_device_t)(int, int, uint32_t);
374 typedef int (*volume_t)(uint32_t, int, uint16_t);
375 typedef int (*mic_mute_t)(uint32_t, int, uint16_t);
376 typedef int (*slow_talk_t)(uint32_t, uint8_t);
377 typedef int (*start_voice_t)(uint32_t);
378 typedef int (*stop_voice_t)(uint32_t);
379 typedef int (*start_playback_t)(uint32_t);
380 typedef int (*stop_playback_t)(uint32_t);
381 typedef int (*start_record_t)(uint32_t, int);
382 typedef int (*stop_record_t)(uint32_t);
383 typedef int (*get_sample_rate_t)(uint32_t *);
384 /* CSD Client structure */
385 struct csd_data {
386     void *csd_client;
387     init_t init;
388     deinit_t deinit;
389     disable_device_t disable_device;
390     enable_device_config_t enable_device_config;
391     enable_device_t enable_device;
392     volume_t volume;
393     mic_mute_t mic_mute;
394     slow_talk_t slow_talk;
395     start_voice_t start_voice;
396     stop_voice_t stop_voice;
397     start_playback_t start_playback;
398     stop_playback_t stop_playback;
399     start_record_t start_record;
400     stop_record_t stop_record;
401     get_sample_rate_t get_sample_rate;
402 };
403 
404 struct audio_backend_cfg {
405     unsigned int   sample_rate;
406     unsigned int   channels;
407     unsigned int   bit_width;
408     bool           passthrough_enabled;
409     audio_format_t format;
410 };
411 
412 typedef struct codec_backend_cfg {
413     uint32_t sample_rate;
414     uint32_t bit_width;
415     uint32_t channels;
416     char     *bitwidth_mixer_ctl;
417     char     *samplerate_mixer_ctl;
418     char     *channels_mixer_ctl;
419 } codec_backend_cfg_t;
420 
421 #define PLATFORM_INFO_XML_PATH          "audio_platform_info.xml"
422 #define PLATFORM_INFO_XML_BASE_STRING   "audio_platform_info"
423 #endif // QCOM_AUDIO_PLATFORM_H
424