blob: 4af0c045df2c4496c854d7cf7f884cf78cba2b91 [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;
vivek mehtade4849c2016-03-03 17:23:38 -0800132
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);
Eric Laurent2bafff12016-03-17 12:17:23 -0700494 ALOGD("%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
Eric Laurent2bafff12016-03-17 12:17:23 -0700837 ALOGD("%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};
vivek mehtade4849c2016-03-03 17:23:38 -0800937 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);
vivek mehtade4849c2016-03-03 17:23:38 -0800965 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700966
vivek mehtade4849c2016-03-03 17:23:38 -0800967 audio_extn_set_snd_card_split(snd_card_name);
968 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700969
vivek mehtade4849c2016-03-03 17:23:38 -0800970 /* Get the codec internal name from the sound card and/or form factor
971 * name and form the mixer paths and platfor info file name dynamically.
972 * This is generic way of picking any codec and forma factor name based
973 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700974
vivek mehtade4849c2016-03-03 17:23:38 -0800975 * current code extends and looks for any of the exteneded mixer path and
976 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -0800977
vivek mehtade4849c2016-03-03 17:23:38 -0800978 * order of picking appropriate file is
979 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
980 * <ii> mixer_paths_<codec_name>.xml, if file not present
981 * <iii> mixer_paths.xml
982
983 * same order is followed for audio_platform_info.xml as well
984 */
985
986 // need to carryforward old file name
987 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
vivek mehta60ea4152016-02-18 17:10:26 -0800988 sizeof(TOMTOM_8226_SND_CARD_NAME))) {
vivek mehtade4849c2016-03-03 17:23:38 -0800989 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -0800990 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -0800991 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -0700992
vivek mehtade4849c2016-03-03 17:23:38 -0800993 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
994 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
995 snd_split_handle->form_factor);
996
997 if (F_OK != access(mixer_xml_file, 0)) {
998 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
999 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1000 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1001
1002 if (F_OK != access(mixer_xml_file, 0)) {
1003 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1004 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1005 }
1006 }
1007
1008 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1009 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1010 snd_split_handle->form_factor);
1011
1012 if (F_OK != access(platform_info_file, 0)) {
1013 memset(platform_info_file, 0, sizeof(platform_info_file));
1014 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1015 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1016
1017 if (F_OK != access(platform_info_file, 0)) {
1018 memset(platform_info_file, 0, sizeof(platform_info_file));
1019 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001020 }
1021 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001022 }
1023
vivek mehtade4849c2016-03-03 17:23:38 -08001024 /* Initialize platform specific ids and/or backends*/
1025 platform_info_init(platform_info_file, my_data);
1026
1027 /* validate the sound card name
1028 * my_data->snd_card_name can contain
1029 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1030 * example: msm8994-tomtom-mtp-snd-card
1031 * <b> or sub string of the card name, i.e. <device>-<codec>
1032 * example: msm8994-tomtom
1033 * so use length of my_data->snd_card_name for comparision
1034 */
1035
1036 if (my_data->snd_card_name != NULL &&
1037 strncmp(snd_card_name, my_data->snd_card_name, strlen(my_data->snd_card_name)) != 0) {
1038 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1039 __func__, snd_card_name, my_data->snd_card_name);
1040 retry_num = 0;
1041 snd_card_num++;
1042 hw_info_deinit(my_data->hw_info);
1043 my_data->hw_info = NULL;
1044 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001045 }
vivek mehtade4849c2016-03-03 17:23:38 -08001046 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1047 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001048
1049 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1050 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1051
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001052 if (!adev->audio_route) {
1053 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001054 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001055 }
1056 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001057 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001058 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001059 }
1060
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001061 if (snd_card_num >= MAX_SND_CARD) {
1062 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001063 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001064 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001065
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001066 //set max volume step for voice call
1067 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1068 my_data->max_vol_index = atoi(value);
1069
vivek mehta65ad12d2015-08-13 18:32:48 -07001070 property_get("persist.audio.dualmic.config",value,"");
1071 if (!strcmp("endfire", value)) {
1072 dual_mic_config = true;
1073 }
1074
Prashant Malanic92c5962015-08-11 15:10:18 -07001075 my_data->source_mic_type = SOURCE_DUAL_MIC;
1076
Eric Laurentb23d5282013-05-14 15:27:20 -07001077 my_data->fluence_in_spkr_mode = false;
1078 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001079 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001080 my_data->fluence_in_voice_rec = false;
1081
vivek mehta65ad12d2015-08-13 18:32:48 -07001082 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001083 if (!strcmp("fluencepro", value)) {
1084 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001085 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001086 my_data->fluence_type = FLUENCE_ENABLE;
1087 } else if (!strcmp("none", value)) {
1088 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001089 }
1090
Prashant Malanic92c5962015-08-11 15:10:18 -07001091 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001092 property_get("persist.audio.fluence.voicecall",value,"");
1093 if (!strcmp("true", value)) {
1094 my_data->fluence_in_voice_call = true;
1095 }
1096
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001097 property_get("persist.audio.fluence.voicecomm",value,"");
1098 if (!strcmp("true", value)) {
1099 my_data->fluence_in_voice_comm = true;
1100 }
1101
Eric Laurentb23d5282013-05-14 15:27:20 -07001102 property_get("persist.audio.fluence.voicerec",value,"");
1103 if (!strcmp("true", value)) {
1104 my_data->fluence_in_voice_rec = true;
1105 }
1106
1107 property_get("persist.audio.fluence.speaker",value,"");
1108 if (!strcmp("true", value)) {
1109 my_data->fluence_in_spkr_mode = true;
1110 }
1111 }
1112
Prashant Malanic92c5962015-08-11 15:10:18 -07001113 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1114 switch (my_data->max_mic_count) {
1115 case 4:
1116 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1117 case 3:
1118 my_data->source_mic_type |= SOURCE_THREE_MIC;
1119 case 2:
1120 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1121 case 1:
1122 my_data->source_mic_type |= SOURCE_MONO_MIC;
1123 break;
1124 default:
1125 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1126 __func__, my_data->max_mic_count);
1127 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1128 break;
1129 }
1130
1131 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1132 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1133 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1134 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1135 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1136
Eric Laurentb23d5282013-05-14 15:27:20 -07001137 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1138 if (my_data->acdb_handle == NULL) {
1139 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1140 } else {
1141 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1142 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1143 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001144 if (!my_data->acdb_deallocate)
1145 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1146 __func__, LIB_ACDB_LOADER);
1147
Eric Laurentb23d5282013-05-14 15:27:20 -07001148 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1149 "acdb_loader_send_audio_cal");
1150 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001151 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001152 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001153
Eric Laurentb23d5282013-05-14 15:27:20 -07001154 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1155 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001156 if (!my_data->acdb_send_voice_cal)
1157 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1158 __func__, LIB_ACDB_LOADER);
1159
1160 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1161 "acdb_loader_reload_vocvoltable");
1162 if (!my_data->acdb_reload_vocvoltable)
1163 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1164 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001165
1166 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1167 "acdb_loader_send_gain_dep_cal");
1168 if (!my_data->acdb_send_gain_dep_cal)
1169 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1170 __func__, LIB_ACDB_LOADER);
1171
vivek mehtac698f132016-02-25 18:50:35 -08001172#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001173 acdb_init_v2_cvd_t acdb_init;
1174 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1175 "acdb_loader_init_v2");
1176 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001177 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001178 goto acdb_init_fail;
1179 }
1180
1181 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1182 get_cvd_version(cvd_version, adev);
1183 if (!cvd_version)
1184 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001185 else
vivek mehtac698f132016-02-25 18:50:35 -08001186 acdb_init((char *)snd_card_name, cvd_version, 0);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001187 free(cvd_version);
1188#elif defined (PLATFORM_MSM8084)
1189 acdb_init_v2_t acdb_init;
1190 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1191 "acdb_loader_init_v2");
1192 if (acdb_init == NULL) {
1193 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1194 goto acdb_init_fail;
1195 }
1196 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001197#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001198 acdb_init_t acdb_init;
1199 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001200 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001201 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001202 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1203 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001204 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001205#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001206 }
1207
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001208acdb_init_fail:
1209
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001210 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001211
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001212 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1213
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001214 /* load csd client */
1215 platform_csd_init(my_data);
1216
Eric Laurentb23d5282013-05-14 15:27:20 -07001217 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001218
1219init_failed:
1220 if (my_data)
1221 free(my_data);
1222 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001223}
1224
1225void platform_deinit(void *platform)
1226{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001227 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001228 struct operator_info *info_item;
1229 struct operator_specific_device *device_item;
1230 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001231
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001232 struct platform_data *my_data = (struct platform_data *)platform;
1233 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001234
vivek mehtade4849c2016-03-03 17:23:38 -08001235 hw_info_deinit(my_data->hw_info);
1236
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001237 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1238 if (backend_tag_table[dev])
1239 free(backend_tag_table[dev]);
1240 if (hw_interface_table[dev])
1241 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001242 if (operator_specific_device_table[dev]) {
1243 while (!list_empty(operator_specific_device_table[dev])) {
1244 node = list_head(operator_specific_device_table[dev]);
1245 list_remove(node);
1246 device_item = node_to_item(node, struct operator_specific_device, list);
1247 free(device_item->operator);
1248 free(device_item->mixer_path);
1249 free(device_item);
1250 }
1251 free(operator_specific_device_table[dev]);
1252 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001253 }
1254
1255 if (my_data->snd_card_name)
1256 free(my_data->snd_card_name);
1257
keunhui.park2f7306a2015-07-16 16:48:06 +09001258 while (!list_empty(&operator_info_list)) {
1259 node = list_head(&operator_info_list);
1260 list_remove(node);
1261 info_item = node_to_item(node, struct operator_info, list);
1262 free(info_item->name);
1263 free(info_item->mccmnc);
1264 free(info_item);
1265 }
1266
Eric Laurentb23d5282013-05-14 15:27:20 -07001267 free(platform);
1268}
1269
1270const char *platform_get_snd_device_name(snd_device_t snd_device)
1271{
keunhui.park2f7306a2015-07-16 16:48:06 +09001272 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1273 if (operator_specific_device_table[snd_device] != NULL) {
1274 return get_operator_specific_device_mixer_path(snd_device);
1275 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001276 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001277 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001278 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001279}
1280
vivek mehtade4849c2016-03-03 17:23:38 -08001281int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1282 char *device_name)
1283{
1284 struct platform_data *my_data = (struct platform_data *)platform;
1285
1286 if (platform == NULL || device_name == NULL) {
1287 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
1288 device_name = platform_get_snd_device_name(snd_device);
1289 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1290 if (operator_specific_device_table[snd_device] != NULL) {
1291 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1292 DEVICE_NAME_MAX_SIZE);
1293 } else {
1294 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1295 }
1296 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1297 } else {
1298 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1299 }
1300
1301 return 0;
1302}
1303
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001304void platform_add_backend_name(void *platform, char *mixer_path,
1305 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001306{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001307 struct platform_data *my_data = (struct platform_data *)platform;
1308
Haynes Mathew George98c95622014-06-20 19:14:25 -07001309 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1310 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1311 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001312 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001313
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001314 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001315
1316 if (suffix != NULL) {
1317 strcat(mixer_path, " ");
1318 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001319 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001320}
1321
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001322bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1323{
1324 bool result = true;
1325
1326 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1327 platform_get_snd_device_name(snd_device1),
1328 platform_get_snd_device_name(snd_device2));
1329
1330 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1331 ALOGE("%s: Invalid snd_device = %s", __func__,
1332 platform_get_snd_device_name(snd_device1));
1333 return false;
1334 }
1335 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1336 ALOGE("%s: Invalid snd_device = %s", __func__,
1337 platform_get_snd_device_name(snd_device2));
1338 return false;
1339 }
1340 const char * be_itf1 = hw_interface_table[snd_device1];
1341 const char * be_itf2 = hw_interface_table[snd_device2];
1342
1343 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001344 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001345 result = false;
1346 }
1347
1348 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1349 return result;
1350}
1351
Eric Laurentb23d5282013-05-14 15:27:20 -07001352int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1353{
1354 int device_id;
1355 if (device_type == PCM_PLAYBACK)
1356 device_id = pcm_device_table[usecase][0];
1357 else
1358 device_id = pcm_device_table[usecase][1];
1359 return device_id;
1360}
1361
Haynes Mathew George98c95622014-06-20 19:14:25 -07001362static int find_index(const struct name_to_index * table, int32_t len,
1363 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001364{
1365 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001366 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001367
Haynes Mathew George98c95622014-06-20 19:14:25 -07001368 if (table == NULL) {
1369 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001370 ret = -ENODEV;
1371 goto done;
1372 }
1373
Haynes Mathew George98c95622014-06-20 19:14:25 -07001374 if (name == NULL) {
1375 ALOGE("null key");
1376 ret = -ENODEV;
1377 goto done;
1378 }
1379
1380 for (i=0; i < len; i++) {
1381 if (!strcmp(table[i].name, name)) {
1382 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001383 goto done;
1384 }
1385 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001386 ALOGE("%s: Could not find index for name = %s",
1387 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001388 ret = -ENODEV;
1389done:
1390 return ret;
1391}
1392
Haynes Mathew George98c95622014-06-20 19:14:25 -07001393int platform_get_snd_device_index(char *device_name)
1394{
1395 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1396}
1397
1398int platform_get_usecase_index(const char *usecase_name)
1399{
1400 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1401}
1402
keunhui.park2f7306a2015-07-16 16:48:06 +09001403void platform_add_operator_specific_device(snd_device_t snd_device,
1404 const char *operator,
1405 const char *mixer_path,
1406 unsigned int acdb_id)
1407{
1408 struct operator_specific_device *device;
1409
1410 if (operator_specific_device_table[snd_device] == NULL) {
1411 operator_specific_device_table[snd_device] =
1412 (struct listnode *)calloc(1, sizeof(struct listnode));
1413 list_init(operator_specific_device_table[snd_device]);
1414 }
1415
1416 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1417
1418 device->operator = strdup(operator);
1419 device->mixer_path = strdup(mixer_path);
1420 device->acdb_id = acdb_id;
1421
1422 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1423
Eric Laurent2bafff12016-03-17 12:17:23 -07001424 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001425 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1426
1427}
1428
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001429int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1430{
1431 int ret = 0;
1432
1433 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1434 ALOGE("%s: Invalid snd_device = %d",
1435 __func__, snd_device);
1436 ret = -EINVAL;
1437 goto done;
1438 }
1439
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001440 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1441 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001442 acdb_device_table[snd_device] = acdb_id;
1443done:
1444 return ret;
1445}
1446
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001447int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1448{
1449 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1450 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1451 return -EINVAL;
1452 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001453
1454 if (operator_specific_device_table[snd_device] != NULL)
1455 return get_operator_specific_device_acdb_id(snd_device);
1456 else
1457 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001458}
1459
Eric Laurentb23d5282013-05-14 15:27:20 -07001460int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1461{
1462 struct platform_data *my_data = (struct platform_data *)platform;
1463 int acdb_dev_id, acdb_dev_type;
1464
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001465 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001466 if (acdb_dev_id < 0) {
1467 ALOGE("%s: Could not find acdb id for device(%d)",
1468 __func__, snd_device);
1469 return -EINVAL;
1470 }
1471 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001472 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001473 __func__, snd_device, acdb_dev_id);
1474 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1475 snd_device < SND_DEVICE_OUT_END)
1476 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1477 else
1478 acdb_dev_type = ACDB_DEV_TYPE_IN;
1479 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1480 }
1481 return 0;
1482}
1483
1484int platform_switch_voice_call_device_pre(void *platform)
1485{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001486 struct platform_data *my_data = (struct platform_data *)platform;
1487 int ret = 0;
1488
1489 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001490 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001491 /* This must be called before disabling mixer controls on APQ side */
1492 ret = my_data->csd->disable_device();
1493 if (ret < 0) {
1494 ALOGE("%s: csd_client_disable_device, failed, error %d",
1495 __func__, ret);
1496 }
1497 }
1498 return ret;
1499}
1500
1501int platform_switch_voice_call_enable_device_config(void *platform,
1502 snd_device_t out_snd_device,
1503 snd_device_t in_snd_device)
1504{
1505 struct platform_data *my_data = (struct platform_data *)platform;
1506 int acdb_rx_id, acdb_tx_id;
1507 int ret = 0;
1508
1509 if (my_data->csd == NULL)
1510 return ret;
1511
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001512 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1513 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001514 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001515 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001516 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001517
keunhui.park2f7306a2015-07-16 16:48:06 +09001518 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001519
1520 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1521 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1522 if (ret < 0) {
1523 ALOGE("%s: csd_enable_device_config, failed, error %d",
1524 __func__, ret);
1525 }
1526 } else {
1527 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1528 acdb_rx_id, acdb_tx_id);
1529 }
1530
1531 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001532}
1533
1534int platform_switch_voice_call_device_post(void *platform,
1535 snd_device_t out_snd_device,
1536 snd_device_t in_snd_device)
1537{
1538 struct platform_data *my_data = (struct platform_data *)platform;
1539 int acdb_rx_id, acdb_tx_id;
1540
1541 if (my_data->acdb_send_voice_cal == NULL) {
1542 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1543 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001544 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1545 audio_extn_spkr_prot_is_enabled())
1546 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1547
keunhui.park2f7306a2015-07-16 16:48:06 +09001548 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1549 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001550
1551 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1552 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1553 else
1554 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1555 acdb_rx_id, acdb_tx_id);
1556 }
1557
1558 return 0;
1559}
1560
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001561int platform_switch_voice_call_usecase_route_post(void *platform,
1562 snd_device_t out_snd_device,
1563 snd_device_t in_snd_device)
1564{
1565 struct platform_data *my_data = (struct platform_data *)platform;
1566 int acdb_rx_id, acdb_tx_id;
1567 int ret = 0;
1568
1569 if (my_data->csd == NULL)
1570 return ret;
1571
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001572 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1573 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001574 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001575 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001576 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001577
keunhui.park2f7306a2015-07-16 16:48:06 +09001578 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001579
1580 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1581 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1582 my_data->adev->acdb_settings);
1583 if (ret < 0) {
1584 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1585 }
1586 } else {
1587 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1588 acdb_rx_id, acdb_tx_id);
1589 }
1590
1591 return ret;
1592}
1593
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001594int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001595{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001596 struct platform_data *my_data = (struct platform_data *)platform;
1597 int ret = 0;
1598
1599 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001600 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001601 if (ret < 0) {
1602 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1603 }
1604 }
1605 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001606}
1607
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001608int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001609{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001610 struct platform_data *my_data = (struct platform_data *)platform;
1611 int ret = 0;
1612
1613 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001614 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001615 if (ret < 0) {
1616 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1617 }
1618 }
1619 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001620}
1621
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001622int platform_get_sample_rate(void *platform, uint32_t *rate)
1623{
1624 struct platform_data *my_data = (struct platform_data *)platform;
1625 int ret = 0;
1626
1627 if (my_data->csd != NULL) {
1628 ret = my_data->csd->get_sample_rate(rate);
1629 if (ret < 0) {
1630 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1631 }
1632 }
1633 return ret;
1634}
1635
vivek mehtab6506412015-08-07 16:55:17 -07001636void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1637 snd_device_t snd_device,
1638 bool enable)
1639{
1640 const char* name;
1641 switch (snd_device) {
1642 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1643 if (enable)
1644 name = "spkr-gain-in-headphone-combo";
1645 else
1646 name = "speaker-gain-default";
1647 break;
1648 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1649 if (enable)
1650 name = "spkr-gain-in-line-combo";
1651 else
1652 name = "speaker-gain-default";
1653 break;
1654 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1655 if (enable)
1656 name = "spkr-safe-gain-in-headphone-combo";
1657 else
1658 name = "speaker-safe-gain-default";
1659 break;
1660 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1661 if (enable)
1662 name = "spkr-safe-gain-in-line-combo";
1663 else
1664 name = "speaker-safe-gain-default";
1665 break;
1666 default:
1667 return;
1668 }
1669
1670 audio_route_apply_and_update_path(adev->audio_route, name);
1671}
1672
Eric Laurentb23d5282013-05-14 15:27:20 -07001673int platform_set_voice_volume(void *platform, int volume)
1674{
1675 struct platform_data *my_data = (struct platform_data *)platform;
1676 struct audio_device *adev = my_data->adev;
1677 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001678 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001679 int vol_index = 0, ret = 0;
1680 uint32_t set_values[ ] = {0,
1681 ALL_SESSION_VSID,
1682 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001683
1684 // Voice volume levels are mapped to adsp volume levels as follows.
1685 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1686 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001687 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001688 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001689
1690 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1691 if (!ctl) {
1692 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1693 __func__, mixer_ctl_name);
1694 return -EINVAL;
1695 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001696 ALOGV("Setting voice volume index: %d", set_values[0]);
1697 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1698
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001699 if (my_data->csd != NULL) {
1700 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1701 DEFAULT_VOLUME_RAMP_DURATION_MS);
1702 if (ret < 0) {
1703 ALOGE("%s: csd_volume error %d", __func__, ret);
1704 }
1705 }
1706 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001707}
1708
1709int platform_set_mic_mute(void *platform, bool state)
1710{
1711 struct platform_data *my_data = (struct platform_data *)platform;
1712 struct audio_device *adev = my_data->adev;
1713 struct mixer_ctl *ctl;
1714 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001715 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001716 uint32_t set_values[ ] = {0,
1717 ALL_SESSION_VSID,
1718 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001719
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001720 if (adev->mode != AUDIO_MODE_IN_CALL &&
1721 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001722 return 0;
1723
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001724 if (adev->enable_hfp)
1725 mixer_ctl_name = "HFP Tx Mute";
1726
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001727 set_values[0] = state;
1728 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1729 if (!ctl) {
1730 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1731 __func__, mixer_ctl_name);
1732 return -EINVAL;
1733 }
1734 ALOGV("Setting voice mute state: %d", state);
1735 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1736
1737 if (my_data->csd != NULL) {
1738 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1739 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001740 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001741 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001742 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001743 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001744 return ret;
1745}
Eric Laurentb23d5282013-05-14 15:27:20 -07001746
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001747int platform_set_device_mute(void *platform, bool state, char *dir)
1748{
1749 struct platform_data *my_data = (struct platform_data *)platform;
1750 struct audio_device *adev = my_data->adev;
1751 struct mixer_ctl *ctl;
1752 char *mixer_ctl_name = NULL;
1753 int ret = 0;
1754 uint32_t set_values[ ] = {0,
1755 ALL_SESSION_VSID,
1756 0};
1757 if(dir == NULL) {
1758 ALOGE("%s: Invalid direction:%s", __func__, dir);
1759 return -EINVAL;
1760 }
1761
1762 if (!strncmp("rx", dir, sizeof("rx"))) {
1763 mixer_ctl_name = "Voice Rx Device Mute";
1764 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1765 mixer_ctl_name = "Voice Tx Device Mute";
1766 } else {
1767 return -EINVAL;
1768 }
1769
1770 set_values[0] = state;
1771 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1772 if (!ctl) {
1773 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1774 __func__, mixer_ctl_name);
1775 return -EINVAL;
1776 }
1777
1778 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1779 __func__,state, mixer_ctl_name);
1780 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1781
1782 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001783}
1784
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001785bool platform_can_split_snd_device(snd_device_t snd_device,
1786 int *num_devices,
1787 snd_device_t *new_snd_devices)
1788{
1789 bool status = false;
1790
1791 if (NULL == num_devices || NULL == new_snd_devices) {
1792 ALOGE("%s: NULL pointer ..", __func__);
1793 return false;
1794 }
1795
1796 /*
1797 * If wired headset/headphones/line devices share the same backend
1798 * with speaker/earpiece this routine returns false.
1799 */
1800 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1801 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1802 *num_devices = 2;
1803 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1804 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1805 status = true;
1806 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1807 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1808 *num_devices = 2;
1809 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1810 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1811 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001812 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1813 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1814 *num_devices = 2;
1815 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1816 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1817 status = true;
1818 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1819 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1820 *num_devices = 2;
1821 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1822 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1823 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001824 }
1825 return status;
1826}
1827
Eric Laurentb23d5282013-05-14 15:27:20 -07001828snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1829{
1830 struct platform_data *my_data = (struct platform_data *)platform;
1831 struct audio_device *adev = my_data->adev;
1832 audio_mode_t mode = adev->mode;
1833 snd_device_t snd_device = SND_DEVICE_NONE;
1834
1835 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1836 if (devices == AUDIO_DEVICE_NONE ||
1837 devices & AUDIO_DEVICE_BIT_IN) {
1838 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1839 goto exit;
1840 }
1841
Eric Laurent1b491552015-09-15 17:52:41 -07001842 if (popcount(devices) == 2) {
1843 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1844 AUDIO_DEVICE_OUT_SPEAKER) ||
1845 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1846 AUDIO_DEVICE_OUT_SPEAKER)) {
1847 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1848 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1849 AUDIO_DEVICE_OUT_SPEAKER)) {
1850 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1851 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1852 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1853 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1854 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1855 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1856 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1857 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1858 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1859 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1860 AUDIO_DEVICE_OUT_SPEAKER)) {
1861 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1862 } else {
1863 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1864 goto exit;
1865 }
1866 if (snd_device != SND_DEVICE_NONE) {
1867 goto exit;
1868 }
1869 }
1870
1871 if (popcount(devices) != 1) {
1872 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1873 goto exit;
1874 }
1875
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001876 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001877 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001878 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1879 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001880 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001881 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001882 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001883 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001884 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001885 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001886 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001887 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001888 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001889 else {
1890 if (devices & AUDIO_DEVICE_OUT_LINE)
1891 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1892 else
1893 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1894 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001895 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001896 if (adev->bt_wb_speech_enabled) {
1897 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1898 } else {
1899 snd_device = SND_DEVICE_OUT_BT_SCO;
1900 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001901 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001902 if (!adev->enable_hfp) {
1903 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1904 } else {
1905 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1906 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001907 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001908 if(adev->voice.hac)
1909 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1910 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001911 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1912 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001913 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001914 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1915 snd_device = SND_DEVICE_OUT_VOICE_TX;
1916
Eric Laurentb23d5282013-05-14 15:27:20 -07001917 if (snd_device != SND_DEVICE_NONE) {
1918 goto exit;
1919 }
1920 }
1921
Eric Laurentb23d5282013-05-14 15:27:20 -07001922 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1923 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1924 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001925 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1926 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001927 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1928 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001929 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001930 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001931 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1932 else
1933 snd_device = SND_DEVICE_OUT_SPEAKER;
1934 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001935 if (adev->bt_wb_speech_enabled) {
1936 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1937 } else {
1938 snd_device = SND_DEVICE_OUT_BT_SCO;
1939 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001940 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1941 snd_device = SND_DEVICE_OUT_HDMI ;
1942 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001943 /*HAC support for voice-ish audio (eg visual voicemail)*/
1944 if(adev->voice.hac)
1945 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1946 else
1947 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001948 } else {
1949 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1950 }
1951exit:
1952 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1953 return snd_device;
1954}
1955
1956snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1957{
1958 struct platform_data *my_data = (struct platform_data *)platform;
1959 struct audio_device *adev = my_data->adev;
1960 audio_source_t source = (adev->active_input == NULL) ?
1961 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1962
1963 audio_mode_t mode = adev->mode;
1964 audio_devices_t in_device = ((adev->active_input == NULL) ?
1965 AUDIO_DEVICE_NONE : adev->active_input->device)
1966 & ~AUDIO_DEVICE_BIT_IN;
1967 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1968 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1969 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001970 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001971
Prashant Malanic92c5962015-08-11 15:10:18 -07001972 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1973 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001974 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001975 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001976 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001977 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1978 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001979 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001980 case TTY_MODE_FULL:
1981 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1982 break;
1983 case TTY_MODE_VCO:
1984 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1985 break;
1986 case TTY_MODE_HCO:
1987 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1988 break;
1989 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001990 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001991 }
1992 goto exit;
1993 }
1994 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001995 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001996 if (my_data->fluence_in_voice_call == false) {
1997 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1998 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001999 if (is_operator_tmus())
2000 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002001 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002002 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002003 }
2004 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2005 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2006 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002007 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002008 if (adev->bluetooth_nrec)
2009 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2010 else
2011 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002012 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002013 if (adev->bluetooth_nrec)
2014 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2015 else
2016 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002017 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002018 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002019 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2020 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2021 out_device & AUDIO_DEVICE_OUT_LINE) {
2022 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2023 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2024 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2025 } else {
2026 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2027 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002028 }
vivek mehtafe121d52015-08-10 23:39:23 -07002029
2030 //select default
2031 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002032 if (!adev->enable_hfp) {
2033 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2034 } else {
2035 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2036 platform_set_echo_reference(adev, true, out_device);
2037 }
vivek mehtafe121d52015-08-10 23:39:23 -07002038 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002039 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002040 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002041 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002042 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2043 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2044 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2045 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2046 }
2047 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2048 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002049 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2050 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2051 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2052 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
2053 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2054 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2055 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
2056 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2057 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2058 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002059 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002060 }
2061 platform_set_echo_reference(adev, true, out_device);
2062 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2063 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2064 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2065 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2066 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2067 snd_device = SND_DEVICE_IN_THREE_MIC;
2068 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2069 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2070 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002071 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002072 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002073 if (adev->active_input->enable_ns)
2074 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2075 else
2076 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002077 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002078 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2079 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002080 }
rago90fb9612015-12-02 11:37:53 -08002081 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2082 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2083 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2084 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2085 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2086 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002087 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002088 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002089 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002090 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2091 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002092 if (adev->active_input->enable_aec &&
2093 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002094 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002095 if (my_data->fluence_in_spkr_mode &&
2096 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002097 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002098 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002099 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002100 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002101 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002102 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002103 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002104 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002105 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002106 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002107 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002108 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002109 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2110 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002111 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002112 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002113 } else if (adev->active_input->enable_aec) {
2114 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2115 if (my_data->fluence_in_spkr_mode &&
2116 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002117 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002118 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002119 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002120 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002121 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002122 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2123 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002124 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002125 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002126 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002127 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002128 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002129 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2130 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2131 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002132 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002133 } else if (adev->active_input->enable_ns) {
2134 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2135 if (my_data->fluence_in_spkr_mode &&
2136 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002137 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002138 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002139 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002140 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002141 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002142 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2143 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002144 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002145 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002146 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002147 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002148 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002149 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002150 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002151 }
2152 } else if (source == AUDIO_SOURCE_DEFAULT) {
2153 goto exit;
2154 }
2155
2156
2157 if (snd_device != SND_DEVICE_NONE) {
2158 goto exit;
2159 }
2160
2161 if (in_device != AUDIO_DEVICE_NONE &&
2162 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2163 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2164 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002165 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2166 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2167 snd_device = SND_DEVICE_IN_QUAD_MIC;
2168 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2169 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2170 snd_device = SND_DEVICE_IN_THREE_MIC;
2171 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2172 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002173 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002174 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2175 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002176 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002177 } else {
2178 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2179 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2180 my_data->source_mic_type, channel_count, channel_mask);
2181 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2182 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002183 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002184 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2185 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002186 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002187 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2188 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002189 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002190 } else {
2191 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2192 " no combination found .. setting to mono", __func__,
2193 my_data->source_mic_type, channel_count);
2194 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2195 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002196 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2197 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2198 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002199 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002200 if (adev->bluetooth_nrec)
2201 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2202 else
2203 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002204 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002205 if (adev->bluetooth_nrec)
2206 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2207 else
2208 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002209 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002210 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2211 snd_device = SND_DEVICE_IN_HDMI_MIC;
2212 } else {
2213 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2214 ALOGW("%s: Using default handset-mic", __func__);
2215 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2216 }
2217 } else {
2218 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2219 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2220 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2221 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002222 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002223 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002224 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002225 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002226 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2227 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002228 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002229 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2230 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002231 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002232 } else {
2233 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2234 " no combination found .. setting to mono", __func__,
2235 my_data->source_mic_type, channel_count);
2236 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2237 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002238 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002239 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002240 if (adev->bluetooth_nrec)
2241 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2242 else
2243 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002244 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002245 if (adev->bluetooth_nrec)
2246 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2247 else
2248 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002249 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002250 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2251 snd_device = SND_DEVICE_IN_HDMI_MIC;
2252 } else {
2253 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2254 ALOGW("%s: Using default handset-mic", __func__);
2255 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2256 }
2257 }
2258exit:
2259 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2260 return snd_device;
2261}
2262
2263int platform_set_hdmi_channels(void *platform, int channel_count)
2264{
2265 struct platform_data *my_data = (struct platform_data *)platform;
2266 struct audio_device *adev = my_data->adev;
2267 struct mixer_ctl *ctl;
2268 const char *channel_cnt_str = NULL;
2269 const char *mixer_ctl_name = "HDMI_RX Channels";
2270 switch (channel_count) {
2271 case 8:
2272 channel_cnt_str = "Eight"; break;
2273 case 7:
2274 channel_cnt_str = "Seven"; break;
2275 case 6:
2276 channel_cnt_str = "Six"; break;
2277 case 5:
2278 channel_cnt_str = "Five"; break;
2279 case 4:
2280 channel_cnt_str = "Four"; break;
2281 case 3:
2282 channel_cnt_str = "Three"; break;
2283 default:
2284 channel_cnt_str = "Two"; break;
2285 }
2286 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2287 if (!ctl) {
2288 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2289 __func__, mixer_ctl_name);
2290 return -EINVAL;
2291 }
2292 ALOGV("HDMI channel count: %s", channel_cnt_str);
2293 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2294 return 0;
2295}
2296
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002297int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002298{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002299 struct platform_data *my_data = (struct platform_data *)platform;
2300 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002301 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2302 char *sad = block;
2303 int num_audio_blocks;
2304 int channel_count;
2305 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002306 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002307
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002308 struct mixer_ctl *ctl;
2309
2310 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2311 if (!ctl) {
2312 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2313 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002314 return 0;
2315 }
2316
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002317 mixer_ctl_update(ctl);
2318
2319 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002320
2321 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002322 if (count > (int)sizeof(block))
2323 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002324
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002325 ret = mixer_ctl_get_array(ctl, block, count);
2326 if (ret != 0) {
2327 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2328 return 0;
2329 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002330
2331 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002332 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002333
2334 for (i = 0; i < num_audio_blocks; i++) {
2335 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002336 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2337 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002338 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002339 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002340
2341 channel_count = (sad[0] & 0x7) + 1;
2342 if (channel_count > max_channels)
2343 max_channels = channel_count;
2344
2345 /* Advance to next block */
2346 sad += 3;
2347 }
2348
2349 return max_channels;
2350}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002351
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002352int platform_set_incall_recording_session_id(void *platform,
2353 uint32_t session_id, int rec_mode)
2354{
2355 int ret = 0;
2356 struct platform_data *my_data = (struct platform_data *)platform;
2357 struct audio_device *adev = my_data->adev;
2358 struct mixer_ctl *ctl;
2359 const char *mixer_ctl_name = "Voc VSID";
2360 int num_ctl_values;
2361 int i;
2362
2363 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2364 if (!ctl) {
2365 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2366 __func__, mixer_ctl_name);
2367 ret = -EINVAL;
2368 } else {
2369 num_ctl_values = mixer_ctl_get_num_values(ctl);
2370 for (i = 0; i < num_ctl_values; i++) {
2371 if (mixer_ctl_set_value(ctl, i, session_id)) {
2372 ALOGV("Error: invalid session_id: %x", session_id);
2373 ret = -EINVAL;
2374 break;
2375 }
2376 }
2377 }
2378
2379 if (my_data->csd != NULL) {
2380 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2381 if (ret < 0) {
2382 ALOGE("%s: csd_client_start_record failed, error %d",
2383 __func__, ret);
2384 }
2385 }
2386
2387 return ret;
2388}
2389
2390int platform_stop_incall_recording_usecase(void *platform)
2391{
2392 int ret = 0;
2393 struct platform_data *my_data = (struct platform_data *)platform;
2394
2395 if (my_data->csd != NULL) {
2396 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2397 if (ret < 0) {
2398 ALOGE("%s: csd_client_stop_record failed, error %d",
2399 __func__, ret);
2400 }
2401 }
2402
2403 return ret;
2404}
2405
2406int platform_start_incall_music_usecase(void *platform)
2407{
2408 int ret = 0;
2409 struct platform_data *my_data = (struct platform_data *)platform;
2410
2411 if (my_data->csd != NULL) {
2412 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2413 if (ret < 0) {
2414 ALOGE("%s: csd_client_start_playback failed, error %d",
2415 __func__, ret);
2416 }
2417 }
2418
2419 return ret;
2420}
2421
2422int platform_stop_incall_music_usecase(void *platform)
2423{
2424 int ret = 0;
2425 struct platform_data *my_data = (struct platform_data *)platform;
2426
2427 if (my_data->csd != NULL) {
2428 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2429 if (ret < 0) {
2430 ALOGE("%s: csd_client_stop_playback failed, error %d",
2431 __func__, ret);
2432 }
2433 }
2434
2435 return ret;
2436}
2437
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002438int platform_set_parameters(void *platform, struct str_parms *parms)
2439{
2440 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002441 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002442 char *kv_pairs = str_parms_to_str(parms);
2443 int ret = 0, err;
2444
2445 if (kv_pairs == NULL) {
2446 ret = -EINVAL;
2447 ALOGE("%s: key-value pair is NULL",__func__);
2448 goto done;
2449 }
2450
2451 ALOGV("%s: enter: %s", __func__, kv_pairs);
2452
2453 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2454 value, sizeof(value));
2455 if (err >= 0) {
2456 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2457 my_data->snd_card_name = strdup(value);
2458 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2459 }
2460
keunhui.park2f7306a2015-07-16 16:48:06 +09002461 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2462 value, sizeof(value));
2463 if (err >= 0) {
2464 struct operator_info *info;
2465 char *str = value;
2466 char *name;
2467
2468 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2469 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2470 name = strtok(str, ";");
2471 info->name = strdup(name);
2472 info->mccmnc = strdup(str + strlen(name) + 1);
2473
2474 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002475 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002476 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002477
2478 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002479 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002480 value, sizeof(value));
2481 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002482 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002483 my_data->max_mic_count = atoi(value);
2484 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002485 }
2486
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002487done:
2488 ALOGV("%s: exit with code(%d)", __func__, ret);
2489 if (kv_pairs != NULL)
2490 free(kv_pairs);
2491
2492 return ret;
2493}
2494
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002495/* Delay in Us */
2496int64_t platform_render_latency(audio_usecase_t usecase)
2497{
2498 switch (usecase) {
2499 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2500 return DEEP_BUFFER_PLATFORM_DELAY;
2501 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2502 return LOW_LATENCY_PLATFORM_DELAY;
2503 default:
2504 return 0;
2505 }
2506}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002507
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002508int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2509 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002510{
2511 int ret = 0;
2512
2513 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2514 ALOGE("%s: Invalid snd_device = %d",
2515 __func__, device);
2516 ret = -EINVAL;
2517 goto done;
2518 }
2519
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002520 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2521 platform_get_snd_device_name(device),
2522 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2523 if (backend_tag_table[device]) {
2524 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002525 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002526 backend_tag_table[device] = strdup(backend_tag);
2527
2528 if (hw_interface != NULL) {
2529 if (hw_interface_table[device])
2530 free(hw_interface_table[device]);
2531 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2532 hw_interface_table[device] = strdup(hw_interface);
2533 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002534done:
2535 return ret;
2536}
2537
2538int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2539{
2540 int ret = 0;
2541 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2542 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2543 ret = -EINVAL;
2544 goto done;
2545 }
2546
2547 if ((type != 0) && (type != 1)) {
2548 ALOGE("%s: invalid usecase type", __func__);
2549 ret = -EINVAL;
2550 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002551 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002552 pcm_device_table[usecase][type] = pcm_id;
2553done:
2554 return ret;
2555}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002556
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002557#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2558int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2559 // backup_gain: gain to try to set in case of an error during ramp
2560 int start_gain, end_gain, step, backup_gain, i;
2561 bool error = false;
2562 const struct mixer_ctl *ctl;
2563 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2564 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2565 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2566 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2567 if (!ctl_left || !ctl_right) {
2568 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2569 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2570 return -EINVAL;
2571 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2572 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2573 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2574 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2575 return -EINVAL;
2576 }
2577 if (ramp_up) {
2578 start_gain = 0;
2579 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2580 step = +1;
2581 backup_gain = end_gain;
2582 } else {
2583 // using same gain on left and right
2584 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2585 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2586 end_gain = 0;
2587 step = -1;
2588 backup_gain = start_gain;
2589 }
2590 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2591 //ALOGV("setting speaker gain to %d", i);
2592 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2593 ALOGE("%s: error setting %s to %d during gain ramp",
2594 __func__, mixer_ctl_name_gain_left, i);
2595 error = true;
2596 break;
2597 }
2598 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2599 ALOGE("%s: error setting %s to %d during gain ramp",
2600 __func__, mixer_ctl_name_gain_right, i);
2601 error = true;
2602 break;
2603 }
2604 usleep(1000);
2605 }
2606 if (error) {
2607 // an error occured during the ramp, let's still try to go back to a safe volume
2608 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2609 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2610 }
2611 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2612 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2613 }
2614 }
2615 return start_gain;
2616}
2617
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002618int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2619{
2620 // only update if there is active pcm playback on speaker
2621 struct audio_usecase *usecase;
2622 struct listnode *node;
2623 struct platform_data *my_data = (struct platform_data *)adev->platform;
2624
2625 if (my_data->speaker_lr_swap != swap_channels) {
2626 my_data->speaker_lr_swap = swap_channels;
2627
2628 list_for_each(node, &adev->usecase_list) {
2629 usecase = node_to_item(node, struct audio_usecase, list);
2630 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002631 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2632 /*
2633 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2634 * to perform device switch to disable the current backend to
2635 * enable it with new acdb data.
2636 */
2637 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2638 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002639 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002640 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002641 if (initial_skpr_gain != -EINVAL) {
2642 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2643 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002644 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002645 const char *mixer_path;
2646 if (swap_channels) {
2647 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2648 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2649 } else {
2650 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2651 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2652 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002653 }
2654 break;
2655 }
2656 }
2657 }
2658 return 0;
2659}