blob: 3f18b50c9dbf040aee943c709e90dcf7f3870584 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa51fd402016-02-04 19:49:33 -08002 * Copyright (C) 2013-2016 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 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
22#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070023#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/properties.h>
25#include <audio_hw.h>
26#include <platform_api.h>
27#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070028#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070029#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070030
vivek mehta60ea4152016-02-18 17:10:26 -080031#define MIXER_XML_DEFAULT_PATH "/system/etc/mixer_paths.xml"
32#define MIXER_XML_BASE_STRING "/system/etc/mixer_paths"
33#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
34#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
35
Eric Laurentb23d5282013-05-14 15:27:20 -070036#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070037#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090038#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070039
Eric Laurentb23d5282013-05-14 15:27:20 -070040
41/*
Eric Laurentb23d5282013-05-14 15:27:20 -070042 * This file will have a maximum of 38 bytes:
43 *
44 * 4 bytes: number of audio blocks
45 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
46 * Maximum 10 * 3 bytes: SAD blocks
47 */
48#define MAX_SAD_BLOCKS 10
49#define SAD_BLOCK_SIZE 3
50
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090051#define MAX_CVD_VERSION_STRING_SIZE 100
52
Eric Laurentb23d5282013-05-14 15:27:20 -070053/* EDID format ID for LPCM audio */
54#define EDID_FORMAT_LPCM 1
55
sangwoo1b9f4b32013-06-21 18:22:55 -070056/* Retry for delay in FW loading*/
57#define RETRY_NUMBER 10
58#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070059#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070060
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070061#define MAX_SND_CARD_NAME_LEN 31
62
vivek mehta1a9b7c02015-06-25 11:49:38 -070063#define DEFAULT_APP_TYPE_RX_PATH 0x11130
64
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090065#define TOSTRING_(x) #x
66#define TOSTRING(x) TOSTRING_(x)
67
Eric Laurentb23d5282013-05-14 15:27:20 -070068struct audio_block_header
69{
70 int reserved;
71 int length;
72};
73
vivek mehta1a9b7c02015-06-25 11:49:38 -070074enum {
75 CAL_MODE_SEND = 0x1,
76 CAL_MODE_PERSIST = 0x2,
77 CAL_MODE_RTAC = 0x4
78};
79
keunhui.park2f7306a2015-07-16 16:48:06 +090080#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
81
82struct operator_info {
83 struct listnode list;
84 char *name;
85 char *mccmnc;
86};
87
88struct operator_specific_device {
89 struct listnode list;
90 char *operator;
91 char *mixer_path;
92 int acdb_id;
93};
94
95static struct listnode operator_info_list;
96static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
97
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070098/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -070099typedef void (*acdb_deallocate_t)();
vivek mehtac698f132016-02-25 18:50:35 -0800100typedef int (*acdb_init_v2_cvd_t)(char *, char *, int);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900101typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -0700102typedef int (*acdb_init_t)();
103typedef void (*acdb_send_audio_cal_t)(int, int);
104typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700105typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700106typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700107
108/* Audio calibration related functions */
109struct platform_data {
110 struct audio_device *adev;
111 bool fluence_in_spkr_mode;
112 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700113 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700114 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700115 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
116 int fluence_type;
117 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700118 bool speaker_lr_swap;
119
Eric Laurentb23d5282013-05-14 15:27:20 -0700120 void *acdb_handle;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700121 acdb_deallocate_t acdb_deallocate;
122 acdb_send_audio_cal_t acdb_send_audio_cal;
123 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700124 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700125 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700126 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800127 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700128
129 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900130 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700131 int max_mic_count;
Eric Laurentb23d5282013-05-14 15:27:20 -0700132};
133
Haynes Mathew George98c95622014-06-20 19:14:25 -0700134static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700135 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
136 DEEP_BUFFER_PCM_DEVICE},
137 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
138 LOWLATENCY_PCM_DEVICE},
139 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
140 MULTIMEDIA2_PCM_DEVICE},
141 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
142 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700143 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
144 MULTIMEDIA2_PCM_DEVICE},
145 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
146 MULTIMEDIA3_PCM_DEVICE},
147
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700148 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
149 AUDIO_RECORD_PCM_DEVICE},
150 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
151 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700152
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700153 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
154 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700155 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
156 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
157 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
158 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800159 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
160 VOICEMMODE1_CALL_PCM_DEVICE},
161 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
162 VOICEMMODE2_CALL_PCM_DEVICE},
163
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700164 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
165 AUDIO_RECORD_PCM_DEVICE},
166 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
167 AUDIO_RECORD_PCM_DEVICE},
168 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
169 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800170 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700171
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700172 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
173 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
174
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700175 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
176 AFE_PROXY_RECORD_PCM_DEVICE},
177 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
178 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800179 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700180
Eric Laurentb23d5282013-05-14 15:27:20 -0700181};
182
183/* Array to store sound devices */
184static const char * const device_table[SND_DEVICE_MAX] = {
185 [SND_DEVICE_NONE] = "none",
186 /* Playback sound devices */
187 [SND_DEVICE_OUT_HANDSET] = "handset",
188 [SND_DEVICE_OUT_SPEAKER] = "speaker",
189 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700190 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700191 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500192 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700193 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700194 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500195 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700196 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700197 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500198 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700199 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
200 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500201 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700202 [SND_DEVICE_OUT_HDMI] = "hdmi",
203 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
204 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700205 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700206 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
207 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
208 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
209 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700210 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700211 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
212 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700213 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700214
215 /* Capture sound devices */
216 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700218 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
219 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
220 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
221 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
222 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
223 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
224 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
225
226 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
227 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
228 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
229 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
230 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
231 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
232 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
233 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
234 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
235
236 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500237 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700238
Eric Laurentb23d5282013-05-14 15:27:20 -0700239 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
240 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700241 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700242 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700243 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700244 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700245
246 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
247 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
248 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
249 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700250 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700251 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700252 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
253 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
254 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700255
Eric Laurentb23d5282013-05-14 15:27:20 -0700256 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700257 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
258 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
259 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700260 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700261
rago90fb9612015-12-02 11:37:53 -0800262 [SND_DEVICE_IN_UNPROCESSED_MIC] = "voice-rec-mic",
263 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
264
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700265 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700266
Prashant Malanic92c5962015-08-11 15:10:18 -0700267 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
268 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700269 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700270 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
271 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700272};
273
274/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700275static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_NONE] = -1,
277 [SND_DEVICE_OUT_HANDSET] = 7,
278 [SND_DEVICE_OUT_SPEAKER] = 15,
279 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700280 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700281 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500282 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700283 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700284 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500285 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700286 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700287 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
288 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500289 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700290 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500291 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700292 [SND_DEVICE_OUT_HDMI] = 18,
293 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
294 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700295 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700296 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700297 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
298 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
299 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700300 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700301 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
302 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700303 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700304
305 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700306 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
307 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
308 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
309 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
310 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
311 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
312 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
313 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
314
315 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
316 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
317 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
318 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
319 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
320 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
321 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
322 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
323 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
324
rago90fb9612015-12-02 11:37:53 -0800325 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500326 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700327
Eric Laurentb23d5282013-05-14 15:27:20 -0700328 [SND_DEVICE_IN_HDMI_MIC] = 4,
329 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700330 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700331 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700332 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700333 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700334
335 [SND_DEVICE_IN_VOICE_DMIC] = 41,
336 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
337 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700338 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700339 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800340 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700341 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
342 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
343 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700344
rago90fb9612015-12-02 11:37:53 -0800345 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700346 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
347 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
348 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800349 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
350
351 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
352 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700353
354 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700355
Prashant Malanic92c5962015-08-11 15:10:18 -0700356 [SND_DEVICE_IN_THREE_MIC] = 46,
357 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700358 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700359 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
360 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
Eric Laurentb23d5282013-05-14 15:27:20 -0700361};
362
Haynes Mathew George98c95622014-06-20 19:14:25 -0700363struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700364 char name[100];
365 unsigned int index;
366};
367
368#define TO_NAME_INDEX(X) #X, X
369
Haynes Mathew George98c95622014-06-20 19:14:25 -0700370/* Used to get index from parsed string */
371static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
372 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700373 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
374 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
375 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700376 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700377 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500378 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700379 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700380 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500381 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700382 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700383 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
384 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700385 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700386 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500387 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700388 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
389 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
390 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
391 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700392 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500393 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700394 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
395 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
396 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700397
398 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700399 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
400 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700401 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700402 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700403 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
404 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
405 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
406 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
407 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
408 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
409 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
410
411 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700412 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700413 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
414 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
415 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
416 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
418 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
419 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
420
421 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700422 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700423
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700424 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
425 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700426 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700427 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700428 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700429 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700430
431 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
432 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
433 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700434 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700435 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
436 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700437 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
438 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
439 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700440
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700441 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700442 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
443 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
444 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700445 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700446
rago90fb9612015-12-02 11:37:53 -0800447 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
448 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
449
Prashant Malanic92c5962015-08-11 15:10:18 -0700450 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700452 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700453 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700455};
456
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700457static char * backend_tag_table[SND_DEVICE_MAX] = {0};
458static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700459
460static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
461 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
462 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
463 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
464 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700465 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
466 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700467 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
468 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
469 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
470 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
471 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
472 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
473 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
474 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
475 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
476 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
477 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700478};
479
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700480#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
481#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
482
Eric Laurentb23d5282013-05-14 15:27:20 -0700483static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
484static bool is_tmus = false;
485
486static void check_operator()
487{
488 char value[PROPERTY_VALUE_MAX];
489 int mccmnc;
490 property_get("gsm.sim.operator.numeric",value,"0");
491 mccmnc = atoi(value);
492 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
493 switch(mccmnc) {
494 /* TMUS MCC(310), MNC(490, 260, 026) */
495 case 310490:
496 case 310260:
497 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900498 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
499 case 310800:
500 case 310660:
501 case 310580:
502 case 310310:
503 case 310270:
504 case 310250:
505 case 310240:
506 case 310230:
507 case 310220:
508 case 310210:
509 case 310200:
510 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700511 is_tmus = true;
512 break;
513 }
514}
515
516bool is_operator_tmus()
517{
518 pthread_once(&check_op_once_ctl, check_operator);
519 return is_tmus;
520}
521
keunhui.park2f7306a2015-07-16 16:48:06 +0900522static char *get_current_operator()
523{
524 struct listnode *node;
525 struct operator_info *info_item;
526 char mccmnc[PROPERTY_VALUE_MAX];
527 char *ret = NULL;
528
529 property_get("gsm.sim.operator.numeric",mccmnc,"0");
530
531 list_for_each(node, &operator_info_list) {
532 info_item = node_to_item(node, struct operator_info, list);
533 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
534 ret = info_item->name;
535 }
536 }
537
538 return ret;
539}
540
541static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
542{
543 struct listnode *node;
544 struct operator_specific_device *ret = NULL;
545 struct operator_specific_device *device_item;
546 char *operator_name;
547
548 operator_name = get_current_operator();
549 if (operator_name == NULL)
550 return ret;
551
552 list_for_each(node, operator_specific_device_table[snd_device]) {
553 device_item = node_to_item(node, struct operator_specific_device, list);
554 if (strcmp(operator_name, device_item->operator) == 0) {
555 ret = device_item;
556 }
557 }
558
559 return ret;
560}
561
562
563static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
564{
565 struct operator_specific_device *device;
566 int ret = acdb_device_table[snd_device];
567
568 device = get_operator_specific_device(snd_device);
569 if (device != NULL)
570 ret = device->acdb_id;
571
572 return ret;
573}
574
575static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
576{
577 struct operator_specific_device *device;
578 const char *ret = device_table[snd_device];
579
580 device = get_operator_specific_device(snd_device);
581 if (device != NULL)
582 ret = device->mixer_path;
583
584 return ret;
585}
586
vivek mehta1a9b7c02015-06-25 11:49:38 -0700587bool platform_send_gain_dep_cal(void *platform, int level)
588{
589 bool ret_val = false;
590 struct platform_data *my_data = (struct platform_data *)platform;
591 struct audio_device *adev = my_data->adev;
592 int acdb_dev_id, app_type;
593 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
594 int mode = CAL_MODE_RTAC;
595 struct listnode *node;
596 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700597
598 if (my_data->acdb_send_gain_dep_cal == NULL) {
599 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
600 return ret_val;
601 }
602
603 if (!voice_is_in_call(adev)) {
604 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
605 __func__, level);
606 app_type = DEFAULT_APP_TYPE_RX_PATH;
607
608 // find the current active sound device
609 list_for_each(node, &adev->usecase_list) {
610 usecase = node_to_item(node, struct audio_usecase, list);
611
612 if (usecase != NULL &&
613 usecase->type == PCM_PLAYBACK &&
614 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
615
616 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700617 if (audio_extn_spkr_prot_is_enabled()) {
618 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
619 } else {
620 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
621 }
622
vivek mehta1a9b7c02015-06-25 11:49:38 -0700623 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
624 acdb_dev_type, mode, level)) {
625 // set ret_val true if at least one calibration is set successfully
626 ret_val = true;
627 } else {
628 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
629 }
630 } else {
631 ALOGW("%s: Usecase list is empty", __func__);
632 }
633 }
634 } else {
635 ALOGW("%s: Voice call in progress .. ignore setting new cal",
636 __func__);
637 }
638 return ret_val;
639}
640
Eric Laurentcefbbac2014-09-04 13:54:10 -0500641void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700642{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800643 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500644 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700645
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800646 if (strcmp(my_data->ec_ref_mixer_path, "")) {
647 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
648 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500649 }
650
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800651 if (enable) {
652 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
653 if (out_device != AUDIO_DEVICE_NONE) {
654 snd_device = platform_get_output_snd_device(adev->platform, out_device);
655 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
656 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500657
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800658 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
659 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
660 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700661}
662
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700663static struct csd_data *open_csd_client(bool i2s_ext_modem)
664{
665 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
666
667 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
668 if (csd->csd_client == NULL) {
669 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
670 goto error;
671 } else {
672 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
673
674 csd->deinit = (deinit_t)dlsym(csd->csd_client,
675 "csd_client_deinit");
676 if (csd->deinit == NULL) {
677 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
678 dlerror());
679 goto error;
680 }
681 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
682 "csd_client_disable_device");
683 if (csd->disable_device == NULL) {
684 ALOGE("%s: dlsym error %s for csd_client_disable_device",
685 __func__, dlerror());
686 goto error;
687 }
688 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
689 "csd_client_enable_device_config");
690 if (csd->enable_device_config == NULL) {
691 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
692 __func__, dlerror());
693 goto error;
694 }
695 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
696 "csd_client_enable_device");
697 if (csd->enable_device == NULL) {
698 ALOGE("%s: dlsym error %s for csd_client_enable_device",
699 __func__, dlerror());
700 goto error;
701 }
702 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
703 "csd_client_start_voice");
704 if (csd->start_voice == NULL) {
705 ALOGE("%s: dlsym error %s for csd_client_start_voice",
706 __func__, dlerror());
707 goto error;
708 }
709 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
710 "csd_client_stop_voice");
711 if (csd->stop_voice == NULL) {
712 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
713 __func__, dlerror());
714 goto error;
715 }
716 csd->volume = (volume_t)dlsym(csd->csd_client,
717 "csd_client_volume");
718 if (csd->volume == NULL) {
719 ALOGE("%s: dlsym error %s for csd_client_volume",
720 __func__, dlerror());
721 goto error;
722 }
723 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
724 "csd_client_mic_mute");
725 if (csd->mic_mute == NULL) {
726 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
727 __func__, dlerror());
728 goto error;
729 }
730 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
731 "csd_client_slow_talk");
732 if (csd->slow_talk == NULL) {
733 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
734 __func__, dlerror());
735 goto error;
736 }
737 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
738 "csd_client_start_playback");
739 if (csd->start_playback == NULL) {
740 ALOGE("%s: dlsym error %s for csd_client_start_playback",
741 __func__, dlerror());
742 goto error;
743 }
744 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
745 "csd_client_stop_playback");
746 if (csd->stop_playback == NULL) {
747 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
748 __func__, dlerror());
749 goto error;
750 }
751 csd->start_record = (start_record_t)dlsym(csd->csd_client,
752 "csd_client_start_record");
753 if (csd->start_record == NULL) {
754 ALOGE("%s: dlsym error %s for csd_client_start_record",
755 __func__, dlerror());
756 goto error;
757 }
758 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
759 "csd_client_stop_record");
760 if (csd->stop_record == NULL) {
761 ALOGE("%s: dlsym error %s for csd_client_stop_record",
762 __func__, dlerror());
763 goto error;
764 }
765
766 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
767 "csd_client_get_sample_rate");
768 if (csd->get_sample_rate == NULL) {
769 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
770 __func__, dlerror());
771
772 goto error;
773 }
774
775 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
776
777 if (csd->init == NULL) {
778 ALOGE("%s: dlsym error %s for csd_client_init",
779 __func__, dlerror());
780 goto error;
781 } else {
782 csd->init(i2s_ext_modem);
783 }
784 }
785 return csd;
786
787error:
788 free(csd);
789 csd = NULL;
790 return csd;
791}
792
793void close_csd_client(struct csd_data *csd)
794{
795 if (csd != NULL) {
796 csd->deinit();
797 dlclose(csd->csd_client);
798 free(csd);
799 csd = NULL;
800 }
801}
802
803static void platform_csd_init(struct platform_data *my_data)
804{
805#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700806 int32_t modems, (*count_modems)(void);
807 const char *name = "libdetectmodem.so";
808 const char *func = "count_modems";
809 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700810
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700811 my_data->csd = NULL;
812
813 void *lib = dlopen(name, RTLD_NOW);
814 error = dlerror();
815 if (!lib) {
816 ALOGE("%s: could not find %s: %s", __func__, name, error);
817 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700818 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700819
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700820 count_modems = NULL;
821 *(void **)(&count_modems) = dlsym(lib, func);
822 error = dlerror();
823 if (!count_modems) {
824 ALOGE("%s: could not find symbol %s in %s: %s",
825 __func__, func, name, error);
826 goto done;
827 }
828
829 modems = count_modems();
830 if (modems < 0) {
831 ALOGE("%s: count_modems failed\n", __func__);
832 goto done;
833 }
834
835 ALOGD("%s: num_modems %d\n", __func__, modems);
836 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700837 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700838
839done:
840 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700841#else
842 my_data->csd = NULL;
843#endif
844}
845
Eric Laurentc6333382015-09-14 12:43:44 -0700846static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700847{
848 int32_t dev;
849 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700850 backend_tag_table[dev] = NULL;
851 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900852 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700853 }
854
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700855 // To overwrite these go to the audio_platform_info.xml file.
856 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700857 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700858 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
859 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
860 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
861 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
862 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700863 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700864 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
865 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700866
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700867 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
868 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
869 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
870 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
871 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
872 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
873 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700874 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700875 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700876 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700877 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
878 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
879 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
880 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
881 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
882 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
883 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
884 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
885 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
886 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
887 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
888 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
889 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
890 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
891 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
892 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700893
894 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700895}
896
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900897void get_cvd_version(char *cvd_version, struct audio_device *adev)
898{
899 struct mixer_ctl *ctl;
900 int count;
901 int ret = 0;
902
903 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
904 if (!ctl) {
905 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
906 goto done;
907 }
908 mixer_ctl_update(ctl);
909
910 count = mixer_ctl_get_num_values(ctl);
911 if (count > MAX_CVD_VERSION_STRING_SIZE)
912 count = MAX_CVD_VERSION_STRING_SIZE - 1;
913
914 ret = mixer_ctl_get_array(ctl, cvd_version, count);
915 if (ret != 0) {
916 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
917 goto done;
918 }
919
920done:
921 return;
922}
923
Eric Laurentb23d5282013-05-14 15:27:20 -0700924void *platform_init(struct audio_device *adev)
925{
926 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800927 struct platform_data *my_data = NULL;
928 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
929 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700930 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900931 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -0800932 char *snd_internal_name = NULL;
933 char *tmp = NULL;
934 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
sangwoo1b9f4b32013-06-21 18:22:55 -0700935
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700936 my_data = calloc(1, sizeof(struct platform_data));
937
938 my_data->adev = adev;
939
keunhui.park2f7306a2015-07-16 16:48:06 +0900940 list_init(&operator_info_list);
941
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700942 set_platform_defaults(my_data);
943
944 /* Initialize platform specific ids and/or backends*/
945 platform_info_init(my_data);
946
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700947 while (snd_card_num < MAX_SND_CARD) {
948 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700949
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700950 while (!adev->mixer && retry_num < RETRY_NUMBER) {
951 usleep(RETRY_US);
952 adev->mixer = mixer_open(snd_card_num);
953 retry_num++;
954 }
955
956 if (!adev->mixer) {
957 ALOGE("%s: Unable to open the mixer card: %d", __func__,
958 snd_card_num);
959 retry_num = 0;
960 snd_card_num++;
961 continue;
962 }
963
964 snd_card_name = mixer_get_name(adev->mixer);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700965
966 /* validate the sound card name */
967 if (my_data->snd_card_name != NULL &&
968 strncmp(snd_card_name, my_data->snd_card_name, MAX_SND_CARD_NAME_LEN) != 0) {
969 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
970 __func__, snd_card_name, my_data->snd_card_name);
971 retry_num = 0;
972 snd_card_num++;
973 continue;
974 }
975
vivek mehta60ea4152016-02-18 17:10:26 -0800976 if ((snd_internal_name = strtok_r(snd_card_name, "-", &tmp)) != NULL) {
977 /* Get the codec internal name from the sound card name
978 * and form the mixer paths file name dynamically. This
979 * is generic way of picking any codec name based mixer
980 * files in future with no code change. This code
981 * assumes mixer files are formed with format as
982 * mixer_paths_internalcodecname.xml
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700983
vivek mehta60ea4152016-02-18 17:10:26 -0800984 * If this dynamically read mixer files fails to open then it
985 * falls back to default mixer file i.e mixer_paths.xml. This is
986 * done to preserve backward compatibility but not mandatory as
987 * long as the mixer files are named as per above assumption.
988 */
989
990 if ((snd_internal_name = strtok_r(NULL, "-", &tmp)) != NULL) {
991 // need to carryforward old file name
992 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
993 sizeof(TOMTOM_8226_SND_CARD_NAME))) {
994 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
995 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
996 } else {
997 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
998 MIXER_XML_BASE_STRING, snd_internal_name);
999 }
1000
1001 if (F_OK == access(mixer_xml_file, 0)) {
1002 use_default_mixer_path = false;
1003 }
1004 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001005 }
1006
vivek mehta60ea4152016-02-18 17:10:26 -08001007 if (use_default_mixer_path) {
1008 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1009 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1010 }
1011
1012 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1013 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1014
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001015 if (!adev->audio_route) {
1016 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001017 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001018 }
1019 adev->snd_card = snd_card_num;
1020 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1021 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001022 }
1023
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001024 if (snd_card_num >= MAX_SND_CARD) {
1025 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001026 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001027 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001028
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001029 //set max volume step for voice call
1030 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1031 my_data->max_vol_index = atoi(value);
1032
vivek mehta65ad12d2015-08-13 18:32:48 -07001033 property_get("persist.audio.dualmic.config",value,"");
1034 if (!strcmp("endfire", value)) {
1035 dual_mic_config = true;
1036 }
1037
Prashant Malanic92c5962015-08-11 15:10:18 -07001038 my_data->source_mic_type = SOURCE_DUAL_MIC;
1039
Eric Laurentb23d5282013-05-14 15:27:20 -07001040 my_data->fluence_in_spkr_mode = false;
1041 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001042 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001043 my_data->fluence_in_voice_rec = false;
1044
vivek mehta65ad12d2015-08-13 18:32:48 -07001045 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001046 if (!strcmp("fluencepro", value)) {
1047 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001048 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001049 my_data->fluence_type = FLUENCE_ENABLE;
1050 } else if (!strcmp("none", value)) {
1051 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001052 }
1053
Prashant Malanic92c5962015-08-11 15:10:18 -07001054 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001055 property_get("persist.audio.fluence.voicecall",value,"");
1056 if (!strcmp("true", value)) {
1057 my_data->fluence_in_voice_call = true;
1058 }
1059
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001060 property_get("persist.audio.fluence.voicecomm",value,"");
1061 if (!strcmp("true", value)) {
1062 my_data->fluence_in_voice_comm = true;
1063 }
1064
Eric Laurentb23d5282013-05-14 15:27:20 -07001065 property_get("persist.audio.fluence.voicerec",value,"");
1066 if (!strcmp("true", value)) {
1067 my_data->fluence_in_voice_rec = true;
1068 }
1069
1070 property_get("persist.audio.fluence.speaker",value,"");
1071 if (!strcmp("true", value)) {
1072 my_data->fluence_in_spkr_mode = true;
1073 }
1074 }
1075
Prashant Malanic92c5962015-08-11 15:10:18 -07001076 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1077 switch (my_data->max_mic_count) {
1078 case 4:
1079 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1080 case 3:
1081 my_data->source_mic_type |= SOURCE_THREE_MIC;
1082 case 2:
1083 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1084 case 1:
1085 my_data->source_mic_type |= SOURCE_MONO_MIC;
1086 break;
1087 default:
1088 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1089 __func__, my_data->max_mic_count);
1090 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1091 break;
1092 }
1093
1094 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1095 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1096 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1097 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1098 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1099
Eric Laurentb23d5282013-05-14 15:27:20 -07001100 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1101 if (my_data->acdb_handle == NULL) {
1102 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1103 } else {
1104 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1105 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1106 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001107 if (!my_data->acdb_deallocate)
1108 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1109 __func__, LIB_ACDB_LOADER);
1110
Eric Laurentb23d5282013-05-14 15:27:20 -07001111 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1112 "acdb_loader_send_audio_cal");
1113 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001114 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001115 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001116
Eric Laurentb23d5282013-05-14 15:27:20 -07001117 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1118 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001119 if (!my_data->acdb_send_voice_cal)
1120 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1121 __func__, LIB_ACDB_LOADER);
1122
1123 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1124 "acdb_loader_reload_vocvoltable");
1125 if (!my_data->acdb_reload_vocvoltable)
1126 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1127 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001128
1129 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1130 "acdb_loader_send_gain_dep_cal");
1131 if (!my_data->acdb_send_gain_dep_cal)
1132 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1133 __func__, LIB_ACDB_LOADER);
1134
vivek mehtac698f132016-02-25 18:50:35 -08001135#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001136 acdb_init_v2_cvd_t acdb_init;
1137 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1138 "acdb_loader_init_v2");
1139 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001140 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001141 goto acdb_init_fail;
1142 }
1143
1144 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1145 get_cvd_version(cvd_version, adev);
1146 if (!cvd_version)
1147 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001148 else
vivek mehtac698f132016-02-25 18:50:35 -08001149 acdb_init((char *)snd_card_name, cvd_version, 0);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001150 free(cvd_version);
1151#elif defined (PLATFORM_MSM8084)
1152 acdb_init_v2_t acdb_init;
1153 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1154 "acdb_loader_init_v2");
1155 if (acdb_init == NULL) {
1156 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1157 goto acdb_init_fail;
1158 }
1159 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001160#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001161 acdb_init_t acdb_init;
1162 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001163 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001164 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001165 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1166 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001167 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001168#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001169 }
1170
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001171acdb_init_fail:
1172
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001173 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001174
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001175 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1176
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001177 /* load csd client */
1178 platform_csd_init(my_data);
1179
Eric Laurentb23d5282013-05-14 15:27:20 -07001180 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001181
1182init_failed:
1183 if (my_data)
1184 free(my_data);
1185 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001186}
1187
1188void platform_deinit(void *platform)
1189{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001190 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001191 struct operator_info *info_item;
1192 struct operator_specific_device *device_item;
1193 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001194
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001195 struct platform_data *my_data = (struct platform_data *)platform;
1196 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001197
1198 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1199 if (backend_tag_table[dev])
1200 free(backend_tag_table[dev]);
1201 if (hw_interface_table[dev])
1202 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001203 if (operator_specific_device_table[dev]) {
1204 while (!list_empty(operator_specific_device_table[dev])) {
1205 node = list_head(operator_specific_device_table[dev]);
1206 list_remove(node);
1207 device_item = node_to_item(node, struct operator_specific_device, list);
1208 free(device_item->operator);
1209 free(device_item->mixer_path);
1210 free(device_item);
1211 }
1212 free(operator_specific_device_table[dev]);
1213 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001214 }
1215
1216 if (my_data->snd_card_name)
1217 free(my_data->snd_card_name);
1218
keunhui.park2f7306a2015-07-16 16:48:06 +09001219 while (!list_empty(&operator_info_list)) {
1220 node = list_head(&operator_info_list);
1221 list_remove(node);
1222 info_item = node_to_item(node, struct operator_info, list);
1223 free(info_item->name);
1224 free(info_item->mccmnc);
1225 free(info_item);
1226 }
1227
Eric Laurentb23d5282013-05-14 15:27:20 -07001228 free(platform);
1229}
1230
1231const char *platform_get_snd_device_name(snd_device_t snd_device)
1232{
keunhui.park2f7306a2015-07-16 16:48:06 +09001233 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1234 if (operator_specific_device_table[snd_device] != NULL) {
1235 return get_operator_specific_device_mixer_path(snd_device);
1236 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001237 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001238 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001239 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001240}
1241
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001242void platform_add_backend_name(void *platform, char *mixer_path,
1243 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001244{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001245 struct platform_data *my_data = (struct platform_data *)platform;
1246
Haynes Mathew George98c95622014-06-20 19:14:25 -07001247 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1248 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1249 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001250 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001251
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001252 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001253
1254 if (suffix != NULL) {
1255 strcat(mixer_path, " ");
1256 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001257 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001258}
1259
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001260bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1261{
1262 bool result = true;
1263
1264 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1265 platform_get_snd_device_name(snd_device1),
1266 platform_get_snd_device_name(snd_device2));
1267
1268 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1269 ALOGE("%s: Invalid snd_device = %s", __func__,
1270 platform_get_snd_device_name(snd_device1));
1271 return false;
1272 }
1273 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1274 ALOGE("%s: Invalid snd_device = %s", __func__,
1275 platform_get_snd_device_name(snd_device2));
1276 return false;
1277 }
1278 const char * be_itf1 = hw_interface_table[snd_device1];
1279 const char * be_itf2 = hw_interface_table[snd_device2];
1280
1281 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001282 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001283 result = false;
1284 }
1285
1286 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1287 return result;
1288}
1289
Eric Laurentb23d5282013-05-14 15:27:20 -07001290int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1291{
1292 int device_id;
1293 if (device_type == PCM_PLAYBACK)
1294 device_id = pcm_device_table[usecase][0];
1295 else
1296 device_id = pcm_device_table[usecase][1];
1297 return device_id;
1298}
1299
Haynes Mathew George98c95622014-06-20 19:14:25 -07001300static int find_index(const struct name_to_index * table, int32_t len,
1301 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001302{
1303 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001304 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001305
Haynes Mathew George98c95622014-06-20 19:14:25 -07001306 if (table == NULL) {
1307 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001308 ret = -ENODEV;
1309 goto done;
1310 }
1311
Haynes Mathew George98c95622014-06-20 19:14:25 -07001312 if (name == NULL) {
1313 ALOGE("null key");
1314 ret = -ENODEV;
1315 goto done;
1316 }
1317
1318 for (i=0; i < len; i++) {
1319 if (!strcmp(table[i].name, name)) {
1320 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001321 goto done;
1322 }
1323 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001324 ALOGE("%s: Could not find index for name = %s",
1325 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001326 ret = -ENODEV;
1327done:
1328 return ret;
1329}
1330
Haynes Mathew George98c95622014-06-20 19:14:25 -07001331int platform_get_snd_device_index(char *device_name)
1332{
1333 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1334}
1335
1336int platform_get_usecase_index(const char *usecase_name)
1337{
1338 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1339}
1340
keunhui.park2f7306a2015-07-16 16:48:06 +09001341void platform_add_operator_specific_device(snd_device_t snd_device,
1342 const char *operator,
1343 const char *mixer_path,
1344 unsigned int acdb_id)
1345{
1346 struct operator_specific_device *device;
1347
1348 if (operator_specific_device_table[snd_device] == NULL) {
1349 operator_specific_device_table[snd_device] =
1350 (struct listnode *)calloc(1, sizeof(struct listnode));
1351 list_init(operator_specific_device_table[snd_device]);
1352 }
1353
1354 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1355
1356 device->operator = strdup(operator);
1357 device->mixer_path = strdup(mixer_path);
1358 device->acdb_id = acdb_id;
1359
1360 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1361
1362 ALOGD("%s : deivce[%s] -> operator[%s] mixer_path[%s] acdb_id [%d]", __func__,
1363 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1364
1365}
1366
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001367int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1368{
1369 int ret = 0;
1370
1371 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1372 ALOGE("%s: Invalid snd_device = %d",
1373 __func__, snd_device);
1374 ret = -EINVAL;
1375 goto done;
1376 }
1377
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001378 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1379 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001380 acdb_device_table[snd_device] = acdb_id;
1381done:
1382 return ret;
1383}
1384
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001385int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1386{
1387 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1388 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1389 return -EINVAL;
1390 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001391
1392 if (operator_specific_device_table[snd_device] != NULL)
1393 return get_operator_specific_device_acdb_id(snd_device);
1394 else
1395 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001396}
1397
Eric Laurentb23d5282013-05-14 15:27:20 -07001398int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1399{
1400 struct platform_data *my_data = (struct platform_data *)platform;
1401 int acdb_dev_id, acdb_dev_type;
1402
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001403 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001404 if (acdb_dev_id < 0) {
1405 ALOGE("%s: Could not find acdb id for device(%d)",
1406 __func__, snd_device);
1407 return -EINVAL;
1408 }
1409 if (my_data->acdb_send_audio_cal) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001410 ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001411 __func__, snd_device, acdb_dev_id);
1412 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1413 snd_device < SND_DEVICE_OUT_END)
1414 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1415 else
1416 acdb_dev_type = ACDB_DEV_TYPE_IN;
1417 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1418 }
1419 return 0;
1420}
1421
1422int platform_switch_voice_call_device_pre(void *platform)
1423{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001424 struct platform_data *my_data = (struct platform_data *)platform;
1425 int ret = 0;
1426
1427 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001428 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001429 /* This must be called before disabling mixer controls on APQ side */
1430 ret = my_data->csd->disable_device();
1431 if (ret < 0) {
1432 ALOGE("%s: csd_client_disable_device, failed, error %d",
1433 __func__, ret);
1434 }
1435 }
1436 return ret;
1437}
1438
1439int platform_switch_voice_call_enable_device_config(void *platform,
1440 snd_device_t out_snd_device,
1441 snd_device_t in_snd_device)
1442{
1443 struct platform_data *my_data = (struct platform_data *)platform;
1444 int acdb_rx_id, acdb_tx_id;
1445 int ret = 0;
1446
1447 if (my_data->csd == NULL)
1448 return ret;
1449
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001450 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1451 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001452 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001453 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001454 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001455
keunhui.park2f7306a2015-07-16 16:48:06 +09001456 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001457
1458 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1459 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1460 if (ret < 0) {
1461 ALOGE("%s: csd_enable_device_config, failed, error %d",
1462 __func__, ret);
1463 }
1464 } else {
1465 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1466 acdb_rx_id, acdb_tx_id);
1467 }
1468
1469 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001470}
1471
1472int platform_switch_voice_call_device_post(void *platform,
1473 snd_device_t out_snd_device,
1474 snd_device_t in_snd_device)
1475{
1476 struct platform_data *my_data = (struct platform_data *)platform;
1477 int acdb_rx_id, acdb_tx_id;
1478
1479 if (my_data->acdb_send_voice_cal == NULL) {
1480 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1481 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001482 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1483 audio_extn_spkr_prot_is_enabled())
1484 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1485
keunhui.park2f7306a2015-07-16 16:48:06 +09001486 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1487 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001488
1489 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1490 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1491 else
1492 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1493 acdb_rx_id, acdb_tx_id);
1494 }
1495
1496 return 0;
1497}
1498
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001499int platform_switch_voice_call_usecase_route_post(void *platform,
1500 snd_device_t out_snd_device,
1501 snd_device_t in_snd_device)
1502{
1503 struct platform_data *my_data = (struct platform_data *)platform;
1504 int acdb_rx_id, acdb_tx_id;
1505 int ret = 0;
1506
1507 if (my_data->csd == NULL)
1508 return ret;
1509
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001510 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1511 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001512 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001513 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001514 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001515
keunhui.park2f7306a2015-07-16 16:48:06 +09001516 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001517
1518 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1519 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1520 my_data->adev->acdb_settings);
1521 if (ret < 0) {
1522 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1523 }
1524 } else {
1525 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1526 acdb_rx_id, acdb_tx_id);
1527 }
1528
1529 return ret;
1530}
1531
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001532int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001533{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001534 struct platform_data *my_data = (struct platform_data *)platform;
1535 int ret = 0;
1536
1537 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001538 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001539 if (ret < 0) {
1540 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1541 }
1542 }
1543 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001544}
1545
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001546int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001547{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001548 struct platform_data *my_data = (struct platform_data *)platform;
1549 int ret = 0;
1550
1551 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001552 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001553 if (ret < 0) {
1554 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1555 }
1556 }
1557 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001558}
1559
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001560int platform_get_sample_rate(void *platform, uint32_t *rate)
1561{
1562 struct platform_data *my_data = (struct platform_data *)platform;
1563 int ret = 0;
1564
1565 if (my_data->csd != NULL) {
1566 ret = my_data->csd->get_sample_rate(rate);
1567 if (ret < 0) {
1568 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1569 }
1570 }
1571 return ret;
1572}
1573
vivek mehtab6506412015-08-07 16:55:17 -07001574void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1575 snd_device_t snd_device,
1576 bool enable)
1577{
1578 const char* name;
1579 switch (snd_device) {
1580 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1581 if (enable)
1582 name = "spkr-gain-in-headphone-combo";
1583 else
1584 name = "speaker-gain-default";
1585 break;
1586 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1587 if (enable)
1588 name = "spkr-gain-in-line-combo";
1589 else
1590 name = "speaker-gain-default";
1591 break;
1592 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1593 if (enable)
1594 name = "spkr-safe-gain-in-headphone-combo";
1595 else
1596 name = "speaker-safe-gain-default";
1597 break;
1598 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1599 if (enable)
1600 name = "spkr-safe-gain-in-line-combo";
1601 else
1602 name = "speaker-safe-gain-default";
1603 break;
1604 default:
1605 return;
1606 }
1607
1608 audio_route_apply_and_update_path(adev->audio_route, name);
1609}
1610
Eric Laurentb23d5282013-05-14 15:27:20 -07001611int platform_set_voice_volume(void *platform, int volume)
1612{
1613 struct platform_data *my_data = (struct platform_data *)platform;
1614 struct audio_device *adev = my_data->adev;
1615 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001616 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001617 int vol_index = 0, ret = 0;
1618 uint32_t set_values[ ] = {0,
1619 ALL_SESSION_VSID,
1620 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001621
1622 // Voice volume levels are mapped to adsp volume levels as follows.
1623 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1624 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001625 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001626 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001627
1628 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1629 if (!ctl) {
1630 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1631 __func__, mixer_ctl_name);
1632 return -EINVAL;
1633 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001634 ALOGV("Setting voice volume index: %d", set_values[0]);
1635 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1636
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001637 if (my_data->csd != NULL) {
1638 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1639 DEFAULT_VOLUME_RAMP_DURATION_MS);
1640 if (ret < 0) {
1641 ALOGE("%s: csd_volume error %d", __func__, ret);
1642 }
1643 }
1644 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001645}
1646
1647int platform_set_mic_mute(void *platform, bool state)
1648{
1649 struct platform_data *my_data = (struct platform_data *)platform;
1650 struct audio_device *adev = my_data->adev;
1651 struct mixer_ctl *ctl;
1652 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001653 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001654 uint32_t set_values[ ] = {0,
1655 ALL_SESSION_VSID,
1656 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001657
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001658 if (adev->mode != AUDIO_MODE_IN_CALL &&
1659 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001660 return 0;
1661
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001662 if (adev->enable_hfp)
1663 mixer_ctl_name = "HFP Tx Mute";
1664
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001665 set_values[0] = state;
1666 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1667 if (!ctl) {
1668 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1669 __func__, mixer_ctl_name);
1670 return -EINVAL;
1671 }
1672 ALOGV("Setting voice mute state: %d", state);
1673 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1674
1675 if (my_data->csd != NULL) {
1676 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1677 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001678 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001679 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001680 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001681 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001682 return ret;
1683}
Eric Laurentb23d5282013-05-14 15:27:20 -07001684
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001685int platform_set_device_mute(void *platform, bool state, char *dir)
1686{
1687 struct platform_data *my_data = (struct platform_data *)platform;
1688 struct audio_device *adev = my_data->adev;
1689 struct mixer_ctl *ctl;
1690 char *mixer_ctl_name = NULL;
1691 int ret = 0;
1692 uint32_t set_values[ ] = {0,
1693 ALL_SESSION_VSID,
1694 0};
1695 if(dir == NULL) {
1696 ALOGE("%s: Invalid direction:%s", __func__, dir);
1697 return -EINVAL;
1698 }
1699
1700 if (!strncmp("rx", dir, sizeof("rx"))) {
1701 mixer_ctl_name = "Voice Rx Device Mute";
1702 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1703 mixer_ctl_name = "Voice Tx Device Mute";
1704 } else {
1705 return -EINVAL;
1706 }
1707
1708 set_values[0] = state;
1709 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1710 if (!ctl) {
1711 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1712 __func__, mixer_ctl_name);
1713 return -EINVAL;
1714 }
1715
1716 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1717 __func__,state, mixer_ctl_name);
1718 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1719
1720 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001721}
1722
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001723bool platform_can_split_snd_device(snd_device_t snd_device,
1724 int *num_devices,
1725 snd_device_t *new_snd_devices)
1726{
1727 bool status = false;
1728
1729 if (NULL == num_devices || NULL == new_snd_devices) {
1730 ALOGE("%s: NULL pointer ..", __func__);
1731 return false;
1732 }
1733
1734 /*
1735 * If wired headset/headphones/line devices share the same backend
1736 * with speaker/earpiece this routine returns false.
1737 */
1738 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1739 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1740 *num_devices = 2;
1741 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1742 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1743 status = true;
1744 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1745 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1746 *num_devices = 2;
1747 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1748 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1749 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001750 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1751 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1752 *num_devices = 2;
1753 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1754 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1755 status = true;
1756 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1757 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1758 *num_devices = 2;
1759 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1760 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1761 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001762 }
1763 return status;
1764}
1765
Eric Laurentb23d5282013-05-14 15:27:20 -07001766snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1767{
1768 struct platform_data *my_data = (struct platform_data *)platform;
1769 struct audio_device *adev = my_data->adev;
1770 audio_mode_t mode = adev->mode;
1771 snd_device_t snd_device = SND_DEVICE_NONE;
1772
1773 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1774 if (devices == AUDIO_DEVICE_NONE ||
1775 devices & AUDIO_DEVICE_BIT_IN) {
1776 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1777 goto exit;
1778 }
1779
Eric Laurent1b491552015-09-15 17:52:41 -07001780 if (popcount(devices) == 2) {
1781 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1782 AUDIO_DEVICE_OUT_SPEAKER) ||
1783 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1784 AUDIO_DEVICE_OUT_SPEAKER)) {
1785 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1786 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1787 AUDIO_DEVICE_OUT_SPEAKER)) {
1788 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1789 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1790 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1791 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1792 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1793 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1794 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1795 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1796 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1797 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1798 AUDIO_DEVICE_OUT_SPEAKER)) {
1799 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1800 } else {
1801 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1802 goto exit;
1803 }
1804 if (snd_device != SND_DEVICE_NONE) {
1805 goto exit;
1806 }
1807 }
1808
1809 if (popcount(devices) != 1) {
1810 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1811 goto exit;
1812 }
1813
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001814 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001815 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001816 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1817 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001818 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001819 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001820 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001821 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001822 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001823 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001824 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001825 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001826 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001827 else {
1828 if (devices & AUDIO_DEVICE_OUT_LINE)
1829 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1830 else
1831 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1832 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001833 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001834 if (adev->bt_wb_speech_enabled) {
1835 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1836 } else {
1837 snd_device = SND_DEVICE_OUT_BT_SCO;
1838 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001839 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001840 if (!adev->enable_hfp) {
1841 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1842 } else {
1843 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1844 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001845 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001846 if(adev->voice.hac)
1847 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1848 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001849 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1850 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001851 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001852 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1853 snd_device = SND_DEVICE_OUT_VOICE_TX;
1854
Eric Laurentb23d5282013-05-14 15:27:20 -07001855 if (snd_device != SND_DEVICE_NONE) {
1856 goto exit;
1857 }
1858 }
1859
Eric Laurentb23d5282013-05-14 15:27:20 -07001860 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1861 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1862 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001863 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1864 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001865 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1866 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001867 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001868 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001869 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1870 else
1871 snd_device = SND_DEVICE_OUT_SPEAKER;
1872 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001873 if (adev->bt_wb_speech_enabled) {
1874 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1875 } else {
1876 snd_device = SND_DEVICE_OUT_BT_SCO;
1877 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001878 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1879 snd_device = SND_DEVICE_OUT_HDMI ;
1880 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001881 /*HAC support for voice-ish audio (eg visual voicemail)*/
1882 if(adev->voice.hac)
1883 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1884 else
1885 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001886 } else {
1887 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1888 }
1889exit:
1890 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1891 return snd_device;
1892}
1893
1894snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1895{
1896 struct platform_data *my_data = (struct platform_data *)platform;
1897 struct audio_device *adev = my_data->adev;
1898 audio_source_t source = (adev->active_input == NULL) ?
1899 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1900
1901 audio_mode_t mode = adev->mode;
1902 audio_devices_t in_device = ((adev->active_input == NULL) ?
1903 AUDIO_DEVICE_NONE : adev->active_input->device)
1904 & ~AUDIO_DEVICE_BIT_IN;
1905 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1906 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1907 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001908 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001909
Prashant Malanic92c5962015-08-11 15:10:18 -07001910 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1911 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001912 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001913 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001914 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001915 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1916 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001917 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001918 case TTY_MODE_FULL:
1919 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1920 break;
1921 case TTY_MODE_VCO:
1922 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1923 break;
1924 case TTY_MODE_HCO:
1925 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1926 break;
1927 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001928 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001929 }
1930 goto exit;
1931 }
1932 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001933 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001934 if (my_data->fluence_in_voice_call == false) {
1935 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1936 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001937 if (is_operator_tmus())
1938 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001939 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001940 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001941 }
1942 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1943 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1944 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001945 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001946 if (adev->bluetooth_nrec)
1947 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1948 else
1949 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001950 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001951 if (adev->bluetooth_nrec)
1952 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1953 else
1954 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001955 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001956 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07001957 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
1958 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1959 out_device & AUDIO_DEVICE_OUT_LINE) {
1960 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
1961 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
1962 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1963 } else {
1964 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1965 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001966 }
vivek mehtafe121d52015-08-10 23:39:23 -07001967
1968 //select default
1969 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001970 if (!adev->enable_hfp) {
1971 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1972 } else {
1973 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
1974 platform_set_echo_reference(adev, true, out_device);
1975 }
vivek mehtafe121d52015-08-10 23:39:23 -07001976 }
Prashant Malanic92c5962015-08-11 15:10:18 -07001977 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001978 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07001979 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001980 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1981 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1982 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1983 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1984 }
1985 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1986 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001987 if (my_data->fluence_in_voice_rec && channel_count == 1) {
1988 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
1989 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
1990 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
1991 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
1992 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
1993 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
1994 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
1995 (my_data->fluence_type == FLUENCE_ENABLE)) &&
1996 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001997 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07001998 }
1999 platform_set_echo_reference(adev, true, out_device);
2000 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2001 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2002 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2003 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2004 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2005 snd_device = SND_DEVICE_IN_THREE_MIC;
2006 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2007 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2008 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002009 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002010 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002011 if (adev->active_input->enable_ns)
2012 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2013 else
2014 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002015 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002016 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2017 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002018 }
rago90fb9612015-12-02 11:37:53 -08002019 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2020 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2021 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2022 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2023 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2024 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002025 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002026 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002027 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002028 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2029 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002030 if (adev->active_input->enable_aec &&
2031 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002032 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002033 if (my_data->fluence_in_spkr_mode &&
2034 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002035 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002036 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002037 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002038 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002039 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002040 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002041 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002042 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002043 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002044 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002045 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002046 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002047 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2048 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002049 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002050 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002051 } else if (adev->active_input->enable_aec) {
2052 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2053 if (my_data->fluence_in_spkr_mode &&
2054 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002055 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002056 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002057 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002058 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002059 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002060 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2061 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002062 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002063 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002064 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002065 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002066 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002067 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2068 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2069 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002070 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002071 } else if (adev->active_input->enable_ns) {
2072 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2073 if (my_data->fluence_in_spkr_mode &&
2074 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002075 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002076 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002077 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002078 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002079 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002080 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2081 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002082 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002083 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002084 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002085 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002086 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002087 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002088 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002089 }
2090 } else if (source == AUDIO_SOURCE_DEFAULT) {
2091 goto exit;
2092 }
2093
2094
2095 if (snd_device != SND_DEVICE_NONE) {
2096 goto exit;
2097 }
2098
2099 if (in_device != AUDIO_DEVICE_NONE &&
2100 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2101 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2102 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002103 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2104 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2105 snd_device = SND_DEVICE_IN_QUAD_MIC;
2106 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2107 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2108 snd_device = SND_DEVICE_IN_THREE_MIC;
2109 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2110 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002111 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002112 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2113 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002114 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002115 } else {
2116 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2117 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2118 my_data->source_mic_type, channel_count, channel_mask);
2119 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2120 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002121 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002122 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2123 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002124 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002125 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2126 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002127 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002128 } else {
2129 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2130 " no combination found .. setting to mono", __func__,
2131 my_data->source_mic_type, channel_count);
2132 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2133 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002134 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2135 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2136 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002137 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002138 if (adev->bluetooth_nrec)
2139 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2140 else
2141 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002142 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002143 if (adev->bluetooth_nrec)
2144 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2145 else
2146 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002147 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002148 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2149 snd_device = SND_DEVICE_IN_HDMI_MIC;
2150 } else {
2151 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2152 ALOGW("%s: Using default handset-mic", __func__);
2153 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2154 }
2155 } else {
2156 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2157 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2158 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2159 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002160 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002161 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002162 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002163 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002164 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2165 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002166 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002167 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2168 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002169 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002170 } else {
2171 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2172 " no combination found .. setting to mono", __func__,
2173 my_data->source_mic_type, channel_count);
2174 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2175 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002176 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002177 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002178 if (adev->bluetooth_nrec)
2179 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2180 else
2181 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002182 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002183 if (adev->bluetooth_nrec)
2184 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2185 else
2186 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002187 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002188 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2189 snd_device = SND_DEVICE_IN_HDMI_MIC;
2190 } else {
2191 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2192 ALOGW("%s: Using default handset-mic", __func__);
2193 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2194 }
2195 }
2196exit:
2197 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2198 return snd_device;
2199}
2200
2201int platform_set_hdmi_channels(void *platform, int channel_count)
2202{
2203 struct platform_data *my_data = (struct platform_data *)platform;
2204 struct audio_device *adev = my_data->adev;
2205 struct mixer_ctl *ctl;
2206 const char *channel_cnt_str = NULL;
2207 const char *mixer_ctl_name = "HDMI_RX Channels";
2208 switch (channel_count) {
2209 case 8:
2210 channel_cnt_str = "Eight"; break;
2211 case 7:
2212 channel_cnt_str = "Seven"; break;
2213 case 6:
2214 channel_cnt_str = "Six"; break;
2215 case 5:
2216 channel_cnt_str = "Five"; break;
2217 case 4:
2218 channel_cnt_str = "Four"; break;
2219 case 3:
2220 channel_cnt_str = "Three"; break;
2221 default:
2222 channel_cnt_str = "Two"; break;
2223 }
2224 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2225 if (!ctl) {
2226 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2227 __func__, mixer_ctl_name);
2228 return -EINVAL;
2229 }
2230 ALOGV("HDMI channel count: %s", channel_cnt_str);
2231 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2232 return 0;
2233}
2234
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002235int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002236{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002237 struct platform_data *my_data = (struct platform_data *)platform;
2238 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002239 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2240 char *sad = block;
2241 int num_audio_blocks;
2242 int channel_count;
2243 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002244 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002245
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002246 struct mixer_ctl *ctl;
2247
2248 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2249 if (!ctl) {
2250 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2251 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002252 return 0;
2253 }
2254
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002255 mixer_ctl_update(ctl);
2256
2257 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002258
2259 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002260 if (count > (int)sizeof(block))
2261 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002262
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002263 ret = mixer_ctl_get_array(ctl, block, count);
2264 if (ret != 0) {
2265 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2266 return 0;
2267 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002268
2269 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002270 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002271
2272 for (i = 0; i < num_audio_blocks; i++) {
2273 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002274 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2275 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002276 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002277 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002278
2279 channel_count = (sad[0] & 0x7) + 1;
2280 if (channel_count > max_channels)
2281 max_channels = channel_count;
2282
2283 /* Advance to next block */
2284 sad += 3;
2285 }
2286
2287 return max_channels;
2288}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002289
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002290int platform_set_incall_recording_session_id(void *platform,
2291 uint32_t session_id, int rec_mode)
2292{
2293 int ret = 0;
2294 struct platform_data *my_data = (struct platform_data *)platform;
2295 struct audio_device *adev = my_data->adev;
2296 struct mixer_ctl *ctl;
2297 const char *mixer_ctl_name = "Voc VSID";
2298 int num_ctl_values;
2299 int i;
2300
2301 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2302 if (!ctl) {
2303 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2304 __func__, mixer_ctl_name);
2305 ret = -EINVAL;
2306 } else {
2307 num_ctl_values = mixer_ctl_get_num_values(ctl);
2308 for (i = 0; i < num_ctl_values; i++) {
2309 if (mixer_ctl_set_value(ctl, i, session_id)) {
2310 ALOGV("Error: invalid session_id: %x", session_id);
2311 ret = -EINVAL;
2312 break;
2313 }
2314 }
2315 }
2316
2317 if (my_data->csd != NULL) {
2318 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2319 if (ret < 0) {
2320 ALOGE("%s: csd_client_start_record failed, error %d",
2321 __func__, ret);
2322 }
2323 }
2324
2325 return ret;
2326}
2327
2328int platform_stop_incall_recording_usecase(void *platform)
2329{
2330 int ret = 0;
2331 struct platform_data *my_data = (struct platform_data *)platform;
2332
2333 if (my_data->csd != NULL) {
2334 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2335 if (ret < 0) {
2336 ALOGE("%s: csd_client_stop_record failed, error %d",
2337 __func__, ret);
2338 }
2339 }
2340
2341 return ret;
2342}
2343
2344int platform_start_incall_music_usecase(void *platform)
2345{
2346 int ret = 0;
2347 struct platform_data *my_data = (struct platform_data *)platform;
2348
2349 if (my_data->csd != NULL) {
2350 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2351 if (ret < 0) {
2352 ALOGE("%s: csd_client_start_playback failed, error %d",
2353 __func__, ret);
2354 }
2355 }
2356
2357 return ret;
2358}
2359
2360int platform_stop_incall_music_usecase(void *platform)
2361{
2362 int ret = 0;
2363 struct platform_data *my_data = (struct platform_data *)platform;
2364
2365 if (my_data->csd != NULL) {
2366 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2367 if (ret < 0) {
2368 ALOGE("%s: csd_client_stop_playback failed, error %d",
2369 __func__, ret);
2370 }
2371 }
2372
2373 return ret;
2374}
2375
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002376int platform_set_parameters(void *platform, struct str_parms *parms)
2377{
2378 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002379 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002380 char *kv_pairs = str_parms_to_str(parms);
2381 int ret = 0, err;
2382
2383 if (kv_pairs == NULL) {
2384 ret = -EINVAL;
2385 ALOGE("%s: key-value pair is NULL",__func__);
2386 goto done;
2387 }
2388
2389 ALOGV("%s: enter: %s", __func__, kv_pairs);
2390
2391 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2392 value, sizeof(value));
2393 if (err >= 0) {
2394 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2395 my_data->snd_card_name = strdup(value);
2396 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2397 }
2398
keunhui.park2f7306a2015-07-16 16:48:06 +09002399 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2400 value, sizeof(value));
2401 if (err >= 0) {
2402 struct operator_info *info;
2403 char *str = value;
2404 char *name;
2405
2406 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2407 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2408 name = strtok(str, ";");
2409 info->name = strdup(name);
2410 info->mccmnc = strdup(str + strlen(name) + 1);
2411
2412 list_add_tail(&operator_info_list, &info->list);
2413 ALOGD("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
2414 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002415
2416 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002417 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002418 value, sizeof(value));
2419 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002420 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002421 my_data->max_mic_count = atoi(value);
2422 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002423 }
2424
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002425done:
2426 ALOGV("%s: exit with code(%d)", __func__, ret);
2427 if (kv_pairs != NULL)
2428 free(kv_pairs);
2429
2430 return ret;
2431}
2432
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002433/* Delay in Us */
2434int64_t platform_render_latency(audio_usecase_t usecase)
2435{
2436 switch (usecase) {
2437 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2438 return DEEP_BUFFER_PLATFORM_DELAY;
2439 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2440 return LOW_LATENCY_PLATFORM_DELAY;
2441 default:
2442 return 0;
2443 }
2444}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002445
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002446int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2447 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002448{
2449 int ret = 0;
2450
2451 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2452 ALOGE("%s: Invalid snd_device = %d",
2453 __func__, device);
2454 ret = -EINVAL;
2455 goto done;
2456 }
2457
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002458 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2459 platform_get_snd_device_name(device),
2460 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2461 if (backend_tag_table[device]) {
2462 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002463 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002464 backend_tag_table[device] = strdup(backend_tag);
2465
2466 if (hw_interface != NULL) {
2467 if (hw_interface_table[device])
2468 free(hw_interface_table[device]);
2469 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2470 hw_interface_table[device] = strdup(hw_interface);
2471 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002472done:
2473 return ret;
2474}
2475
2476int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2477{
2478 int ret = 0;
2479 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2480 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2481 ret = -EINVAL;
2482 goto done;
2483 }
2484
2485 if ((type != 0) && (type != 1)) {
2486 ALOGE("%s: invalid usecase type", __func__);
2487 ret = -EINVAL;
2488 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002489 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002490 pcm_device_table[usecase][type] = pcm_id;
2491done:
2492 return ret;
2493}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002494
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002495#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2496int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2497 // backup_gain: gain to try to set in case of an error during ramp
2498 int start_gain, end_gain, step, backup_gain, i;
2499 bool error = false;
2500 const struct mixer_ctl *ctl;
2501 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2502 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2503 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2504 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2505 if (!ctl_left || !ctl_right) {
2506 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2507 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2508 return -EINVAL;
2509 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2510 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2511 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2512 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2513 return -EINVAL;
2514 }
2515 if (ramp_up) {
2516 start_gain = 0;
2517 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2518 step = +1;
2519 backup_gain = end_gain;
2520 } else {
2521 // using same gain on left and right
2522 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2523 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2524 end_gain = 0;
2525 step = -1;
2526 backup_gain = start_gain;
2527 }
2528 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2529 //ALOGV("setting speaker gain to %d", i);
2530 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2531 ALOGE("%s: error setting %s to %d during gain ramp",
2532 __func__, mixer_ctl_name_gain_left, i);
2533 error = true;
2534 break;
2535 }
2536 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2537 ALOGE("%s: error setting %s to %d during gain ramp",
2538 __func__, mixer_ctl_name_gain_right, i);
2539 error = true;
2540 break;
2541 }
2542 usleep(1000);
2543 }
2544 if (error) {
2545 // an error occured during the ramp, let's still try to go back to a safe volume
2546 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2547 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2548 }
2549 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2550 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2551 }
2552 }
2553 return start_gain;
2554}
2555
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002556int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2557{
2558 // only update if there is active pcm playback on speaker
2559 struct audio_usecase *usecase;
2560 struct listnode *node;
2561 struct platform_data *my_data = (struct platform_data *)adev->platform;
2562
2563 if (my_data->speaker_lr_swap != swap_channels) {
2564 my_data->speaker_lr_swap = swap_channels;
2565
2566 list_for_each(node, &adev->usecase_list) {
2567 usecase = node_to_item(node, struct audio_usecase, list);
2568 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002569 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2570 /*
2571 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2572 * to perform device switch to disable the current backend to
2573 * enable it with new acdb data.
2574 */
2575 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2576 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002577 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002578 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002579 if (initial_skpr_gain != -EINVAL) {
2580 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2581 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002582 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002583 const char *mixer_path;
2584 if (swap_channels) {
2585 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2586 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2587 } else {
2588 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2589 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2590 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002591 }
2592 break;
2593 }
2594 }
2595 }
2596 return 0;
2597}