blob: 7dc755c47b1a63f448dc6ee9c3555a1c0c9c3fa4 [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;
Ed Tamb0b0d572016-03-21 10:45:37 -0700132
133 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700134};
135
Haynes Mathew George98c95622014-06-20 19:14:25 -0700136static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700137 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
138 DEEP_BUFFER_PCM_DEVICE},
139 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
140 LOWLATENCY_PCM_DEVICE},
141 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
142 MULTIMEDIA2_PCM_DEVICE},
143 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
144 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700145 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
146 MULTIMEDIA2_PCM_DEVICE},
147 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
148 MULTIMEDIA3_PCM_DEVICE},
149
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700150 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
151 AUDIO_RECORD_PCM_DEVICE},
152 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
153 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700154
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700155 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
156 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700157 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
158 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
159 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
160 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800161 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
162 VOICEMMODE1_CALL_PCM_DEVICE},
163 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
164 VOICEMMODE2_CALL_PCM_DEVICE},
165
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700166 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
167 AUDIO_RECORD_PCM_DEVICE},
168 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
169 AUDIO_RECORD_PCM_DEVICE},
170 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
171 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800172 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700173
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700174 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
175 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
176
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700177 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
178 AFE_PROXY_RECORD_PCM_DEVICE},
179 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
180 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800181 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700182
Eric Laurentb23d5282013-05-14 15:27:20 -0700183};
184
185/* Array to store sound devices */
186static const char * const device_table[SND_DEVICE_MAX] = {
187 [SND_DEVICE_NONE] = "none",
188 /* Playback sound devices */
189 [SND_DEVICE_OUT_HANDSET] = "handset",
190 [SND_DEVICE_OUT_SPEAKER] = "speaker",
191 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700192 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700193 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500194 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700195 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700196 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500197 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700198 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700199 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500200 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700201 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
202 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500203 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700204 [SND_DEVICE_OUT_HDMI] = "hdmi",
205 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
206 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700207 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700208 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
209 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
210 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
211 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700212 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700213 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
214 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700215 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700216
217 /* Capture sound devices */
218 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700219 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700220 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
221 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
222 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
223 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
224 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
225 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
226 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
227
228 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
229 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
230 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
231 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
232 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
233 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
234 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
235 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
236 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
237
238 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500239 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700240
Eric Laurentb23d5282013-05-14 15:27:20 -0700241 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
242 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700243 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700244 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700245 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700246 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700247
248 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
249 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
250 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
251 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700252 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700253 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700254 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
255 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
256 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700257
Eric Laurentb23d5282013-05-14 15:27:20 -0700258 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700259 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
260 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
261 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700262 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700263
rago90fb9612015-12-02 11:37:53 -0800264 [SND_DEVICE_IN_UNPROCESSED_MIC] = "voice-rec-mic",
265 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
266
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700267 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700268
Prashant Malanic92c5962015-08-11 15:10:18 -0700269 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
270 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700271 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700272 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
273 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700274};
275
276/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700277static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700278 [SND_DEVICE_NONE] = -1,
279 [SND_DEVICE_OUT_HANDSET] = 7,
280 [SND_DEVICE_OUT_SPEAKER] = 15,
281 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700282 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700283 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500284 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700285 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700286 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500287 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700288 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700289 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
290 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500291 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700292 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500293 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700294 [SND_DEVICE_OUT_HDMI] = 18,
295 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
296 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700297 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700298 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700299 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
300 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
301 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700302 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700303 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
304 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700305 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700306
307 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700308 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
309 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
310 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
311 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
312 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
313 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
314 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
315 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
316
317 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
318 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
319 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
320 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
321 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
322 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
323 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
324 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
325 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
326
rago90fb9612015-12-02 11:37:53 -0800327 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500328 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700329
Eric Laurentb23d5282013-05-14 15:27:20 -0700330 [SND_DEVICE_IN_HDMI_MIC] = 4,
331 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700332 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700333 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700334 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700335 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700336
337 [SND_DEVICE_IN_VOICE_DMIC] = 41,
338 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
339 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700340 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700341 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800342 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700343 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
344 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
345 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700346
rago90fb9612015-12-02 11:37:53 -0800347 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700348 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
349 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
350 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800351 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
352
353 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
354 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700355
356 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700357
Prashant Malanic92c5962015-08-11 15:10:18 -0700358 [SND_DEVICE_IN_THREE_MIC] = 46,
359 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700360 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700361 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
362 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
Eric Laurentb23d5282013-05-14 15:27:20 -0700363};
364
Haynes Mathew George98c95622014-06-20 19:14:25 -0700365struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700366 char name[100];
367 unsigned int index;
368};
369
370#define TO_NAME_INDEX(X) #X, X
371
Haynes Mathew George98c95622014-06-20 19:14:25 -0700372/* Used to get index from parsed string */
373static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
374 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700375 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
376 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
377 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700378 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700379 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500380 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700381 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700382 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500383 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700384 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700385 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
386 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700387 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700388 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500389 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700390 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
391 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
392 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
393 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700394 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500395 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700396 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
397 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
398 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700399
400 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700401 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
402 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700403 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700404 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700405 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
406 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
407 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
408 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
409 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
410 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
411 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
412
413 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700414 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700415 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
416 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
418 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
419 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
420 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
421 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
422
423 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700424 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700425
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700426 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
427 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700428 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700429 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700430 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700431 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700432
433 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
435 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700436 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700437 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
438 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700439 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
440 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700442
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700443 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700444 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
445 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
446 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700447 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700448
rago90fb9612015-12-02 11:37:53 -0800449 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
450 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
451
Prashant Malanic92c5962015-08-11 15:10:18 -0700452 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700454 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700455 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
456 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700457};
458
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700459static char * backend_tag_table[SND_DEVICE_MAX] = {0};
460static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700461
462static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
463 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
464 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
465 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
466 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700467 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
468 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700469 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
470 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
471 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
472 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
473 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
474 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
475 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
476 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
477 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
478 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
479 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700480};
481
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700482#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
483#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
484
Eric Laurentb23d5282013-05-14 15:27:20 -0700485static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
486static bool is_tmus = false;
487
488static void check_operator()
489{
490 char value[PROPERTY_VALUE_MAX];
491 int mccmnc;
492 property_get("gsm.sim.operator.numeric",value,"0");
493 mccmnc = atoi(value);
Joe Onorato188b6222016-03-01 11:02:27 -0800494 ALOGV("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700495 switch(mccmnc) {
496 /* TMUS MCC(310), MNC(490, 260, 026) */
497 case 310490:
498 case 310260:
499 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900500 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
501 case 310800:
502 case 310660:
503 case 310580:
504 case 310310:
505 case 310270:
506 case 310250:
507 case 310240:
508 case 310230:
509 case 310220:
510 case 310210:
511 case 310200:
512 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700513 is_tmus = true;
514 break;
515 }
516}
517
518bool is_operator_tmus()
519{
520 pthread_once(&check_op_once_ctl, check_operator);
521 return is_tmus;
522}
523
keunhui.park2f7306a2015-07-16 16:48:06 +0900524static char *get_current_operator()
525{
526 struct listnode *node;
527 struct operator_info *info_item;
528 char mccmnc[PROPERTY_VALUE_MAX];
529 char *ret = NULL;
530
531 property_get("gsm.sim.operator.numeric",mccmnc,"0");
532
533 list_for_each(node, &operator_info_list) {
534 info_item = node_to_item(node, struct operator_info, list);
535 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
536 ret = info_item->name;
537 }
538 }
539
540 return ret;
541}
542
543static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
544{
545 struct listnode *node;
546 struct operator_specific_device *ret = NULL;
547 struct operator_specific_device *device_item;
548 char *operator_name;
549
550 operator_name = get_current_operator();
551 if (operator_name == NULL)
552 return ret;
553
554 list_for_each(node, operator_specific_device_table[snd_device]) {
555 device_item = node_to_item(node, struct operator_specific_device, list);
556 if (strcmp(operator_name, device_item->operator) == 0) {
557 ret = device_item;
558 }
559 }
560
561 return ret;
562}
563
564
565static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
566{
567 struct operator_specific_device *device;
568 int ret = acdb_device_table[snd_device];
569
570 device = get_operator_specific_device(snd_device);
571 if (device != NULL)
572 ret = device->acdb_id;
573
574 return ret;
575}
576
577static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
578{
579 struct operator_specific_device *device;
580 const char *ret = device_table[snd_device];
581
582 device = get_operator_specific_device(snd_device);
583 if (device != NULL)
584 ret = device->mixer_path;
585
586 return ret;
587}
588
vivek mehta1a9b7c02015-06-25 11:49:38 -0700589bool platform_send_gain_dep_cal(void *platform, int level)
590{
591 bool ret_val = false;
592 struct platform_data *my_data = (struct platform_data *)platform;
593 struct audio_device *adev = my_data->adev;
594 int acdb_dev_id, app_type;
595 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
596 int mode = CAL_MODE_RTAC;
597 struct listnode *node;
598 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700599
600 if (my_data->acdb_send_gain_dep_cal == NULL) {
601 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
602 return ret_val;
603 }
604
605 if (!voice_is_in_call(adev)) {
606 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
607 __func__, level);
608 app_type = DEFAULT_APP_TYPE_RX_PATH;
609
610 // find the current active sound device
611 list_for_each(node, &adev->usecase_list) {
612 usecase = node_to_item(node, struct audio_usecase, list);
613
614 if (usecase != NULL &&
615 usecase->type == PCM_PLAYBACK &&
616 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
617
618 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700619 if (audio_extn_spkr_prot_is_enabled()) {
620 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
621 } else {
622 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
623 }
624
vivek mehta1a9b7c02015-06-25 11:49:38 -0700625 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
626 acdb_dev_type, mode, level)) {
627 // set ret_val true if at least one calibration is set successfully
628 ret_val = true;
629 } else {
630 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
631 }
632 } else {
633 ALOGW("%s: Usecase list is empty", __func__);
634 }
635 }
636 } else {
637 ALOGW("%s: Voice call in progress .. ignore setting new cal",
638 __func__);
639 }
640 return ret_val;
641}
642
Eric Laurentcefbbac2014-09-04 13:54:10 -0500643void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700644{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800645 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500646 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700647
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800648 if (strcmp(my_data->ec_ref_mixer_path, "")) {
649 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
650 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500651 }
652
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800653 if (enable) {
654 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
655 if (out_device != AUDIO_DEVICE_NONE) {
656 snd_device = platform_get_output_snd_device(adev->platform, out_device);
657 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
658 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500659
Joe Onorato188b6222016-03-01 11:02:27 -0800660 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800661 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
662 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700663}
664
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700665static struct csd_data *open_csd_client(bool i2s_ext_modem)
666{
667 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
668
669 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
670 if (csd->csd_client == NULL) {
671 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
672 goto error;
673 } else {
674 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
675
676 csd->deinit = (deinit_t)dlsym(csd->csd_client,
677 "csd_client_deinit");
678 if (csd->deinit == NULL) {
679 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
680 dlerror());
681 goto error;
682 }
683 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
684 "csd_client_disable_device");
685 if (csd->disable_device == NULL) {
686 ALOGE("%s: dlsym error %s for csd_client_disable_device",
687 __func__, dlerror());
688 goto error;
689 }
690 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
691 "csd_client_enable_device_config");
692 if (csd->enable_device_config == NULL) {
693 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
694 __func__, dlerror());
695 goto error;
696 }
697 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
698 "csd_client_enable_device");
699 if (csd->enable_device == NULL) {
700 ALOGE("%s: dlsym error %s for csd_client_enable_device",
701 __func__, dlerror());
702 goto error;
703 }
704 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
705 "csd_client_start_voice");
706 if (csd->start_voice == NULL) {
707 ALOGE("%s: dlsym error %s for csd_client_start_voice",
708 __func__, dlerror());
709 goto error;
710 }
711 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
712 "csd_client_stop_voice");
713 if (csd->stop_voice == NULL) {
714 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
715 __func__, dlerror());
716 goto error;
717 }
718 csd->volume = (volume_t)dlsym(csd->csd_client,
719 "csd_client_volume");
720 if (csd->volume == NULL) {
721 ALOGE("%s: dlsym error %s for csd_client_volume",
722 __func__, dlerror());
723 goto error;
724 }
725 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
726 "csd_client_mic_mute");
727 if (csd->mic_mute == NULL) {
728 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
729 __func__, dlerror());
730 goto error;
731 }
732 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
733 "csd_client_slow_talk");
734 if (csd->slow_talk == NULL) {
735 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
736 __func__, dlerror());
737 goto error;
738 }
739 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
740 "csd_client_start_playback");
741 if (csd->start_playback == NULL) {
742 ALOGE("%s: dlsym error %s for csd_client_start_playback",
743 __func__, dlerror());
744 goto error;
745 }
746 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
747 "csd_client_stop_playback");
748 if (csd->stop_playback == NULL) {
749 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
750 __func__, dlerror());
751 goto error;
752 }
753 csd->start_record = (start_record_t)dlsym(csd->csd_client,
754 "csd_client_start_record");
755 if (csd->start_record == NULL) {
756 ALOGE("%s: dlsym error %s for csd_client_start_record",
757 __func__, dlerror());
758 goto error;
759 }
760 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
761 "csd_client_stop_record");
762 if (csd->stop_record == NULL) {
763 ALOGE("%s: dlsym error %s for csd_client_stop_record",
764 __func__, dlerror());
765 goto error;
766 }
767
768 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
769 "csd_client_get_sample_rate");
770 if (csd->get_sample_rate == NULL) {
771 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
772 __func__, dlerror());
773
774 goto error;
775 }
776
777 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
778
779 if (csd->init == NULL) {
780 ALOGE("%s: dlsym error %s for csd_client_init",
781 __func__, dlerror());
782 goto error;
783 } else {
784 csd->init(i2s_ext_modem);
785 }
786 }
787 return csd;
788
789error:
790 free(csd);
791 csd = NULL;
792 return csd;
793}
794
795void close_csd_client(struct csd_data *csd)
796{
797 if (csd != NULL) {
798 csd->deinit();
799 dlclose(csd->csd_client);
800 free(csd);
801 csd = NULL;
802 }
803}
804
805static void platform_csd_init(struct platform_data *my_data)
806{
807#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700808 int32_t modems, (*count_modems)(void);
809 const char *name = "libdetectmodem.so";
810 const char *func = "count_modems";
811 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700812
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700813 my_data->csd = NULL;
814
815 void *lib = dlopen(name, RTLD_NOW);
816 error = dlerror();
817 if (!lib) {
818 ALOGE("%s: could not find %s: %s", __func__, name, error);
819 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700820 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700821
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700822 count_modems = NULL;
823 *(void **)(&count_modems) = dlsym(lib, func);
824 error = dlerror();
825 if (!count_modems) {
826 ALOGE("%s: could not find symbol %s in %s: %s",
827 __func__, func, name, error);
828 goto done;
829 }
830
831 modems = count_modems();
832 if (modems < 0) {
833 ALOGE("%s: count_modems failed\n", __func__);
834 goto done;
835 }
836
Joe Onorato188b6222016-03-01 11:02:27 -0800837 ALOGV("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700838 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700839 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700840
841done:
842 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700843#else
844 my_data->csd = NULL;
845#endif
846}
847
Eric Laurentc6333382015-09-14 12:43:44 -0700848static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700849{
850 int32_t dev;
851 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700852 backend_tag_table[dev] = NULL;
853 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900854 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700855 }
856
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700857 // To overwrite these go to the audio_platform_info.xml file.
858 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700859 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700860 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
861 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
862 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
863 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
864 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700865 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700866 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
867 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700868
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700869 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
870 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
871 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
872 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
873 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
874 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
875 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700876 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700877 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700878 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700879 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
880 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
881 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
882 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
883 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
884 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
885 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
886 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
887 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
888 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
889 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
890 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
891 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
892 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
893 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
894 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700895
896 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700897}
898
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900899void get_cvd_version(char *cvd_version, struct audio_device *adev)
900{
901 struct mixer_ctl *ctl;
902 int count;
903 int ret = 0;
904
905 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
906 if (!ctl) {
907 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
908 goto done;
909 }
910 mixer_ctl_update(ctl);
911
912 count = mixer_ctl_get_num_values(ctl);
913 if (count > MAX_CVD_VERSION_STRING_SIZE)
914 count = MAX_CVD_VERSION_STRING_SIZE - 1;
915
916 ret = mixer_ctl_get_array(ctl, cvd_version, count);
917 if (ret != 0) {
918 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
919 goto done;
920 }
921
922done:
923 return;
924}
925
Eric Laurentb23d5282013-05-14 15:27:20 -0700926void *platform_init(struct audio_device *adev)
927{
928 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800929 struct platform_data *my_data = NULL;
930 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
931 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700932 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900933 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -0800934 char *snd_internal_name = NULL;
935 char *tmp = NULL;
936 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
Ed Tamb0b0d572016-03-21 10:45:37 -0700937 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
938 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700939 my_data = calloc(1, sizeof(struct platform_data));
940
941 my_data->adev = adev;
942
keunhui.park2f7306a2015-07-16 16:48:06 +0900943 list_init(&operator_info_list);
944
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700945 set_platform_defaults(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
Ed Tamb0b0d572016-03-21 10:45:37 -0700976 set_snd_card_split(snd_card_name);
977 snd_split_handle = get_snd_card_split();
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700978
Ed Tamb0b0d572016-03-21 10:45:37 -0700979 my_data->hw_info = hw_info_init(snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -0800980
Ed Tamb0b0d572016-03-21 10:45:37 -0700981 /* Get the codec internal name from the sound card and/or form factor
982 * name and form the mixer paths and platfor info file name dynamically.
983 * This is generic way of picking any codec and forma factor name based
984 * mixer and platform info files in future with no code change.
985
986 * current code extends and looks for any of the exteneded mixer path and
987 * platform info file present based on codec and form factor.
988
989 * order of picking appropriate file is
990 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
991 * <ii> mixer_paths_<codec_name>.xml, if file not present
992 * <iii> mixer_paths.xml
993
994 * same order is followed for audio_platform_info.xml as well
995 */
996
997 // need to carryforward old file name
998 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
vivek mehta60ea4152016-02-18 17:10:26 -0800999 sizeof(TOMTOM_8226_SND_CARD_NAME))) {
Ed Tamb0b0d572016-03-21 10:45:37 -07001000 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001001 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
Ed Tamb0b0d572016-03-21 10:45:37 -07001002 } else {
vivek mehta62dd1dc2016-03-03 17:23:38 -08001003
Ed Tamb0b0d572016-03-21 10:45:37 -07001004 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1005 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1006 snd_split_handle->form_factor);
1007
1008 if (F_OK != access(mixer_xml_file, 0)) {
1009 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1010 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1011 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1012
1013 if (F_OK != access(mixer_xml_file, 0)) {
1014 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1015 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1016 }
1017 }
1018
1019 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1020 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1021 snd_split_handle->form_factor);
1022
1023 if (F_OK != access(platform_info_file, 0)) {
1024 memset(platform_info_file, 0, sizeof(platform_info_file));
1025 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1026 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1027
1028 if (F_OK != access(platform_info_file, 0)) {
1029 memset(platform_info_file, 0, sizeof(platform_info_file));
1030 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001031 }
1032 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001033 }
1034
Ed Tamb0b0d572016-03-21 10:45:37 -07001035 /* Initialize platform specific ids and/or backends*/
1036 platform_info_init(platform_info_file, my_data);
vivek mehta60ea4152016-02-18 17:10:26 -08001037
1038 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1039 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1040
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001041 if (!adev->audio_route) {
1042 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001043 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001044 }
1045 adev->snd_card = snd_card_num;
Joe Onorato188b6222016-03-01 11:02:27 -08001046 ALOGV("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001047 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001048 }
1049
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001050 if (snd_card_num >= MAX_SND_CARD) {
1051 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001052 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001053 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001054
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001055 //set max volume step for voice call
1056 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1057 my_data->max_vol_index = atoi(value);
1058
vivek mehta65ad12d2015-08-13 18:32:48 -07001059 property_get("persist.audio.dualmic.config",value,"");
1060 if (!strcmp("endfire", value)) {
1061 dual_mic_config = true;
1062 }
1063
Prashant Malanic92c5962015-08-11 15:10:18 -07001064 my_data->source_mic_type = SOURCE_DUAL_MIC;
1065
Eric Laurentb23d5282013-05-14 15:27:20 -07001066 my_data->fluence_in_spkr_mode = false;
1067 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001068 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001069 my_data->fluence_in_voice_rec = false;
1070
vivek mehta65ad12d2015-08-13 18:32:48 -07001071 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001072 if (!strcmp("fluencepro", value)) {
1073 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001074 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001075 my_data->fluence_type = FLUENCE_ENABLE;
1076 } else if (!strcmp("none", value)) {
1077 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001078 }
1079
Prashant Malanic92c5962015-08-11 15:10:18 -07001080 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001081 property_get("persist.audio.fluence.voicecall",value,"");
1082 if (!strcmp("true", value)) {
1083 my_data->fluence_in_voice_call = true;
1084 }
1085
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001086 property_get("persist.audio.fluence.voicecomm",value,"");
1087 if (!strcmp("true", value)) {
1088 my_data->fluence_in_voice_comm = true;
1089 }
1090
Eric Laurentb23d5282013-05-14 15:27:20 -07001091 property_get("persist.audio.fluence.voicerec",value,"");
1092 if (!strcmp("true", value)) {
1093 my_data->fluence_in_voice_rec = true;
1094 }
1095
1096 property_get("persist.audio.fluence.speaker",value,"");
1097 if (!strcmp("true", value)) {
1098 my_data->fluence_in_spkr_mode = true;
1099 }
1100 }
1101
Prashant Malanic92c5962015-08-11 15:10:18 -07001102 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1103 switch (my_data->max_mic_count) {
1104 case 4:
1105 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1106 case 3:
1107 my_data->source_mic_type |= SOURCE_THREE_MIC;
1108 case 2:
1109 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1110 case 1:
1111 my_data->source_mic_type |= SOURCE_MONO_MIC;
1112 break;
1113 default:
1114 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1115 __func__, my_data->max_mic_count);
1116 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1117 break;
1118 }
1119
1120 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1121 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1122 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1123 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1124 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1125
Eric Laurentb23d5282013-05-14 15:27:20 -07001126 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1127 if (my_data->acdb_handle == NULL) {
1128 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1129 } else {
1130 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1131 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1132 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001133 if (!my_data->acdb_deallocate)
1134 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1135 __func__, LIB_ACDB_LOADER);
1136
Eric Laurentb23d5282013-05-14 15:27:20 -07001137 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1138 "acdb_loader_send_audio_cal");
1139 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001140 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001141 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001142
Eric Laurentb23d5282013-05-14 15:27:20 -07001143 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1144 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001145 if (!my_data->acdb_send_voice_cal)
1146 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1147 __func__, LIB_ACDB_LOADER);
1148
1149 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1150 "acdb_loader_reload_vocvoltable");
1151 if (!my_data->acdb_reload_vocvoltable)
1152 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1153 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001154
1155 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1156 "acdb_loader_send_gain_dep_cal");
1157 if (!my_data->acdb_send_gain_dep_cal)
1158 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1159 __func__, LIB_ACDB_LOADER);
1160
vivek mehtac698f132016-02-25 18:50:35 -08001161#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001162 acdb_init_v2_cvd_t acdb_init;
1163 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1164 "acdb_loader_init_v2");
1165 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001166 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001167 goto acdb_init_fail;
1168 }
1169
1170 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1171 get_cvd_version(cvd_version, adev);
1172 if (!cvd_version)
1173 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001174 else
vivek mehtac698f132016-02-25 18:50:35 -08001175 acdb_init((char *)snd_card_name, cvd_version, 0);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001176 free(cvd_version);
1177#elif defined (PLATFORM_MSM8084)
1178 acdb_init_v2_t acdb_init;
1179 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1180 "acdb_loader_init_v2");
1181 if (acdb_init == NULL) {
1182 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1183 goto acdb_init_fail;
1184 }
1185 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001186#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001187 acdb_init_t acdb_init;
1188 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001189 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001190 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001191 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1192 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001193 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001194#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001195 }
1196
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001197acdb_init_fail:
1198
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001199 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001200
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001201 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1202
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001203 /* load csd client */
1204 platform_csd_init(my_data);
1205
Eric Laurentb23d5282013-05-14 15:27:20 -07001206 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001207
1208init_failed:
1209 if (my_data)
1210 free(my_data);
1211 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001212}
1213
1214void platform_deinit(void *platform)
1215{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001216 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001217 struct operator_info *info_item;
1218 struct operator_specific_device *device_item;
1219 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001220
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001221 struct platform_data *my_data = (struct platform_data *)platform;
1222 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001223
Ed Tamb0b0d572016-03-21 10:45:37 -07001224 hw_info_deinit(my_data->hw_info);
1225
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001226 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1227 if (backend_tag_table[dev])
1228 free(backend_tag_table[dev]);
1229 if (hw_interface_table[dev])
1230 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001231 if (operator_specific_device_table[dev]) {
1232 while (!list_empty(operator_specific_device_table[dev])) {
1233 node = list_head(operator_specific_device_table[dev]);
1234 list_remove(node);
1235 device_item = node_to_item(node, struct operator_specific_device, list);
1236 free(device_item->operator);
1237 free(device_item->mixer_path);
1238 free(device_item);
1239 }
1240 free(operator_specific_device_table[dev]);
1241 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001242 }
1243
1244 if (my_data->snd_card_name)
1245 free(my_data->snd_card_name);
1246
keunhui.park2f7306a2015-07-16 16:48:06 +09001247 while (!list_empty(&operator_info_list)) {
1248 node = list_head(&operator_info_list);
1249 list_remove(node);
1250 info_item = node_to_item(node, struct operator_info, list);
1251 free(info_item->name);
1252 free(info_item->mccmnc);
1253 free(info_item);
1254 }
1255
Eric Laurentb23d5282013-05-14 15:27:20 -07001256 free(platform);
1257}
1258
1259const char *platform_get_snd_device_name(snd_device_t snd_device)
1260{
keunhui.park2f7306a2015-07-16 16:48:06 +09001261 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1262 if (operator_specific_device_table[snd_device] != NULL) {
1263 return get_operator_specific_device_mixer_path(snd_device);
1264 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001265 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001266 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001267 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001268}
1269
Ed Tamb0b0d572016-03-21 10:45:37 -07001270int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1271 char *device_name)
1272{
1273 struct platform_data *my_data = (struct platform_data *)platform;
1274
1275 if (platform == NULL || device_name == NULL) {
1276 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
1277 device_name = platform_get_snd_device_name(snd_device);
1278 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1279 if (operator_specific_device_table[snd_device] != NULL) {
1280 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1281 DEVICE_NAME_MAX_SIZE);
1282 } else {
1283 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1284 }
1285 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1286 } else {
1287 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1288 }
1289
1290 return 0;
1291}
1292
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001293void platform_add_backend_name(void *platform, char *mixer_path,
1294 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001295{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001296 struct platform_data *my_data = (struct platform_data *)platform;
1297
Haynes Mathew George98c95622014-06-20 19:14:25 -07001298 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1299 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1300 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001301 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001302
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001303 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001304
1305 if (suffix != NULL) {
1306 strcat(mixer_path, " ");
1307 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001308 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001309}
1310
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001311bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1312{
1313 bool result = true;
1314
1315 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1316 platform_get_snd_device_name(snd_device1),
1317 platform_get_snd_device_name(snd_device2));
1318
1319 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1320 ALOGE("%s: Invalid snd_device = %s", __func__,
1321 platform_get_snd_device_name(snd_device1));
1322 return false;
1323 }
1324 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1325 ALOGE("%s: Invalid snd_device = %s", __func__,
1326 platform_get_snd_device_name(snd_device2));
1327 return false;
1328 }
1329 const char * be_itf1 = hw_interface_table[snd_device1];
1330 const char * be_itf2 = hw_interface_table[snd_device2];
1331
1332 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001333 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001334 result = false;
1335 }
1336
1337 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1338 return result;
1339}
1340
Eric Laurentb23d5282013-05-14 15:27:20 -07001341int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1342{
1343 int device_id;
1344 if (device_type == PCM_PLAYBACK)
1345 device_id = pcm_device_table[usecase][0];
1346 else
1347 device_id = pcm_device_table[usecase][1];
1348 return device_id;
1349}
1350
Haynes Mathew George98c95622014-06-20 19:14:25 -07001351static int find_index(const struct name_to_index * table, int32_t len,
1352 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001353{
1354 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001355 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001356
Haynes Mathew George98c95622014-06-20 19:14:25 -07001357 if (table == NULL) {
1358 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001359 ret = -ENODEV;
1360 goto done;
1361 }
1362
Haynes Mathew George98c95622014-06-20 19:14:25 -07001363 if (name == NULL) {
1364 ALOGE("null key");
1365 ret = -ENODEV;
1366 goto done;
1367 }
1368
1369 for (i=0; i < len; i++) {
1370 if (!strcmp(table[i].name, name)) {
1371 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001372 goto done;
1373 }
1374 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001375 ALOGE("%s: Could not find index for name = %s",
1376 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001377 ret = -ENODEV;
1378done:
1379 return ret;
1380}
1381
Haynes Mathew George98c95622014-06-20 19:14:25 -07001382int platform_get_snd_device_index(char *device_name)
1383{
1384 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1385}
1386
1387int platform_get_usecase_index(const char *usecase_name)
1388{
1389 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1390}
1391
keunhui.park2f7306a2015-07-16 16:48:06 +09001392void platform_add_operator_specific_device(snd_device_t snd_device,
1393 const char *operator,
1394 const char *mixer_path,
1395 unsigned int acdb_id)
1396{
1397 struct operator_specific_device *device;
1398
1399 if (operator_specific_device_table[snd_device] == NULL) {
1400 operator_specific_device_table[snd_device] =
1401 (struct listnode *)calloc(1, sizeof(struct listnode));
1402 list_init(operator_specific_device_table[snd_device]);
1403 }
1404
1405 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1406
1407 device->operator = strdup(operator);
1408 device->mixer_path = strdup(mixer_path);
1409 device->acdb_id = acdb_id;
1410
1411 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1412
Joe Onorato188b6222016-03-01 11:02:27 -08001413 ALOGV("%s : deivce[%s] -> operator[%s] mixer_path[%s] acdb_id [%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001414 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1415
1416}
1417
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001418int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1419{
1420 int ret = 0;
1421
1422 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1423 ALOGE("%s: Invalid snd_device = %d",
1424 __func__, snd_device);
1425 ret = -EINVAL;
1426 goto done;
1427 }
1428
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001429 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1430 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001431 acdb_device_table[snd_device] = acdb_id;
1432done:
1433 return ret;
1434}
1435
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001436int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1437{
1438 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1439 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1440 return -EINVAL;
1441 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001442
1443 if (operator_specific_device_table[snd_device] != NULL)
1444 return get_operator_specific_device_acdb_id(snd_device);
1445 else
1446 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001447}
1448
Eric Laurentb23d5282013-05-14 15:27:20 -07001449int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1450{
1451 struct platform_data *my_data = (struct platform_data *)platform;
1452 int acdb_dev_id, acdb_dev_type;
1453
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001454 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001455 if (acdb_dev_id < 0) {
1456 ALOGE("%s: Could not find acdb id for device(%d)",
1457 __func__, snd_device);
1458 return -EINVAL;
1459 }
1460 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001461 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001462 __func__, snd_device, acdb_dev_id);
1463 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1464 snd_device < SND_DEVICE_OUT_END)
1465 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1466 else
1467 acdb_dev_type = ACDB_DEV_TYPE_IN;
1468 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1469 }
1470 return 0;
1471}
1472
1473int platform_switch_voice_call_device_pre(void *platform)
1474{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001475 struct platform_data *my_data = (struct platform_data *)platform;
1476 int ret = 0;
1477
1478 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001479 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001480 /* This must be called before disabling mixer controls on APQ side */
1481 ret = my_data->csd->disable_device();
1482 if (ret < 0) {
1483 ALOGE("%s: csd_client_disable_device, failed, error %d",
1484 __func__, ret);
1485 }
1486 }
1487 return ret;
1488}
1489
1490int platform_switch_voice_call_enable_device_config(void *platform,
1491 snd_device_t out_snd_device,
1492 snd_device_t in_snd_device)
1493{
1494 struct platform_data *my_data = (struct platform_data *)platform;
1495 int acdb_rx_id, acdb_tx_id;
1496 int ret = 0;
1497
1498 if (my_data->csd == NULL)
1499 return ret;
1500
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001501 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1502 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001503 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001504 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001505 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001506
keunhui.park2f7306a2015-07-16 16:48:06 +09001507 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001508
1509 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1510 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1511 if (ret < 0) {
1512 ALOGE("%s: csd_enable_device_config, failed, error %d",
1513 __func__, ret);
1514 }
1515 } else {
1516 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1517 acdb_rx_id, acdb_tx_id);
1518 }
1519
1520 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001521}
1522
1523int platform_switch_voice_call_device_post(void *platform,
1524 snd_device_t out_snd_device,
1525 snd_device_t in_snd_device)
1526{
1527 struct platform_data *my_data = (struct platform_data *)platform;
1528 int acdb_rx_id, acdb_tx_id;
1529
1530 if (my_data->acdb_send_voice_cal == NULL) {
1531 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1532 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001533 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1534 audio_extn_spkr_prot_is_enabled())
1535 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1536
keunhui.park2f7306a2015-07-16 16:48:06 +09001537 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1538 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001539
1540 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1541 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1542 else
1543 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1544 acdb_rx_id, acdb_tx_id);
1545 }
1546
1547 return 0;
1548}
1549
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001550int platform_switch_voice_call_usecase_route_post(void *platform,
1551 snd_device_t out_snd_device,
1552 snd_device_t in_snd_device)
1553{
1554 struct platform_data *my_data = (struct platform_data *)platform;
1555 int acdb_rx_id, acdb_tx_id;
1556 int ret = 0;
1557
1558 if (my_data->csd == NULL)
1559 return ret;
1560
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001561 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1562 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001563 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001564 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001565 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001566
keunhui.park2f7306a2015-07-16 16:48:06 +09001567 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001568
1569 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1570 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1571 my_data->adev->acdb_settings);
1572 if (ret < 0) {
1573 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1574 }
1575 } else {
1576 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1577 acdb_rx_id, acdb_tx_id);
1578 }
1579
1580 return ret;
1581}
1582
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001583int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001584{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001585 struct platform_data *my_data = (struct platform_data *)platform;
1586 int ret = 0;
1587
1588 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001589 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001590 if (ret < 0) {
1591 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1592 }
1593 }
1594 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001595}
1596
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001597int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001598{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001599 struct platform_data *my_data = (struct platform_data *)platform;
1600 int ret = 0;
1601
1602 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001603 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001604 if (ret < 0) {
1605 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1606 }
1607 }
1608 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001609}
1610
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001611int platform_get_sample_rate(void *platform, uint32_t *rate)
1612{
1613 struct platform_data *my_data = (struct platform_data *)platform;
1614 int ret = 0;
1615
1616 if (my_data->csd != NULL) {
1617 ret = my_data->csd->get_sample_rate(rate);
1618 if (ret < 0) {
1619 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1620 }
1621 }
1622 return ret;
1623}
1624
vivek mehtab6506412015-08-07 16:55:17 -07001625void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1626 snd_device_t snd_device,
1627 bool enable)
1628{
1629 const char* name;
1630 switch (snd_device) {
1631 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1632 if (enable)
1633 name = "spkr-gain-in-headphone-combo";
1634 else
1635 name = "speaker-gain-default";
1636 break;
1637 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1638 if (enable)
1639 name = "spkr-gain-in-line-combo";
1640 else
1641 name = "speaker-gain-default";
1642 break;
1643 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1644 if (enable)
1645 name = "spkr-safe-gain-in-headphone-combo";
1646 else
1647 name = "speaker-safe-gain-default";
1648 break;
1649 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1650 if (enable)
1651 name = "spkr-safe-gain-in-line-combo";
1652 else
1653 name = "speaker-safe-gain-default";
1654 break;
1655 default:
1656 return;
1657 }
1658
1659 audio_route_apply_and_update_path(adev->audio_route, name);
1660}
1661
Eric Laurentb23d5282013-05-14 15:27:20 -07001662int platform_set_voice_volume(void *platform, int volume)
1663{
1664 struct platform_data *my_data = (struct platform_data *)platform;
1665 struct audio_device *adev = my_data->adev;
1666 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001667 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001668 int vol_index = 0, ret = 0;
1669 uint32_t set_values[ ] = {0,
1670 ALL_SESSION_VSID,
1671 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001672
1673 // Voice volume levels are mapped to adsp volume levels as follows.
1674 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1675 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001676 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001677 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001678
1679 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1680 if (!ctl) {
1681 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1682 __func__, mixer_ctl_name);
1683 return -EINVAL;
1684 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001685 ALOGV("Setting voice volume index: %d", set_values[0]);
1686 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1687
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001688 if (my_data->csd != NULL) {
1689 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1690 DEFAULT_VOLUME_RAMP_DURATION_MS);
1691 if (ret < 0) {
1692 ALOGE("%s: csd_volume error %d", __func__, ret);
1693 }
1694 }
1695 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001696}
1697
1698int platform_set_mic_mute(void *platform, bool state)
1699{
1700 struct platform_data *my_data = (struct platform_data *)platform;
1701 struct audio_device *adev = my_data->adev;
1702 struct mixer_ctl *ctl;
1703 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001704 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001705 uint32_t set_values[ ] = {0,
1706 ALL_SESSION_VSID,
1707 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001708
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001709 if (adev->mode != AUDIO_MODE_IN_CALL &&
1710 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001711 return 0;
1712
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001713 if (adev->enable_hfp)
1714 mixer_ctl_name = "HFP Tx Mute";
1715
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001716 set_values[0] = state;
1717 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1718 if (!ctl) {
1719 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1720 __func__, mixer_ctl_name);
1721 return -EINVAL;
1722 }
1723 ALOGV("Setting voice mute state: %d", state);
1724 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1725
1726 if (my_data->csd != NULL) {
1727 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1728 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001729 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001730 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001731 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001732 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001733 return ret;
1734}
Eric Laurentb23d5282013-05-14 15:27:20 -07001735
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001736int platform_set_device_mute(void *platform, bool state, char *dir)
1737{
1738 struct platform_data *my_data = (struct platform_data *)platform;
1739 struct audio_device *adev = my_data->adev;
1740 struct mixer_ctl *ctl;
1741 char *mixer_ctl_name = NULL;
1742 int ret = 0;
1743 uint32_t set_values[ ] = {0,
1744 ALL_SESSION_VSID,
1745 0};
1746 if(dir == NULL) {
1747 ALOGE("%s: Invalid direction:%s", __func__, dir);
1748 return -EINVAL;
1749 }
1750
1751 if (!strncmp("rx", dir, sizeof("rx"))) {
1752 mixer_ctl_name = "Voice Rx Device Mute";
1753 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1754 mixer_ctl_name = "Voice Tx Device Mute";
1755 } else {
1756 return -EINVAL;
1757 }
1758
1759 set_values[0] = state;
1760 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1761 if (!ctl) {
1762 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1763 __func__, mixer_ctl_name);
1764 return -EINVAL;
1765 }
1766
1767 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1768 __func__,state, mixer_ctl_name);
1769 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1770
1771 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001772}
1773
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001774bool platform_can_split_snd_device(snd_device_t snd_device,
1775 int *num_devices,
1776 snd_device_t *new_snd_devices)
1777{
1778 bool status = false;
1779
1780 if (NULL == num_devices || NULL == new_snd_devices) {
1781 ALOGE("%s: NULL pointer ..", __func__);
1782 return false;
1783 }
1784
1785 /*
1786 * If wired headset/headphones/line devices share the same backend
1787 * with speaker/earpiece this routine returns false.
1788 */
1789 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1790 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1791 *num_devices = 2;
1792 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1793 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1794 status = true;
1795 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1796 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1797 *num_devices = 2;
1798 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1799 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1800 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001801 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1802 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1803 *num_devices = 2;
1804 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1805 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1806 status = true;
1807 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1808 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1809 *num_devices = 2;
1810 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1811 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1812 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001813 }
1814 return status;
1815}
1816
Eric Laurentb23d5282013-05-14 15:27:20 -07001817snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1818{
1819 struct platform_data *my_data = (struct platform_data *)platform;
1820 struct audio_device *adev = my_data->adev;
1821 audio_mode_t mode = adev->mode;
1822 snd_device_t snd_device = SND_DEVICE_NONE;
1823
1824 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1825 if (devices == AUDIO_DEVICE_NONE ||
1826 devices & AUDIO_DEVICE_BIT_IN) {
1827 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1828 goto exit;
1829 }
1830
Eric Laurent1b491552015-09-15 17:52:41 -07001831 if (popcount(devices) == 2) {
1832 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1833 AUDIO_DEVICE_OUT_SPEAKER) ||
1834 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1835 AUDIO_DEVICE_OUT_SPEAKER)) {
1836 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1837 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1838 AUDIO_DEVICE_OUT_SPEAKER)) {
1839 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1840 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1841 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1842 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1843 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1844 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1845 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1846 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1847 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1848 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1849 AUDIO_DEVICE_OUT_SPEAKER)) {
1850 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1851 } else {
1852 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1853 goto exit;
1854 }
1855 if (snd_device != SND_DEVICE_NONE) {
1856 goto exit;
1857 }
1858 }
1859
1860 if (popcount(devices) != 1) {
1861 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1862 goto exit;
1863 }
1864
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001865 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001866 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001867 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1868 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001869 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001870 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001871 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001872 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001873 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001874 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001875 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001876 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001877 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001878 else {
1879 if (devices & AUDIO_DEVICE_OUT_LINE)
1880 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1881 else
1882 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1883 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001884 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001885 if (adev->bt_wb_speech_enabled) {
1886 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1887 } else {
1888 snd_device = SND_DEVICE_OUT_BT_SCO;
1889 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001890 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001891 if (!adev->enable_hfp) {
1892 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1893 } else {
1894 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1895 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001896 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001897 if(adev->voice.hac)
1898 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1899 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001900 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1901 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001902 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001903 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1904 snd_device = SND_DEVICE_OUT_VOICE_TX;
1905
Eric Laurentb23d5282013-05-14 15:27:20 -07001906 if (snd_device != SND_DEVICE_NONE) {
1907 goto exit;
1908 }
1909 }
1910
Eric Laurentb23d5282013-05-14 15:27:20 -07001911 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1912 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1913 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001914 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1915 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001916 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1917 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001918 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001919 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001920 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1921 else
1922 snd_device = SND_DEVICE_OUT_SPEAKER;
1923 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001924 if (adev->bt_wb_speech_enabled) {
1925 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1926 } else {
1927 snd_device = SND_DEVICE_OUT_BT_SCO;
1928 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001929 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1930 snd_device = SND_DEVICE_OUT_HDMI ;
1931 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001932 /*HAC support for voice-ish audio (eg visual voicemail)*/
1933 if(adev->voice.hac)
1934 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1935 else
1936 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001937 } else {
1938 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1939 }
1940exit:
1941 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1942 return snd_device;
1943}
1944
1945snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1946{
1947 struct platform_data *my_data = (struct platform_data *)platform;
1948 struct audio_device *adev = my_data->adev;
1949 audio_source_t source = (adev->active_input == NULL) ?
1950 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1951
1952 audio_mode_t mode = adev->mode;
1953 audio_devices_t in_device = ((adev->active_input == NULL) ?
1954 AUDIO_DEVICE_NONE : adev->active_input->device)
1955 & ~AUDIO_DEVICE_BIT_IN;
1956 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1957 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1958 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001959 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001960
Prashant Malanic92c5962015-08-11 15:10:18 -07001961 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1962 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001963 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001964 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001965 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001966 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1967 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001968 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001969 case TTY_MODE_FULL:
1970 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1971 break;
1972 case TTY_MODE_VCO:
1973 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1974 break;
1975 case TTY_MODE_HCO:
1976 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1977 break;
1978 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001979 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001980 }
1981 goto exit;
1982 }
1983 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001984 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001985 if (my_data->fluence_in_voice_call == false) {
1986 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1987 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001988 if (is_operator_tmus())
1989 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001990 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001991 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001992 }
1993 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1994 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1995 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001996 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001997 if (adev->bluetooth_nrec)
1998 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1999 else
2000 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002001 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002002 if (adev->bluetooth_nrec)
2003 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2004 else
2005 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002006 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002007 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002008 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2009 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2010 out_device & AUDIO_DEVICE_OUT_LINE) {
2011 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2012 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2013 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2014 } else {
2015 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2016 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002017 }
vivek mehtafe121d52015-08-10 23:39:23 -07002018
2019 //select default
2020 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002021 if (!adev->enable_hfp) {
2022 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2023 } else {
2024 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2025 platform_set_echo_reference(adev, true, out_device);
2026 }
vivek mehtafe121d52015-08-10 23:39:23 -07002027 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002028 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002029 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002030 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002031 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2032 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2033 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2034 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2035 }
2036 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2037 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002038 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2039 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2040 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2041 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
2042 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2043 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2044 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
2045 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2046 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2047 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002048 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002049 }
2050 platform_set_echo_reference(adev, true, out_device);
2051 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2052 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2053 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2054 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2055 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2056 snd_device = SND_DEVICE_IN_THREE_MIC;
2057 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2058 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2059 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002060 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002061 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002062 if (adev->active_input->enable_ns)
2063 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2064 else
2065 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002066 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002067 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2068 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002069 }
rago90fb9612015-12-02 11:37:53 -08002070 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2071 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2072 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2073 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2074 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2075 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002076 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002077 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002078 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002079 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2080 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002081 if (adev->active_input->enable_aec &&
2082 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002083 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002084 if (my_data->fluence_in_spkr_mode &&
2085 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002086 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002087 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002088 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002089 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002090 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002091 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002092 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002093 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002094 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002095 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002096 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002097 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002098 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2099 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002100 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002101 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002102 } else if (adev->active_input->enable_aec) {
2103 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2104 if (my_data->fluence_in_spkr_mode &&
2105 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002106 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002107 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002108 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002109 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002110 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002111 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2112 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002113 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002114 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002115 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002116 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002117 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002118 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2119 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2120 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002121 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002122 } else if (adev->active_input->enable_ns) {
2123 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2124 if (my_data->fluence_in_spkr_mode &&
2125 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002126 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002127 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002128 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002129 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002130 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002131 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2132 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002133 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002134 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002135 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002136 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002137 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002138 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002139 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002140 }
2141 } else if (source == AUDIO_SOURCE_DEFAULT) {
2142 goto exit;
2143 }
2144
2145
2146 if (snd_device != SND_DEVICE_NONE) {
2147 goto exit;
2148 }
2149
2150 if (in_device != AUDIO_DEVICE_NONE &&
2151 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2152 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2153 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002154 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2155 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2156 snd_device = SND_DEVICE_IN_QUAD_MIC;
2157 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2158 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2159 snd_device = SND_DEVICE_IN_THREE_MIC;
2160 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2161 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002162 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002163 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2164 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002165 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002166 } else {
2167 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2168 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2169 my_data->source_mic_type, channel_count, channel_mask);
2170 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2171 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002172 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002173 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2174 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002175 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002176 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2177 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002178 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002179 } else {
2180 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2181 " no combination found .. setting to mono", __func__,
2182 my_data->source_mic_type, channel_count);
2183 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2184 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002185 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2186 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2187 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002188 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002189 if (adev->bluetooth_nrec)
2190 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2191 else
2192 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002193 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002194 if (adev->bluetooth_nrec)
2195 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2196 else
2197 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002198 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002199 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2200 snd_device = SND_DEVICE_IN_HDMI_MIC;
2201 } else {
2202 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2203 ALOGW("%s: Using default handset-mic", __func__);
2204 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2205 }
2206 } else {
2207 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2208 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2209 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2210 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002211 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002212 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002213 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002214 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002215 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2216 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002217 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002218 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2219 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002220 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002221 } else {
2222 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2223 " no combination found .. setting to mono", __func__,
2224 my_data->source_mic_type, channel_count);
2225 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2226 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002227 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002228 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002229 if (adev->bluetooth_nrec)
2230 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2231 else
2232 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002233 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002234 if (adev->bluetooth_nrec)
2235 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2236 else
2237 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002238 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002239 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2240 snd_device = SND_DEVICE_IN_HDMI_MIC;
2241 } else {
2242 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2243 ALOGW("%s: Using default handset-mic", __func__);
2244 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2245 }
2246 }
2247exit:
2248 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2249 return snd_device;
2250}
2251
2252int platform_set_hdmi_channels(void *platform, int channel_count)
2253{
2254 struct platform_data *my_data = (struct platform_data *)platform;
2255 struct audio_device *adev = my_data->adev;
2256 struct mixer_ctl *ctl;
2257 const char *channel_cnt_str = NULL;
2258 const char *mixer_ctl_name = "HDMI_RX Channels";
2259 switch (channel_count) {
2260 case 8:
2261 channel_cnt_str = "Eight"; break;
2262 case 7:
2263 channel_cnt_str = "Seven"; break;
2264 case 6:
2265 channel_cnt_str = "Six"; break;
2266 case 5:
2267 channel_cnt_str = "Five"; break;
2268 case 4:
2269 channel_cnt_str = "Four"; break;
2270 case 3:
2271 channel_cnt_str = "Three"; break;
2272 default:
2273 channel_cnt_str = "Two"; break;
2274 }
2275 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2276 if (!ctl) {
2277 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2278 __func__, mixer_ctl_name);
2279 return -EINVAL;
2280 }
2281 ALOGV("HDMI channel count: %s", channel_cnt_str);
2282 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2283 return 0;
2284}
2285
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002286int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002287{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002288 struct platform_data *my_data = (struct platform_data *)platform;
2289 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002290 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2291 char *sad = block;
2292 int num_audio_blocks;
2293 int channel_count;
2294 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002295 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002296
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002297 struct mixer_ctl *ctl;
2298
2299 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2300 if (!ctl) {
2301 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2302 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002303 return 0;
2304 }
2305
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002306 mixer_ctl_update(ctl);
2307
2308 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002309
2310 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002311 if (count > (int)sizeof(block))
2312 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002313
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002314 ret = mixer_ctl_get_array(ctl, block, count);
2315 if (ret != 0) {
2316 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2317 return 0;
2318 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002319
2320 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002321 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002322
2323 for (i = 0; i < num_audio_blocks; i++) {
2324 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002325 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2326 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002327 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002328 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002329
2330 channel_count = (sad[0] & 0x7) + 1;
2331 if (channel_count > max_channels)
2332 max_channels = channel_count;
2333
2334 /* Advance to next block */
2335 sad += 3;
2336 }
2337
2338 return max_channels;
2339}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002340
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002341int platform_set_incall_recording_session_id(void *platform,
2342 uint32_t session_id, int rec_mode)
2343{
2344 int ret = 0;
2345 struct platform_data *my_data = (struct platform_data *)platform;
2346 struct audio_device *adev = my_data->adev;
2347 struct mixer_ctl *ctl;
2348 const char *mixer_ctl_name = "Voc VSID";
2349 int num_ctl_values;
2350 int i;
2351
2352 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2353 if (!ctl) {
2354 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2355 __func__, mixer_ctl_name);
2356 ret = -EINVAL;
2357 } else {
2358 num_ctl_values = mixer_ctl_get_num_values(ctl);
2359 for (i = 0; i < num_ctl_values; i++) {
2360 if (mixer_ctl_set_value(ctl, i, session_id)) {
2361 ALOGV("Error: invalid session_id: %x", session_id);
2362 ret = -EINVAL;
2363 break;
2364 }
2365 }
2366 }
2367
2368 if (my_data->csd != NULL) {
2369 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2370 if (ret < 0) {
2371 ALOGE("%s: csd_client_start_record failed, error %d",
2372 __func__, ret);
2373 }
2374 }
2375
2376 return ret;
2377}
2378
2379int platform_stop_incall_recording_usecase(void *platform)
2380{
2381 int ret = 0;
2382 struct platform_data *my_data = (struct platform_data *)platform;
2383
2384 if (my_data->csd != NULL) {
2385 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2386 if (ret < 0) {
2387 ALOGE("%s: csd_client_stop_record failed, error %d",
2388 __func__, ret);
2389 }
2390 }
2391
2392 return ret;
2393}
2394
2395int platform_start_incall_music_usecase(void *platform)
2396{
2397 int ret = 0;
2398 struct platform_data *my_data = (struct platform_data *)platform;
2399
2400 if (my_data->csd != NULL) {
2401 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2402 if (ret < 0) {
2403 ALOGE("%s: csd_client_start_playback failed, error %d",
2404 __func__, ret);
2405 }
2406 }
2407
2408 return ret;
2409}
2410
2411int platform_stop_incall_music_usecase(void *platform)
2412{
2413 int ret = 0;
2414 struct platform_data *my_data = (struct platform_data *)platform;
2415
2416 if (my_data->csd != NULL) {
2417 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2418 if (ret < 0) {
2419 ALOGE("%s: csd_client_stop_playback failed, error %d",
2420 __func__, ret);
2421 }
2422 }
2423
2424 return ret;
2425}
2426
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002427int platform_set_parameters(void *platform, struct str_parms *parms)
2428{
2429 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002430 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002431 char *kv_pairs = str_parms_to_str(parms);
2432 int ret = 0, err;
2433
2434 if (kv_pairs == NULL) {
2435 ret = -EINVAL;
2436 ALOGE("%s: key-value pair is NULL",__func__);
2437 goto done;
2438 }
2439
2440 ALOGV("%s: enter: %s", __func__, kv_pairs);
2441
2442 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2443 value, sizeof(value));
2444 if (err >= 0) {
2445 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2446 my_data->snd_card_name = strdup(value);
2447 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2448 }
2449
keunhui.park2f7306a2015-07-16 16:48:06 +09002450 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2451 value, sizeof(value));
2452 if (err >= 0) {
2453 struct operator_info *info;
2454 char *str = value;
2455 char *name;
2456
2457 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2458 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2459 name = strtok(str, ";");
2460 info->name = strdup(name);
2461 info->mccmnc = strdup(str + strlen(name) + 1);
2462
2463 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002464 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002465 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002466
2467 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002468 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002469 value, sizeof(value));
2470 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002471 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002472 my_data->max_mic_count = atoi(value);
2473 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002474 }
2475
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002476done:
2477 ALOGV("%s: exit with code(%d)", __func__, ret);
2478 if (kv_pairs != NULL)
2479 free(kv_pairs);
2480
2481 return ret;
2482}
2483
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002484/* Delay in Us */
2485int64_t platform_render_latency(audio_usecase_t usecase)
2486{
2487 switch (usecase) {
2488 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2489 return DEEP_BUFFER_PLATFORM_DELAY;
2490 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2491 return LOW_LATENCY_PLATFORM_DELAY;
2492 default:
2493 return 0;
2494 }
2495}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002496
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002497int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2498 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002499{
2500 int ret = 0;
2501
2502 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2503 ALOGE("%s: Invalid snd_device = %d",
2504 __func__, device);
2505 ret = -EINVAL;
2506 goto done;
2507 }
2508
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002509 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2510 platform_get_snd_device_name(device),
2511 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2512 if (backend_tag_table[device]) {
2513 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002514 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002515 backend_tag_table[device] = strdup(backend_tag);
2516
2517 if (hw_interface != NULL) {
2518 if (hw_interface_table[device])
2519 free(hw_interface_table[device]);
2520 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2521 hw_interface_table[device] = strdup(hw_interface);
2522 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002523done:
2524 return ret;
2525}
2526
2527int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2528{
2529 int ret = 0;
2530 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2531 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2532 ret = -EINVAL;
2533 goto done;
2534 }
2535
2536 if ((type != 0) && (type != 1)) {
2537 ALOGE("%s: invalid usecase type", __func__);
2538 ret = -EINVAL;
2539 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002540 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002541 pcm_device_table[usecase][type] = pcm_id;
2542done:
2543 return ret;
2544}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002545
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002546#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2547int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2548 // backup_gain: gain to try to set in case of an error during ramp
2549 int start_gain, end_gain, step, backup_gain, i;
2550 bool error = false;
2551 const struct mixer_ctl *ctl;
2552 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2553 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2554 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2555 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2556 if (!ctl_left || !ctl_right) {
2557 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2558 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2559 return -EINVAL;
2560 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2561 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2562 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2563 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2564 return -EINVAL;
2565 }
2566 if (ramp_up) {
2567 start_gain = 0;
2568 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2569 step = +1;
2570 backup_gain = end_gain;
2571 } else {
2572 // using same gain on left and right
2573 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2574 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2575 end_gain = 0;
2576 step = -1;
2577 backup_gain = start_gain;
2578 }
2579 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2580 //ALOGV("setting speaker gain to %d", i);
2581 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2582 ALOGE("%s: error setting %s to %d during gain ramp",
2583 __func__, mixer_ctl_name_gain_left, i);
2584 error = true;
2585 break;
2586 }
2587 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2588 ALOGE("%s: error setting %s to %d during gain ramp",
2589 __func__, mixer_ctl_name_gain_right, i);
2590 error = true;
2591 break;
2592 }
2593 usleep(1000);
2594 }
2595 if (error) {
2596 // an error occured during the ramp, let's still try to go back to a safe volume
2597 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2598 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2599 }
2600 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2601 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2602 }
2603 }
2604 return start_gain;
2605}
2606
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002607int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2608{
2609 // only update if there is active pcm playback on speaker
2610 struct audio_usecase *usecase;
2611 struct listnode *node;
2612 struct platform_data *my_data = (struct platform_data *)adev->platform;
2613
2614 if (my_data->speaker_lr_swap != swap_channels) {
2615 my_data->speaker_lr_swap = swap_channels;
2616
2617 list_for_each(node, &adev->usecase_list) {
2618 usecase = node_to_item(node, struct audio_usecase, list);
2619 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002620 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2621 /*
2622 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2623 * to perform device switch to disable the current backend to
2624 * enable it with new acdb data.
2625 */
2626 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2627 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002628 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002629 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002630 if (initial_skpr_gain != -EINVAL) {
2631 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2632 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002633 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002634 const char *mixer_path;
2635 if (swap_channels) {
2636 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2637 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2638 } else {
2639 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2640 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2641 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002642 }
2643 break;
2644 }
2645 }
2646 }
2647 return 0;
2648}