blob: f4f2f73f29aa17718524541ab24d2c5558074fe8 [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",
vivek mehta733c1df2016-04-04 15:09:24 -0700261 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700262 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
263 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700264 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700265
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700266 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
rago90fb9612015-12-02 11:37:53 -0800267 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "headset-mic",
268
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700269 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700270
Prashant Malanic92c5962015-08-11 15:10:18 -0700271 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
272 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700273 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700274 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
275 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700276 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
277 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700278};
279
280/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700281static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700282 [SND_DEVICE_NONE] = -1,
283 [SND_DEVICE_OUT_HANDSET] = 7,
284 [SND_DEVICE_OUT_SPEAKER] = 15,
285 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700286 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700287 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500288 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700289 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700290 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500291 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700292 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700293 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
294 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500295 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700296 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500297 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700298 [SND_DEVICE_OUT_HDMI] = 18,
299 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
300 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700301 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700302 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700303 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
304 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
305 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700306 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700307 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
308 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700309 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700310
311 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700312 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
313 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
314 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
315 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
316 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
317 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
318 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
319 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
320
321 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
322 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
323 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
324 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
325 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
326 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
327 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
328 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
329 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
330
rago90fb9612015-12-02 11:37:53 -0800331 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500332 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700333
Eric Laurentb23d5282013-05-14 15:27:20 -0700334 [SND_DEVICE_IN_HDMI_MIC] = 4,
335 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700336 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700337 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700338 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700339 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700340
341 [SND_DEVICE_IN_VOICE_DMIC] = 41,
342 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
343 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700344 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700345 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800346 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700347 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
348 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
349 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700350
rago90fb9612015-12-02 11:37:53 -0800351 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700352 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700353 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700354 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
355 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800356 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
357
358 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
359 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700360
361 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700362
Prashant Malanic92c5962015-08-11 15:10:18 -0700363 [SND_DEVICE_IN_THREE_MIC] = 46,
364 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700365 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700366 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
367 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700368 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
369 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700370};
371
Haynes Mathew George98c95622014-06-20 19:14:25 -0700372struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700373 char name[100];
374 unsigned int index;
375};
376
377#define TO_NAME_INDEX(X) #X, X
378
Haynes Mathew George98c95622014-06-20 19:14:25 -0700379/* Used to get index from parsed string */
380static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
381 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700382 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
383 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
384 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700385 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700386 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500387 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700388 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700389 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500390 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700391 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700392 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
393 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700394 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700395 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500396 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700397 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
398 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
399 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
400 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700401 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500402 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700403 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
404 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
405 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700406
407 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700408 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
409 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700410 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700411 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700412 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
413 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
414 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
415 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
416 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
418 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
419
420 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700421 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700422 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
423 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
424 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
425 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
426 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
427 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
428 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
429
430 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700431 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700432
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700433 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
434 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700435 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700436 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700437 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700438 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700439
440 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
441 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
442 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700443 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700444 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
445 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700446 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
447 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
448 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700449
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700450 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700451 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700452 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700453 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700455 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700456
rago90fb9612015-12-02 11:37:53 -0800457 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
458 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
459
Prashant Malanic92c5962015-08-11 15:10:18 -0700460 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
461 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700462 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700463 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
464 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700465 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700467};
468
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700469static char * backend_tag_table[SND_DEVICE_MAX] = {0};
470static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700471
472static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
473 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
474 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
475 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
476 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700477 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
478 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700479 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
480 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
481 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
482 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
483 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
484 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
485 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
486 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
487 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
488 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
489 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700490};
491
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700492#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
493#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
494
Eric Laurentb23d5282013-05-14 15:27:20 -0700495static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
496static bool is_tmus = false;
497
498static void check_operator()
499{
500 char value[PROPERTY_VALUE_MAX];
501 int mccmnc;
502 property_get("gsm.sim.operator.numeric",value,"0");
503 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700504 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700505 switch(mccmnc) {
506 /* TMUS MCC(310), MNC(490, 260, 026) */
507 case 310490:
508 case 310260:
509 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900510 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
511 case 310800:
512 case 310660:
513 case 310580:
514 case 310310:
515 case 310270:
516 case 310250:
517 case 310240:
518 case 310230:
519 case 310220:
520 case 310210:
521 case 310200:
522 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700523 is_tmus = true;
524 break;
525 }
526}
527
528bool is_operator_tmus()
529{
530 pthread_once(&check_op_once_ctl, check_operator);
531 return is_tmus;
532}
533
keunhui.park2f7306a2015-07-16 16:48:06 +0900534static char *get_current_operator()
535{
536 struct listnode *node;
537 struct operator_info *info_item;
538 char mccmnc[PROPERTY_VALUE_MAX];
539 char *ret = NULL;
540
541 property_get("gsm.sim.operator.numeric",mccmnc,"0");
542
543 list_for_each(node, &operator_info_list) {
544 info_item = node_to_item(node, struct operator_info, list);
545 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
546 ret = info_item->name;
547 }
548 }
549
550 return ret;
551}
552
553static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
554{
555 struct listnode *node;
556 struct operator_specific_device *ret = NULL;
557 struct operator_specific_device *device_item;
558 char *operator_name;
559
560 operator_name = get_current_operator();
561 if (operator_name == NULL)
562 return ret;
563
564 list_for_each(node, operator_specific_device_table[snd_device]) {
565 device_item = node_to_item(node, struct operator_specific_device, list);
566 if (strcmp(operator_name, device_item->operator) == 0) {
567 ret = device_item;
568 }
569 }
570
571 return ret;
572}
573
574
575static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
576{
577 struct operator_specific_device *device;
578 int ret = acdb_device_table[snd_device];
579
580 device = get_operator_specific_device(snd_device);
581 if (device != NULL)
582 ret = device->acdb_id;
583
584 return ret;
585}
586
587static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
588{
589 struct operator_specific_device *device;
590 const char *ret = device_table[snd_device];
591
592 device = get_operator_specific_device(snd_device);
593 if (device != NULL)
594 ret = device->mixer_path;
595
596 return ret;
597}
598
vivek mehta1a9b7c02015-06-25 11:49:38 -0700599bool platform_send_gain_dep_cal(void *platform, int level)
600{
601 bool ret_val = false;
602 struct platform_data *my_data = (struct platform_data *)platform;
603 struct audio_device *adev = my_data->adev;
604 int acdb_dev_id, app_type;
605 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
606 int mode = CAL_MODE_RTAC;
607 struct listnode *node;
608 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700609
610 if (my_data->acdb_send_gain_dep_cal == NULL) {
611 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
612 return ret_val;
613 }
614
615 if (!voice_is_in_call(adev)) {
616 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
617 __func__, level);
618 app_type = DEFAULT_APP_TYPE_RX_PATH;
619
620 // find the current active sound device
621 list_for_each(node, &adev->usecase_list) {
622 usecase = node_to_item(node, struct audio_usecase, list);
623
624 if (usecase != NULL &&
625 usecase->type == PCM_PLAYBACK &&
626 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
627
628 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700629 if (audio_extn_spkr_prot_is_enabled()) {
630 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
631 } else {
632 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
633 }
634
vivek mehta1a9b7c02015-06-25 11:49:38 -0700635 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
636 acdb_dev_type, mode, level)) {
637 // set ret_val true if at least one calibration is set successfully
638 ret_val = true;
639 } else {
640 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
641 }
642 } else {
643 ALOGW("%s: Usecase list is empty", __func__);
644 }
645 }
646 } else {
647 ALOGW("%s: Voice call in progress .. ignore setting new cal",
648 __func__);
649 }
650 return ret_val;
651}
652
Eric Laurentcefbbac2014-09-04 13:54:10 -0500653void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700654{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800655 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500656 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700657
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800658 if (strcmp(my_data->ec_ref_mixer_path, "")) {
659 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
660 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500661 }
662
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800663 if (enable) {
664 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
665 if (out_device != AUDIO_DEVICE_NONE) {
666 snd_device = platform_get_output_snd_device(adev->platform, out_device);
667 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
668 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500669
Joe Onorato188b6222016-03-01 11:02:27 -0800670 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800671 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
672 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700673}
674
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700675static struct csd_data *open_csd_client(bool i2s_ext_modem)
676{
677 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
678
679 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
680 if (csd->csd_client == NULL) {
681 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
682 goto error;
683 } else {
684 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
685
686 csd->deinit = (deinit_t)dlsym(csd->csd_client,
687 "csd_client_deinit");
688 if (csd->deinit == NULL) {
689 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
690 dlerror());
691 goto error;
692 }
693 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
694 "csd_client_disable_device");
695 if (csd->disable_device == NULL) {
696 ALOGE("%s: dlsym error %s for csd_client_disable_device",
697 __func__, dlerror());
698 goto error;
699 }
700 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
701 "csd_client_enable_device_config");
702 if (csd->enable_device_config == NULL) {
703 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
704 __func__, dlerror());
705 goto error;
706 }
707 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
708 "csd_client_enable_device");
709 if (csd->enable_device == NULL) {
710 ALOGE("%s: dlsym error %s for csd_client_enable_device",
711 __func__, dlerror());
712 goto error;
713 }
714 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
715 "csd_client_start_voice");
716 if (csd->start_voice == NULL) {
717 ALOGE("%s: dlsym error %s for csd_client_start_voice",
718 __func__, dlerror());
719 goto error;
720 }
721 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
722 "csd_client_stop_voice");
723 if (csd->stop_voice == NULL) {
724 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
725 __func__, dlerror());
726 goto error;
727 }
728 csd->volume = (volume_t)dlsym(csd->csd_client,
729 "csd_client_volume");
730 if (csd->volume == NULL) {
731 ALOGE("%s: dlsym error %s for csd_client_volume",
732 __func__, dlerror());
733 goto error;
734 }
735 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
736 "csd_client_mic_mute");
737 if (csd->mic_mute == NULL) {
738 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
739 __func__, dlerror());
740 goto error;
741 }
742 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
743 "csd_client_slow_talk");
744 if (csd->slow_talk == NULL) {
745 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
746 __func__, dlerror());
747 goto error;
748 }
749 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
750 "csd_client_start_playback");
751 if (csd->start_playback == NULL) {
752 ALOGE("%s: dlsym error %s for csd_client_start_playback",
753 __func__, dlerror());
754 goto error;
755 }
756 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
757 "csd_client_stop_playback");
758 if (csd->stop_playback == NULL) {
759 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
760 __func__, dlerror());
761 goto error;
762 }
763 csd->start_record = (start_record_t)dlsym(csd->csd_client,
764 "csd_client_start_record");
765 if (csd->start_record == NULL) {
766 ALOGE("%s: dlsym error %s for csd_client_start_record",
767 __func__, dlerror());
768 goto error;
769 }
770 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
771 "csd_client_stop_record");
772 if (csd->stop_record == NULL) {
773 ALOGE("%s: dlsym error %s for csd_client_stop_record",
774 __func__, dlerror());
775 goto error;
776 }
777
778 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
779 "csd_client_get_sample_rate");
780 if (csd->get_sample_rate == NULL) {
781 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
782 __func__, dlerror());
783
784 goto error;
785 }
786
787 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
788
789 if (csd->init == NULL) {
790 ALOGE("%s: dlsym error %s for csd_client_init",
791 __func__, dlerror());
792 goto error;
793 } else {
794 csd->init(i2s_ext_modem);
795 }
796 }
797 return csd;
798
799error:
800 free(csd);
801 csd = NULL;
802 return csd;
803}
804
805void close_csd_client(struct csd_data *csd)
806{
807 if (csd != NULL) {
808 csd->deinit();
809 dlclose(csd->csd_client);
810 free(csd);
811 csd = NULL;
812 }
813}
814
815static void platform_csd_init(struct platform_data *my_data)
816{
817#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700818 int32_t modems, (*count_modems)(void);
819 const char *name = "libdetectmodem.so";
820 const char *func = "count_modems";
821 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700822
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700823 my_data->csd = NULL;
824
825 void *lib = dlopen(name, RTLD_NOW);
826 error = dlerror();
827 if (!lib) {
828 ALOGE("%s: could not find %s: %s", __func__, name, error);
829 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700830 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700831
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700832 count_modems = NULL;
833 *(void **)(&count_modems) = dlsym(lib, func);
834 error = dlerror();
835 if (!count_modems) {
836 ALOGE("%s: could not find symbol %s in %s: %s",
837 __func__, func, name, error);
838 goto done;
839 }
840
841 modems = count_modems();
842 if (modems < 0) {
843 ALOGE("%s: count_modems failed\n", __func__);
844 goto done;
845 }
846
Eric Laurent2bafff12016-03-17 12:17:23 -0700847 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700848 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700849 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700850
851done:
852 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700853#else
854 my_data->csd = NULL;
855#endif
856}
857
Eric Laurentc6333382015-09-14 12:43:44 -0700858static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700859{
860 int32_t dev;
861 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700862 backend_tag_table[dev] = NULL;
863 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900864 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700865 }
866
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700867 // To overwrite these go to the audio_platform_info.xml file.
868 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700869 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700870 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
871 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
872 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
873 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
874 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700875 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700876 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
877 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700878
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700879 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
880 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
881 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
882 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
883 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
884 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
885 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700886 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700887 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700888 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700889 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
890 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
891 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
892 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
893 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
894 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
895 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
896 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
897 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
898 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
899 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
900 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
901 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
902 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
903 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
904 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700905
906 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700907}
908
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900909void get_cvd_version(char *cvd_version, struct audio_device *adev)
910{
911 struct mixer_ctl *ctl;
912 int count;
913 int ret = 0;
914
915 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
916 if (!ctl) {
917 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
918 goto done;
919 }
920 mixer_ctl_update(ctl);
921
922 count = mixer_ctl_get_num_values(ctl);
923 if (count > MAX_CVD_VERSION_STRING_SIZE)
924 count = MAX_CVD_VERSION_STRING_SIZE - 1;
925
926 ret = mixer_ctl_get_array(ctl, cvd_version, count);
927 if (ret != 0) {
928 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
929 goto done;
930 }
931
932done:
933 return;
934}
935
Eric Laurentb23d5282013-05-14 15:27:20 -0700936void *platform_init(struct audio_device *adev)
937{
938 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -0800939 struct platform_data *my_data = NULL;
940 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
941 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700942 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900943 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -0800944 char *snd_internal_name = NULL;
945 char *tmp = NULL;
946 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -0800947 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
948 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700949 my_data = calloc(1, sizeof(struct platform_data));
950
951 my_data->adev = adev;
952
keunhui.park2f7306a2015-07-16 16:48:06 +0900953 list_init(&operator_info_list);
954
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700955 set_platform_defaults(my_data);
956
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700957 while (snd_card_num < MAX_SND_CARD) {
958 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700959
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700960 while (!adev->mixer && retry_num < RETRY_NUMBER) {
961 usleep(RETRY_US);
962 adev->mixer = mixer_open(snd_card_num);
963 retry_num++;
964 }
965
966 if (!adev->mixer) {
967 ALOGE("%s: Unable to open the mixer card: %d", __func__,
968 snd_card_num);
969 retry_num = 0;
970 snd_card_num++;
971 continue;
972 }
973
974 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -0800975 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700976
vivek mehtade4849c2016-03-03 17:23:38 -0800977 audio_extn_set_snd_card_split(snd_card_name);
978 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700979
vivek mehtade4849c2016-03-03 17:23:38 -0800980 /* Get the codec internal name from the sound card and/or form factor
981 * name and form the mixer paths and platfor info file name dynamically.
982 * This is generic way of picking any codec and forma factor name based
983 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700984
vivek mehtade4849c2016-03-03 17:23:38 -0800985 * current code extends and looks for any of the exteneded mixer path and
986 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -0800987
vivek mehtade4849c2016-03-03 17:23:38 -0800988 * order of picking appropriate file is
989 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
990 * <ii> mixer_paths_<codec_name>.xml, if file not present
991 * <iii> mixer_paths.xml
992
993 * same order is followed for audio_platform_info.xml as well
994 */
995
996 // need to carryforward old file name
997 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -0700998 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -0800999 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001000 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001001 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001002
vivek mehtade4849c2016-03-03 17:23:38 -08001003 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1004 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1005 snd_split_handle->form_factor);
1006
1007 if (F_OK != access(mixer_xml_file, 0)) {
1008 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1009 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1010 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1011
1012 if (F_OK != access(mixer_xml_file, 0)) {
1013 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1014 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1015 }
1016 }
1017
1018 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1019 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1020 snd_split_handle->form_factor);
1021
1022 if (F_OK != access(platform_info_file, 0)) {
1023 memset(platform_info_file, 0, sizeof(platform_info_file));
1024 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1025 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1026
1027 if (F_OK != access(platform_info_file, 0)) {
1028 memset(platform_info_file, 0, sizeof(platform_info_file));
1029 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001030 }
1031 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001032 }
1033
vivek mehtade4849c2016-03-03 17:23:38 -08001034 /* Initialize platform specific ids and/or backends*/
1035 platform_info_init(platform_info_file, my_data);
1036
1037 /* validate the sound card name
1038 * my_data->snd_card_name can contain
1039 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1040 * example: msm8994-tomtom-mtp-snd-card
1041 * <b> or sub string of the card name, i.e. <device>-<codec>
1042 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001043 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1044 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001045 */
1046
1047 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001048 strncmp(snd_card_name, my_data->snd_card_name,
1049 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001050 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1051 __func__, snd_card_name, my_data->snd_card_name);
1052 retry_num = 0;
1053 snd_card_num++;
1054 hw_info_deinit(my_data->hw_info);
1055 my_data->hw_info = NULL;
1056 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001057 }
vivek mehtade4849c2016-03-03 17:23:38 -08001058 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1059 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001060
1061 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1062 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1063
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001064 if (!adev->audio_route) {
1065 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001066 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001067 }
1068 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001069 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001070 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001071 }
1072
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001073 if (snd_card_num >= MAX_SND_CARD) {
1074 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001075 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001076 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001077
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001078 //set max volume step for voice call
1079 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1080 my_data->max_vol_index = atoi(value);
1081
vivek mehta65ad12d2015-08-13 18:32:48 -07001082 property_get("persist.audio.dualmic.config",value,"");
1083 if (!strcmp("endfire", value)) {
1084 dual_mic_config = true;
1085 }
1086
Prashant Malanic92c5962015-08-11 15:10:18 -07001087 my_data->source_mic_type = SOURCE_DUAL_MIC;
1088
Eric Laurentb23d5282013-05-14 15:27:20 -07001089 my_data->fluence_in_spkr_mode = false;
1090 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001091 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001092 my_data->fluence_in_voice_rec = false;
1093
vivek mehta65ad12d2015-08-13 18:32:48 -07001094 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001095 if (!strcmp("fluencepro", value)) {
1096 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001097 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001098 my_data->fluence_type = FLUENCE_ENABLE;
1099 } else if (!strcmp("none", value)) {
1100 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001101 }
1102
Prashant Malanic92c5962015-08-11 15:10:18 -07001103 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001104 property_get("persist.audio.fluence.voicecall",value,"");
1105 if (!strcmp("true", value)) {
1106 my_data->fluence_in_voice_call = true;
1107 }
1108
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001109 property_get("persist.audio.fluence.voicecomm",value,"");
1110 if (!strcmp("true", value)) {
1111 my_data->fluence_in_voice_comm = true;
1112 }
1113
Eric Laurentb23d5282013-05-14 15:27:20 -07001114 property_get("persist.audio.fluence.voicerec",value,"");
1115 if (!strcmp("true", value)) {
1116 my_data->fluence_in_voice_rec = true;
1117 }
1118
1119 property_get("persist.audio.fluence.speaker",value,"");
1120 if (!strcmp("true", value)) {
1121 my_data->fluence_in_spkr_mode = true;
1122 }
1123 }
1124
Prashant Malanic92c5962015-08-11 15:10:18 -07001125 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1126 switch (my_data->max_mic_count) {
1127 case 4:
1128 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1129 case 3:
1130 my_data->source_mic_type |= SOURCE_THREE_MIC;
1131 case 2:
1132 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1133 case 1:
1134 my_data->source_mic_type |= SOURCE_MONO_MIC;
1135 break;
1136 default:
1137 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1138 __func__, my_data->max_mic_count);
1139 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1140 break;
1141 }
1142
1143 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1144 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1145 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1146 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1147 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1148
Eric Laurentb23d5282013-05-14 15:27:20 -07001149 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1150 if (my_data->acdb_handle == NULL) {
1151 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1152 } else {
1153 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1154 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1155 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001156 if (!my_data->acdb_deallocate)
1157 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1158 __func__, LIB_ACDB_LOADER);
1159
Eric Laurentb23d5282013-05-14 15:27:20 -07001160 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1161 "acdb_loader_send_audio_cal");
1162 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001163 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001164 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001165
Eric Laurentb23d5282013-05-14 15:27:20 -07001166 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1167 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001168 if (!my_data->acdb_send_voice_cal)
1169 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1170 __func__, LIB_ACDB_LOADER);
1171
1172 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1173 "acdb_loader_reload_vocvoltable");
1174 if (!my_data->acdb_reload_vocvoltable)
1175 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1176 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001177
1178 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1179 "acdb_loader_send_gain_dep_cal");
1180 if (!my_data->acdb_send_gain_dep_cal)
1181 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1182 __func__, LIB_ACDB_LOADER);
1183
vivek mehtac698f132016-02-25 18:50:35 -08001184#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001185 acdb_init_v2_cvd_t acdb_init;
1186 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1187 "acdb_loader_init_v2");
1188 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001189 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001190 goto acdb_init_fail;
1191 }
1192
1193 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1194 get_cvd_version(cvd_version, adev);
1195 if (!cvd_version)
1196 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001197 else
vivek mehtac698f132016-02-25 18:50:35 -08001198 acdb_init((char *)snd_card_name, cvd_version, 0);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001199 free(cvd_version);
1200#elif defined (PLATFORM_MSM8084)
1201 acdb_init_v2_t acdb_init;
1202 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1203 "acdb_loader_init_v2");
1204 if (acdb_init == NULL) {
1205 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1206 goto acdb_init_fail;
1207 }
1208 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001209#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001210 acdb_init_t acdb_init;
1211 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001212 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001213 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001214 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1215 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001216 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001217#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001218 }
1219
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001220acdb_init_fail:
1221
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001222 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001223
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001224 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1225
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001226 /* load csd client */
1227 platform_csd_init(my_data);
1228
Eric Laurentb23d5282013-05-14 15:27:20 -07001229 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001230
1231init_failed:
1232 if (my_data)
1233 free(my_data);
1234 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001235}
1236
1237void platform_deinit(void *platform)
1238{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001239 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001240 struct operator_info *info_item;
1241 struct operator_specific_device *device_item;
1242 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001243
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001244 struct platform_data *my_data = (struct platform_data *)platform;
1245 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001246
vivek mehtade4849c2016-03-03 17:23:38 -08001247 hw_info_deinit(my_data->hw_info);
1248
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001249 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1250 if (backend_tag_table[dev])
1251 free(backend_tag_table[dev]);
1252 if (hw_interface_table[dev])
1253 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001254 if (operator_specific_device_table[dev]) {
1255 while (!list_empty(operator_specific_device_table[dev])) {
1256 node = list_head(operator_specific_device_table[dev]);
1257 list_remove(node);
1258 device_item = node_to_item(node, struct operator_specific_device, list);
1259 free(device_item->operator);
1260 free(device_item->mixer_path);
1261 free(device_item);
1262 }
1263 free(operator_specific_device_table[dev]);
1264 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001265 }
1266
1267 if (my_data->snd_card_name)
1268 free(my_data->snd_card_name);
1269
keunhui.park2f7306a2015-07-16 16:48:06 +09001270 while (!list_empty(&operator_info_list)) {
1271 node = list_head(&operator_info_list);
1272 list_remove(node);
1273 info_item = node_to_item(node, struct operator_info, list);
1274 free(info_item->name);
1275 free(info_item->mccmnc);
1276 free(info_item);
1277 }
1278
Eric Laurentb23d5282013-05-14 15:27:20 -07001279 free(platform);
1280}
1281
1282const char *platform_get_snd_device_name(snd_device_t snd_device)
1283{
keunhui.park2f7306a2015-07-16 16:48:06 +09001284 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1285 if (operator_specific_device_table[snd_device] != NULL) {
1286 return get_operator_specific_device_mixer_path(snd_device);
1287 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001288 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001289 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001290 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001291}
1292
vivek mehtade4849c2016-03-03 17:23:38 -08001293int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1294 char *device_name)
1295{
1296 struct platform_data *my_data = (struct platform_data *)platform;
1297
1298 if (platform == NULL || device_name == NULL) {
1299 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
1300 device_name = platform_get_snd_device_name(snd_device);
1301 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1302 if (operator_specific_device_table[snd_device] != NULL) {
1303 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1304 DEVICE_NAME_MAX_SIZE);
1305 } else {
1306 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1307 }
1308 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1309 } else {
1310 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1311 }
1312
1313 return 0;
1314}
1315
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001316void platform_add_backend_name(void *platform, char *mixer_path,
1317 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001318{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001319 struct platform_data *my_data = (struct platform_data *)platform;
1320
Haynes Mathew George98c95622014-06-20 19:14:25 -07001321 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1322 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1323 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001324 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001325
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001326 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001327
1328 if (suffix != NULL) {
1329 strcat(mixer_path, " ");
1330 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001331 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001332}
1333
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001334bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1335{
1336 bool result = true;
1337
1338 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1339 platform_get_snd_device_name(snd_device1),
1340 platform_get_snd_device_name(snd_device2));
1341
1342 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1343 ALOGE("%s: Invalid snd_device = %s", __func__,
1344 platform_get_snd_device_name(snd_device1));
1345 return false;
1346 }
1347 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1348 ALOGE("%s: Invalid snd_device = %s", __func__,
1349 platform_get_snd_device_name(snd_device2));
1350 return false;
1351 }
1352 const char * be_itf1 = hw_interface_table[snd_device1];
1353 const char * be_itf2 = hw_interface_table[snd_device2];
1354
1355 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001356 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001357 result = false;
1358 }
1359
1360 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1361 return result;
1362}
1363
Eric Laurentb23d5282013-05-14 15:27:20 -07001364int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1365{
1366 int device_id;
1367 if (device_type == PCM_PLAYBACK)
1368 device_id = pcm_device_table[usecase][0];
1369 else
1370 device_id = pcm_device_table[usecase][1];
1371 return device_id;
1372}
1373
Haynes Mathew George98c95622014-06-20 19:14:25 -07001374static int find_index(const struct name_to_index * table, int32_t len,
1375 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001376{
1377 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001378 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001379
Haynes Mathew George98c95622014-06-20 19:14:25 -07001380 if (table == NULL) {
1381 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001382 ret = -ENODEV;
1383 goto done;
1384 }
1385
Haynes Mathew George98c95622014-06-20 19:14:25 -07001386 if (name == NULL) {
1387 ALOGE("null key");
1388 ret = -ENODEV;
1389 goto done;
1390 }
1391
1392 for (i=0; i < len; i++) {
1393 if (!strcmp(table[i].name, name)) {
1394 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001395 goto done;
1396 }
1397 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001398 ALOGE("%s: Could not find index for name = %s",
1399 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001400 ret = -ENODEV;
1401done:
1402 return ret;
1403}
1404
Haynes Mathew George98c95622014-06-20 19:14:25 -07001405int platform_get_snd_device_index(char *device_name)
1406{
1407 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1408}
1409
1410int platform_get_usecase_index(const char *usecase_name)
1411{
1412 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1413}
1414
keunhui.park2f7306a2015-07-16 16:48:06 +09001415void platform_add_operator_specific_device(snd_device_t snd_device,
1416 const char *operator,
1417 const char *mixer_path,
1418 unsigned int acdb_id)
1419{
1420 struct operator_specific_device *device;
1421
1422 if (operator_specific_device_table[snd_device] == NULL) {
1423 operator_specific_device_table[snd_device] =
1424 (struct listnode *)calloc(1, sizeof(struct listnode));
1425 list_init(operator_specific_device_table[snd_device]);
1426 }
1427
1428 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1429
1430 device->operator = strdup(operator);
1431 device->mixer_path = strdup(mixer_path);
1432 device->acdb_id = acdb_id;
1433
1434 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1435
Eric Laurent2bafff12016-03-17 12:17:23 -07001436 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001437 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1438
1439}
1440
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001441int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1442{
1443 int ret = 0;
1444
1445 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1446 ALOGE("%s: Invalid snd_device = %d",
1447 __func__, snd_device);
1448 ret = -EINVAL;
1449 goto done;
1450 }
1451
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001452 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1453 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001454 acdb_device_table[snd_device] = acdb_id;
1455done:
1456 return ret;
1457}
1458
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001459int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1460{
1461 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1462 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1463 return -EINVAL;
1464 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001465
1466 if (operator_specific_device_table[snd_device] != NULL)
1467 return get_operator_specific_device_acdb_id(snd_device);
1468 else
1469 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001470}
1471
Eric Laurentb23d5282013-05-14 15:27:20 -07001472int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1473{
1474 struct platform_data *my_data = (struct platform_data *)platform;
1475 int acdb_dev_id, acdb_dev_type;
1476
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001477 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001478 if (acdb_dev_id < 0) {
1479 ALOGE("%s: Could not find acdb id for device(%d)",
1480 __func__, snd_device);
1481 return -EINVAL;
1482 }
1483 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001484 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001485 __func__, snd_device, acdb_dev_id);
1486 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1487 snd_device < SND_DEVICE_OUT_END)
1488 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1489 else
1490 acdb_dev_type = ACDB_DEV_TYPE_IN;
1491 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1492 }
1493 return 0;
1494}
1495
1496int platform_switch_voice_call_device_pre(void *platform)
1497{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001498 struct platform_data *my_data = (struct platform_data *)platform;
1499 int ret = 0;
1500
1501 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001502 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001503 /* This must be called before disabling mixer controls on APQ side */
1504 ret = my_data->csd->disable_device();
1505 if (ret < 0) {
1506 ALOGE("%s: csd_client_disable_device, failed, error %d",
1507 __func__, ret);
1508 }
1509 }
1510 return ret;
1511}
1512
1513int platform_switch_voice_call_enable_device_config(void *platform,
1514 snd_device_t out_snd_device,
1515 snd_device_t in_snd_device)
1516{
1517 struct platform_data *my_data = (struct platform_data *)platform;
1518 int acdb_rx_id, acdb_tx_id;
1519 int ret = 0;
1520
1521 if (my_data->csd == NULL)
1522 return ret;
1523
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001524 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1525 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001526 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001527 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001528 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001529
keunhui.park2f7306a2015-07-16 16:48:06 +09001530 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001531
1532 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1533 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1534 if (ret < 0) {
1535 ALOGE("%s: csd_enable_device_config, failed, error %d",
1536 __func__, ret);
1537 }
1538 } else {
1539 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1540 acdb_rx_id, acdb_tx_id);
1541 }
1542
1543 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001544}
1545
1546int platform_switch_voice_call_device_post(void *platform,
1547 snd_device_t out_snd_device,
1548 snd_device_t in_snd_device)
1549{
1550 struct platform_data *my_data = (struct platform_data *)platform;
1551 int acdb_rx_id, acdb_tx_id;
1552
1553 if (my_data->acdb_send_voice_cal == NULL) {
1554 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1555 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001556 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1557 audio_extn_spkr_prot_is_enabled())
1558 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1559
keunhui.park2f7306a2015-07-16 16:48:06 +09001560 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1561 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001562
1563 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1564 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1565 else
1566 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1567 acdb_rx_id, acdb_tx_id);
1568 }
1569
1570 return 0;
1571}
1572
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001573int platform_switch_voice_call_usecase_route_post(void *platform,
1574 snd_device_t out_snd_device,
1575 snd_device_t in_snd_device)
1576{
1577 struct platform_data *my_data = (struct platform_data *)platform;
1578 int acdb_rx_id, acdb_tx_id;
1579 int ret = 0;
1580
1581 if (my_data->csd == NULL)
1582 return ret;
1583
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001584 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1585 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001586 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001587 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001588 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001589
keunhui.park2f7306a2015-07-16 16:48:06 +09001590 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001591
1592 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1593 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1594 my_data->adev->acdb_settings);
1595 if (ret < 0) {
1596 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1597 }
1598 } else {
1599 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1600 acdb_rx_id, acdb_tx_id);
1601 }
1602
1603 return ret;
1604}
1605
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001606int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001607{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001608 struct platform_data *my_data = (struct platform_data *)platform;
1609 int ret = 0;
1610
1611 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001612 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001613 if (ret < 0) {
1614 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1615 }
1616 }
1617 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001618}
1619
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001620int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001621{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001622 struct platform_data *my_data = (struct platform_data *)platform;
1623 int ret = 0;
1624
1625 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001626 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001627 if (ret < 0) {
1628 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1629 }
1630 }
1631 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001632}
1633
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001634int platform_get_sample_rate(void *platform, uint32_t *rate)
1635{
1636 struct platform_data *my_data = (struct platform_data *)platform;
1637 int ret = 0;
1638
1639 if (my_data->csd != NULL) {
1640 ret = my_data->csd->get_sample_rate(rate);
1641 if (ret < 0) {
1642 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1643 }
1644 }
1645 return ret;
1646}
1647
vivek mehtab6506412015-08-07 16:55:17 -07001648void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1649 snd_device_t snd_device,
1650 bool enable)
1651{
1652 const char* name;
1653 switch (snd_device) {
1654 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1655 if (enable)
1656 name = "spkr-gain-in-headphone-combo";
1657 else
1658 name = "speaker-gain-default";
1659 break;
1660 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1661 if (enable)
1662 name = "spkr-gain-in-line-combo";
1663 else
1664 name = "speaker-gain-default";
1665 break;
1666 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1667 if (enable)
1668 name = "spkr-safe-gain-in-headphone-combo";
1669 else
1670 name = "speaker-safe-gain-default";
1671 break;
1672 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1673 if (enable)
1674 name = "spkr-safe-gain-in-line-combo";
1675 else
1676 name = "speaker-safe-gain-default";
1677 break;
1678 default:
1679 return;
1680 }
1681
1682 audio_route_apply_and_update_path(adev->audio_route, name);
1683}
1684
Eric Laurentb23d5282013-05-14 15:27:20 -07001685int platform_set_voice_volume(void *platform, int volume)
1686{
1687 struct platform_data *my_data = (struct platform_data *)platform;
1688 struct audio_device *adev = my_data->adev;
1689 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001690 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001691 int vol_index = 0, ret = 0;
1692 uint32_t set_values[ ] = {0,
1693 ALL_SESSION_VSID,
1694 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001695
1696 // Voice volume levels are mapped to adsp volume levels as follows.
1697 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1698 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001699 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001700 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001701
1702 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1703 if (!ctl) {
1704 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1705 __func__, mixer_ctl_name);
1706 return -EINVAL;
1707 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001708 ALOGV("Setting voice volume index: %d", set_values[0]);
1709 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1710
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001711 if (my_data->csd != NULL) {
1712 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1713 DEFAULT_VOLUME_RAMP_DURATION_MS);
1714 if (ret < 0) {
1715 ALOGE("%s: csd_volume error %d", __func__, ret);
1716 }
1717 }
1718 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001719}
1720
1721int platform_set_mic_mute(void *platform, bool state)
1722{
1723 struct platform_data *my_data = (struct platform_data *)platform;
1724 struct audio_device *adev = my_data->adev;
1725 struct mixer_ctl *ctl;
1726 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001727 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001728 uint32_t set_values[ ] = {0,
1729 ALL_SESSION_VSID,
1730 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001731
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001732 if (adev->mode != AUDIO_MODE_IN_CALL &&
1733 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001734 return 0;
1735
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001736 if (adev->enable_hfp)
1737 mixer_ctl_name = "HFP Tx Mute";
1738
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001739 set_values[0] = state;
1740 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1741 if (!ctl) {
1742 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1743 __func__, mixer_ctl_name);
1744 return -EINVAL;
1745 }
1746 ALOGV("Setting voice mute state: %d", state);
1747 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1748
1749 if (my_data->csd != NULL) {
1750 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1751 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001752 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001753 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001754 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001755 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001756 return ret;
1757}
Eric Laurentb23d5282013-05-14 15:27:20 -07001758
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001759int platform_set_device_mute(void *platform, bool state, char *dir)
1760{
1761 struct platform_data *my_data = (struct platform_data *)platform;
1762 struct audio_device *adev = my_data->adev;
1763 struct mixer_ctl *ctl;
1764 char *mixer_ctl_name = NULL;
1765 int ret = 0;
1766 uint32_t set_values[ ] = {0,
1767 ALL_SESSION_VSID,
1768 0};
1769 if(dir == NULL) {
1770 ALOGE("%s: Invalid direction:%s", __func__, dir);
1771 return -EINVAL;
1772 }
1773
1774 if (!strncmp("rx", dir, sizeof("rx"))) {
1775 mixer_ctl_name = "Voice Rx Device Mute";
1776 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1777 mixer_ctl_name = "Voice Tx Device Mute";
1778 } else {
1779 return -EINVAL;
1780 }
1781
1782 set_values[0] = state;
1783 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1784 if (!ctl) {
1785 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1786 __func__, mixer_ctl_name);
1787 return -EINVAL;
1788 }
1789
1790 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1791 __func__,state, mixer_ctl_name);
1792 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1793
1794 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001795}
1796
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001797bool platform_can_split_snd_device(snd_device_t snd_device,
1798 int *num_devices,
1799 snd_device_t *new_snd_devices)
1800{
1801 bool status = false;
1802
1803 if (NULL == num_devices || NULL == new_snd_devices) {
1804 ALOGE("%s: NULL pointer ..", __func__);
1805 return false;
1806 }
1807
1808 /*
1809 * If wired headset/headphones/line devices share the same backend
1810 * with speaker/earpiece this routine returns false.
1811 */
1812 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1813 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1814 *num_devices = 2;
1815 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1816 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1817 status = true;
1818 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1819 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1820 *num_devices = 2;
1821 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1822 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1823 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001824 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1825 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1826 *num_devices = 2;
1827 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1828 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1829 status = true;
1830 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1831 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1832 *num_devices = 2;
1833 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1834 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1835 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001836 }
1837 return status;
1838}
1839
Eric Laurentb23d5282013-05-14 15:27:20 -07001840snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1841{
1842 struct platform_data *my_data = (struct platform_data *)platform;
1843 struct audio_device *adev = my_data->adev;
1844 audio_mode_t mode = adev->mode;
1845 snd_device_t snd_device = SND_DEVICE_NONE;
1846
1847 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1848 if (devices == AUDIO_DEVICE_NONE ||
1849 devices & AUDIO_DEVICE_BIT_IN) {
1850 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1851 goto exit;
1852 }
1853
Eric Laurent1b491552015-09-15 17:52:41 -07001854 if (popcount(devices) == 2) {
1855 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1856 AUDIO_DEVICE_OUT_SPEAKER) ||
1857 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1858 AUDIO_DEVICE_OUT_SPEAKER)) {
1859 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1860 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1861 AUDIO_DEVICE_OUT_SPEAKER)) {
1862 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1863 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1864 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1865 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1866 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1867 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1868 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1869 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1870 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1871 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1872 AUDIO_DEVICE_OUT_SPEAKER)) {
1873 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1874 } else {
1875 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1876 goto exit;
1877 }
1878 if (snd_device != SND_DEVICE_NONE) {
1879 goto exit;
1880 }
1881 }
1882
1883 if (popcount(devices) != 1) {
1884 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1885 goto exit;
1886 }
1887
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001888 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001889 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001890 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1891 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001892 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001893 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001894 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001895 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001896 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001897 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001898 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001899 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001900 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001901 else {
1902 if (devices & AUDIO_DEVICE_OUT_LINE)
1903 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1904 else
1905 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1906 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001907 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001908 if (adev->bt_wb_speech_enabled) {
1909 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1910 } else {
1911 snd_device = SND_DEVICE_OUT_BT_SCO;
1912 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001913 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07001914 if (!adev->enable_hfp) {
1915 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1916 } else {
1917 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
1918 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001919 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001920 if(adev->voice.hac)
1921 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1922 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001923 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1924 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001925 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001926 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1927 snd_device = SND_DEVICE_OUT_VOICE_TX;
1928
Eric Laurentb23d5282013-05-14 15:27:20 -07001929 if (snd_device != SND_DEVICE_NONE) {
1930 goto exit;
1931 }
1932 }
1933
Eric Laurentb23d5282013-05-14 15:27:20 -07001934 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1935 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1936 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001937 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1938 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001939 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1940 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001941 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001942 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001943 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1944 else
1945 snd_device = SND_DEVICE_OUT_SPEAKER;
1946 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001947 if (adev->bt_wb_speech_enabled) {
1948 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1949 } else {
1950 snd_device = SND_DEVICE_OUT_BT_SCO;
1951 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001952 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1953 snd_device = SND_DEVICE_OUT_HDMI ;
1954 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001955 /*HAC support for voice-ish audio (eg visual voicemail)*/
1956 if(adev->voice.hac)
1957 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1958 else
1959 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001960 } else {
1961 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1962 }
1963exit:
1964 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1965 return snd_device;
1966}
1967
1968snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1969{
1970 struct platform_data *my_data = (struct platform_data *)platform;
1971 struct audio_device *adev = my_data->adev;
1972 audio_source_t source = (adev->active_input == NULL) ?
1973 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1974
1975 audio_mode_t mode = adev->mode;
1976 audio_devices_t in_device = ((adev->active_input == NULL) ?
1977 AUDIO_DEVICE_NONE : adev->active_input->device)
1978 & ~AUDIO_DEVICE_BIT_IN;
1979 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1980 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1981 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001982 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001983
Prashant Malanic92c5962015-08-11 15:10:18 -07001984 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1985 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001986 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001987 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001988 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001989 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1990 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001991 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001992 case TTY_MODE_FULL:
1993 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1994 break;
1995 case TTY_MODE_VCO:
1996 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1997 break;
1998 case TTY_MODE_HCO:
1999 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2000 break;
2001 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002002 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002003 }
2004 goto exit;
2005 }
2006 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002007 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002008 if (my_data->fluence_in_voice_call == false) {
2009 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2010 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002011 if (is_operator_tmus())
2012 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002013 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002014 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002015 }
2016 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2017 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2018 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002019 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002020 if (adev->bluetooth_nrec)
2021 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2022 else
2023 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002024 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002025 if (adev->bluetooth_nrec)
2026 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2027 else
2028 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002029 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002030 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002031 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2032 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2033 out_device & AUDIO_DEVICE_OUT_LINE) {
2034 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2035 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2036 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2037 } else {
2038 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2039 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002040 }
vivek mehtafe121d52015-08-10 23:39:23 -07002041
2042 //select default
2043 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002044 if (!adev->enable_hfp) {
2045 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2046 } else {
2047 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2048 platform_set_echo_reference(adev, true, out_device);
2049 }
vivek mehtafe121d52015-08-10 23:39:23 -07002050 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002051 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002052 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002053 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002054 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2055 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2056 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2057 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2058 }
2059 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2060 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002061 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2062 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2063 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002064 if (adev->active_input->enable_aec)
2065 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2066 else
2067 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002068 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2069 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002070 if (adev->active_input->enable_aec)
2071 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2072 else
2073 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002074 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2075 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2076 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002077 if (adev->active_input->enable_aec)
2078 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2079 else
2080 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002081 }
2082 platform_set_echo_reference(adev, true, out_device);
2083 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2084 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2085 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2086 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
2087 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2088 snd_device = SND_DEVICE_IN_THREE_MIC;
2089 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
2090 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2091 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002092 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002093 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002094 if (adev->active_input->enable_ns)
2095 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
vivek mehta733c1df2016-04-04 15:09:24 -07002096 else if (adev->active_input->enable_aec) {
2097 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2098 platform_set_echo_reference(adev, true, out_device);
2099 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002100 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002101 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002102 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2103 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002104 }
rago90fb9612015-12-02 11:37:53 -08002105 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2106 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2107 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2108 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2109 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2110 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002111 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002112 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002113 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002114 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2115 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002116 if (adev->active_input->enable_aec &&
2117 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002118 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002119 if (my_data->fluence_in_spkr_mode &&
2120 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002121 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002122 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002123 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002124 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002125 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002126 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002127 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002128 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002129 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002130 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002131 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002132 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002133 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2134 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002135 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002136 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002137 } else if (adev->active_input->enable_aec) {
2138 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2139 if (my_data->fluence_in_spkr_mode &&
2140 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002141 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002142 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002143 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002144 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002145 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002146 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2147 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002148 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002149 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002150 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002151 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002152 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002153 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2154 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2155 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002156 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002157 } else if (adev->active_input->enable_ns) {
2158 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2159 if (my_data->fluence_in_spkr_mode &&
2160 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002161 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002162 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002163 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002164 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002165 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002166 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2167 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002168 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002169 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002170 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002171 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002172 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002173 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002174 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002175 }
2176 } else if (source == AUDIO_SOURCE_DEFAULT) {
2177 goto exit;
2178 }
2179
2180
2181 if (snd_device != SND_DEVICE_NONE) {
2182 goto exit;
2183 }
2184
2185 if (in_device != AUDIO_DEVICE_NONE &&
2186 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2187 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2188 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002189 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2190 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2191 snd_device = SND_DEVICE_IN_QUAD_MIC;
2192 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2193 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2194 snd_device = SND_DEVICE_IN_THREE_MIC;
2195 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2196 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002197 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002198 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2199 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002200 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002201 } else {
2202 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2203 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2204 my_data->source_mic_type, channel_count, channel_mask);
2205 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2206 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002207 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002208 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2209 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002210 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002211 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2212 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002213 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002214 } else {
2215 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2216 " no combination found .. setting to mono", __func__,
2217 my_data->source_mic_type, channel_count);
2218 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2219 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002220 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2221 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2222 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002223 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002224 if (adev->bluetooth_nrec)
2225 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2226 else
2227 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002228 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002229 if (adev->bluetooth_nrec)
2230 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2231 else
2232 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002233 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002234 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2235 snd_device = SND_DEVICE_IN_HDMI_MIC;
2236 } else {
2237 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2238 ALOGW("%s: Using default handset-mic", __func__);
2239 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2240 }
2241 } else {
2242 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2243 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2244 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2245 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002246 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002247 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002248 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002249 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002250 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2251 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002252 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002253 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2254 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002255 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002256 } else {
2257 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2258 " no combination found .. setting to mono", __func__,
2259 my_data->source_mic_type, channel_count);
2260 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2261 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002262 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002263 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002264 if (adev->bluetooth_nrec)
2265 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2266 else
2267 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002268 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002269 if (adev->bluetooth_nrec)
2270 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2271 else
2272 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002273 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002274 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2275 snd_device = SND_DEVICE_IN_HDMI_MIC;
2276 } else {
2277 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2278 ALOGW("%s: Using default handset-mic", __func__);
2279 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2280 }
2281 }
2282exit:
2283 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2284 return snd_device;
2285}
2286
2287int platform_set_hdmi_channels(void *platform, int channel_count)
2288{
2289 struct platform_data *my_data = (struct platform_data *)platform;
2290 struct audio_device *adev = my_data->adev;
2291 struct mixer_ctl *ctl;
2292 const char *channel_cnt_str = NULL;
2293 const char *mixer_ctl_name = "HDMI_RX Channels";
2294 switch (channel_count) {
2295 case 8:
2296 channel_cnt_str = "Eight"; break;
2297 case 7:
2298 channel_cnt_str = "Seven"; break;
2299 case 6:
2300 channel_cnt_str = "Six"; break;
2301 case 5:
2302 channel_cnt_str = "Five"; break;
2303 case 4:
2304 channel_cnt_str = "Four"; break;
2305 case 3:
2306 channel_cnt_str = "Three"; break;
2307 default:
2308 channel_cnt_str = "Two"; break;
2309 }
2310 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2311 if (!ctl) {
2312 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2313 __func__, mixer_ctl_name);
2314 return -EINVAL;
2315 }
2316 ALOGV("HDMI channel count: %s", channel_cnt_str);
2317 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2318 return 0;
2319}
2320
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002321int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002322{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002323 struct platform_data *my_data = (struct platform_data *)platform;
2324 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002325 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2326 char *sad = block;
2327 int num_audio_blocks;
2328 int channel_count;
2329 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002330 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002331
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002332 struct mixer_ctl *ctl;
2333
2334 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2335 if (!ctl) {
2336 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2337 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002338 return 0;
2339 }
2340
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002341 mixer_ctl_update(ctl);
2342
2343 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002344
2345 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002346 if (count > (int)sizeof(block))
2347 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002348
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002349 ret = mixer_ctl_get_array(ctl, block, count);
2350 if (ret != 0) {
2351 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2352 return 0;
2353 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002354
2355 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002356 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002357
2358 for (i = 0; i < num_audio_blocks; i++) {
2359 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002360 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2361 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002362 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002363 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002364
2365 channel_count = (sad[0] & 0x7) + 1;
2366 if (channel_count > max_channels)
2367 max_channels = channel_count;
2368
2369 /* Advance to next block */
2370 sad += 3;
2371 }
2372
2373 return max_channels;
2374}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002375
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002376int platform_set_incall_recording_session_id(void *platform,
2377 uint32_t session_id, int rec_mode)
2378{
2379 int ret = 0;
2380 struct platform_data *my_data = (struct platform_data *)platform;
2381 struct audio_device *adev = my_data->adev;
2382 struct mixer_ctl *ctl;
2383 const char *mixer_ctl_name = "Voc VSID";
2384 int num_ctl_values;
2385 int i;
2386
2387 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2388 if (!ctl) {
2389 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2390 __func__, mixer_ctl_name);
2391 ret = -EINVAL;
2392 } else {
2393 num_ctl_values = mixer_ctl_get_num_values(ctl);
2394 for (i = 0; i < num_ctl_values; i++) {
2395 if (mixer_ctl_set_value(ctl, i, session_id)) {
2396 ALOGV("Error: invalid session_id: %x", session_id);
2397 ret = -EINVAL;
2398 break;
2399 }
2400 }
2401 }
2402
2403 if (my_data->csd != NULL) {
2404 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2405 if (ret < 0) {
2406 ALOGE("%s: csd_client_start_record failed, error %d",
2407 __func__, ret);
2408 }
2409 }
2410
2411 return ret;
2412}
2413
2414int platform_stop_incall_recording_usecase(void *platform)
2415{
2416 int ret = 0;
2417 struct platform_data *my_data = (struct platform_data *)platform;
2418
2419 if (my_data->csd != NULL) {
2420 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2421 if (ret < 0) {
2422 ALOGE("%s: csd_client_stop_record failed, error %d",
2423 __func__, ret);
2424 }
2425 }
2426
2427 return ret;
2428}
2429
2430int platform_start_incall_music_usecase(void *platform)
2431{
2432 int ret = 0;
2433 struct platform_data *my_data = (struct platform_data *)platform;
2434
2435 if (my_data->csd != NULL) {
2436 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2437 if (ret < 0) {
2438 ALOGE("%s: csd_client_start_playback failed, error %d",
2439 __func__, ret);
2440 }
2441 }
2442
2443 return ret;
2444}
2445
2446int platform_stop_incall_music_usecase(void *platform)
2447{
2448 int ret = 0;
2449 struct platform_data *my_data = (struct platform_data *)platform;
2450
2451 if (my_data->csd != NULL) {
2452 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2453 if (ret < 0) {
2454 ALOGE("%s: csd_client_stop_playback failed, error %d",
2455 __func__, ret);
2456 }
2457 }
2458
2459 return ret;
2460}
2461
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002462int platform_set_parameters(void *platform, struct str_parms *parms)
2463{
2464 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002465 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002466 char *kv_pairs = str_parms_to_str(parms);
2467 int ret = 0, err;
2468
2469 if (kv_pairs == NULL) {
2470 ret = -EINVAL;
2471 ALOGE("%s: key-value pair is NULL",__func__);
2472 goto done;
2473 }
2474
2475 ALOGV("%s: enter: %s", __func__, kv_pairs);
2476
2477 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2478 value, sizeof(value));
2479 if (err >= 0) {
2480 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2481 my_data->snd_card_name = strdup(value);
2482 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2483 }
2484
keunhui.park2f7306a2015-07-16 16:48:06 +09002485 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2486 value, sizeof(value));
2487 if (err >= 0) {
2488 struct operator_info *info;
2489 char *str = value;
2490 char *name;
2491
2492 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2493 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2494 name = strtok(str, ";");
2495 info->name = strdup(name);
2496 info->mccmnc = strdup(str + strlen(name) + 1);
2497
2498 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002499 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002500 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002501
2502 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002503 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002504 value, sizeof(value));
2505 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002506 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002507 my_data->max_mic_count = atoi(value);
2508 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002509 }
2510
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002511done:
2512 ALOGV("%s: exit with code(%d)", __func__, ret);
2513 if (kv_pairs != NULL)
2514 free(kv_pairs);
2515
2516 return ret;
2517}
2518
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002519/* Delay in Us */
2520int64_t platform_render_latency(audio_usecase_t usecase)
2521{
2522 switch (usecase) {
2523 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2524 return DEEP_BUFFER_PLATFORM_DELAY;
2525 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2526 return LOW_LATENCY_PLATFORM_DELAY;
2527 default:
2528 return 0;
2529 }
2530}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002531
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002532int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2533 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002534{
2535 int ret = 0;
2536
2537 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2538 ALOGE("%s: Invalid snd_device = %d",
2539 __func__, device);
2540 ret = -EINVAL;
2541 goto done;
2542 }
2543
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002544 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2545 platform_get_snd_device_name(device),
2546 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2547 if (backend_tag_table[device]) {
2548 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002549 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002550 backend_tag_table[device] = strdup(backend_tag);
2551
2552 if (hw_interface != NULL) {
2553 if (hw_interface_table[device])
2554 free(hw_interface_table[device]);
2555 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2556 hw_interface_table[device] = strdup(hw_interface);
2557 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002558done:
2559 return ret;
2560}
2561
2562int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2563{
2564 int ret = 0;
2565 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2566 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2567 ret = -EINVAL;
2568 goto done;
2569 }
2570
2571 if ((type != 0) && (type != 1)) {
2572 ALOGE("%s: invalid usecase type", __func__);
2573 ret = -EINVAL;
2574 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002575 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002576 pcm_device_table[usecase][type] = pcm_id;
2577done:
2578 return ret;
2579}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002580
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002581#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2582int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2583 // backup_gain: gain to try to set in case of an error during ramp
2584 int start_gain, end_gain, step, backup_gain, i;
2585 bool error = false;
2586 const struct mixer_ctl *ctl;
2587 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2588 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2589 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2590 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2591 if (!ctl_left || !ctl_right) {
2592 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2593 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2594 return -EINVAL;
2595 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2596 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2597 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2598 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2599 return -EINVAL;
2600 }
2601 if (ramp_up) {
2602 start_gain = 0;
2603 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2604 step = +1;
2605 backup_gain = end_gain;
2606 } else {
2607 // using same gain on left and right
2608 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2609 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2610 end_gain = 0;
2611 step = -1;
2612 backup_gain = start_gain;
2613 }
2614 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2615 //ALOGV("setting speaker gain to %d", i);
2616 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2617 ALOGE("%s: error setting %s to %d during gain ramp",
2618 __func__, mixer_ctl_name_gain_left, i);
2619 error = true;
2620 break;
2621 }
2622 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2623 ALOGE("%s: error setting %s to %d during gain ramp",
2624 __func__, mixer_ctl_name_gain_right, i);
2625 error = true;
2626 break;
2627 }
2628 usleep(1000);
2629 }
2630 if (error) {
2631 // an error occured during the ramp, let's still try to go back to a safe volume
2632 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2633 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2634 }
2635 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2636 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2637 }
2638 }
2639 return start_gain;
2640}
2641
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002642int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2643{
2644 // only update if there is active pcm playback on speaker
2645 struct audio_usecase *usecase;
2646 struct listnode *node;
2647 struct platform_data *my_data = (struct platform_data *)adev->platform;
2648
2649 if (my_data->speaker_lr_swap != swap_channels) {
2650 my_data->speaker_lr_swap = swap_channels;
2651
2652 list_for_each(node, &adev->usecase_list) {
2653 usecase = node_to_item(node, struct audio_usecase, list);
2654 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002655 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2656 /*
2657 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2658 * to perform device switch to disable the current backend to
2659 * enable it with new acdb data.
2660 */
2661 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2662 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002663 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002664 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002665 if (initial_skpr_gain != -EINVAL) {
2666 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2667 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002668 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002669 const char *mixer_path;
2670 if (swap_channels) {
2671 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2672 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2673 } else {
2674 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2675 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2676 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002677 }
2678 break;
2679 }
2680 }
2681 }
2682 return 0;
2683}