1 /*
2  *
3  * Copyright (C) 2013 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef QCOM_AUDIO_PLATFORM_H
19 #define QCOM_AUDIO_PLATFORM_H
20 
21 enum {
22     FLUENCE_NONE,
23     FLUENCE_DUAL_MIC = 0x1,
24     FLUENCE_QUAD_MIC = 0x2,
25 };
26 
27 enum {
28     FLUENCE_ENDFIRE = 0x1,
29     FLUENCE_BROADSIDE = 0x2,
30 };
31 
32 /*
33  * Below are the devices for which is back end is same, SLIMBUS_0_RX.
34  * All these devices are handled by the internal HW codec. We can
35  * enable any one of these devices at any time. An exception here is
36  * 44.1k headphone which uses different backend. This is filtered
37  * as different hal internal device in the code but remains same
38  * as standard android device AUDIO_DEVICE_OUT_WIRED_HEADPHONE
39  * for other layers.
40  */
41 #define AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND \
42     (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | \
43      AUDIO_DEVICE_OUT_WIRED_HEADSET | AUDIO_DEVICE_OUT_WIRED_HEADPHONE|\
44      AUDIO_DEVICE_OUT_LINE)
45 
46 /* Sound devices specific to the platform
47  * The DEVICE_OUT_* and DEVICE_IN_* should be mapped to these sound
48  * devices to enable corresponding mixer paths
49  */
50 enum {
51     SND_DEVICE_NONE = 0,
52 
53     /* Playback devices */
54     SND_DEVICE_MIN,
55     SND_DEVICE_OUT_BEGIN = SND_DEVICE_MIN,
56     SND_DEVICE_OUT_HANDSET = SND_DEVICE_OUT_BEGIN,
57     SND_DEVICE_OUT_SPEAKER,
58     SND_DEVICE_OUT_SPEAKER_REVERSE,
59     SND_DEVICE_OUT_LINE,
60     SND_DEVICE_OUT_HEADPHONES,
61     SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES,
62     SND_DEVICE_OUT_SPEAKER_AND_LINE,
63     SND_DEVICE_OUT_VOICE_HANDSET,
64     SND_DEVICE_OUT_VOICE_HAC_HANDSET,
65     SND_DEVICE_OUT_VOICE_SPEAKER,
66     SND_DEVICE_OUT_VOICE_SPEAKER_HFP,
67     SND_DEVICE_OUT_VOICE_HEADPHONES,
68     SND_DEVICE_OUT_VOICE_LINE,
69     SND_DEVICE_OUT_HDMI,
70     SND_DEVICE_OUT_SPEAKER_AND_HDMI,
71     SND_DEVICE_OUT_BT_SCO,
72     SND_DEVICE_OUT_BT_SCO_WB,
73     SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES,
74     SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES,
75     SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET,
76     SND_DEVICE_OUT_VOICE_TX,
77     SND_DEVICE_OUT_AFE_PROXY,
78     SND_DEVICE_OUT_USB_HEADSET,
79     SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET,
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_SPEAKER_MIC_HFP,
117     SND_DEVICE_IN_VOICE_HEADSET_MIC,
118     SND_DEVICE_IN_HDMI_MIC,
119     SND_DEVICE_IN_BT_SCO_MIC,
120     SND_DEVICE_IN_BT_SCO_MIC_NREC,
121     SND_DEVICE_IN_BT_SCO_MIC_WB,
122     SND_DEVICE_IN_BT_SCO_MIC_WB_NREC,
123     SND_DEVICE_IN_CAMCORDER_MIC,
124     SND_DEVICE_IN_VOICE_DMIC,
125     SND_DEVICE_IN_VOICE_SPEAKER_DMIC,
126     SND_DEVICE_IN_VOICE_SPEAKER_QMIC,
127     SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC,
128     SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC,
129     SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC,
130     SND_DEVICE_IN_VOICE_REC_MIC,
131     SND_DEVICE_IN_VOICE_REC_MIC_NS,
132     SND_DEVICE_IN_VOICE_REC_DMIC_STEREO,
133     SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE,
134     SND_DEVICE_IN_VOICE_RX,
135     SND_DEVICE_IN_USB_HEADSET_MIC,
136     SND_DEVICE_IN_CAPTURE_FM,
137     SND_DEVICE_IN_AANC_HANDSET_MIC,
138     SND_DEVICE_IN_QUAD_MIC,
139     SND_DEVICE_IN_HANDSET_STEREO_DMIC,
140     SND_DEVICE_IN_SPEAKER_STEREO_DMIC,
141     SND_DEVICE_IN_CAPTURE_VI_FEEDBACK,
142     SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE,
143     SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE,
144     SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE,
145     SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE,
146     SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE,
147     SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC,
148     SND_DEVICE_IN_HANDSET_QMIC,
149     SND_DEVICE_IN_SPEAKER_QMIC_AEC,
150     SND_DEVICE_IN_SPEAKER_QMIC_NS,
151     SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS,
152     SND_DEVICE_IN_END,
153 
154     SND_DEVICE_MAX = SND_DEVICE_IN_END,
155 
156 };
157 
158 #define DEFAULT_OUTPUT_SAMPLING_RATE 48000
159 
160 #define ALL_SESSION_VSID                0xFFFFFFFF
161 #define DEFAULT_MUTE_RAMP_DURATION_MS   20
162 #define DEFAULT_VOLUME_RAMP_DURATION_MS 20
163 #define MIXER_PATH_MAX_LENGTH 100
164 
165 #define MAX_VOL_INDEX 5
166 #define MIN_VOL_INDEX 0
167 #define percent_to_index(val, min, max) \
168             ((val) * ((max) - (min)) * 0.01 + (min) + .5)
169 
170 /*
171  * tinyAlsa library interprets period size as number of frames
172  * one frame = channel_count * sizeof (pcm sample)
173  * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes
174  * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes
175  * We should take care of returning proper size when AudioFlinger queries for
176  * the buffer size of an input/output stream
177  */
178 #define DEEP_BUFFER_OUTPUT_PERIOD_SIZE 1920
179 #define DEEP_BUFFER_OUTPUT_PERIOD_COUNT 2
180 #define LOW_LATENCY_OUTPUT_PERIOD_SIZE 240
181 #define LOW_LATENCY_OUTPUT_PERIOD_COUNT 2
182 
183 #define LOW_LATENCY_CAPTURE_SAMPLE_RATE 48000
184 #define LOW_LATENCY_CAPTURE_PERIOD_SIZE 240
185 #define LOW_LATENCY_CAPTURE_USE_CASE 1
186 
187 #define HDMI_MULTI_PERIOD_SIZE  336
188 #define HDMI_MULTI_PERIOD_COUNT 8
189 #define HDMI_MULTI_DEFAULT_CHANNEL_COUNT 6
190 #define HDMI_MULTI_PERIOD_BYTES (HDMI_MULTI_PERIOD_SIZE * HDMI_MULTI_DEFAULT_CHANNEL_COUNT * 2)
191 
192 #define AUDIO_CAPTURE_PERIOD_DURATION_MSEC 20
193 #define AUDIO_CAPTURE_PERIOD_COUNT 2
194 
195 #define LOW_LATENCY_CAPTURE_SAMPLE_RATE 48000
196 #define LOW_LATENCY_CAPTURE_PERIOD_SIZE 240
197 #define LOW_LATENCY_CAPTURE_USE_CASE 1
198 
199 #define DEVICE_NAME_MAX_SIZE 128
200 #define HW_INFO_ARRAY_MAX_SIZE 32
201 
202 #define DEEP_BUFFER_PCM_DEVICE 0
203 #define AUDIO_RECORD_PCM_DEVICE 0
204 #define MULTIMEDIA2_PCM_DEVICE 1
205 #define MULTIMEDIA3_PCM_DEVICE 4
206 #define FM_PLAYBACK_PCM_DEVICE 5
207 #define FM_CAPTURE_PCM_DEVICE  6
208 #define HFP_PCM_RX 5
209 #define HFP_SCO_RX 17
210 #define HFP_ASM_RX_TX 18
211 
212 #define INCALL_MUSIC_UPLINK_PCM_DEVICE 1
213 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 16
214 #define SPKR_PROT_CALIB_RX_PCM_DEVICE 5
215 #define SPKR_PROT_CALIB_TX_PCM_DEVICE 26
216 #define PLAYBACK_OFFLOAD_DEVICE 9
217 #define PLAYBACK_OFFLOAD_DEVICE2 24
218 
219 /* Define macro for Internal FM volume mixer */
220 #define FM_RX_VOLUME "Internal FM RX Volume"
221 
222 #define LOWLATENCY_PCM_DEVICE 12
223 #define EC_REF_RX "I2S_RX"
224 
225 #define VOICE_CALL_PCM_DEVICE 2
226 #define VOICE2_CALL_PCM_DEVICE 13
227 #define VOLTE_CALL_PCM_DEVICE 15
228 #define QCHAT_CALL_PCM_DEVICE 26
229 #define QCHAT_CALL_PCM_DEVICE_OF_EXT_CODEC 28
230 #define VOWLAN_CALL_PCM_DEVICE 16
231 
232 #define AFE_PROXY_PLAYBACK_PCM_DEVICE 7
233 #define AFE_PROXY_RECORD_PCM_DEVICE 8
234 
235 #define LIB_CSD_CLIENT "libcsd-client.so"
236 /* CSD-CLIENT related functions */
237 typedef int (*init_t)();
238 typedef int (*deinit_t)();
239 typedef int (*disable_device_t)();
240 typedef int (*enable_device_config_t)(int, int);
241 typedef int (*enable_device_t)(int, int, uint32_t);
242 typedef int (*volume_t)(uint32_t, int, uint16_t);
243 typedef int (*mic_mute_t)(uint32_t, int, uint16_t);
244 typedef int (*slow_talk_t)(uint32_t, uint8_t);
245 typedef int (*start_voice_t)(uint32_t);
246 typedef int (*stop_voice_t)(uint32_t);
247 typedef int (*start_playback_t)(uint32_t);
248 typedef int (*stop_playback_t)(uint32_t);
249 typedef int (*start_record_t)(uint32_t, int);
250 typedef int (*stop_record_t)(uint32_t);
251 /* CSD Client structure */
252 struct csd_data {
253     void *csd_client;
254     init_t init;
255     deinit_t deinit;
256     disable_device_t disable_device;
257     enable_device_config_t enable_device_config;
258     enable_device_t enable_device;
259     volume_t volume;
260     mic_mute_t mic_mute;
261     slow_talk_t slow_talk;
262     start_voice_t start_voice;
263     stop_voice_t stop_voice;
264     start_playback_t start_playback;
265     stop_playback_t stop_playback;
266     start_record_t start_record;
267     stop_record_t stop_record;
268 };
269 
270 #define PLATFORM_INFO_XML_PATH          "/system/etc/audio_platform_info.xml"
271 #define PLATFORM_INFO_XML_BASE_STRING   "/system/etc/audio_platform_info"
272 
273 #endif // QCOM_AUDIO_PLATFORM_H
274