1 /*
2  * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
3  * Not a Contribution.
4  *
5  * Copyright (C) 2013 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef QCOM_AUDIO_PLATFORM_H
21 #define QCOM_AUDIO_PLATFORM_H
22 #include <sound/voice_params.h>
23 
24 enum {
25     FLUENCE_NONE,
26     FLUENCE_DUAL_MIC = 0x1,
27     FLUENCE_QUAD_MIC = 0x2,
28 };
29 
30 enum {
31     FLUENCE_ENDFIRE = 0x1,
32     FLUENCE_BROADSIDE = 0x2,
33 };
34 
35 /*
36  * Below are the devices for which is back end is same, SLIMBUS_0_RX.
37  * All these devices are handled by the internal HW codec. We can
38  * enable any one of these devices at any time
39  */
40 #define AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND \
41     (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | \
42      AUDIO_DEVICE_OUT_WIRED_HEADSET | AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
43 
44 /* Sound devices specific to the platform
45  * The DEVICE_OUT_* and DEVICE_IN_* should be mapped to these sound
46  * devices to enable corresponding mixer paths
47  */
48 enum {
49     SND_DEVICE_NONE = 0,
50 
51     /* Playback devices */
52     SND_DEVICE_MIN,
53     SND_DEVICE_OUT_BEGIN = SND_DEVICE_MIN,
54     SND_DEVICE_OUT_HANDSET = SND_DEVICE_OUT_BEGIN,
55     SND_DEVICE_OUT_SPEAKER,
56     SND_DEVICE_OUT_SPEAKER_EXTERNAL_1,
57     SND_DEVICE_OUT_SPEAKER_EXTERNAL_2,
58     SND_DEVICE_OUT_SPEAKER_REVERSE,
59     SND_DEVICE_OUT_HEADPHONES,
60     SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES,
61     SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1,
62     SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2,
63     SND_DEVICE_OUT_VOICE_HANDSET,
64     SND_DEVICE_OUT_VOICE_SPEAKER,
65     SND_DEVICE_OUT_VOICE_HEADPHONES,
66     SND_DEVICE_OUT_HDMI,
67     SND_DEVICE_OUT_SPEAKER_AND_HDMI,
68     SND_DEVICE_OUT_BT_SCO,
69     SND_DEVICE_OUT_BT_SCO_WB,
70     SND_DEVICE_OUT_BT_A2DP,
71     SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP,
72     SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES,
73     SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES,
74     SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET,
75     SND_DEVICE_OUT_VOICE_TX,
76     SND_DEVICE_OUT_AFE_PROXY,
77     SND_DEVICE_OUT_USB_HEADSET,
78     SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET,
79     SND_DEVICE_OUT_TRANSMISSION_FM,
80     SND_DEVICE_OUT_ANC_HEADSET,
81     SND_DEVICE_OUT_ANC_FB_HEADSET,
82     SND_DEVICE_OUT_VOICE_ANC_HEADSET,
83     SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET,
84     SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET,
85     SND_DEVICE_OUT_ANC_HANDSET,
86     SND_DEVICE_OUT_SPEAKER_PROTECTED,
87     SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED,
88     SND_DEVICE_OUT_END,
89 
90     /*
91      * Note: IN_BEGIN should be same as OUT_END because total number of devices
92      * SND_DEVICES_MAX should not exceed MAX_RX + MAX_TX devices.
93      */
94     /* Capture devices */
95     SND_DEVICE_IN_BEGIN = SND_DEVICE_OUT_END,
96     SND_DEVICE_IN_HANDSET_MIC  = SND_DEVICE_IN_BEGIN,
97     SND_DEVICE_IN_HANDSET_MIC_EXTERNAL,
98     SND_DEVICE_IN_HANDSET_MIC_AEC,
99     SND_DEVICE_IN_HANDSET_MIC_NS,
100     SND_DEVICE_IN_HANDSET_MIC_AEC_NS,
101     SND_DEVICE_IN_HANDSET_DMIC,
102     SND_DEVICE_IN_HANDSET_DMIC_AEC,
103     SND_DEVICE_IN_HANDSET_DMIC_NS,
104     SND_DEVICE_IN_HANDSET_DMIC_AEC_NS,
105     SND_DEVICE_IN_SPEAKER_MIC,
106     SND_DEVICE_IN_SPEAKER_MIC_AEC,
107     SND_DEVICE_IN_SPEAKER_MIC_NS,
108     SND_DEVICE_IN_SPEAKER_MIC_AEC_NS,
109     SND_DEVICE_IN_SPEAKER_DMIC,
110     SND_DEVICE_IN_SPEAKER_DMIC_AEC,
111     SND_DEVICE_IN_SPEAKER_DMIC_NS,
112     SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS,
113     SND_DEVICE_IN_HEADSET_MIC,
114     SND_DEVICE_IN_HEADSET_MIC_FLUENCE,
115     SND_DEVICE_IN_VOICE_SPEAKER_MIC,
116     SND_DEVICE_IN_VOICE_HEADSET_MIC,
117     SND_DEVICE_IN_HDMI_MIC,
118     SND_DEVICE_IN_BT_SCO_MIC,
119     SND_DEVICE_IN_BT_SCO_MIC_NREC,
120     SND_DEVICE_IN_BT_SCO_MIC_WB,
121     SND_DEVICE_IN_BT_SCO_MIC_WB_NREC,
122     SND_DEVICE_IN_CAMCORDER_MIC,
123     SND_DEVICE_IN_VOICE_DMIC,
124     SND_DEVICE_IN_VOICE_SPEAKER_DMIC,
125     SND_DEVICE_IN_VOICE_SPEAKER_QMIC,
126     SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC,
127     SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC,
128     SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC,
129     SND_DEVICE_IN_VOICE_REC_MIC,
130     SND_DEVICE_IN_VOICE_REC_MIC_NS,
131     SND_DEVICE_IN_VOICE_REC_DMIC_STEREO,
132     SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE,
133     SND_DEVICE_IN_VOICE_RX,
134     SND_DEVICE_IN_USB_HEADSET_MIC,
135     SND_DEVICE_IN_CAPTURE_FM,
136     SND_DEVICE_IN_AANC_HANDSET_MIC,
137     SND_DEVICE_IN_QUAD_MIC,
138     SND_DEVICE_IN_HANDSET_STEREO_DMIC,
139     SND_DEVICE_IN_SPEAKER_STEREO_DMIC,
140     SND_DEVICE_IN_CAPTURE_VI_FEEDBACK,
141     SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE,
142     SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE,
143     SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE,
144     SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE,
145     SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE,
146     SND_DEVICE_IN_END,
147 
148     SND_DEVICE_MAX = SND_DEVICE_IN_END,
149 
150 };
151 
152 #define DEFAULT_OUTPUT_SAMPLING_RATE 48000
153 
154 #define ALL_SESSION_VSID                0xFFFFFFFF
155 #define DEFAULT_MUTE_RAMP_DURATION_MS   20
156 #define DEFAULT_VOLUME_RAMP_DURATION_MS 20
157 #define MIXER_PATH_MAX_LENGTH 100
158 
159 #define MAX_VOL_INDEX 5
160 #define MIN_VOL_INDEX 0
161 #define percent_to_index(val, min, max) \
162             ((val) * ((max) - (min)) * 0.01 + (min) + .5)
163 
164 /*
165  * tinyAlsa library interprets period size as number of frames
166  * one frame = channel_count * sizeof (pcm sample)
167  * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes
168  * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes
169  * We should take care of returning proper size when AudioFlinger queries for
170  * the buffer size of an input/output stream
171  */
172 #define DEEP_BUFFER_OUTPUT_PERIOD_SIZE 960
173 #define DEEP_BUFFER_OUTPUT_PERIOD_COUNT 4
174 #define LOW_LATENCY_OUTPUT_PERIOD_SIZE 240
175 #define LOW_LATENCY_OUTPUT_PERIOD_COUNT 2
176 
177 #define HDMI_MULTI_PERIOD_SIZE  336
178 #define HDMI_MULTI_PERIOD_COUNT 8
179 #define HDMI_MULTI_DEFAULT_CHANNEL_COUNT 6
180 #define HDMI_MULTI_PERIOD_BYTES (HDMI_MULTI_PERIOD_SIZE * HDMI_MULTI_DEFAULT_CHANNEL_COUNT * 2)
181 
182 #define AUDIO_CAPTURE_PERIOD_DURATION_MSEC 20
183 #define AUDIO_CAPTURE_PERIOD_COUNT 2
184 
185 #define LOW_LATENCY_CAPTURE_SAMPLE_RATE 48000
186 #define LOW_LATENCY_CAPTURE_PERIOD_SIZE 240
187 #define LOW_LATENCY_CAPTURE_USE_CASE 1
188 
189 #define DEVICE_NAME_MAX_SIZE 128
190 #define HW_INFO_ARRAY_MAX_SIZE 32
191 
192 #define DEEP_BUFFER_PCM_DEVICE 0
193 #define AUDIO_RECORD_PCM_DEVICE 0
194 #define MULTIMEDIA2_PCM_DEVICE 1
195 #define FM_PLAYBACK_PCM_DEVICE 5
196 #define FM_CAPTURE_PCM_DEVICE  6
197 #define HFP_PCM_RX 5
198 
199 #define INCALL_MUSIC_UPLINK_PCM_DEVICE 1
200 
201 #ifdef PLATFORM_MSM8610
202 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 14
203 #elif PLATFORM_MSM8x26
204 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 16
205 #elif PLATFORM_APQ8084
206 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 34
207 #else
208 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 35
209 #endif
210 
211 #define SPKR_PROT_CALIB_RX_PCM_DEVICE 5
212 #ifdef PLATFORM_APQ8084
213 #define SPKR_PROT_CALIB_TX_PCM_DEVICE 35
214 #else
215 #define SPKR_PROT_CALIB_TX_PCM_DEVICE 25
216 #endif
217 #define PLAYBACK_OFFLOAD_DEVICE 9
218 
219 #ifdef MULTIPLE_OFFLOAD_ENABLED
220 #ifdef PLATFORM_APQ8084
221 #define PLAYBACK_OFFLOAD_DEVICE2 17
222 #define PLAYBACK_OFFLOAD_DEVICE3 18
223 #define PLAYBACK_OFFLOAD_DEVICE4 34
224 #define PLAYBACK_OFFLOAD_DEVICE5 35
225 #define PLAYBACK_OFFLOAD_DEVICE6 36
226 #define PLAYBACK_OFFLOAD_DEVICE7 37
227 #define PLAYBACK_OFFLOAD_DEVICE8 38
228 #define PLAYBACK_OFFLOAD_DEVICE9 39
229 #endif
230 #ifdef PLATFORM_MSM8994
231 #define PLAYBACK_OFFLOAD_DEVICE2 17
232 #define PLAYBACK_OFFLOAD_DEVICE3 18
233 #define PLAYBACK_OFFLOAD_DEVICE4 37
234 #define PLAYBACK_OFFLOAD_DEVICE5 38
235 #define PLAYBACK_OFFLOAD_DEVICE6 39
236 #define PLAYBACK_OFFLOAD_DEVICE7 40
237 #define PLAYBACK_OFFLOAD_DEVICE8 41
238 #define PLAYBACK_OFFLOAD_DEVICE9 42
239 #endif
240 #endif
241 
242 #define COMPRESS_VOIP_CALL_PCM_DEVICE 3
243 
244 #ifdef PLATFORM_MSM8610
245 #define LOWLATENCY_PCM_DEVICE 12
246 #define EC_REF_RX "SEC_I2S_RX"
247 #else
248 #define LOWLATENCY_PCM_DEVICE 15
249 #define EC_REF_RX "SLIM_RX"
250 #endif
251 #ifdef PLATFORM_MSM8x26
252 #define COMPRESS_CAPTURE_DEVICE 20
253 #else
254 #define COMPRESS_CAPTURE_DEVICE 19
255 #endif
256 
257 #ifdef PLATFORM_MSM8x26
258 #define VOICE_CALL_PCM_DEVICE 2
259 #define VOICE2_CALL_PCM_DEVICE 14
260 #define VOLTE_CALL_PCM_DEVICE 17
261 #define QCHAT_CALL_PCM_DEVICE 18
262 #define VOWLAN_CALL_PCM_DEVICE 30
263 #elif PLATFORM_APQ8084
264 #define VOICE_CALL_PCM_DEVICE 20
265 #define VOICE2_CALL_PCM_DEVICE 25
266 #define VOLTE_CALL_PCM_DEVICE 21
267 #define QCHAT_CALL_PCM_DEVICE 33
268 #define VOWLAN_CALL_PCM_DEVICE -1
269 #elif PLATFORM_MSM8610
270 #define VOICE_CALL_PCM_DEVICE 2
271 #define VOICE2_CALL_PCM_DEVICE 13
272 #define VOLTE_CALL_PCM_DEVICE 15
273 #define QCHAT_CALL_PCM_DEVICE 14
274 #define VOWLAN_CALL_PCM_DEVICE -1
275 #elif PLATFORM_MSM8994
276 #define VOICE_CALL_PCM_DEVICE 2
277 #define VOICE2_CALL_PCM_DEVICE 22
278 #define VOLTE_CALL_PCM_DEVICE 14
279 #define QCHAT_CALL_PCM_DEVICE 20
280 #define VOWLAN_CALL_PCM_DEVICE 36
281 #else
282 #define VOICE_CALL_PCM_DEVICE 2
283 #define VOICE2_CALL_PCM_DEVICE 22
284 #define VOLTE_CALL_PCM_DEVICE 14
285 #define QCHAT_CALL_PCM_DEVICE 20
286 #define VOWLAN_CALL_PCM_DEVICE 36
287 #endif
288 
289 #define AFE_PROXY_PLAYBACK_PCM_DEVICE 7
290 #define AFE_PROXY_RECORD_PCM_DEVICE 8
291 
292 #ifdef PLATFORM_MSM8x26
293 #define HFP_SCO_RX 28
294 #define HFP_ASM_RX_TX 29
295 #else
296 #define HFP_SCO_RX 23
297 #define HFP_ASM_RX_TX 24
298 #endif
299 
300 #ifdef PLATFORM_APQ8084
301 #define FM_RX_VOLUME "Quat MI2S FM RX Volume"
302 #elif PLATFORM_MSM8994
303 #define FM_RX_VOLUME "PRI MI2S LOOPBACK Volume"
304 #else
305 #define FM_RX_VOLUME "Internal FM RX Volume"
306 #endif
307 
308 #define LIB_CSD_CLIENT "libcsd-client.so"
309 /* CSD-CLIENT related functions */
310 typedef int (*init_t)(bool);
311 typedef int (*deinit_t)();
312 typedef int (*disable_device_t)();
313 typedef int (*enable_device_config_t)(int, int);
314 typedef int (*enable_device_t)(int, int, uint32_t);
315 typedef int (*volume_t)(uint32_t, int, uint16_t);
316 typedef int (*mic_mute_t)(uint32_t, int, uint16_t);
317 typedef int (*slow_talk_t)(uint32_t, uint8_t);
318 typedef int (*start_voice_t)(uint32_t);
319 typedef int (*stop_voice_t)(uint32_t);
320 typedef int (*start_playback_t)(uint32_t);
321 typedef int (*stop_playback_t)(uint32_t);
322 typedef int (*set_lch_t)(uint32_t, enum voice_lch_mode);
323 typedef int (*start_record_t)(uint32_t, int);
324 typedef int (*stop_record_t)(uint32_t);
325 typedef int (*get_sample_rate_t)(uint32_t *);
326 /* CSD Client structure */
327 struct csd_data {
328     void *csd_client;
329     init_t init;
330     deinit_t deinit;
331     disable_device_t disable_device;
332     enable_device_config_t enable_device_config;
333     enable_device_t enable_device;
334     volume_t volume;
335     mic_mute_t mic_mute;
336     slow_talk_t slow_talk;
337     start_voice_t start_voice;
338     stop_voice_t stop_voice;
339     start_playback_t start_playback;
340     stop_playback_t stop_playback;
341     set_lch_t set_lch;
342     start_record_t start_record;
343     stop_record_t stop_record;
344     get_sample_rate_t get_sample_rate;
345 };
346 
347 /*
348  * ID for setting mute and lateny on the device side
349  * through Device PP Params mixer control.
350  */
351 #define DEVICE_PARAM_MUTE_ID    0
352 #define DEVICE_PARAM_LATENCY_ID 1
353 
354 #define ENUM_TO_STRING(X) #X
355 
356 struct audio_device_to_audio_interface {
357     audio_devices_t device;
358     char device_name[100];
359     char interface_name[100];
360 };
361 #endif // QCOM_AUDIO_PLATFORM_H
362