blob: a068a826f29f37abfbb72ad75089d893e9848883 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002 * Copyright (C) 2013-2014 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
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#define LOG_TAG "msm8974_platform"
18/*#define LOG_NDEBUG 0*/
19#define LOG_NDDEBUG 0
20
21#include <stdlib.h>
22#include <dlfcn.h>
23#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070024#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070025#include <cutils/properties.h>
26#include <audio_hw.h>
27#include <platform_api.h>
28#include "platform.h"
29
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070030#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070031#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070032#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Eric Laurentb23d5282013-05-14 15:27:20 -070033
34#define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */
35#define DUALMIC_CONFIG_ENDFIRE 1
36#define DUALMIC_CONFIG_BROADSIDE 2
37
38/*
Eric Laurentb23d5282013-05-14 15:27:20 -070039 * This file will have a maximum of 38 bytes:
40 *
41 * 4 bytes: number of audio blocks
42 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
43 * Maximum 10 * 3 bytes: SAD blocks
44 */
45#define MAX_SAD_BLOCKS 10
46#define SAD_BLOCK_SIZE 3
47
48/* EDID format ID for LPCM audio */
49#define EDID_FORMAT_LPCM 1
50
sangwoo1b9f4b32013-06-21 18:22:55 -070051/* Retry for delay in FW loading*/
52#define RETRY_NUMBER 10
53#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070054#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070055
Eric Laurentb23d5282013-05-14 15:27:20 -070056struct audio_block_header
57{
58 int reserved;
59 int length;
60};
61
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070062/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -070063typedef void (*acdb_deallocate_t)();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070064#ifdef PLATFORM_MSM8084
65typedef int (*acdb_init_t)(char *);
66#else
Eric Laurentb23d5282013-05-14 15:27:20 -070067typedef int (*acdb_init_t)();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070068#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070069typedef void (*acdb_send_audio_cal_t)(int, int);
70typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070071typedef int (*acdb_reload_vocvoltable_t)(int);
Eric Laurentb23d5282013-05-14 15:27:20 -070072
73/* Audio calibration related functions */
74struct platform_data {
75 struct audio_device *adev;
76 bool fluence_in_spkr_mode;
77 bool fluence_in_voice_call;
78 bool fluence_in_voice_rec;
79 int dualmic_config;
Eric Laurentb23d5282013-05-14 15:27:20 -070080 void *acdb_handle;
81 acdb_init_t acdb_init;
82 acdb_deallocate_t acdb_deallocate;
83 acdb_send_audio_cal_t acdb_send_audio_cal;
84 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070085 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
86 struct csd_data *csd;
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -050087 bool ext_speaker;
88 bool ext_earpiece;
Eric Laurentb23d5282013-05-14 15:27:20 -070089};
90
Haynes Mathew George98c95622014-06-20 19:14:25 -070091static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070092 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
93 DEEP_BUFFER_PCM_DEVICE},
94 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
95 LOWLATENCY_PCM_DEVICE},
96 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
97 MULTIMEDIA2_PCM_DEVICE},
98 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
99 PLAYBACK_OFFLOAD_DEVICE},
100 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
101 AUDIO_RECORD_PCM_DEVICE},
102 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
103 LOWLATENCY_PCM_DEVICE},
104 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
105 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700106 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
107 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
108 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
109 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
110 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
111 AUDIO_RECORD_PCM_DEVICE},
112 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
113 AUDIO_RECORD_PCM_DEVICE},
114 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
115 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800116 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Eric Laurent8edfd662014-07-09 17:39:11 -0700117
118 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
119 AFE_PROXY_RECORD_PCM_DEVICE},
120 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
121 AFE_PROXY_RECORD_PCM_DEVICE},
122
Eric Laurentb23d5282013-05-14 15:27:20 -0700123};
124
125/* Array to store sound devices */
126static const char * const device_table[SND_DEVICE_MAX] = {
127 [SND_DEVICE_NONE] = "none",
128 /* Playback sound devices */
129 [SND_DEVICE_OUT_HANDSET] = "handset",
130 [SND_DEVICE_OUT_SPEAKER] = "speaker",
131 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
132 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500133 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700134 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
135 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500136 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700137 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
138 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500139 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700140 [SND_DEVICE_OUT_HDMI] = "hdmi",
141 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
142 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700143 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700144 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
145 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
146 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
147 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Eric Laurent8edfd662014-07-09 17:39:11 -0700148 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Eric Laurentb23d5282013-05-14 15:27:20 -0700149
150 /* Capture sound devices */
151 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
152 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
153 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
154 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Eric Laurent34fa7692014-03-07 09:31:06 -0800155 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic-aec",
Eric Laurentb23d5282013-05-14 15:27:20 -0700156 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
157 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
158 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
159 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
160 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700161 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700162 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
163 [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef",
164 [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs",
165 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus",
166 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef",
167 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs",
168 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
169 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
170 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
171 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
172 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef",
173 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs",
174 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence",
175 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence",
Eric Laurent8edfd662014-07-09 17:39:11 -0700176 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Eric Laurentb23d5282013-05-14 15:27:20 -0700177};
178
179/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700180static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700181 [SND_DEVICE_NONE] = -1,
182 [SND_DEVICE_OUT_HANDSET] = 7,
183 [SND_DEVICE_OUT_SPEAKER] = 15,
184 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
185 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500186 [SND_DEVICE_OUT_LINE] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700187 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -0500188#ifdef PLATFORM_MSM8084
189 [SND_DEVICE_OUT_VOICE_HANDSET] = 67,
190 [SND_DEVICE_OUT_VOICE_SPEAKER] = 66,
191#else
Eric Laurentb23d5282013-05-14 15:27:20 -0700192 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
193 [SND_DEVICE_OUT_VOICE_SPEAKER] = 15,
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -0500194#endif
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500195 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700196 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500197 [SND_DEVICE_OUT_VOICE_LINE] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700198 [SND_DEVICE_OUT_HDMI] = 18,
199 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
200 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700201 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700202 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700203 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
204 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
205 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Eric Laurent8edfd662014-07-09 17:39:11 -0700206 [SND_DEVICE_OUT_VOICE_TX] = 45,
Eric Laurentb23d5282013-05-14 15:27:20 -0700207
208 [SND_DEVICE_IN_HANDSET_MIC] = 4,
209 [SND_DEVICE_IN_SPEAKER_MIC] = 4, /* ToDo: Check if this needs to changed to 11 */
210 [SND_DEVICE_IN_HEADSET_MIC] = 8,
211 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40,
212 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42,
213 [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47,
214 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
215 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
216 [SND_DEVICE_IN_HDMI_MIC] = 4,
217 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700218 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700219 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
220 [SND_DEVICE_IN_VOICE_DMIC_EF] = 41,
221 [SND_DEVICE_IN_VOICE_DMIC_BS] = 5,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700222 [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700223 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 43,
224 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12,
225 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
226 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
227 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
228 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
229 /* TODO: Update with proper acdb ids */
230 [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62,
231 [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62,
232 [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6,
233 [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5,
Eric Laurent8edfd662014-07-09 17:39:11 -0700234 [SND_DEVICE_IN_VOICE_RX] = 44,
Eric Laurentb23d5282013-05-14 15:27:20 -0700235};
236
Haynes Mathew George98c95622014-06-20 19:14:25 -0700237struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700238 char name[100];
239 unsigned int index;
240};
241
242#define TO_NAME_INDEX(X) #X, X
243
Haynes Mathew George98c95622014-06-20 19:14:25 -0700244/* Used to get index from parsed string */
245static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
246 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700247 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
248 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
249 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
250 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500251 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700252 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
253 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
254 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
255 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500256 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700257 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
258 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
259 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
260 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700261 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500262 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700263 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
264 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
265 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700266
267 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700268 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700269 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700270 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700271 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
272 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
273 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700274 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
275 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
276 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
277 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
278 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
279 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700280 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_EF)},
281 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_BS)},
282 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_EF_TMUS)},
283 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF)},
284 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700285 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
286 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
287 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
288 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700289 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_EF)},
290 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_BS)},
291 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE)},
292 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE)},
293};
294
295static char * backend_table[SND_DEVICE_MAX] = {0};
296
297static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
298 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
299 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
300 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
301 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
302 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
303 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
304 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
305 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
306 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
307 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
308 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
309 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
310 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
311 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
312 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700313};
314
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700315#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
316#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
317
Eric Laurentb23d5282013-05-14 15:27:20 -0700318static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
319static bool is_tmus = false;
320
321static void check_operator()
322{
323 char value[PROPERTY_VALUE_MAX];
324 int mccmnc;
325 property_get("gsm.sim.operator.numeric",value,"0");
326 mccmnc = atoi(value);
327 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
328 switch(mccmnc) {
329 /* TMUS MCC(310), MNC(490, 260, 026) */
330 case 310490:
331 case 310260:
332 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900333 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
334 case 310800:
335 case 310660:
336 case 310580:
337 case 310310:
338 case 310270:
339 case 310250:
340 case 310240:
341 case 310230:
342 case 310220:
343 case 310210:
344 case 310200:
345 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700346 is_tmus = true;
347 break;
348 }
349}
350
351bool is_operator_tmus()
352{
353 pthread_once(&check_op_once_ctl, check_operator);
354 return is_tmus;
355}
356
357static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
358{
359 struct mixer_ctl *ctl;
360 const char *mixer_ctl_name = "EC_REF_RX";
361
362 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
363 if (!ctl) {
364 ALOGE("%s: Could not get ctl for mixer cmd - %s",
365 __func__, mixer_ctl_name);
366 return -EINVAL;
367 }
368 ALOGV("Setting EC Reference: %s", ec_ref);
369 mixer_ctl_set_enum_by_string(ctl, ec_ref);
370 return 0;
371}
372
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700373static struct csd_data *open_csd_client(bool i2s_ext_modem)
374{
375 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
376
377 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
378 if (csd->csd_client == NULL) {
379 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
380 goto error;
381 } else {
382 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
383
384 csd->deinit = (deinit_t)dlsym(csd->csd_client,
385 "csd_client_deinit");
386 if (csd->deinit == NULL) {
387 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
388 dlerror());
389 goto error;
390 }
391 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
392 "csd_client_disable_device");
393 if (csd->disable_device == NULL) {
394 ALOGE("%s: dlsym error %s for csd_client_disable_device",
395 __func__, dlerror());
396 goto error;
397 }
398 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
399 "csd_client_enable_device_config");
400 if (csd->enable_device_config == NULL) {
401 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
402 __func__, dlerror());
403 goto error;
404 }
405 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
406 "csd_client_enable_device");
407 if (csd->enable_device == NULL) {
408 ALOGE("%s: dlsym error %s for csd_client_enable_device",
409 __func__, dlerror());
410 goto error;
411 }
412 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
413 "csd_client_start_voice");
414 if (csd->start_voice == NULL) {
415 ALOGE("%s: dlsym error %s for csd_client_start_voice",
416 __func__, dlerror());
417 goto error;
418 }
419 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
420 "csd_client_stop_voice");
421 if (csd->stop_voice == NULL) {
422 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
423 __func__, dlerror());
424 goto error;
425 }
426 csd->volume = (volume_t)dlsym(csd->csd_client,
427 "csd_client_volume");
428 if (csd->volume == NULL) {
429 ALOGE("%s: dlsym error %s for csd_client_volume",
430 __func__, dlerror());
431 goto error;
432 }
433 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
434 "csd_client_mic_mute");
435 if (csd->mic_mute == NULL) {
436 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
437 __func__, dlerror());
438 goto error;
439 }
440 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
441 "csd_client_slow_talk");
442 if (csd->slow_talk == NULL) {
443 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
444 __func__, dlerror());
445 goto error;
446 }
447 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
448 "csd_client_start_playback");
449 if (csd->start_playback == NULL) {
450 ALOGE("%s: dlsym error %s for csd_client_start_playback",
451 __func__, dlerror());
452 goto error;
453 }
454 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
455 "csd_client_stop_playback");
456 if (csd->stop_playback == NULL) {
457 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
458 __func__, dlerror());
459 goto error;
460 }
461 csd->start_record = (start_record_t)dlsym(csd->csd_client,
462 "csd_client_start_record");
463 if (csd->start_record == NULL) {
464 ALOGE("%s: dlsym error %s for csd_client_start_record",
465 __func__, dlerror());
466 goto error;
467 }
468 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
469 "csd_client_stop_record");
470 if (csd->stop_record == NULL) {
471 ALOGE("%s: dlsym error %s for csd_client_stop_record",
472 __func__, dlerror());
473 goto error;
474 }
475
476 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
477 "csd_client_get_sample_rate");
478 if (csd->get_sample_rate == NULL) {
479 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
480 __func__, dlerror());
481
482 goto error;
483 }
484
485 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
486
487 if (csd->init == NULL) {
488 ALOGE("%s: dlsym error %s for csd_client_init",
489 __func__, dlerror());
490 goto error;
491 } else {
492 csd->init(i2s_ext_modem);
493 }
494 }
495 return csd;
496
497error:
498 free(csd);
499 csd = NULL;
500 return csd;
501}
502
503void close_csd_client(struct csd_data *csd)
504{
505 if (csd != NULL) {
506 csd->deinit();
507 dlclose(csd->csd_client);
508 free(csd);
509 csd = NULL;
510 }
511}
512
513static void platform_csd_init(struct platform_data *my_data)
514{
515#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700516 int32_t modems, (*count_modems)(void);
517 const char *name = "libdetectmodem.so";
518 const char *func = "count_modems";
519 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700520
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700521 my_data->csd = NULL;
522
523 void *lib = dlopen(name, RTLD_NOW);
524 error = dlerror();
525 if (!lib) {
526 ALOGE("%s: could not find %s: %s", __func__, name, error);
527 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700528 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700529
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700530 count_modems = NULL;
531 *(void **)(&count_modems) = dlsym(lib, func);
532 error = dlerror();
533 if (!count_modems) {
534 ALOGE("%s: could not find symbol %s in %s: %s",
535 __func__, func, name, error);
536 goto done;
537 }
538
539 modems = count_modems();
540 if (modems < 0) {
541 ALOGE("%s: count_modems failed\n", __func__);
542 goto done;
543 }
544
545 ALOGD("%s: num_modems %d\n", __func__, modems);
546 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700547 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700548
549done:
550 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700551#else
552 my_data->csd = NULL;
553#endif
554}
555
Haynes Mathew George98c95622014-06-20 19:14:25 -0700556static void set_platform_defaults(struct platform_data * my_data)
557{
558 int32_t dev;
559 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
560 backend_table[dev] = NULL;
561 }
562
563 // TBD - do these go to the platform-info.xml file.
564 // will help in avoiding strdups here
565 backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
566 backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
567 backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
568 backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
569 backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
570 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Eric Laurent8edfd662014-07-09 17:39:11 -0700571 backend_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
572 backend_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700573
574 if (my_data->ext_speaker) {
575 backend_table[SND_DEVICE_OUT_SPEAKER] = strdup("speaker");
576 backend_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("speaker");
577 backend_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("speaker");
578 backend_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] =
579 strdup("speaker-and-headphones");
580 }
581
582 if (my_data->ext_earpiece) {
583 backend_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("handset");
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500584 backend_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("handset");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700585 backend_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("handset");
586 backend_table[SND_DEVICE_OUT_HANDSET] = strdup("handset");
587 backend_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("handset");
588 }
589}
590
Eric Laurentb23d5282013-05-14 15:27:20 -0700591void *platform_init(struct audio_device *adev)
592{
593 char value[PROPERTY_VALUE_MAX];
594 struct platform_data *my_data;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700595 int retry_num = 0, snd_card_num = 0;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700596 const char *snd_card_name;
sangwoo1b9f4b32013-06-21 18:22:55 -0700597
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700598 while (snd_card_num < MAX_SND_CARD) {
599 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700600
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700601 while (!adev->mixer && retry_num < RETRY_NUMBER) {
602 usleep(RETRY_US);
603 adev->mixer = mixer_open(snd_card_num);
604 retry_num++;
605 }
606
607 if (!adev->mixer) {
608 ALOGE("%s: Unable to open the mixer card: %d", __func__,
609 snd_card_num);
610 retry_num = 0;
611 snd_card_num++;
612 continue;
613 }
614
615 snd_card_name = mixer_get_name(adev->mixer);
616 ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
617
618 adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH);
619 if (!adev->audio_route) {
620 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
621 return NULL;
622 }
623 adev->snd_card = snd_card_num;
624 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
625 break;
sangwoo1b9f4b32013-06-21 18:22:55 -0700626 }
627
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700628 if (snd_card_num >= MAX_SND_CARD) {
629 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
sangwoo1b9f4b32013-06-21 18:22:55 -0700630 return NULL;
631 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700632
633 my_data = calloc(1, sizeof(struct platform_data));
634
635 my_data->adev = adev;
636 my_data->dualmic_config = DUALMIC_CONFIG_NONE;
637 my_data->fluence_in_spkr_mode = false;
638 my_data->fluence_in_voice_call = false;
639 my_data->fluence_in_voice_rec = false;
640
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -0500641 /*
642 * The default assumption is that earpiece (handset), speaker and headphones
643 * devices are connected to internal HW codec and communicated through
644 * slimbus backend. If any platform communicates with speaker or earpiece
645 * or headphones through non-slimbus backend such as MI2S or AUXPCM etc.,
646 * the ext_xxxx flags must be set accordingly.
647 */
648 if (strstr(snd_card_name, "tfa9890_stereo")) {
649 my_data->ext_speaker = true;
650 my_data->ext_earpiece = true;
651 } else if (strstr(snd_card_name, "tfa9890")) {
652 my_data->ext_speaker = true;
653 }
654
Eric Laurentb23d5282013-05-14 15:27:20 -0700655 property_get("persist.audio.dualmic.config",value,"");
656 if (!strcmp("broadside", value)) {
657 my_data->dualmic_config = DUALMIC_CONFIG_BROADSIDE;
658 adev->acdb_settings |= DMIC_FLAG;
659 } else if (!strcmp("endfire", value)) {
660 my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
661 adev->acdb_settings |= DMIC_FLAG;
662 }
663
664 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
665 property_get("persist.audio.fluence.voicecall",value,"");
666 if (!strcmp("true", value)) {
667 my_data->fluence_in_voice_call = true;
668 }
669
670 property_get("persist.audio.fluence.voicerec",value,"");
671 if (!strcmp("true", value)) {
672 my_data->fluence_in_voice_rec = true;
673 }
674
675 property_get("persist.audio.fluence.speaker",value,"");
676 if (!strcmp("true", value)) {
677 my_data->fluence_in_spkr_mode = true;
678 }
679 }
680
681 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
682 if (my_data->acdb_handle == NULL) {
683 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
684 } else {
685 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
686 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
687 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700688 if (!my_data->acdb_deallocate)
689 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
690 __func__, LIB_ACDB_LOADER);
691
Eric Laurentb23d5282013-05-14 15:27:20 -0700692 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
693 "acdb_loader_send_audio_cal");
694 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700695 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -0700696 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700697
Eric Laurentb23d5282013-05-14 15:27:20 -0700698 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
699 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700700 if (!my_data->acdb_send_voice_cal)
701 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
702 __func__, LIB_ACDB_LOADER);
703
704 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
705 "acdb_loader_reload_vocvoltable");
706 if (!my_data->acdb_reload_vocvoltable)
707 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
708 __func__, LIB_ACDB_LOADER);
709#ifdef PLATFORM_MSM8084
710 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
711 "acdb_loader_init_v2");
712 if (my_data->acdb_init == NULL)
713 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
714 else
Haynes Mathew George98c95622014-06-20 19:14:25 -0700715 my_data->acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700716#else
Eric Laurentb23d5282013-05-14 15:27:20 -0700717 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
718 "acdb_loader_init_ACDB");
719 if (my_data->acdb_init == NULL)
720 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
721 else
722 my_data->acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700723#endif
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700724
Eric Laurentb23d5282013-05-14 15:27:20 -0700725 }
726
Haynes Mathew George98c95622014-06-20 19:14:25 -0700727 set_platform_defaults(my_data);
728
729 /* Initialize platform specific ids and/or backends*/
730 platform_info_init();
731
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700732 /* load csd client */
733 platform_csd_init(my_data);
734
Eric Laurentb23d5282013-05-14 15:27:20 -0700735 return my_data;
736}
737
738void platform_deinit(void *platform)
739{
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700740 struct platform_data *my_data = (struct platform_data *)platform;
741 close_csd_client(my_data->csd);
Eric Laurentb23d5282013-05-14 15:27:20 -0700742 free(platform);
743}
744
745const char *platform_get_snd_device_name(snd_device_t snd_device)
746{
747 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
748 return device_table[snd_device];
749 else
750 return "";
751}
752
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -0500753void platform_add_backend_name(void *platform, char *mixer_path,
754 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700755{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -0500756 struct platform_data *my_data = (struct platform_data *)platform;
757
Haynes Mathew George98c95622014-06-20 19:14:25 -0700758 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
759 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
760 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -0500761 }
Haynes Mathew George98c95622014-06-20 19:14:25 -0700762
763 const char * suffix = backend_table[snd_device];
764
765 if (suffix != NULL) {
766 strcat(mixer_path, " ");
767 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -0500768 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700769}
770
771int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
772{
773 int device_id;
774 if (device_type == PCM_PLAYBACK)
775 device_id = pcm_device_table[usecase][0];
776 else
777 device_id = pcm_device_table[usecase][1];
778 return device_id;
779}
780
Haynes Mathew George98c95622014-06-20 19:14:25 -0700781static int find_index(const struct name_to_index * table, int32_t len,
782 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700783{
784 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700785 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700786
Haynes Mathew George98c95622014-06-20 19:14:25 -0700787 if (table == NULL) {
788 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700789 ret = -ENODEV;
790 goto done;
791 }
792
Haynes Mathew George98c95622014-06-20 19:14:25 -0700793 if (name == NULL) {
794 ALOGE("null key");
795 ret = -ENODEV;
796 goto done;
797 }
798
799 for (i=0; i < len; i++) {
800 if (!strcmp(table[i].name, name)) {
801 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700802 goto done;
803 }
804 }
Haynes Mathew George98c95622014-06-20 19:14:25 -0700805 ALOGE("%s: Could not find index for name = %s",
806 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700807 ret = -ENODEV;
808done:
809 return ret;
810}
811
Haynes Mathew George98c95622014-06-20 19:14:25 -0700812int platform_get_snd_device_index(char *device_name)
813{
814 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
815}
816
817int platform_get_usecase_index(const char *usecase_name)
818{
819 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
820}
821
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700822int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
823{
824 int ret = 0;
825
826 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
827 ALOGE("%s: Invalid snd_device = %d",
828 __func__, snd_device);
829 ret = -EINVAL;
830 goto done;
831 }
832
833 acdb_device_table[snd_device] = acdb_id;
834done:
835 return ret;
836}
837
Eric Laurentb23d5282013-05-14 15:27:20 -0700838int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
839{
840 struct platform_data *my_data = (struct platform_data *)platform;
841 int acdb_dev_id, acdb_dev_type;
842
843 acdb_dev_id = acdb_device_table[snd_device];
844 if (acdb_dev_id < 0) {
845 ALOGE("%s: Could not find acdb id for device(%d)",
846 __func__, snd_device);
847 return -EINVAL;
848 }
849 if (my_data->acdb_send_audio_cal) {
Eric Laurent994a6932013-07-17 11:51:42 -0700850 ("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -0700851 __func__, snd_device, acdb_dev_id);
852 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
853 snd_device < SND_DEVICE_OUT_END)
854 acdb_dev_type = ACDB_DEV_TYPE_OUT;
855 else
856 acdb_dev_type = ACDB_DEV_TYPE_IN;
857 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
858 }
859 return 0;
860}
861
862int platform_switch_voice_call_device_pre(void *platform)
863{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700864 struct platform_data *my_data = (struct platform_data *)platform;
865 int ret = 0;
866
867 if (my_data->csd != NULL &&
868 my_data->adev->mode == AUDIO_MODE_IN_CALL) {
869 /* This must be called before disabling mixer controls on APQ side */
870 ret = my_data->csd->disable_device();
871 if (ret < 0) {
872 ALOGE("%s: csd_client_disable_device, failed, error %d",
873 __func__, ret);
874 }
875 }
876 return ret;
877}
878
879int platform_switch_voice_call_enable_device_config(void *platform,
880 snd_device_t out_snd_device,
881 snd_device_t in_snd_device)
882{
883 struct platform_data *my_data = (struct platform_data *)platform;
884 int acdb_rx_id, acdb_tx_id;
885 int ret = 0;
886
887 if (my_data->csd == NULL)
888 return ret;
889
890 acdb_rx_id = acdb_device_table[out_snd_device];
891
892 acdb_tx_id = acdb_device_table[in_snd_device];
893
894 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
895 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
896 if (ret < 0) {
897 ALOGE("%s: csd_enable_device_config, failed, error %d",
898 __func__, ret);
899 }
900 } else {
901 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
902 acdb_rx_id, acdb_tx_id);
903 }
904
905 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -0700906}
907
908int platform_switch_voice_call_device_post(void *platform,
909 snd_device_t out_snd_device,
910 snd_device_t in_snd_device)
911{
912 struct platform_data *my_data = (struct platform_data *)platform;
913 int acdb_rx_id, acdb_tx_id;
914
915 if (my_data->acdb_send_voice_cal == NULL) {
916 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
917 } else {
918 acdb_rx_id = acdb_device_table[out_snd_device];
919 acdb_tx_id = acdb_device_table[in_snd_device];
920
921 if (acdb_rx_id > 0 && acdb_tx_id > 0)
922 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
923 else
924 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
925 acdb_rx_id, acdb_tx_id);
926 }
927
928 return 0;
929}
930
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700931int platform_switch_voice_call_usecase_route_post(void *platform,
932 snd_device_t out_snd_device,
933 snd_device_t in_snd_device)
934{
935 struct platform_data *my_data = (struct platform_data *)platform;
936 int acdb_rx_id, acdb_tx_id;
937 int ret = 0;
938
939 if (my_data->csd == NULL)
940 return ret;
941
942 acdb_rx_id = acdb_device_table[out_snd_device];
943
944 acdb_tx_id = acdb_device_table[in_snd_device];
945
946 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
947 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
948 my_data->adev->acdb_settings);
949 if (ret < 0) {
950 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
951 }
952 } else {
953 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
954 acdb_rx_id, acdb_tx_id);
955 }
956
957 return ret;
958}
959
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700960int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -0700961{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700962 struct platform_data *my_data = (struct platform_data *)platform;
963 int ret = 0;
964
965 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700966 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700967 if (ret < 0) {
968 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
969 }
970 }
971 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -0700972}
973
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700974int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -0700975{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700976 struct platform_data *my_data = (struct platform_data *)platform;
977 int ret = 0;
978
979 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700980 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700981 if (ret < 0) {
982 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
983 }
984 }
985 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -0700986}
987
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700988int platform_get_sample_rate(void *platform, uint32_t *rate)
989{
990 struct platform_data *my_data = (struct platform_data *)platform;
991 int ret = 0;
992
993 if (my_data->csd != NULL) {
994 ret = my_data->csd->get_sample_rate(rate);
995 if (ret < 0) {
996 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
997 }
998 }
999 return ret;
1000}
1001
Eric Laurentb23d5282013-05-14 15:27:20 -07001002int platform_set_voice_volume(void *platform, int volume)
1003{
1004 struct platform_data *my_data = (struct platform_data *)platform;
1005 struct audio_device *adev = my_data->adev;
1006 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001007 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001008 int vol_index = 0, ret = 0;
1009 uint32_t set_values[ ] = {0,
1010 ALL_SESSION_VSID,
1011 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001012
1013 // Voice volume levels are mapped to adsp volume levels as follows.
1014 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1015 // But this values don't changed in kernel. So, below change is need.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001016 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1017 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001018
1019 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1020 if (!ctl) {
1021 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1022 __func__, mixer_ctl_name);
1023 return -EINVAL;
1024 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001025 ALOGV("Setting voice volume index: %d", set_values[0]);
1026 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1027
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001028 if (my_data->csd != NULL) {
1029 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1030 DEFAULT_VOLUME_RAMP_DURATION_MS);
1031 if (ret < 0) {
1032 ALOGE("%s: csd_volume error %d", __func__, ret);
1033 }
1034 }
1035 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001036}
1037
1038int platform_set_mic_mute(void *platform, bool state)
1039{
1040 struct platform_data *my_data = (struct platform_data *)platform;
1041 struct audio_device *adev = my_data->adev;
1042 struct mixer_ctl *ctl;
1043 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001044 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001045 uint32_t set_values[ ] = {0,
1046 ALL_SESSION_VSID,
1047 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001048
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001049 if (adev->mode != AUDIO_MODE_IN_CALL)
1050 return 0;
1051
1052 set_values[0] = state;
1053 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1054 if (!ctl) {
1055 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1056 __func__, mixer_ctl_name);
1057 return -EINVAL;
1058 }
1059 ALOGV("Setting voice mute state: %d", state);
1060 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1061
1062 if (my_data->csd != NULL) {
1063 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1064 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001065 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001066 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001067 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001068 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001069 return ret;
1070}
Eric Laurentb23d5282013-05-14 15:27:20 -07001071
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001072int platform_set_device_mute(void *platform, bool state, char *dir)
1073{
1074 struct platform_data *my_data = (struct platform_data *)platform;
1075 struct audio_device *adev = my_data->adev;
1076 struct mixer_ctl *ctl;
1077 char *mixer_ctl_name = NULL;
1078 int ret = 0;
1079 uint32_t set_values[ ] = {0,
1080 ALL_SESSION_VSID,
1081 0};
1082 if(dir == NULL) {
1083 ALOGE("%s: Invalid direction:%s", __func__, dir);
1084 return -EINVAL;
1085 }
1086
1087 if (!strncmp("rx", dir, sizeof("rx"))) {
1088 mixer_ctl_name = "Voice Rx Device Mute";
1089 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1090 mixer_ctl_name = "Voice Tx Device Mute";
1091 } else {
1092 return -EINVAL;
1093 }
1094
1095 set_values[0] = state;
1096 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1097 if (!ctl) {
1098 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1099 __func__, mixer_ctl_name);
1100 return -EINVAL;
1101 }
1102
1103 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1104 __func__,state, mixer_ctl_name);
1105 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1106
1107 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001108}
1109
1110snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1111{
1112 struct platform_data *my_data = (struct platform_data *)platform;
1113 struct audio_device *adev = my_data->adev;
1114 audio_mode_t mode = adev->mode;
1115 snd_device_t snd_device = SND_DEVICE_NONE;
1116
1117 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1118 if (devices == AUDIO_DEVICE_NONE ||
1119 devices & AUDIO_DEVICE_BIT_IN) {
1120 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1121 goto exit;
1122 }
1123
1124 if (mode == AUDIO_MODE_IN_CALL) {
1125 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001126 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1127 devices & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001128 if (adev->voice.tty_mode == TTY_MODE_FULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001129 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001130 else if (adev->voice.tty_mode == TTY_MODE_VCO)
Eric Laurentb23d5282013-05-14 15:27:20 -07001131 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001132 else if (adev->voice.tty_mode == TTY_MODE_HCO)
Eric Laurentb23d5282013-05-14 15:27:20 -07001133 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001134 else {
1135 if (devices & AUDIO_DEVICE_OUT_LINE)
1136 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1137 else
1138 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1139 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001140 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001141 if (adev->bt_wb_speech_enabled) {
1142 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1143 } else {
1144 snd_device = SND_DEVICE_OUT_BT_SCO;
1145 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001146 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1147 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1148 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001149 if(adev->voice.hac)
1150 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1151 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001152 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1153 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001154 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Eric Laurent8edfd662014-07-09 17:39:11 -07001155 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1156 snd_device = SND_DEVICE_OUT_VOICE_TX;
1157
Eric Laurentb23d5282013-05-14 15:27:20 -07001158 if (snd_device != SND_DEVICE_NONE) {
1159 goto exit;
1160 }
1161 }
1162
1163 if (popcount(devices) == 2) {
1164 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1165 AUDIO_DEVICE_OUT_SPEAKER)) {
1166 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1167 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1168 AUDIO_DEVICE_OUT_SPEAKER)) {
1169 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1170 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1171 AUDIO_DEVICE_OUT_SPEAKER)) {
1172 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1173 } else {
1174 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1175 goto exit;
1176 }
1177 if (snd_device != SND_DEVICE_NONE) {
1178 goto exit;
1179 }
1180 }
1181
1182 if (popcount(devices) != 1) {
1183 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1184 goto exit;
1185 }
1186
1187 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1188 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1189 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001190 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1191 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001192 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
1193 if (adev->speaker_lr_swap)
1194 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1195 else
1196 snd_device = SND_DEVICE_OUT_SPEAKER;
1197 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001198 if (adev->bt_wb_speech_enabled) {
1199 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1200 } else {
1201 snd_device = SND_DEVICE_OUT_BT_SCO;
1202 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001203 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1204 snd_device = SND_DEVICE_OUT_HDMI ;
1205 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001206 /*HAC support for voice-ish audio (eg visual voicemail)*/
1207 if(adev->voice.hac)
1208 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1209 else
1210 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001211 } else {
1212 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1213 }
1214exit:
1215 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1216 return snd_device;
1217}
1218
1219snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1220{
1221 struct platform_data *my_data = (struct platform_data *)platform;
1222 struct audio_device *adev = my_data->adev;
1223 audio_source_t source = (adev->active_input == NULL) ?
1224 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1225
1226 audio_mode_t mode = adev->mode;
1227 audio_devices_t in_device = ((adev->active_input == NULL) ?
1228 AUDIO_DEVICE_NONE : adev->active_input->device)
1229 & ~AUDIO_DEVICE_BIT_IN;
1230 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1231 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1232 snd_device_t snd_device = SND_DEVICE_NONE;
1233
1234 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1235 __func__, out_device, in_device);
1236 if (mode == AUDIO_MODE_IN_CALL) {
1237 if (out_device == AUDIO_DEVICE_NONE) {
1238 ALOGE("%s: No output device set for voice call", __func__);
1239 goto exit;
1240 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001241 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001242 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001243 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1244 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001245 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001246 case TTY_MODE_FULL:
1247 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1248 break;
1249 case TTY_MODE_VCO:
1250 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1251 break;
1252 case TTY_MODE_HCO:
1253 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1254 break;
1255 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001256 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001257 }
1258 goto exit;
1259 }
1260 }
1261 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
1262 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
1263 if (my_data->fluence_in_voice_call == false) {
1264 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -08001265 set_echo_reference(adev->mixer, "SLIM_RX");
Eric Laurentb23d5282013-05-14 15:27:20 -07001266 } else {
1267 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
1268 if (is_operator_tmus())
1269 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS;
1270 else
1271 snd_device = SND_DEVICE_IN_VOICE_DMIC_EF;
1272 } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE)
1273 snd_device = SND_DEVICE_IN_VOICE_DMIC_BS;
1274 else
1275 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1276 }
1277 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1278 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1279 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001280 if (adev->bt_wb_speech_enabled) {
1281 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1282 } else {
1283 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1284 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001285 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
1286 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
1287 my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
1288 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF;
1289 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
1290 my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
1291 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS;
1292 } else {
1293 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1294 }
Eric Laurent8edfd662014-07-09 17:39:11 -07001295 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1296 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurentb23d5282013-05-14 15:27:20 -07001297 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1298 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1299 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1300 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1301 }
1302 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1303 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1304 if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) {
1305 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
1306 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF;
1307 else if (my_data->fluence_in_voice_rec)
1308 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE;
1309 } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) {
1310 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
1311 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS;
1312 else if (my_data->fluence_in_voice_rec)
1313 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE;
1314 }
1315
1316 if (snd_device == SND_DEVICE_NONE) {
1317 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
1318 }
1319 }
1320 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
1321 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
1322 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1323 if (adev->active_input) {
1324 if (adev->active_input->enable_aec) {
1325 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1326 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1327 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1328 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
1329 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1330 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
1331 }
1332 set_echo_reference(adev->mixer, "SLIM_RX");
1333 } else
1334 set_echo_reference(adev->mixer, "NONE");
1335 }
1336 } else if (source == AUDIO_SOURCE_DEFAULT) {
1337 goto exit;
1338 }
1339
1340
1341 if (snd_device != SND_DEVICE_NONE) {
1342 goto exit;
1343 }
1344
1345 if (in_device != AUDIO_DEVICE_NONE &&
1346 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1347 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1348 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1349 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1350 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1351 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
1352 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1353 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1354 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001355 if (adev->bt_wb_speech_enabled) {
1356 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1357 } else {
1358 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1359 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001360 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1361 snd_device = SND_DEVICE_IN_HDMI_MIC;
1362 } else {
1363 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1364 ALOGW("%s: Using default handset-mic", __func__);
1365 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1366 }
1367 } else {
1368 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1369 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1370 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1371 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1372 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
1373 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001374 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1375 out_device & AUDIO_DEVICE_OUT_LINE) {
1376 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001377 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001378 if (adev->bt_wb_speech_enabled) {
1379 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
1380 } else {
1381 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
1382 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001383 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1384 snd_device = SND_DEVICE_IN_HDMI_MIC;
1385 } else {
1386 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1387 ALOGW("%s: Using default handset-mic", __func__);
1388 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1389 }
1390 }
1391exit:
1392 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1393 return snd_device;
1394}
1395
1396int platform_set_hdmi_channels(void *platform, int channel_count)
1397{
1398 struct platform_data *my_data = (struct platform_data *)platform;
1399 struct audio_device *adev = my_data->adev;
1400 struct mixer_ctl *ctl;
1401 const char *channel_cnt_str = NULL;
1402 const char *mixer_ctl_name = "HDMI_RX Channels";
1403 switch (channel_count) {
1404 case 8:
1405 channel_cnt_str = "Eight"; break;
1406 case 7:
1407 channel_cnt_str = "Seven"; break;
1408 case 6:
1409 channel_cnt_str = "Six"; break;
1410 case 5:
1411 channel_cnt_str = "Five"; break;
1412 case 4:
1413 channel_cnt_str = "Four"; break;
1414 case 3:
1415 channel_cnt_str = "Three"; break;
1416 default:
1417 channel_cnt_str = "Two"; break;
1418 }
1419 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1420 if (!ctl) {
1421 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1422 __func__, mixer_ctl_name);
1423 return -EINVAL;
1424 }
1425 ALOGV("HDMI channel count: %s", channel_cnt_str);
1426 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
1427 return 0;
1428}
1429
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001430int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07001431{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001432 struct platform_data *my_data = (struct platform_data *)platform;
1433 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07001434 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
1435 char *sad = block;
1436 int num_audio_blocks;
1437 int channel_count;
1438 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001439 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07001440
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001441 struct mixer_ctl *ctl;
1442
1443 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
1444 if (!ctl) {
1445 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1446 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07001447 return 0;
1448 }
1449
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001450 mixer_ctl_update(ctl);
1451
1452 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07001453
1454 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001455 if (count > (int)sizeof(block))
1456 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07001457
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001458 ret = mixer_ctl_get_array(ctl, block, count);
1459 if (ret != 0) {
1460 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
1461 return 0;
1462 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001463
1464 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001465 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001466
1467 for (i = 0; i < num_audio_blocks; i++) {
1468 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001469 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
1470 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07001471 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07001472 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001473
1474 channel_count = (sad[0] & 0x7) + 1;
1475 if (channel_count > max_channels)
1476 max_channels = channel_count;
1477
1478 /* Advance to next block */
1479 sad += 3;
1480 }
1481
1482 return max_channels;
1483}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001484
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001485int platform_set_incall_recording_session_id(void *platform,
1486 uint32_t session_id, int rec_mode)
1487{
1488 int ret = 0;
1489 struct platform_data *my_data = (struct platform_data *)platform;
1490 struct audio_device *adev = my_data->adev;
1491 struct mixer_ctl *ctl;
1492 const char *mixer_ctl_name = "Voc VSID";
1493 int num_ctl_values;
1494 int i;
1495
1496 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1497 if (!ctl) {
1498 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1499 __func__, mixer_ctl_name);
1500 ret = -EINVAL;
1501 } else {
1502 num_ctl_values = mixer_ctl_get_num_values(ctl);
1503 for (i = 0; i < num_ctl_values; i++) {
1504 if (mixer_ctl_set_value(ctl, i, session_id)) {
1505 ALOGV("Error: invalid session_id: %x", session_id);
1506 ret = -EINVAL;
1507 break;
1508 }
1509 }
1510 }
1511
1512 if (my_data->csd != NULL) {
1513 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
1514 if (ret < 0) {
1515 ALOGE("%s: csd_client_start_record failed, error %d",
1516 __func__, ret);
1517 }
1518 }
1519
1520 return ret;
1521}
1522
1523int platform_stop_incall_recording_usecase(void *platform)
1524{
1525 int ret = 0;
1526 struct platform_data *my_data = (struct platform_data *)platform;
1527
1528 if (my_data->csd != NULL) {
1529 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
1530 if (ret < 0) {
1531 ALOGE("%s: csd_client_stop_record failed, error %d",
1532 __func__, ret);
1533 }
1534 }
1535
1536 return ret;
1537}
1538
1539int platform_start_incall_music_usecase(void *platform)
1540{
1541 int ret = 0;
1542 struct platform_data *my_data = (struct platform_data *)platform;
1543
1544 if (my_data->csd != NULL) {
1545 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
1546 if (ret < 0) {
1547 ALOGE("%s: csd_client_start_playback failed, error %d",
1548 __func__, ret);
1549 }
1550 }
1551
1552 return ret;
1553}
1554
1555int platform_stop_incall_music_usecase(void *platform)
1556{
1557 int ret = 0;
1558 struct platform_data *my_data = (struct platform_data *)platform;
1559
1560 if (my_data->csd != NULL) {
1561 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
1562 if (ret < 0) {
1563 ALOGE("%s: csd_client_stop_playback failed, error %d",
1564 __func__, ret);
1565 }
1566 }
1567
1568 return ret;
1569}
1570
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07001571/* Delay in Us */
1572int64_t platform_render_latency(audio_usecase_t usecase)
1573{
1574 switch (usecase) {
1575 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
1576 return DEEP_BUFFER_PLATFORM_DELAY;
1577 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
1578 return LOW_LATENCY_PLATFORM_DELAY;
1579 default:
1580 return 0;
1581 }
1582}
Haynes Mathew George98c95622014-06-20 19:14:25 -07001583
1584int platform_set_snd_device_backend(snd_device_t device, const char *backend)
1585{
1586 int ret = 0;
1587
1588 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
1589 ALOGE("%s: Invalid snd_device = %d",
1590 __func__, device);
1591 ret = -EINVAL;
1592 goto done;
1593 }
1594
1595 if (backend_table[device]) {
1596 free(backend_table[device]);
1597 }
1598 backend_table[device] = strdup(backend);
1599done:
1600 return ret;
1601}
1602
1603int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
1604{
1605 int ret = 0;
1606 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
1607 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
1608 ret = -EINVAL;
1609 goto done;
1610 }
1611
1612 if ((type != 0) && (type != 1)) {
1613 ALOGE("%s: invalid usecase type", __func__);
1614 ret = -EINVAL;
1615 }
1616 pcm_device_table[usecase][type] = pcm_id;
1617done:
1618 return ret;
1619}