blob: 89b6de518bb69ff3aa4bfc6d2bbe49cfdb35030a [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 Laurentf9583c32016-03-28 13:50:50 -070040#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070041
42/*
Eric Laurentb23d5282013-05-14 15:27:20 -070043 * This file will have a maximum of 38 bytes:
44 *
45 * 4 bytes: number of audio blocks
46 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
47 * Maximum 10 * 3 bytes: SAD blocks
48 */
49#define MAX_SAD_BLOCKS 10
50#define SAD_BLOCK_SIZE 3
51
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090052#define MAX_CVD_VERSION_STRING_SIZE 100
53
Eric Laurentb23d5282013-05-14 15:27:20 -070054/* EDID format ID for LPCM audio */
55#define EDID_FORMAT_LPCM 1
56
sangwoo1b9f4b32013-06-21 18:22:55 -070057/* Retry for delay in FW loading*/
58#define RETRY_NUMBER 10
59#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070060#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070061
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070062#define MAX_SND_CARD_NAME_LEN 31
63
vivek mehta1a9b7c02015-06-25 11:49:38 -070064#define DEFAULT_APP_TYPE_RX_PATH 0x11130
65
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090066#define TOSTRING_(x) #x
67#define TOSTRING(x) TOSTRING_(x)
68
Eric Laurentb23d5282013-05-14 15:27:20 -070069struct audio_block_header
70{
71 int reserved;
72 int length;
73};
74
vivek mehta1a9b7c02015-06-25 11:49:38 -070075enum {
76 CAL_MODE_SEND = 0x1,
77 CAL_MODE_PERSIST = 0x2,
78 CAL_MODE_RTAC = 0x4
79};
80
keunhui.park2f7306a2015-07-16 16:48:06 +090081#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
82
83struct operator_info {
84 struct listnode list;
85 char *name;
86 char *mccmnc;
87};
88
89struct operator_specific_device {
90 struct listnode list;
91 char *operator;
92 char *mixer_path;
93 int acdb_id;
94};
95
96static struct listnode operator_info_list;
97static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
98
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070099/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700100typedef void (*acdb_deallocate_t)();
vivek mehtac698f132016-02-25 18:50:35 -0800101typedef int (*acdb_init_v2_cvd_t)(char *, char *, int);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900102typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -0700103typedef int (*acdb_init_t)();
104typedef void (*acdb_send_audio_cal_t)(int, int);
105typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700106typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700107typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700108
109/* Audio calibration related functions */
110struct platform_data {
111 struct audio_device *adev;
112 bool fluence_in_spkr_mode;
113 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700114 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700115 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700116 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
117 int fluence_type;
118 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700119 bool speaker_lr_swap;
120
Eric Laurentb23d5282013-05-14 15:27:20 -0700121 void *acdb_handle;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700122 acdb_deallocate_t acdb_deallocate;
123 acdb_send_audio_cal_t acdb_send_audio_cal;
124 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700125 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700126 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700127 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800128 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700129
130 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900131 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700132 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800133
134 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700135};
136
Haynes Mathew George98c95622014-06-20 19:14:25 -0700137static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700138 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
139 DEEP_BUFFER_PCM_DEVICE},
140 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
141 LOWLATENCY_PCM_DEVICE},
142 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
143 MULTIMEDIA2_PCM_DEVICE},
144 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
145 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700146 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
147 MULTIMEDIA2_PCM_DEVICE},
148 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
149 MULTIMEDIA3_PCM_DEVICE},
150
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700151 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
152 AUDIO_RECORD_PCM_DEVICE},
153 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
154 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700155
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700156 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
157 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700158 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
159 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
160 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
161 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800162 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
163 VOICEMMODE1_CALL_PCM_DEVICE},
164 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
165 VOICEMMODE2_CALL_PCM_DEVICE},
166
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700167 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
168 AUDIO_RECORD_PCM_DEVICE},
169 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
170 AUDIO_RECORD_PCM_DEVICE},
171 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
172 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800173 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700174
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700175 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
176 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
177
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700178 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
179 AFE_PROXY_RECORD_PCM_DEVICE},
180 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
181 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800182 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700183
Eric Laurentb23d5282013-05-14 15:27:20 -0700184};
185
186/* Array to store sound devices */
187static const char * const device_table[SND_DEVICE_MAX] = {
188 [SND_DEVICE_NONE] = "none",
189 /* Playback sound devices */
190 [SND_DEVICE_OUT_HANDSET] = "handset",
191 [SND_DEVICE_OUT_SPEAKER] = "speaker",
192 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700193 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700194 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500195 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700196 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700197 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500198 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700199 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700200 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500201 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700202 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
203 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500204 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700205 [SND_DEVICE_OUT_HDMI] = "hdmi",
206 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
207 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700208 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700209 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
210 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
211 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
212 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700213 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700214 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
215 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700216 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217
218 /* Capture sound devices */
219 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700220 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700221 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
222 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
223 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
224 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
225 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
226 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
227 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
228
229 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
230 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
231 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
232 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
233 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
234 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
235 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
236 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
237 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
238
239 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500240 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700241
Eric Laurentb23d5282013-05-14 15:27:20 -0700242 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
243 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700244 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700245 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700246 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700247 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700248
249 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
250 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
251 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
252 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700253 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700254 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
256 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
257 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700258
Eric Laurentb23d5282013-05-14 15:27:20 -0700259 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700260 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
261 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
262 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700263 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700264
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700265 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
rago90fb9612015-12-02 11:37:53 -0800266 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
267
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700268 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700269
Prashant Malanic92c5962015-08-11 15:10:18 -0700270 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
271 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700272 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700273 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
274 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700275};
276
277/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700278static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700279 [SND_DEVICE_NONE] = -1,
280 [SND_DEVICE_OUT_HANDSET] = 7,
281 [SND_DEVICE_OUT_SPEAKER] = 15,
282 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700283 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700284 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500285 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700286 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700287 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500288 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700289 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700290 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
291 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500292 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700293 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500294 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700295 [SND_DEVICE_OUT_HDMI] = 18,
296 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
297 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700298 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700299 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700300 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
301 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
302 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700303 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700304 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
305 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700306 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700307
308 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700309 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
310 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
311 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
312 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
313 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
314 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
315 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
316 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
317
318 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
319 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
320 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
321 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
322 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
323 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
324 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
325 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
326 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
327
rago90fb9612015-12-02 11:37:53 -0800328 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500329 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700330
Eric Laurentb23d5282013-05-14 15:27:20 -0700331 [SND_DEVICE_IN_HDMI_MIC] = 4,
332 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700333 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700334 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700335 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700336 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700337
338 [SND_DEVICE_IN_VOICE_DMIC] = 41,
339 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
340 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700341 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700342 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800343 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700344 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
345 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
346 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700347
rago90fb9612015-12-02 11:37:53 -0800348 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700349 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
350 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
351 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800352 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
353
354 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
355 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700356
357 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700358
Prashant Malanic92c5962015-08-11 15:10:18 -0700359 [SND_DEVICE_IN_THREE_MIC] = 46,
360 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700361 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700362 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
363 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
Eric Laurentb23d5282013-05-14 15:27:20 -0700364};
365
Haynes Mathew George98c95622014-06-20 19:14:25 -0700366struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700367 char name[100];
368 unsigned int index;
369};
370
371#define TO_NAME_INDEX(X) #X, X
372
Haynes Mathew George98c95622014-06-20 19:14:25 -0700373/* Used to get index from parsed string */
374static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
375 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700376 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
377 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
378 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700379 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700380 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500381 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700382 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700383 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500384 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700385 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700386 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
387 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700388 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700389 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500390 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700391 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
392 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
393 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
394 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700395 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500396 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700397 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
398 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
399 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700400
401 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700402 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
403 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700404 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700405 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700406 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
407 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
408 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
409 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
410 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
411 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
412 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
413
414 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700415 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700416 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
418 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
419 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
420 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
421 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
422 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
423
424 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700425 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700426
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700427 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
428 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700429 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700430 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700431 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700432 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700433
434 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
435 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
436 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700437 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700438 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
439 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700440 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700443
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700444 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700445 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
446 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
447 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700448 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700449
rago90fb9612015-12-02 11:37:53 -0800450 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
452
Prashant Malanic92c5962015-08-11 15:10:18 -0700453 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700455 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700456 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
457 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700458};
459
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700460static char * backend_tag_table[SND_DEVICE_MAX] = {0};
461static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700462
463static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
464 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
465 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
466 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
467 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700468 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
469 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700470 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
471 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
472 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
473 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
474 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
475 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
476 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
477 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
478 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
479 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
480 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700481};
482
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700483#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
484#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
485
Eric Laurentb23d5282013-05-14 15:27:20 -0700486static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
487static bool is_tmus = false;
488
489static void check_operator()
490{
491 char value[PROPERTY_VALUE_MAX];
492 int mccmnc;
493 property_get("gsm.sim.operator.numeric",value,"0");
494 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700495 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700496 switch(mccmnc) {
497 /* TMUS MCC(310), MNC(490, 260, 026) */
498 case 310490:
499 case 310260:
500 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900501 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
502 case 310800:
503 case 310660:
504 case 310580:
505 case 310310:
506 case 310270:
507 case 310250:
508 case 310240:
509 case 310230:
510 case 310220:
511 case 310210:
512 case 310200:
513 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700514 is_tmus = true;
515 break;
516 }
517}
518
519bool is_operator_tmus()
520{
521 pthread_once(&check_op_once_ctl, check_operator);
522 return is_tmus;
523}
524
keunhui.park2f7306a2015-07-16 16:48:06 +0900525static char *get_current_operator()
526{
527 struct listnode *node;
528 struct operator_info *info_item;
529 char mccmnc[PROPERTY_VALUE_MAX];
530 char *ret = NULL;
531
532 property_get("gsm.sim.operator.numeric",mccmnc,"0");
533
534 list_for_each(node, &operator_info_list) {
535 info_item = node_to_item(node, struct operator_info, list);
536 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
537 ret = info_item->name;
538 }
539 }
540
541 return ret;
542}
543
544static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
545{
546 struct listnode *node;
547 struct operator_specific_device *ret = NULL;
548 struct operator_specific_device *device_item;
549 char *operator_name;
550
551 operator_name = get_current_operator();
552 if (operator_name == NULL)
553 return ret;
554
555 list_for_each(node, operator_specific_device_table[snd_device]) {
556 device_item = node_to_item(node, struct operator_specific_device, list);
557 if (strcmp(operator_name, device_item->operator) == 0) {
558 ret = device_item;
559 }
560 }
561
562 return ret;
563}
564
565
566static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
567{
568 struct operator_specific_device *device;
569 int ret = acdb_device_table[snd_device];
570
571 device = get_operator_specific_device(snd_device);
572 if (device != NULL)
573 ret = device->acdb_id;
574
575 return ret;
576}
577
578static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
579{
580 struct operator_specific_device *device;
581 const char *ret = device_table[snd_device];
582
583 device = get_operator_specific_device(snd_device);
584 if (device != NULL)
585 ret = device->mixer_path;
586
587 return ret;
588}
589
vivek mehta1a9b7c02015-06-25 11:49:38 -0700590bool platform_send_gain_dep_cal(void *platform, int level)
591{
592 bool ret_val = false;
593 struct platform_data *my_data = (struct platform_data *)platform;
594 struct audio_device *adev = my_data->adev;
595 int acdb_dev_id, app_type;
596 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
597 int mode = CAL_MODE_RTAC;
598 struct listnode *node;
599 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700600
601 if (my_data->acdb_send_gain_dep_cal == NULL) {
602 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
603 return ret_val;
604 }
605
606 if (!voice_is_in_call(adev)) {
607 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
608 __func__, level);
609 app_type = DEFAULT_APP_TYPE_RX_PATH;
610
611 // find the current active sound device
612 list_for_each(node, &adev->usecase_list) {
613 usecase = node_to_item(node, struct audio_usecase, list);
614
615 if (usecase != NULL &&
616 usecase->type == PCM_PLAYBACK &&
617 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
618
619 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700620 if (audio_extn_spkr_prot_is_enabled()) {
621 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
622 } else {
623 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
624 }
625
vivek mehta1a9b7c02015-06-25 11:49:38 -0700626 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
627 acdb_dev_type, mode, level)) {
628 // set ret_val true if at least one calibration is set successfully
629 ret_val = true;
630 } else {
631 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
632 }
633 } else {
634 ALOGW("%s: Usecase list is empty", __func__);
635 }
636 }
637 } else {
638 ALOGW("%s: Voice call in progress .. ignore setting new cal",
639 __func__);
640 }
641 return ret_val;
642}
643
Eric Laurentcefbbac2014-09-04 13:54:10 -0500644void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700645{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800646 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500647 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700648
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800649 if (strcmp(my_data->ec_ref_mixer_path, "")) {
650 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
651 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500652 }
653
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800654 if (enable) {
655 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
656 if (out_device != AUDIO_DEVICE_NONE) {
657 snd_device = platform_get_output_snd_device(adev->platform, out_device);
658 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
659 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500660
Joe Onorato188b6222016-03-01 11:02:27 -0800661 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800662 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
663 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700664}
665
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700666static struct csd_data *open_csd_client(bool i2s_ext_modem)
667{
668 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
669
670 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
671 if (csd->csd_client == NULL) {
672 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
673 goto error;
674 } else {
675 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
676
677 csd->deinit = (deinit_t)dlsym(csd->csd_client,
678 "csd_client_deinit");
679 if (csd->deinit == NULL) {
680 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
681 dlerror());
682 goto error;
683 }
684 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
685 "csd_client_disable_device");
686 if (csd->disable_device == NULL) {
687 ALOGE("%s: dlsym error %s for csd_client_disable_device",
688 __func__, dlerror());
689 goto error;
690 }
691 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
692 "csd_client_enable_device_config");
693 if (csd->enable_device_config == NULL) {
694 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
695 __func__, dlerror());
696 goto error;
697 }
698 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
699 "csd_client_enable_device");
700 if (csd->enable_device == NULL) {
701 ALOGE("%s: dlsym error %s for csd_client_enable_device",
702 __func__, dlerror());
703 goto error;
704 }
705 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
706 "csd_client_start_voice");
707 if (csd->start_voice == NULL) {
708 ALOGE("%s: dlsym error %s for csd_client_start_voice",
709 __func__, dlerror());
710 goto error;
711 }
712 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
713 "csd_client_stop_voice");
714 if (csd->stop_voice == NULL) {
715 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
716 __func__, dlerror());
717 goto error;
718 }
719 csd->volume = (volume_t)dlsym(csd->csd_client,
720 "csd_client_volume");
721 if (csd->volume == NULL) {
722 ALOGE("%s: dlsym error %s for csd_client_volume",
723 __func__, dlerror());
724 goto error;
725 }
726 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
727 "csd_client_mic_mute");
728 if (csd->mic_mute == NULL) {
729 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
730 __func__, dlerror());
731 goto error;
732 }
733 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
734 "csd_client_slow_talk");
735 if (csd->slow_talk == NULL) {
736 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
737 __func__, dlerror());
738 goto error;
739 }
740 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
741 "csd_client_start_playback");
742 if (csd->start_playback == NULL) {
743 ALOGE("%s: dlsym error %s for csd_client_start_playback",
744 __func__, dlerror());
745 goto error;
746 }
747 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
748 "csd_client_stop_playback");
749 if (csd->stop_playback == NULL) {
750 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
751 __func__, dlerror());
752 goto error;
753 }
754 csd->start_record = (start_record_t)dlsym(csd->csd_client,
755 "csd_client_start_record");
756 if (csd->start_record == NULL) {
757 ALOGE("%s: dlsym error %s for csd_client_start_record",
758 __func__, dlerror());
759 goto error;
760 }
761 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
762 "csd_client_stop_record");
763 if (csd->stop_record == NULL) {
764 ALOGE("%s: dlsym error %s for csd_client_stop_record",
765 __func__, dlerror());
766 goto error;
767 }
768
769 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
770 "csd_client_get_sample_rate");
771 if (csd->get_sample_rate == NULL) {
772 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
773 __func__, dlerror());
774
775 goto error;
776 }
777
778 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
779
780 if (csd->init == NULL) {
781 ALOGE("%s: dlsym error %s for csd_client_init",
782 __func__, dlerror());
783 goto error;
784 } else {
785 csd->init(i2s_ext_modem);
786 }
787 }
788 return csd;
789
790error:
791 free(csd);
792 csd = NULL;
793 return csd;
794}
795
796void close_csd_client(struct csd_data *csd)
797{
798 if (csd != NULL) {
799 csd->deinit();
800 dlclose(csd->csd_client);
801 free(csd);
802 csd = NULL;
803 }
804}
805
806static void platform_csd_init(struct platform_data *my_data)
807{
808#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700809 int32_t modems, (*count_modems)(void);
810 const char *name = "libdetectmodem.so";
811 const char *func = "count_modems";
812 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700813
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700814 my_data->csd = NULL;
815
816 void *lib = dlopen(name, RTLD_NOW);
817 error = dlerror();
818 if (!lib) {
819 ALOGE("%s: could not find %s: %s", __func__, name, error);
820 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700821 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700822
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700823 count_modems = NULL;
824 *(void **)(&count_modems) = dlsym(lib, func);
825 error = dlerror();
826 if (!count_modems) {
827 ALOGE("%s: could not find symbol %s in %s: %s",
828 __func__, func, name, error);
829 goto done;
830 }
831
832 modems = count_modems();
833 if (modems < 0) {
834 ALOGE("%s: count_modems failed\n", __func__);
835 goto done;
836 }
837
Eric Laurent2bafff12016-03-17 12:17:23 -0700838 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700839 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700840 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700841
842done:
843 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700844#else
845 my_data->csd = NULL;
846#endif
847}
848
Eric Laurentc6333382015-09-14 12:43:44 -0700849static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700850{
851 int32_t dev;
852 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700853 backend_tag_table[dev] = NULL;
854 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900855 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700856 }
857
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700858 // To overwrite these go to the audio_platform_info.xml file.
859 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700860 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700861 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
862 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
863 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
864 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
865 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700866 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700867 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
868 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700869
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700870 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
871 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
872 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
873 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
874 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
875 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
876 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700877 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700878 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700879 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700880 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
881 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
882 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
883 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
884 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
885 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
886 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
887 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
888 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
889 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
890 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
891 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
892 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
893 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
894 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
895 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700896
897 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700898}
899
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900900void get_cvd_version(char *cvd_version, struct audio_device *adev)
901{
902 struct mixer_ctl *ctl;
903 int count;
904 int ret = 0;
905
906 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
907 if (!ctl) {
908 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
909 goto done;
910 }
911 mixer_ctl_update(ctl);
912
913 count = mixer_ctl_get_num_values(ctl);
914 if (count > MAX_CVD_VERSION_STRING_SIZE)
915 count = MAX_CVD_VERSION_STRING_SIZE - 1;
916
917 ret = mixer_ctl_get_array(ctl, cvd_version, count);
918 if (ret != 0) {
919 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
920 goto done;
921 }
922
923done:
924 return;
925}
926
Eric Laurentb23d5282013-05-14 15:27:20 -0700927void *platform_init(struct audio_device *adev)
928{
929 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800930 struct platform_data *my_data = NULL;
931 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
932 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700933 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900934 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -0800935 char *snd_internal_name = NULL;
936 char *tmp = NULL;
937 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -0800938 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
939 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700940 my_data = calloc(1, sizeof(struct platform_data));
941
942 my_data->adev = adev;
943
keunhui.park2f7306a2015-07-16 16:48:06 +0900944 list_init(&operator_info_list);
945
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700946 set_platform_defaults(my_data);
947
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700948 while (snd_card_num < MAX_SND_CARD) {
949 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700950
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700951 while (!adev->mixer && retry_num < RETRY_NUMBER) {
952 usleep(RETRY_US);
953 adev->mixer = mixer_open(snd_card_num);
954 retry_num++;
955 }
956
957 if (!adev->mixer) {
958 ALOGE("%s: Unable to open the mixer card: %d", __func__,
959 snd_card_num);
960 retry_num = 0;
961 snd_card_num++;
962 continue;
963 }
964
965 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -0800966 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700967
vivek mehtade4849c2016-03-03 17:23:38 -0800968 audio_extn_set_snd_card_split(snd_card_name);
969 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700970
vivek mehtade4849c2016-03-03 17:23:38 -0800971 /* Get the codec internal name from the sound card and/or form factor
972 * name and form the mixer paths and platfor info file name dynamically.
973 * This is generic way of picking any codec and forma factor name based
974 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700975
vivek mehtade4849c2016-03-03 17:23:38 -0800976 * current code extends and looks for any of the exteneded mixer path and
977 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -0800978
vivek mehtade4849c2016-03-03 17:23:38 -0800979 * order of picking appropriate file is
980 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
981 * <ii> mixer_paths_<codec_name>.xml, if file not present
982 * <iii> mixer_paths.xml
983
984 * same order is followed for audio_platform_info.xml as well
985 */
986
987 // need to carryforward old file name
988 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -0700989 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -0800990 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -0800991 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -0800992 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -0700993
vivek mehtade4849c2016-03-03 17:23:38 -0800994 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
995 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
996 snd_split_handle->form_factor);
997
998 if (F_OK != access(mixer_xml_file, 0)) {
999 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1000 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1001 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1002
1003 if (F_OK != access(mixer_xml_file, 0)) {
1004 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1005 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1006 }
1007 }
1008
1009 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1010 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1011 snd_split_handle->form_factor);
1012
1013 if (F_OK != access(platform_info_file, 0)) {
1014 memset(platform_info_file, 0, sizeof(platform_info_file));
1015 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1016 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1017
1018 if (F_OK != access(platform_info_file, 0)) {
1019 memset(platform_info_file, 0, sizeof(platform_info_file));
1020 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001021 }
1022 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001023 }
1024
vivek mehtade4849c2016-03-03 17:23:38 -08001025 /* Initialize platform specific ids and/or backends*/
1026 platform_info_init(platform_info_file, my_data);
1027
1028 /* validate the sound card name
1029 * my_data->snd_card_name can contain
1030 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1031 * example: msm8994-tomtom-mtp-snd-card
1032 * <b> or sub string of the card name, i.e. <device>-<codec>
1033 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001034 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1035 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001036 */
1037
1038 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001039 strncmp(snd_card_name, my_data->snd_card_name,
1040 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001041 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1042 __func__, snd_card_name, my_data->snd_card_name);
1043 retry_num = 0;
1044 snd_card_num++;
1045 hw_info_deinit(my_data->hw_info);
1046 my_data->hw_info = NULL;
1047 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001048 }
vivek mehtade4849c2016-03-03 17:23:38 -08001049 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1050 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001051
1052 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1053 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1054
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001055 if (!adev->audio_route) {
1056 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001057 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001058 }
1059 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001060 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001061 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001062 }
1063
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001064 if (snd_card_num >= MAX_SND_CARD) {
1065 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001066 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001067 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001068
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001069 //set max volume step for voice call
1070 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1071 my_data->max_vol_index = atoi(value);
1072
vivek mehta65ad12d2015-08-13 18:32:48 -07001073 property_get("persist.audio.dualmic.config",value,"");
1074 if (!strcmp("endfire", value)) {
1075 dual_mic_config = true;
1076 }
1077
Prashant Malanic92c5962015-08-11 15:10:18 -07001078 my_data->source_mic_type = SOURCE_DUAL_MIC;
1079
Eric Laurentb23d5282013-05-14 15:27:20 -07001080 my_data->fluence_in_spkr_mode = false;
1081 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001082 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001083 my_data->fluence_in_voice_rec = false;
1084
vivek mehta65ad12d2015-08-13 18:32:48 -07001085 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001086 if (!strcmp("fluencepro", value)) {
1087 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001088 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001089 my_data->fluence_type = FLUENCE_ENABLE;
1090 } else if (!strcmp("none", value)) {
1091 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001092 }
1093
Prashant Malanic92c5962015-08-11 15:10:18 -07001094 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001095 property_get("persist.audio.fluence.voicecall",value,"");
1096 if (!strcmp("true", value)) {
1097 my_data->fluence_in_voice_call = true;
1098 }
1099
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001100 property_get("persist.audio.fluence.voicecomm",value,"");
1101 if (!strcmp("true", value)) {
1102 my_data->fluence_in_voice_comm = true;
1103 }
1104
Eric Laurentb23d5282013-05-14 15:27:20 -07001105 property_get("persist.audio.fluence.voicerec",value,"");
1106 if (!strcmp("true", value)) {
1107 my_data->fluence_in_voice_rec = true;
1108 }
1109
1110 property_get("persist.audio.fluence.speaker",value,"");
1111 if (!strcmp("true", value)) {
1112 my_data->fluence_in_spkr_mode = true;
1113 }
1114 }
1115
Prashant Malanic92c5962015-08-11 15:10:18 -07001116 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1117 switch (my_data->max_mic_count) {
1118 case 4:
1119 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1120 case 3:
1121 my_data->source_mic_type |= SOURCE_THREE_MIC;
1122 case 2:
1123 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1124 case 1:
1125 my_data->source_mic_type |= SOURCE_MONO_MIC;
1126 break;
1127 default:
1128 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1129 __func__, my_data->max_mic_count);
1130 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1131 break;
1132 }
1133
1134 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1135 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1136 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1137 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1138 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1139
Eric Laurentb23d5282013-05-14 15:27:20 -07001140 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1141 if (my_data->acdb_handle == NULL) {
1142 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1143 } else {
1144 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1145 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1146 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001147 if (!my_data->acdb_deallocate)
1148 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1149 __func__, LIB_ACDB_LOADER);
1150
Eric Laurentb23d5282013-05-14 15:27:20 -07001151 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1152 "acdb_loader_send_audio_cal");
1153 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001154 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001155 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001156
Eric Laurentb23d5282013-05-14 15:27:20 -07001157 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1158 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001159 if (!my_data->acdb_send_voice_cal)
1160 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1161 __func__, LIB_ACDB_LOADER);
1162
1163 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1164 "acdb_loader_reload_vocvoltable");
1165 if (!my_data->acdb_reload_vocvoltable)
1166 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1167 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001168
1169 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1170 "acdb_loader_send_gain_dep_cal");
1171 if (!my_data->acdb_send_gain_dep_cal)
1172 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1173 __func__, LIB_ACDB_LOADER);
1174
vivek mehtac698f132016-02-25 18:50:35 -08001175#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001176 acdb_init_v2_cvd_t acdb_init;
1177 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1178 "acdb_loader_init_v2");
1179 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001180 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001181 goto acdb_init_fail;
1182 }
1183
1184 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1185 get_cvd_version(cvd_version, adev);
1186 if (!cvd_version)
1187 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001188 else
vivek mehtac698f132016-02-25 18:50:35 -08001189 acdb_init((char *)snd_card_name, cvd_version, 0);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001190 free(cvd_version);
1191#elif defined (PLATFORM_MSM8084)
1192 acdb_init_v2_t acdb_init;
1193 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1194 "acdb_loader_init_v2");
1195 if (acdb_init == NULL) {
1196 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1197 goto acdb_init_fail;
1198 }
1199 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001200#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001201 acdb_init_t acdb_init;
1202 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001203 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001204 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001205 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1206 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001207 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001208#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001209 }
1210
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001211acdb_init_fail:
1212
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001213 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001214
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001215 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1216
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001217 /* load csd client */
1218 platform_csd_init(my_data);
1219
Eric Laurentb23d5282013-05-14 15:27:20 -07001220 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001221
1222init_failed:
1223 if (my_data)
1224 free(my_data);
1225 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001226}
1227
1228void platform_deinit(void *platform)
1229{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001230 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001231 struct operator_info *info_item;
1232 struct operator_specific_device *device_item;
1233 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001234
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001235 struct platform_data *my_data = (struct platform_data *)platform;
1236 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001237
vivek mehtade4849c2016-03-03 17:23:38 -08001238 hw_info_deinit(my_data->hw_info);
1239
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001240 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1241 if (backend_tag_table[dev])
1242 free(backend_tag_table[dev]);
1243 if (hw_interface_table[dev])
1244 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001245 if (operator_specific_device_table[dev]) {
1246 while (!list_empty(operator_specific_device_table[dev])) {
1247 node = list_head(operator_specific_device_table[dev]);
1248 list_remove(node);
1249 device_item = node_to_item(node, struct operator_specific_device, list);
1250 free(device_item->operator);
1251 free(device_item->mixer_path);
1252 free(device_item);
1253 }
1254 free(operator_specific_device_table[dev]);
1255 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001256 }
1257
1258 if (my_data->snd_card_name)
1259 free(my_data->snd_card_name);
1260
keunhui.park2f7306a2015-07-16 16:48:06 +09001261 while (!list_empty(&operator_info_list)) {
1262 node = list_head(&operator_info_list);
1263 list_remove(node);
1264 info_item = node_to_item(node, struct operator_info, list);
1265 free(info_item->name);
1266 free(info_item->mccmnc);
1267 free(info_item);
1268 }
1269
Eric Laurentb23d5282013-05-14 15:27:20 -07001270 free(platform);
1271}
1272
1273const char *platform_get_snd_device_name(snd_device_t snd_device)
1274{
keunhui.park2f7306a2015-07-16 16:48:06 +09001275 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1276 if (operator_specific_device_table[snd_device] != NULL) {
1277 return get_operator_specific_device_mixer_path(snd_device);
1278 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001279 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001280 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001281 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001282}
1283
vivek mehtade4849c2016-03-03 17:23:38 -08001284int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1285 char *device_name)
1286{
1287 struct platform_data *my_data = (struct platform_data *)platform;
1288
1289 if (platform == NULL || device_name == NULL) {
1290 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
1291 device_name = platform_get_snd_device_name(snd_device);
1292 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1293 if (operator_specific_device_table[snd_device] != NULL) {
1294 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1295 DEVICE_NAME_MAX_SIZE);
1296 } else {
1297 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1298 }
1299 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1300 } else {
1301 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1302 }
1303
1304 return 0;
1305}
1306
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001307void platform_add_backend_name(void *platform, char *mixer_path,
1308 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001309{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001310 struct platform_data *my_data = (struct platform_data *)platform;
1311
Haynes Mathew George98c95622014-06-20 19:14:25 -07001312 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1313 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1314 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001315 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001316
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001317 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001318
1319 if (suffix != NULL) {
1320 strcat(mixer_path, " ");
1321 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001322 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001323}
1324
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001325bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1326{
1327 bool result = true;
1328
1329 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1330 platform_get_snd_device_name(snd_device1),
1331 platform_get_snd_device_name(snd_device2));
1332
1333 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1334 ALOGE("%s: Invalid snd_device = %s", __func__,
1335 platform_get_snd_device_name(snd_device1));
1336 return false;
1337 }
1338 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1339 ALOGE("%s: Invalid snd_device = %s", __func__,
1340 platform_get_snd_device_name(snd_device2));
1341 return false;
1342 }
1343 const char * be_itf1 = hw_interface_table[snd_device1];
1344 const char * be_itf2 = hw_interface_table[snd_device2];
1345
1346 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001347 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001348 result = false;
1349 }
1350
1351 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1352 return result;
1353}
1354
Eric Laurentb23d5282013-05-14 15:27:20 -07001355int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1356{
1357 int device_id;
1358 if (device_type == PCM_PLAYBACK)
1359 device_id = pcm_device_table[usecase][0];
1360 else
1361 device_id = pcm_device_table[usecase][1];
1362 return device_id;
1363}
1364
Haynes Mathew George98c95622014-06-20 19:14:25 -07001365static int find_index(const struct name_to_index * table, int32_t len,
1366 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001367{
1368 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001369 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001370
Haynes Mathew George98c95622014-06-20 19:14:25 -07001371 if (table == NULL) {
1372 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001373 ret = -ENODEV;
1374 goto done;
1375 }
1376
Haynes Mathew George98c95622014-06-20 19:14:25 -07001377 if (name == NULL) {
1378 ALOGE("null key");
1379 ret = -ENODEV;
1380 goto done;
1381 }
1382
1383 for (i=0; i < len; i++) {
1384 if (!strcmp(table[i].name, name)) {
1385 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001386 goto done;
1387 }
1388 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001389 ALOGE("%s: Could not find index for name = %s",
1390 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001391 ret = -ENODEV;
1392done:
1393 return ret;
1394}
1395
Haynes Mathew George98c95622014-06-20 19:14:25 -07001396int platform_get_snd_device_index(char *device_name)
1397{
1398 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1399}
1400
1401int platform_get_usecase_index(const char *usecase_name)
1402{
1403 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1404}
1405
keunhui.park2f7306a2015-07-16 16:48:06 +09001406void platform_add_operator_specific_device(snd_device_t snd_device,
1407 const char *operator,
1408 const char *mixer_path,
1409 unsigned int acdb_id)
1410{
1411 struct operator_specific_device *device;
1412
1413 if (operator_specific_device_table[snd_device] == NULL) {
1414 operator_specific_device_table[snd_device] =
1415 (struct listnode *)calloc(1, sizeof(struct listnode));
1416 list_init(operator_specific_device_table[snd_device]);
1417 }
1418
1419 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1420
1421 device->operator = strdup(operator);
1422 device->mixer_path = strdup(mixer_path);
1423 device->acdb_id = acdb_id;
1424
1425 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1426
Eric Laurent2bafff12016-03-17 12:17:23 -07001427 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001428 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1429
1430}
1431
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001432int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1433{
1434 int ret = 0;
1435
1436 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1437 ALOGE("%s: Invalid snd_device = %d",
1438 __func__, snd_device);
1439 ret = -EINVAL;
1440 goto done;
1441 }
1442
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001443 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1444 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001445 acdb_device_table[snd_device] = acdb_id;
1446done:
1447 return ret;
1448}
1449
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001450int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1451{
1452 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1453 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1454 return -EINVAL;
1455 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001456
1457 if (operator_specific_device_table[snd_device] != NULL)
1458 return get_operator_specific_device_acdb_id(snd_device);
1459 else
1460 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001461}
1462
Eric Laurentb23d5282013-05-14 15:27:20 -07001463int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1464{
1465 struct platform_data *my_data = (struct platform_data *)platform;
1466 int acdb_dev_id, acdb_dev_type;
1467
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001468 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001469 if (acdb_dev_id < 0) {
1470 ALOGE("%s: Could not find acdb id for device(%d)",
1471 __func__, snd_device);
1472 return -EINVAL;
1473 }
1474 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001475 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001476 __func__, snd_device, acdb_dev_id);
1477 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1478 snd_device < SND_DEVICE_OUT_END)
1479 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1480 else
1481 acdb_dev_type = ACDB_DEV_TYPE_IN;
1482 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1483 }
1484 return 0;
1485}
1486
1487int platform_switch_voice_call_device_pre(void *platform)
1488{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001489 struct platform_data *my_data = (struct platform_data *)platform;
1490 int ret = 0;
1491
1492 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001493 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001494 /* This must be called before disabling mixer controls on APQ side */
1495 ret = my_data->csd->disable_device();
1496 if (ret < 0) {
1497 ALOGE("%s: csd_client_disable_device, failed, error %d",
1498 __func__, ret);
1499 }
1500 }
1501 return ret;
1502}
1503
1504int platform_switch_voice_call_enable_device_config(void *platform,
1505 snd_device_t out_snd_device,
1506 snd_device_t in_snd_device)
1507{
1508 struct platform_data *my_data = (struct platform_data *)platform;
1509 int acdb_rx_id, acdb_tx_id;
1510 int ret = 0;
1511
1512 if (my_data->csd == NULL)
1513 return ret;
1514
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001515 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1516 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001517 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001518 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001519 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001520
keunhui.park2f7306a2015-07-16 16:48:06 +09001521 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001522
1523 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1524 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1525 if (ret < 0) {
1526 ALOGE("%s: csd_enable_device_config, failed, error %d",
1527 __func__, ret);
1528 }
1529 } else {
1530 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1531 acdb_rx_id, acdb_tx_id);
1532 }
1533
1534 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001535}
1536
1537int platform_switch_voice_call_device_post(void *platform,
1538 snd_device_t out_snd_device,
1539 snd_device_t in_snd_device)
1540{
1541 struct platform_data *my_data = (struct platform_data *)platform;
1542 int acdb_rx_id, acdb_tx_id;
1543
1544 if (my_data->acdb_send_voice_cal == NULL) {
1545 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1546 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001547 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1548 audio_extn_spkr_prot_is_enabled())
1549 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1550
keunhui.park2f7306a2015-07-16 16:48:06 +09001551 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1552 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001553
1554 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1555 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1556 else
1557 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1558 acdb_rx_id, acdb_tx_id);
1559 }
1560
1561 return 0;
1562}
1563
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001564int platform_switch_voice_call_usecase_route_post(void *platform,
1565 snd_device_t out_snd_device,
1566 snd_device_t in_snd_device)
1567{
1568 struct platform_data *my_data = (struct platform_data *)platform;
1569 int acdb_rx_id, acdb_tx_id;
1570 int ret = 0;
1571
1572 if (my_data->csd == NULL)
1573 return ret;
1574
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001575 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1576 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001577 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001578 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001579 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001580
keunhui.park2f7306a2015-07-16 16:48:06 +09001581 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001582
1583 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1584 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1585 my_data->adev->acdb_settings);
1586 if (ret < 0) {
1587 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1588 }
1589 } else {
1590 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1591 acdb_rx_id, acdb_tx_id);
1592 }
1593
1594 return ret;
1595}
1596
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001597int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001598{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001599 struct platform_data *my_data = (struct platform_data *)platform;
1600 int ret = 0;
1601
1602 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001603 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001604 if (ret < 0) {
1605 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1606 }
1607 }
1608 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001609}
1610
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001611int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001612{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001613 struct platform_data *my_data = (struct platform_data *)platform;
1614 int ret = 0;
1615
1616 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001617 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001618 if (ret < 0) {
1619 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1620 }
1621 }
1622 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001623}
1624
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001625int platform_get_sample_rate(void *platform, uint32_t *rate)
1626{
1627 struct platform_data *my_data = (struct platform_data *)platform;
1628 int ret = 0;
1629
1630 if (my_data->csd != NULL) {
1631 ret = my_data->csd->get_sample_rate(rate);
1632 if (ret < 0) {
1633 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1634 }
1635 }
1636 return ret;
1637}
1638
vivek mehtab6506412015-08-07 16:55:17 -07001639void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1640 snd_device_t snd_device,
1641 bool enable)
1642{
1643 const char* name;
1644 switch (snd_device) {
1645 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1646 if (enable)
1647 name = "spkr-gain-in-headphone-combo";
1648 else
1649 name = "speaker-gain-default";
1650 break;
1651 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1652 if (enable)
1653 name = "spkr-gain-in-line-combo";
1654 else
1655 name = "speaker-gain-default";
1656 break;
1657 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1658 if (enable)
1659 name = "spkr-safe-gain-in-headphone-combo";
1660 else
1661 name = "speaker-safe-gain-default";
1662 break;
1663 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1664 if (enable)
1665 name = "spkr-safe-gain-in-line-combo";
1666 else
1667 name = "speaker-safe-gain-default";
1668 break;
1669 default:
1670 return;
1671 }
1672
1673 audio_route_apply_and_update_path(adev->audio_route, name);
1674}
1675
Eric Laurentb23d5282013-05-14 15:27:20 -07001676int platform_set_voice_volume(void *platform, int volume)
1677{
1678 struct platform_data *my_data = (struct platform_data *)platform;
1679 struct audio_device *adev = my_data->adev;
1680 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001681 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001682 int vol_index = 0, ret = 0;
1683 uint32_t set_values[ ] = {0,
1684 ALL_SESSION_VSID,
1685 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001686
1687 // Voice volume levels are mapped to adsp volume levels as follows.
1688 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1689 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001690 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001691 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001692
1693 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1694 if (!ctl) {
1695 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1696 __func__, mixer_ctl_name);
1697 return -EINVAL;
1698 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001699 ALOGV("Setting voice volume index: %d", set_values[0]);
1700 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1701
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001702 if (my_data->csd != NULL) {
1703 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1704 DEFAULT_VOLUME_RAMP_DURATION_MS);
1705 if (ret < 0) {
1706 ALOGE("%s: csd_volume error %d", __func__, ret);
1707 }
1708 }
1709 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001710}
1711
1712int platform_set_mic_mute(void *platform, bool state)
1713{
1714 struct platform_data *my_data = (struct platform_data *)platform;
1715 struct audio_device *adev = my_data->adev;
1716 struct mixer_ctl *ctl;
1717 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001718 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001719 uint32_t set_values[ ] = {0,
1720 ALL_SESSION_VSID,
1721 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001722
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001723 if (adev->mode != AUDIO_MODE_IN_CALL &&
1724 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001725 return 0;
1726
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001727 if (adev->enable_hfp)
1728 mixer_ctl_name = "HFP Tx Mute";
1729
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001730 set_values[0] = state;
1731 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1732 if (!ctl) {
1733 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1734 __func__, mixer_ctl_name);
1735 return -EINVAL;
1736 }
1737 ALOGV("Setting voice mute state: %d", state);
1738 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1739
1740 if (my_data->csd != NULL) {
1741 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1742 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001743 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001744 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001745 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001746 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001747 return ret;
1748}
Eric Laurentb23d5282013-05-14 15:27:20 -07001749
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001750int platform_set_device_mute(void *platform, bool state, char *dir)
1751{
1752 struct platform_data *my_data = (struct platform_data *)platform;
1753 struct audio_device *adev = my_data->adev;
1754 struct mixer_ctl *ctl;
1755 char *mixer_ctl_name = NULL;
1756 int ret = 0;
1757 uint32_t set_values[ ] = {0,
1758 ALL_SESSION_VSID,
1759 0};
1760 if(dir == NULL) {
1761 ALOGE("%s: Invalid direction:%s", __func__, dir);
1762 return -EINVAL;
1763 }
1764
1765 if (!strncmp("rx", dir, sizeof("rx"))) {
1766 mixer_ctl_name = "Voice Rx Device Mute";
1767 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1768 mixer_ctl_name = "Voice Tx Device Mute";
1769 } else {
1770 return -EINVAL;
1771 }
1772
1773 set_values[0] = state;
1774 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1775 if (!ctl) {
1776 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1777 __func__, mixer_ctl_name);
1778 return -EINVAL;
1779 }
1780
1781 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1782 __func__,state, mixer_ctl_name);
1783 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1784
1785 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001786}
1787
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001788bool platform_can_split_snd_device(snd_device_t snd_device,
1789 int *num_devices,
1790 snd_device_t *new_snd_devices)
1791{
1792 bool status = false;
1793
1794 if (NULL == num_devices || NULL == new_snd_devices) {
1795 ALOGE("%s: NULL pointer ..", __func__);
1796 return false;
1797 }
1798
1799 /*
1800 * If wired headset/headphones/line devices share the same backend
1801 * with speaker/earpiece this routine returns false.
1802 */
1803 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1804 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1805 *num_devices = 2;
1806 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1807 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1808 status = true;
1809 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1810 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1811 *num_devices = 2;
1812 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1813 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1814 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001815 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1816 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1817 *num_devices = 2;
1818 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1819 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1820 status = true;
1821 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1822 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1823 *num_devices = 2;
1824 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1825 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1826 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001827 }
1828 return status;
1829}
1830
Eric Laurentb23d5282013-05-14 15:27:20 -07001831snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1832{
1833 struct platform_data *my_data = (struct platform_data *)platform;
1834 struct audio_device *adev = my_data->adev;
1835 audio_mode_t mode = adev->mode;
1836 snd_device_t snd_device = SND_DEVICE_NONE;
1837
1838 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1839 if (devices == AUDIO_DEVICE_NONE ||
1840 devices & AUDIO_DEVICE_BIT_IN) {
1841 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1842 goto exit;
1843 }
1844
Eric Laurent1b491552015-09-15 17:52:41 -07001845 if (popcount(devices) == 2) {
1846 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1847 AUDIO_DEVICE_OUT_SPEAKER) ||
1848 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1849 AUDIO_DEVICE_OUT_SPEAKER)) {
1850 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1851 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1852 AUDIO_DEVICE_OUT_SPEAKER)) {
1853 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1854 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1855 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1856 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1857 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1858 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1859 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1860 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1861 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1862 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1863 AUDIO_DEVICE_OUT_SPEAKER)) {
1864 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1865 } else {
1866 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1867 goto exit;
1868 }
1869 if (snd_device != SND_DEVICE_NONE) {
1870 goto exit;
1871 }
1872 }
1873
1874 if (popcount(devices) != 1) {
1875 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1876 goto exit;
1877 }
1878
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001879 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001880 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001881 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1882 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001883 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001884 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001885 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_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_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001888 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001889 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001890 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001891 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001892 else {
1893 if (devices & AUDIO_DEVICE_OUT_LINE)
1894 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1895 else
1896 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1897 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001898 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001899 if (adev->bt_wb_speech_enabled) {
1900 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1901 } else {
1902 snd_device = SND_DEVICE_OUT_BT_SCO;
1903 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001904 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001905 if (!adev->enable_hfp) {
1906 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1907 } else {
1908 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1909 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001910 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001911 if(adev->voice.hac)
1912 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1913 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001914 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1915 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001916 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001917 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1918 snd_device = SND_DEVICE_OUT_VOICE_TX;
1919
Eric Laurentb23d5282013-05-14 15:27:20 -07001920 if (snd_device != SND_DEVICE_NONE) {
1921 goto exit;
1922 }
1923 }
1924
Eric Laurentb23d5282013-05-14 15:27:20 -07001925 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1926 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1927 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001928 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1929 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001930 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1931 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001932 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001933 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001934 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1935 else
1936 snd_device = SND_DEVICE_OUT_SPEAKER;
1937 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001938 if (adev->bt_wb_speech_enabled) {
1939 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1940 } else {
1941 snd_device = SND_DEVICE_OUT_BT_SCO;
1942 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001943 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1944 snd_device = SND_DEVICE_OUT_HDMI ;
1945 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001946 /*HAC support for voice-ish audio (eg visual voicemail)*/
1947 if(adev->voice.hac)
1948 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1949 else
1950 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001951 } else {
1952 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1953 }
1954exit:
1955 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1956 return snd_device;
1957}
1958
1959snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1960{
1961 struct platform_data *my_data = (struct platform_data *)platform;
1962 struct audio_device *adev = my_data->adev;
1963 audio_source_t source = (adev->active_input == NULL) ?
1964 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1965
1966 audio_mode_t mode = adev->mode;
1967 audio_devices_t in_device = ((adev->active_input == NULL) ?
1968 AUDIO_DEVICE_NONE : adev->active_input->device)
1969 & ~AUDIO_DEVICE_BIT_IN;
1970 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1971 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1972 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001973 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001974
Prashant Malanic92c5962015-08-11 15:10:18 -07001975 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1976 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001977 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001978 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001979 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001980 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1981 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001982 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001983 case TTY_MODE_FULL:
1984 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1985 break;
1986 case TTY_MODE_VCO:
1987 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1988 break;
1989 case TTY_MODE_HCO:
1990 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1991 break;
1992 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001993 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001994 }
1995 goto exit;
1996 }
1997 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001998 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001999 if (my_data->fluence_in_voice_call == false) {
2000 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2001 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002002 if (is_operator_tmus())
2003 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002004 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002005 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002006 }
2007 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2008 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2009 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002010 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002011 if (adev->bluetooth_nrec)
2012 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2013 else
2014 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002015 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002016 if (adev->bluetooth_nrec)
2017 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2018 else
2019 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002020 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002021 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002022 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2023 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2024 out_device & AUDIO_DEVICE_OUT_LINE) {
2025 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2026 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2027 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2028 } else {
2029 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2030 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002031 }
vivek mehtafe121d52015-08-10 23:39:23 -07002032
2033 //select default
2034 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002035 if (!adev->enable_hfp) {
2036 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2037 } else {
2038 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2039 platform_set_echo_reference(adev, true, out_device);
2040 }
vivek mehtafe121d52015-08-10 23:39:23 -07002041 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002042 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002043 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002044 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002045 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2046 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2047 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2048 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2049 }
2050 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2051 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002052 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2053 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2054 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2055 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
2056 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2057 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2058 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
2059 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2060 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2061 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002062 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002063 }
2064 platform_set_echo_reference(adev, true, out_device);
2065 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2066 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2067 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2068 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2069 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2070 snd_device = SND_DEVICE_IN_THREE_MIC;
2071 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2072 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2073 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002074 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002075 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002076 if (adev->active_input->enable_ns)
2077 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2078 else
2079 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002080 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002081 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2082 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002083 }
rago90fb9612015-12-02 11:37:53 -08002084 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2085 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2086 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2087 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2088 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2089 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002090 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002091 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002092 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002093 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2094 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002095 if (adev->active_input->enable_aec &&
2096 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002097 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002098 if (my_data->fluence_in_spkr_mode &&
2099 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002100 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002101 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002102 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002103 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002104 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002105 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002106 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002107 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002108 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002109 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002110 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002111 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002112 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2113 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002114 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002115 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002116 } else if (adev->active_input->enable_aec) {
2117 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2118 if (my_data->fluence_in_spkr_mode &&
2119 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002120 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002121 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002122 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002123 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002124 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002125 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2126 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002127 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002128 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002129 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002130 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002131 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002132 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2133 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2134 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002135 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002136 } else if (adev->active_input->enable_ns) {
2137 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2138 if (my_data->fluence_in_spkr_mode &&
2139 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002140 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002141 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002142 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002143 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002144 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002145 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2146 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002147 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002148 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002149 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002150 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002151 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002152 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002153 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002154 }
2155 } else if (source == AUDIO_SOURCE_DEFAULT) {
2156 goto exit;
2157 }
2158
2159
2160 if (snd_device != SND_DEVICE_NONE) {
2161 goto exit;
2162 }
2163
2164 if (in_device != AUDIO_DEVICE_NONE &&
2165 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2166 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2167 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002168 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2169 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2170 snd_device = SND_DEVICE_IN_QUAD_MIC;
2171 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2172 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2173 snd_device = SND_DEVICE_IN_THREE_MIC;
2174 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2175 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002176 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002177 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2178 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002179 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002180 } else {
2181 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2182 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2183 my_data->source_mic_type, channel_count, channel_mask);
2184 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2185 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002186 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002187 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2188 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002189 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002190 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2191 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002192 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002193 } else {
2194 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2195 " no combination found .. setting to mono", __func__,
2196 my_data->source_mic_type, channel_count);
2197 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2198 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002199 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2200 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2201 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002202 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002203 if (adev->bluetooth_nrec)
2204 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2205 else
2206 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002207 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002208 if (adev->bluetooth_nrec)
2209 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2210 else
2211 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002212 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002213 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2214 snd_device = SND_DEVICE_IN_HDMI_MIC;
2215 } else {
2216 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2217 ALOGW("%s: Using default handset-mic", __func__);
2218 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2219 }
2220 } else {
2221 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2222 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2223 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2224 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002225 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002226 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002227 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002228 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002229 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2230 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002231 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002232 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2233 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002234 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002235 } else {
2236 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2237 " no combination found .. setting to mono", __func__,
2238 my_data->source_mic_type, channel_count);
2239 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2240 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002241 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002242 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002243 if (adev->bluetooth_nrec)
2244 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2245 else
2246 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002247 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002248 if (adev->bluetooth_nrec)
2249 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2250 else
2251 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002252 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002253 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2254 snd_device = SND_DEVICE_IN_HDMI_MIC;
2255 } else {
2256 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2257 ALOGW("%s: Using default handset-mic", __func__);
2258 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2259 }
2260 }
2261exit:
2262 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2263 return snd_device;
2264}
2265
2266int platform_set_hdmi_channels(void *platform, int channel_count)
2267{
2268 struct platform_data *my_data = (struct platform_data *)platform;
2269 struct audio_device *adev = my_data->adev;
2270 struct mixer_ctl *ctl;
2271 const char *channel_cnt_str = NULL;
2272 const char *mixer_ctl_name = "HDMI_RX Channels";
2273 switch (channel_count) {
2274 case 8:
2275 channel_cnt_str = "Eight"; break;
2276 case 7:
2277 channel_cnt_str = "Seven"; break;
2278 case 6:
2279 channel_cnt_str = "Six"; break;
2280 case 5:
2281 channel_cnt_str = "Five"; break;
2282 case 4:
2283 channel_cnt_str = "Four"; break;
2284 case 3:
2285 channel_cnt_str = "Three"; break;
2286 default:
2287 channel_cnt_str = "Two"; break;
2288 }
2289 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2290 if (!ctl) {
2291 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2292 __func__, mixer_ctl_name);
2293 return -EINVAL;
2294 }
2295 ALOGV("HDMI channel count: %s", channel_cnt_str);
2296 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2297 return 0;
2298}
2299
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002300int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002301{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002302 struct platform_data *my_data = (struct platform_data *)platform;
2303 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002304 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2305 char *sad = block;
2306 int num_audio_blocks;
2307 int channel_count;
2308 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002309 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002310
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002311 struct mixer_ctl *ctl;
2312
2313 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2314 if (!ctl) {
2315 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2316 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002317 return 0;
2318 }
2319
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002320 mixer_ctl_update(ctl);
2321
2322 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002323
2324 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002325 if (count > (int)sizeof(block))
2326 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002327
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002328 ret = mixer_ctl_get_array(ctl, block, count);
2329 if (ret != 0) {
2330 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2331 return 0;
2332 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002333
2334 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002335 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002336
2337 for (i = 0; i < num_audio_blocks; i++) {
2338 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002339 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2340 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002341 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002342 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002343
2344 channel_count = (sad[0] & 0x7) + 1;
2345 if (channel_count > max_channels)
2346 max_channels = channel_count;
2347
2348 /* Advance to next block */
2349 sad += 3;
2350 }
2351
2352 return max_channels;
2353}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002354
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002355int platform_set_incall_recording_session_id(void *platform,
2356 uint32_t session_id, int rec_mode)
2357{
2358 int ret = 0;
2359 struct platform_data *my_data = (struct platform_data *)platform;
2360 struct audio_device *adev = my_data->adev;
2361 struct mixer_ctl *ctl;
2362 const char *mixer_ctl_name = "Voc VSID";
2363 int num_ctl_values;
2364 int i;
2365
2366 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2367 if (!ctl) {
2368 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2369 __func__, mixer_ctl_name);
2370 ret = -EINVAL;
2371 } else {
2372 num_ctl_values = mixer_ctl_get_num_values(ctl);
2373 for (i = 0; i < num_ctl_values; i++) {
2374 if (mixer_ctl_set_value(ctl, i, session_id)) {
2375 ALOGV("Error: invalid session_id: %x", session_id);
2376 ret = -EINVAL;
2377 break;
2378 }
2379 }
2380 }
2381
2382 if (my_data->csd != NULL) {
2383 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2384 if (ret < 0) {
2385 ALOGE("%s: csd_client_start_record failed, error %d",
2386 __func__, ret);
2387 }
2388 }
2389
2390 return ret;
2391}
2392
2393int platform_stop_incall_recording_usecase(void *platform)
2394{
2395 int ret = 0;
2396 struct platform_data *my_data = (struct platform_data *)platform;
2397
2398 if (my_data->csd != NULL) {
2399 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2400 if (ret < 0) {
2401 ALOGE("%s: csd_client_stop_record failed, error %d",
2402 __func__, ret);
2403 }
2404 }
2405
2406 return ret;
2407}
2408
2409int platform_start_incall_music_usecase(void *platform)
2410{
2411 int ret = 0;
2412 struct platform_data *my_data = (struct platform_data *)platform;
2413
2414 if (my_data->csd != NULL) {
2415 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2416 if (ret < 0) {
2417 ALOGE("%s: csd_client_start_playback failed, error %d",
2418 __func__, ret);
2419 }
2420 }
2421
2422 return ret;
2423}
2424
2425int platform_stop_incall_music_usecase(void *platform)
2426{
2427 int ret = 0;
2428 struct platform_data *my_data = (struct platform_data *)platform;
2429
2430 if (my_data->csd != NULL) {
2431 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2432 if (ret < 0) {
2433 ALOGE("%s: csd_client_stop_playback failed, error %d",
2434 __func__, ret);
2435 }
2436 }
2437
2438 return ret;
2439}
2440
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002441int platform_set_parameters(void *platform, struct str_parms *parms)
2442{
2443 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002444 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002445 char *kv_pairs = str_parms_to_str(parms);
2446 int ret = 0, err;
2447
2448 if (kv_pairs == NULL) {
2449 ret = -EINVAL;
2450 ALOGE("%s: key-value pair is NULL",__func__);
2451 goto done;
2452 }
2453
2454 ALOGV("%s: enter: %s", __func__, kv_pairs);
2455
2456 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2457 value, sizeof(value));
2458 if (err >= 0) {
2459 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2460 my_data->snd_card_name = strdup(value);
2461 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2462 }
2463
keunhui.park2f7306a2015-07-16 16:48:06 +09002464 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2465 value, sizeof(value));
2466 if (err >= 0) {
2467 struct operator_info *info;
2468 char *str = value;
2469 char *name;
2470
2471 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2472 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2473 name = strtok(str, ";");
2474 info->name = strdup(name);
2475 info->mccmnc = strdup(str + strlen(name) + 1);
2476
2477 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002478 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002479 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002480
2481 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002482 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002483 value, sizeof(value));
2484 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002485 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002486 my_data->max_mic_count = atoi(value);
2487 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002488 }
2489
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002490done:
2491 ALOGV("%s: exit with code(%d)", __func__, ret);
2492 if (kv_pairs != NULL)
2493 free(kv_pairs);
2494
2495 return ret;
2496}
2497
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002498/* Delay in Us */
2499int64_t platform_render_latency(audio_usecase_t usecase)
2500{
2501 switch (usecase) {
2502 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2503 return DEEP_BUFFER_PLATFORM_DELAY;
2504 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2505 return LOW_LATENCY_PLATFORM_DELAY;
2506 default:
2507 return 0;
2508 }
2509}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002510
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002511int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2512 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002513{
2514 int ret = 0;
2515
2516 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2517 ALOGE("%s: Invalid snd_device = %d",
2518 __func__, device);
2519 ret = -EINVAL;
2520 goto done;
2521 }
2522
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002523 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2524 platform_get_snd_device_name(device),
2525 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2526 if (backend_tag_table[device]) {
2527 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002528 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002529 backend_tag_table[device] = strdup(backend_tag);
2530
2531 if (hw_interface != NULL) {
2532 if (hw_interface_table[device])
2533 free(hw_interface_table[device]);
2534 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2535 hw_interface_table[device] = strdup(hw_interface);
2536 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002537done:
2538 return ret;
2539}
2540
2541int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2542{
2543 int ret = 0;
2544 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2545 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2546 ret = -EINVAL;
2547 goto done;
2548 }
2549
2550 if ((type != 0) && (type != 1)) {
2551 ALOGE("%s: invalid usecase type", __func__);
2552 ret = -EINVAL;
2553 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002554 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002555 pcm_device_table[usecase][type] = pcm_id;
2556done:
2557 return ret;
2558}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002559
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002560#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2561int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2562 // backup_gain: gain to try to set in case of an error during ramp
2563 int start_gain, end_gain, step, backup_gain, i;
2564 bool error = false;
2565 const struct mixer_ctl *ctl;
2566 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2567 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2568 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2569 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2570 if (!ctl_left || !ctl_right) {
2571 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2572 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2573 return -EINVAL;
2574 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2575 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2576 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2577 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2578 return -EINVAL;
2579 }
2580 if (ramp_up) {
2581 start_gain = 0;
2582 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2583 step = +1;
2584 backup_gain = end_gain;
2585 } else {
2586 // using same gain on left and right
2587 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2588 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2589 end_gain = 0;
2590 step = -1;
2591 backup_gain = start_gain;
2592 }
2593 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2594 //ALOGV("setting speaker gain to %d", i);
2595 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2596 ALOGE("%s: error setting %s to %d during gain ramp",
2597 __func__, mixer_ctl_name_gain_left, i);
2598 error = true;
2599 break;
2600 }
2601 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2602 ALOGE("%s: error setting %s to %d during gain ramp",
2603 __func__, mixer_ctl_name_gain_right, i);
2604 error = true;
2605 break;
2606 }
2607 usleep(1000);
2608 }
2609 if (error) {
2610 // an error occured during the ramp, let's still try to go back to a safe volume
2611 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2612 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2613 }
2614 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2615 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2616 }
2617 }
2618 return start_gain;
2619}
2620
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002621int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2622{
2623 // only update if there is active pcm playback on speaker
2624 struct audio_usecase *usecase;
2625 struct listnode *node;
2626 struct platform_data *my_data = (struct platform_data *)adev->platform;
2627
2628 if (my_data->speaker_lr_swap != swap_channels) {
2629 my_data->speaker_lr_swap = swap_channels;
2630
2631 list_for_each(node, &adev->usecase_list) {
2632 usecase = node_to_item(node, struct audio_usecase, list);
2633 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002634 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2635 /*
2636 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2637 * to perform device switch to disable the current backend to
2638 * enable it with new acdb data.
2639 */
2640 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2641 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002642 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002643 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002644 if (initial_skpr_gain != -EINVAL) {
2645 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2646 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002647 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002648 const char *mixer_path;
2649 if (swap_channels) {
2650 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2651 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2652 } else {
2653 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2654 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2655 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002656 }
2657 break;
2658 }
2659 }
2660 }
2661 return 0;
2662}