blob: 66da24986b24ae174a98e7efa72dc4910ef50dc1 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002 * Copyright (C) 2013-2014 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
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070031#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070032#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070033#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090034#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070035
Eric Laurentb23d5282013-05-14 15:27:20 -070036
37/*
Eric Laurentb23d5282013-05-14 15:27:20 -070038 * This file will have a maximum of 38 bytes:
39 *
40 * 4 bytes: number of audio blocks
41 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
42 * Maximum 10 * 3 bytes: SAD blocks
43 */
44#define MAX_SAD_BLOCKS 10
45#define SAD_BLOCK_SIZE 3
46
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090047#define MAX_CVD_VERSION_STRING_SIZE 100
48
Eric Laurentb23d5282013-05-14 15:27:20 -070049/* EDID format ID for LPCM audio */
50#define EDID_FORMAT_LPCM 1
51
sangwoo1b9f4b32013-06-21 18:22:55 -070052/* Retry for delay in FW loading*/
53#define RETRY_NUMBER 10
54#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070055#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070056
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070057#define MAX_SND_CARD_NAME_LEN 31
58
vivek mehta1a9b7c02015-06-25 11:49:38 -070059#define DEFAULT_APP_TYPE_RX_PATH 0x11130
60
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090061#define TOSTRING_(x) #x
62#define TOSTRING(x) TOSTRING_(x)
63
Eric Laurentb23d5282013-05-14 15:27:20 -070064struct audio_block_header
65{
66 int reserved;
67 int length;
68};
69
vivek mehta1a9b7c02015-06-25 11:49:38 -070070enum {
71 CAL_MODE_SEND = 0x1,
72 CAL_MODE_PERSIST = 0x2,
73 CAL_MODE_RTAC = 0x4
74};
75
keunhui.park2f7306a2015-07-16 16:48:06 +090076#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
77
78struct operator_info {
79 struct listnode list;
80 char *name;
81 char *mccmnc;
82};
83
84struct operator_specific_device {
85 struct listnode list;
86 char *operator;
87 char *mixer_path;
88 int acdb_id;
89};
90
91static struct listnode operator_info_list;
92static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
93
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070094/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -070095typedef void (*acdb_deallocate_t)();
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090096typedef int (*acdb_init_v2_cvd_t)(char *, char *);
97typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -070098typedef int (*acdb_init_t)();
99typedef void (*acdb_send_audio_cal_t)(int, int);
100typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700101typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700102typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700103
104/* Audio calibration related functions */
105struct platform_data {
106 struct audio_device *adev;
107 bool fluence_in_spkr_mode;
108 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700109 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700110 bool fluence_in_voice_rec;
vivek mehtadae44712015-07-27 14:13:18 -0700111 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
112 int fluence_type;
113 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700114 bool speaker_lr_swap;
115
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 void *acdb_handle;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700117 acdb_deallocate_t acdb_deallocate;
118 acdb_send_audio_cal_t acdb_send_audio_cal;
119 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700120 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700121 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700122 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800123 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700124
125 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900126 int max_vol_index;
vivek mehtadae44712015-07-27 14:13:18 -0700127 int max_mic_count;
Eric Laurentb23d5282013-05-14 15:27:20 -0700128};
129
Haynes Mathew George98c95622014-06-20 19:14:25 -0700130static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700131 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
132 DEEP_BUFFER_PCM_DEVICE},
133 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
134 LOWLATENCY_PCM_DEVICE},
135 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
136 MULTIMEDIA2_PCM_DEVICE},
137 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
138 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700139 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
140 MULTIMEDIA2_PCM_DEVICE},
141 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
142 MULTIMEDIA3_PCM_DEVICE},
143
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700144 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
145 AUDIO_RECORD_PCM_DEVICE},
146 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
147 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700148
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700149 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
150 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700151 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
152 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
153 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
154 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
155 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
156 AUDIO_RECORD_PCM_DEVICE},
157 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
158 AUDIO_RECORD_PCM_DEVICE},
159 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
160 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800161 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700162
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700163 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
164 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
165
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700166 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
167 AFE_PROXY_RECORD_PCM_DEVICE},
168 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
169 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800170 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700171
Eric Laurentb23d5282013-05-14 15:27:20 -0700172};
173
174/* Array to store sound devices */
175static const char * const device_table[SND_DEVICE_MAX] = {
176 [SND_DEVICE_NONE] = "none",
177 /* Playback sound devices */
178 [SND_DEVICE_OUT_HANDSET] = "handset",
179 [SND_DEVICE_OUT_SPEAKER] = "speaker",
180 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700181 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700182 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500183 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700184 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700185 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500186 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700187 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700188 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500189 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700190 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
191 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500192 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700193 [SND_DEVICE_OUT_HDMI] = "hdmi",
194 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
195 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700196 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700197 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
198 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
199 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
200 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700201 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700202 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
203 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Eric Laurentb23d5282013-05-14 15:27:20 -0700204
205 /* Capture sound devices */
206 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700207 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700208 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
209 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
210 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
211 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
212 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
213 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
214 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
215
216 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
217 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
218 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
219 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
220 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
221 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
222 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
223 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
224 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
225
226 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500227 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700228
Eric Laurentb23d5282013-05-14 15:27:20 -0700229 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
230 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700231 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700232 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700233 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700234 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700235
236 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
237 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
238 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
239 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
240 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700241 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
242 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
243 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700244
Eric Laurentb23d5282013-05-14 15:27:20 -0700245 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700246 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
247 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
248 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700249 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700250
251 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700252
vivek mehtadae44712015-07-27 14:13:18 -0700253 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
254 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700255 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
vivek mehtadae44712015-07-27 14:13:18 -0700256 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
257 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700258};
259
260/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700261static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700262 [SND_DEVICE_NONE] = -1,
263 [SND_DEVICE_OUT_HANDSET] = 7,
264 [SND_DEVICE_OUT_SPEAKER] = 15,
265 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700266 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700267 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500268 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700269 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700270 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500271 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700272 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700273 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
274 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500275 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500277 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700278 [SND_DEVICE_OUT_HDMI] = 18,
279 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
280 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700281 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700282 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700283 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
284 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
285 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700286 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700287 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
288 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Eric Laurentb23d5282013-05-14 15:27:20 -0700289
290 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700291 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
292 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
293 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
294 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
295 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
296 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
297 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
298 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
299
300 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
301 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
302 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
303 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
304 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
305 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
306 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
307 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
308 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
309
Eric Laurentb23d5282013-05-14 15:27:20 -0700310 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500311 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700312
Eric Laurentb23d5282013-05-14 15:27:20 -0700313 [SND_DEVICE_IN_HDMI_MIC] = 4,
314 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700315 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700316 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700317 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700318 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700319
320 [SND_DEVICE_IN_VOICE_DMIC] = 41,
321 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
322 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
323 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
324 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
Eric Laurentb23d5282013-05-14 15:27:20 -0700325 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
326 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
327 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700328
Eric Laurentb23d5282013-05-14 15:27:20 -0700329 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700330 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
331 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
332 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700333 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = 8,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700334
335 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700336
vivek mehtadae44712015-07-27 14:13:18 -0700337 [SND_DEVICE_IN_THREE_MIC] = 46,
338 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700339 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
vivek mehtadae44712015-07-27 14:13:18 -0700340 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
341 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
Eric Laurentb23d5282013-05-14 15:27:20 -0700342};
343
Haynes Mathew George98c95622014-06-20 19:14:25 -0700344struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700345 char name[100];
346 unsigned int index;
347};
348
349#define TO_NAME_INDEX(X) #X, X
350
Haynes Mathew George98c95622014-06-20 19:14:25 -0700351/* Used to get index from parsed string */
352static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
353 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700354 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
355 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
356 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700357 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700358 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500359 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700360 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700361 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500362 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700363 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700364 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
365 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
366 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500367 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700368 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
369 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
370 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
371 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700372 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500373 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700374 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
375 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
376 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700377
378 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700379 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
380 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700381 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700382 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700383 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
384 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
385 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
386 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
387 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
388 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
389 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
390
391 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700392 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700393 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
394 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
395 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
396 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
397 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
398 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
399 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
400
401 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700402 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700403
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700404 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
405 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700406 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700407 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700408 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700409 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700410
411 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
412 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
413 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
414 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
415 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700416 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
417 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
418 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700419
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700420 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700421 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
422 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
423 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700424 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700425
vivek mehtadae44712015-07-27 14:13:18 -0700426 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
427 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700428 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
vivek mehtadae44712015-07-27 14:13:18 -0700429 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
430 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700431};
432
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700433static char * backend_tag_table[SND_DEVICE_MAX] = {0};
434static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700435
436static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
437 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
438 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
439 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
440 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700441 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
442 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700443 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
444 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
445 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
446 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
447 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
448 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
449 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
450 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
451 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
452 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
453 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700454};
455
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700456#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
457#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
458
Eric Laurentb23d5282013-05-14 15:27:20 -0700459static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
460static bool is_tmus = false;
461
462static void check_operator()
463{
464 char value[PROPERTY_VALUE_MAX];
465 int mccmnc;
466 property_get("gsm.sim.operator.numeric",value,"0");
467 mccmnc = atoi(value);
468 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
469 switch(mccmnc) {
470 /* TMUS MCC(310), MNC(490, 260, 026) */
471 case 310490:
472 case 310260:
473 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900474 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
475 case 310800:
476 case 310660:
477 case 310580:
478 case 310310:
479 case 310270:
480 case 310250:
481 case 310240:
482 case 310230:
483 case 310220:
484 case 310210:
485 case 310200:
486 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700487 is_tmus = true;
488 break;
489 }
490}
491
492bool is_operator_tmus()
493{
494 pthread_once(&check_op_once_ctl, check_operator);
495 return is_tmus;
496}
497
keunhui.park2f7306a2015-07-16 16:48:06 +0900498static char *get_current_operator()
499{
500 struct listnode *node;
501 struct operator_info *info_item;
502 char mccmnc[PROPERTY_VALUE_MAX];
503 char *ret = NULL;
504
505 property_get("gsm.sim.operator.numeric",mccmnc,"0");
506
507 list_for_each(node, &operator_info_list) {
508 info_item = node_to_item(node, struct operator_info, list);
509 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
510 ret = info_item->name;
511 }
512 }
513
514 return ret;
515}
516
517static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
518{
519 struct listnode *node;
520 struct operator_specific_device *ret = NULL;
521 struct operator_specific_device *device_item;
522 char *operator_name;
523
524 operator_name = get_current_operator();
525 if (operator_name == NULL)
526 return ret;
527
528 list_for_each(node, operator_specific_device_table[snd_device]) {
529 device_item = node_to_item(node, struct operator_specific_device, list);
530 if (strcmp(operator_name, device_item->operator) == 0) {
531 ret = device_item;
532 }
533 }
534
535 return ret;
536}
537
538
539static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
540{
541 struct operator_specific_device *device;
542 int ret = acdb_device_table[snd_device];
543
544 device = get_operator_specific_device(snd_device);
545 if (device != NULL)
546 ret = device->acdb_id;
547
548 return ret;
549}
550
551static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
552{
553 struct operator_specific_device *device;
554 const char *ret = device_table[snd_device];
555
556 device = get_operator_specific_device(snd_device);
557 if (device != NULL)
558 ret = device->mixer_path;
559
560 return ret;
561}
562
vivek mehta1a9b7c02015-06-25 11:49:38 -0700563bool platform_send_gain_dep_cal(void *platform, int level)
564{
565 bool ret_val = false;
566 struct platform_data *my_data = (struct platform_data *)platform;
567 struct audio_device *adev = my_data->adev;
568 int acdb_dev_id, app_type;
569 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
570 int mode = CAL_MODE_RTAC;
571 struct listnode *node;
572 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700573
574 if (my_data->acdb_send_gain_dep_cal == NULL) {
575 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
576 return ret_val;
577 }
578
579 if (!voice_is_in_call(adev)) {
580 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
581 __func__, level);
582 app_type = DEFAULT_APP_TYPE_RX_PATH;
583
584 // find the current active sound device
585 list_for_each(node, &adev->usecase_list) {
586 usecase = node_to_item(node, struct audio_usecase, list);
587
588 if (usecase != NULL &&
589 usecase->type == PCM_PLAYBACK &&
590 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
591
592 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700593 if (audio_extn_spkr_prot_is_enabled()) {
594 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
595 } else {
596 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
597 }
598
vivek mehta1a9b7c02015-06-25 11:49:38 -0700599 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
600 acdb_dev_type, mode, level)) {
601 // set ret_val true if at least one calibration is set successfully
602 ret_val = true;
603 } else {
604 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
605 }
606 } else {
607 ALOGW("%s: Usecase list is empty", __func__);
608 }
609 }
610 } else {
611 ALOGW("%s: Voice call in progress .. ignore setting new cal",
612 __func__);
613 }
614 return ret_val;
615}
616
Eric Laurentcefbbac2014-09-04 13:54:10 -0500617void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700618{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800619 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500620 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700621
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800622 if (strcmp(my_data->ec_ref_mixer_path, "")) {
623 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
624 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500625 }
626
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800627 if (enable) {
628 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
629 if (out_device != AUDIO_DEVICE_NONE) {
630 snd_device = platform_get_output_snd_device(adev->platform, out_device);
631 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
632 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500633
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800634 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
635 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
636 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700637}
638
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700639static struct csd_data *open_csd_client(bool i2s_ext_modem)
640{
641 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
642
643 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
644 if (csd->csd_client == NULL) {
645 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
646 goto error;
647 } else {
648 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
649
650 csd->deinit = (deinit_t)dlsym(csd->csd_client,
651 "csd_client_deinit");
652 if (csd->deinit == NULL) {
653 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
654 dlerror());
655 goto error;
656 }
657 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
658 "csd_client_disable_device");
659 if (csd->disable_device == NULL) {
660 ALOGE("%s: dlsym error %s for csd_client_disable_device",
661 __func__, dlerror());
662 goto error;
663 }
664 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
665 "csd_client_enable_device_config");
666 if (csd->enable_device_config == NULL) {
667 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
668 __func__, dlerror());
669 goto error;
670 }
671 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
672 "csd_client_enable_device");
673 if (csd->enable_device == NULL) {
674 ALOGE("%s: dlsym error %s for csd_client_enable_device",
675 __func__, dlerror());
676 goto error;
677 }
678 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
679 "csd_client_start_voice");
680 if (csd->start_voice == NULL) {
681 ALOGE("%s: dlsym error %s for csd_client_start_voice",
682 __func__, dlerror());
683 goto error;
684 }
685 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
686 "csd_client_stop_voice");
687 if (csd->stop_voice == NULL) {
688 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
689 __func__, dlerror());
690 goto error;
691 }
692 csd->volume = (volume_t)dlsym(csd->csd_client,
693 "csd_client_volume");
694 if (csd->volume == NULL) {
695 ALOGE("%s: dlsym error %s for csd_client_volume",
696 __func__, dlerror());
697 goto error;
698 }
699 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
700 "csd_client_mic_mute");
701 if (csd->mic_mute == NULL) {
702 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
703 __func__, dlerror());
704 goto error;
705 }
706 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
707 "csd_client_slow_talk");
708 if (csd->slow_talk == NULL) {
709 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
710 __func__, dlerror());
711 goto error;
712 }
713 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
714 "csd_client_start_playback");
715 if (csd->start_playback == NULL) {
716 ALOGE("%s: dlsym error %s for csd_client_start_playback",
717 __func__, dlerror());
718 goto error;
719 }
720 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
721 "csd_client_stop_playback");
722 if (csd->stop_playback == NULL) {
723 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
724 __func__, dlerror());
725 goto error;
726 }
727 csd->start_record = (start_record_t)dlsym(csd->csd_client,
728 "csd_client_start_record");
729 if (csd->start_record == NULL) {
730 ALOGE("%s: dlsym error %s for csd_client_start_record",
731 __func__, dlerror());
732 goto error;
733 }
734 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
735 "csd_client_stop_record");
736 if (csd->stop_record == NULL) {
737 ALOGE("%s: dlsym error %s for csd_client_stop_record",
738 __func__, dlerror());
739 goto error;
740 }
741
742 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
743 "csd_client_get_sample_rate");
744 if (csd->get_sample_rate == NULL) {
745 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
746 __func__, dlerror());
747
748 goto error;
749 }
750
751 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
752
753 if (csd->init == NULL) {
754 ALOGE("%s: dlsym error %s for csd_client_init",
755 __func__, dlerror());
756 goto error;
757 } else {
758 csd->init(i2s_ext_modem);
759 }
760 }
761 return csd;
762
763error:
764 free(csd);
765 csd = NULL;
766 return csd;
767}
768
769void close_csd_client(struct csd_data *csd)
770{
771 if (csd != NULL) {
772 csd->deinit();
773 dlclose(csd->csd_client);
774 free(csd);
775 csd = NULL;
776 }
777}
778
779static void platform_csd_init(struct platform_data *my_data)
780{
781#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700782 int32_t modems, (*count_modems)(void);
783 const char *name = "libdetectmodem.so";
784 const char *func = "count_modems";
785 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700786
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700787 my_data->csd = NULL;
788
789 void *lib = dlopen(name, RTLD_NOW);
790 error = dlerror();
791 if (!lib) {
792 ALOGE("%s: could not find %s: %s", __func__, name, error);
793 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700794 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700795
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700796 count_modems = NULL;
797 *(void **)(&count_modems) = dlsym(lib, func);
798 error = dlerror();
799 if (!count_modems) {
800 ALOGE("%s: could not find symbol %s in %s: %s",
801 __func__, func, name, error);
802 goto done;
803 }
804
805 modems = count_modems();
806 if (modems < 0) {
807 ALOGE("%s: count_modems failed\n", __func__);
808 goto done;
809 }
810
811 ALOGD("%s: num_modems %d\n", __func__, modems);
812 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700813 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700814
815done:
816 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700817#else
818 my_data->csd = NULL;
819#endif
820}
821
Eric Laurentc6333382015-09-14 12:43:44 -0700822static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700823{
824 int32_t dev;
825 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700826 backend_tag_table[dev] = NULL;
827 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900828 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700829 }
830
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700831 // To overwrite these go to the audio_platform_info.xml file.
832 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700833 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700834 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
835 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
836 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
837 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
838 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700839 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700840 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
841 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700842
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700843 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
844 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
845 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
846 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
847 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
848 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
849 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700850 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700851 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700852 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700853 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
854 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
855 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
856 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
857 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
858 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
859 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
860 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
861 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
862 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
863 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
864 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
865 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
866 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
867 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
868 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700869
870 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700871}
872
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900873void get_cvd_version(char *cvd_version, struct audio_device *adev)
874{
875 struct mixer_ctl *ctl;
876 int count;
877 int ret = 0;
878
879 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
880 if (!ctl) {
881 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
882 goto done;
883 }
884 mixer_ctl_update(ctl);
885
886 count = mixer_ctl_get_num_values(ctl);
887 if (count > MAX_CVD_VERSION_STRING_SIZE)
888 count = MAX_CVD_VERSION_STRING_SIZE - 1;
889
890 ret = mixer_ctl_get_array(ctl, cvd_version, count);
891 if (ret != 0) {
892 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
893 goto done;
894 }
895
896done:
897 return;
898}
899
Eric Laurentb23d5282013-05-14 15:27:20 -0700900void *platform_init(struct audio_device *adev)
901{
902 char value[PROPERTY_VALUE_MAX];
903 struct platform_data *my_data;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700904 int retry_num = 0, snd_card_num = 0;
vivek mehta65ad12d2015-08-13 18:32:48 -0700905 bool dual_mic_config = false;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700906 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900907 char *cvd_version = NULL;
sangwoo1b9f4b32013-06-21 18:22:55 -0700908
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700909 my_data = calloc(1, sizeof(struct platform_data));
910
911 my_data->adev = adev;
912
keunhui.park2f7306a2015-07-16 16:48:06 +0900913 list_init(&operator_info_list);
914
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700915 set_platform_defaults(my_data);
916
917 /* Initialize platform specific ids and/or backends*/
918 platform_info_init(my_data);
919
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700920 while (snd_card_num < MAX_SND_CARD) {
921 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700922
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700923 while (!adev->mixer && retry_num < RETRY_NUMBER) {
924 usleep(RETRY_US);
925 adev->mixer = mixer_open(snd_card_num);
926 retry_num++;
927 }
928
929 if (!adev->mixer) {
930 ALOGE("%s: Unable to open the mixer card: %d", __func__,
931 snd_card_num);
932 retry_num = 0;
933 snd_card_num++;
934 continue;
935 }
936
937 snd_card_name = mixer_get_name(adev->mixer);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700938
939 /* validate the sound card name */
940 if (my_data->snd_card_name != NULL &&
941 strncmp(snd_card_name, my_data->snd_card_name, MAX_SND_CARD_NAME_LEN) != 0) {
942 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
943 __func__, snd_card_name, my_data->snd_card_name);
944 retry_num = 0;
945 snd_card_num++;
946 continue;
947 }
948
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700949 ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
950
951 adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH);
952 if (!adev->audio_route) {
953 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700954 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700955 }
956 adev->snd_card = snd_card_num;
957 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
958 break;
sangwoo1b9f4b32013-06-21 18:22:55 -0700959 }
960
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700961 if (snd_card_num >= MAX_SND_CARD) {
962 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700963 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -0700964 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700965
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900966 //set max volume step for voice call
967 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
968 my_data->max_vol_index = atoi(value);
969
vivek mehta65ad12d2015-08-13 18:32:48 -0700970 property_get("persist.audio.dualmic.config",value,"");
971 if (!strcmp("endfire", value)) {
972 dual_mic_config = true;
973 }
974
vivek mehtadae44712015-07-27 14:13:18 -0700975 my_data->source_mic_type = SOURCE_DUAL_MIC;
976
Eric Laurentb23d5282013-05-14 15:27:20 -0700977 my_data->fluence_in_spkr_mode = false;
978 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700979 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -0700980 my_data->fluence_in_voice_rec = false;
981
vivek mehta65ad12d2015-08-13 18:32:48 -0700982 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
vivek mehtadae44712015-07-27 14:13:18 -0700983 if (!strcmp("fluencepro", value)) {
984 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -0700985 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
vivek mehtadae44712015-07-27 14:13:18 -0700986 my_data->fluence_type = FLUENCE_ENABLE;
987 } else if (!strcmp("none", value)) {
988 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700989 }
990
vivek mehtadae44712015-07-27 14:13:18 -0700991 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700992 property_get("persist.audio.fluence.voicecall",value,"");
993 if (!strcmp("true", value)) {
994 my_data->fluence_in_voice_call = true;
995 }
996
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700997 property_get("persist.audio.fluence.voicecomm",value,"");
998 if (!strcmp("true", value)) {
999 my_data->fluence_in_voice_comm = true;
1000 }
1001
Eric Laurentb23d5282013-05-14 15:27:20 -07001002 property_get("persist.audio.fluence.voicerec",value,"");
1003 if (!strcmp("true", value)) {
1004 my_data->fluence_in_voice_rec = true;
1005 }
1006
1007 property_get("persist.audio.fluence.speaker",value,"");
1008 if (!strcmp("true", value)) {
1009 my_data->fluence_in_spkr_mode = true;
1010 }
1011 }
1012
vivek mehtadae44712015-07-27 14:13:18 -07001013 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1014 switch (my_data->max_mic_count) {
1015 case 4:
1016 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1017 case 3:
1018 my_data->source_mic_type |= SOURCE_THREE_MIC;
1019 case 2:
1020 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1021 case 1:
1022 my_data->source_mic_type |= SOURCE_MONO_MIC;
1023 break;
1024 default:
1025 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1026 __func__, my_data->max_mic_count);
1027 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1028 break;
1029 }
1030
1031 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1032 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1033 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1034 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1035 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1036
Eric Laurentb23d5282013-05-14 15:27:20 -07001037 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1038 if (my_data->acdb_handle == NULL) {
1039 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1040 } else {
1041 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1042 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1043 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001044 if (!my_data->acdb_deallocate)
1045 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1046 __func__, LIB_ACDB_LOADER);
1047
Eric Laurentb23d5282013-05-14 15:27:20 -07001048 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1049 "acdb_loader_send_audio_cal");
1050 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001051 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001052 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001053
Eric Laurentb23d5282013-05-14 15:27:20 -07001054 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1055 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001056 if (!my_data->acdb_send_voice_cal)
1057 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1058 __func__, LIB_ACDB_LOADER);
1059
1060 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1061 "acdb_loader_reload_vocvoltable");
1062 if (!my_data->acdb_reload_vocvoltable)
1063 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1064 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001065
1066 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1067 "acdb_loader_send_gain_dep_cal");
1068 if (!my_data->acdb_send_gain_dep_cal)
1069 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1070 __func__, LIB_ACDB_LOADER);
1071
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001072#if defined (PLATFORM_MSM8994)
1073 acdb_init_v2_cvd_t acdb_init;
1074 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1075 "acdb_loader_init_v2");
1076 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001077 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001078 goto acdb_init_fail;
1079 }
1080
1081 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1082 get_cvd_version(cvd_version, adev);
1083 if (!cvd_version)
1084 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001085 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001086 acdb_init((char *)snd_card_name, cvd_version);
1087 free(cvd_version);
1088#elif defined (PLATFORM_MSM8084)
1089 acdb_init_v2_t acdb_init;
1090 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1091 "acdb_loader_init_v2");
1092 if (acdb_init == NULL) {
1093 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1094 goto acdb_init_fail;
1095 }
1096 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001097#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001098 acdb_init_t acdb_init;
1099 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001100 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001101 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001102 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1103 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001104 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001105#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001106 }
1107
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001108acdb_init_fail:
1109
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001110 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001111
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001112 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1113
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001114 /* load csd client */
1115 platform_csd_init(my_data);
1116
Eric Laurentb23d5282013-05-14 15:27:20 -07001117 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001118
1119init_failed:
1120 if (my_data)
1121 free(my_data);
1122 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001123}
1124
1125void platform_deinit(void *platform)
1126{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001127 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001128 struct operator_info *info_item;
1129 struct operator_specific_device *device_item;
1130 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001131
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001132 struct platform_data *my_data = (struct platform_data *)platform;
1133 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001134
1135 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1136 if (backend_tag_table[dev])
1137 free(backend_tag_table[dev]);
1138 if (hw_interface_table[dev])
1139 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001140 if (operator_specific_device_table[dev]) {
1141 while (!list_empty(operator_specific_device_table[dev])) {
1142 node = list_head(operator_specific_device_table[dev]);
1143 list_remove(node);
1144 device_item = node_to_item(node, struct operator_specific_device, list);
1145 free(device_item->operator);
1146 free(device_item->mixer_path);
1147 free(device_item);
1148 }
1149 free(operator_specific_device_table[dev]);
1150 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001151 }
1152
1153 if (my_data->snd_card_name)
1154 free(my_data->snd_card_name);
1155
keunhui.park2f7306a2015-07-16 16:48:06 +09001156 while (!list_empty(&operator_info_list)) {
1157 node = list_head(&operator_info_list);
1158 list_remove(node);
1159 info_item = node_to_item(node, struct operator_info, list);
1160 free(info_item->name);
1161 free(info_item->mccmnc);
1162 free(info_item);
1163 }
1164
Eric Laurentb23d5282013-05-14 15:27:20 -07001165 free(platform);
1166}
1167
1168const char *platform_get_snd_device_name(snd_device_t snd_device)
1169{
keunhui.park2f7306a2015-07-16 16:48:06 +09001170 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1171 if (operator_specific_device_table[snd_device] != NULL) {
1172 return get_operator_specific_device_mixer_path(snd_device);
1173 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001174 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001175 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001176 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001177}
1178
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001179void platform_add_backend_name(void *platform, char *mixer_path,
1180 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001181{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001182 struct platform_data *my_data = (struct platform_data *)platform;
1183
Haynes Mathew George98c95622014-06-20 19:14:25 -07001184 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1185 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1186 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001187 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001188
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001189 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001190
1191 if (suffix != NULL) {
1192 strcat(mixer_path, " ");
1193 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001194 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001195}
1196
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001197bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1198{
1199 bool result = true;
1200
1201 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1202 platform_get_snd_device_name(snd_device1),
1203 platform_get_snd_device_name(snd_device2));
1204
1205 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1206 ALOGE("%s: Invalid snd_device = %s", __func__,
1207 platform_get_snd_device_name(snd_device1));
1208 return false;
1209 }
1210 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1211 ALOGE("%s: Invalid snd_device = %s", __func__,
1212 platform_get_snd_device_name(snd_device2));
1213 return false;
1214 }
1215 const char * be_itf1 = hw_interface_table[snd_device1];
1216 const char * be_itf2 = hw_interface_table[snd_device2];
1217
1218 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001219 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001220 result = false;
1221 }
1222
1223 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1224 return result;
1225}
1226
Eric Laurentb23d5282013-05-14 15:27:20 -07001227int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1228{
1229 int device_id;
1230 if (device_type == PCM_PLAYBACK)
1231 device_id = pcm_device_table[usecase][0];
1232 else
1233 device_id = pcm_device_table[usecase][1];
1234 return device_id;
1235}
1236
Haynes Mathew George98c95622014-06-20 19:14:25 -07001237static int find_index(const struct name_to_index * table, int32_t len,
1238 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001239{
1240 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001241 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001242
Haynes Mathew George98c95622014-06-20 19:14:25 -07001243 if (table == NULL) {
1244 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001245 ret = -ENODEV;
1246 goto done;
1247 }
1248
Haynes Mathew George98c95622014-06-20 19:14:25 -07001249 if (name == NULL) {
1250 ALOGE("null key");
1251 ret = -ENODEV;
1252 goto done;
1253 }
1254
1255 for (i=0; i < len; i++) {
1256 if (!strcmp(table[i].name, name)) {
1257 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001258 goto done;
1259 }
1260 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001261 ALOGE("%s: Could not find index for name = %s",
1262 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001263 ret = -ENODEV;
1264done:
1265 return ret;
1266}
1267
Haynes Mathew George98c95622014-06-20 19:14:25 -07001268int platform_get_snd_device_index(char *device_name)
1269{
1270 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1271}
1272
1273int platform_get_usecase_index(const char *usecase_name)
1274{
1275 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1276}
1277
keunhui.park2f7306a2015-07-16 16:48:06 +09001278void platform_add_operator_specific_device(snd_device_t snd_device,
1279 const char *operator,
1280 const char *mixer_path,
1281 unsigned int acdb_id)
1282{
1283 struct operator_specific_device *device;
1284
1285 if (operator_specific_device_table[snd_device] == NULL) {
1286 operator_specific_device_table[snd_device] =
1287 (struct listnode *)calloc(1, sizeof(struct listnode));
1288 list_init(operator_specific_device_table[snd_device]);
1289 }
1290
1291 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1292
1293 device->operator = strdup(operator);
1294 device->mixer_path = strdup(mixer_path);
1295 device->acdb_id = acdb_id;
1296
1297 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1298
1299 ALOGD("%s : deivce[%s] -> operator[%s] mixer_path[%s] acdb_id [%d]", __func__,
1300 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1301
1302}
1303
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001304int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1305{
1306 int ret = 0;
1307
1308 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1309 ALOGE("%s: Invalid snd_device = %d",
1310 __func__, snd_device);
1311 ret = -EINVAL;
1312 goto done;
1313 }
1314
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001315 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1316 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001317 acdb_device_table[snd_device] = acdb_id;
1318done:
1319 return ret;
1320}
1321
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001322int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1323{
1324 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1325 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1326 return -EINVAL;
1327 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001328
1329 if (operator_specific_device_table[snd_device] != NULL)
1330 return get_operator_specific_device_acdb_id(snd_device);
1331 else
1332 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001333}
1334
Eric Laurentb23d5282013-05-14 15:27:20 -07001335int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1336{
1337 struct platform_data *my_data = (struct platform_data *)platform;
1338 int acdb_dev_id, acdb_dev_type;
1339
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001340 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001341 if (acdb_dev_id < 0) {
1342 ALOGE("%s: Could not find acdb id for device(%d)",
1343 __func__, snd_device);
1344 return -EINVAL;
1345 }
1346 if (my_data->acdb_send_audio_cal) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001347 ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001348 __func__, snd_device, acdb_dev_id);
1349 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1350 snd_device < SND_DEVICE_OUT_END)
1351 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1352 else
1353 acdb_dev_type = ACDB_DEV_TYPE_IN;
1354 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1355 }
1356 return 0;
1357}
1358
1359int platform_switch_voice_call_device_pre(void *platform)
1360{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001361 struct platform_data *my_data = (struct platform_data *)platform;
1362 int ret = 0;
1363
1364 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001365 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001366 /* This must be called before disabling mixer controls on APQ side */
1367 ret = my_data->csd->disable_device();
1368 if (ret < 0) {
1369 ALOGE("%s: csd_client_disable_device, failed, error %d",
1370 __func__, ret);
1371 }
1372 }
1373 return ret;
1374}
1375
1376int platform_switch_voice_call_enable_device_config(void *platform,
1377 snd_device_t out_snd_device,
1378 snd_device_t in_snd_device)
1379{
1380 struct platform_data *my_data = (struct platform_data *)platform;
1381 int acdb_rx_id, acdb_tx_id;
1382 int ret = 0;
1383
1384 if (my_data->csd == NULL)
1385 return ret;
1386
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001387 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1388 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001389 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001390 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001391 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001392
keunhui.park2f7306a2015-07-16 16:48:06 +09001393 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001394
1395 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1396 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1397 if (ret < 0) {
1398 ALOGE("%s: csd_enable_device_config, failed, error %d",
1399 __func__, ret);
1400 }
1401 } else {
1402 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1403 acdb_rx_id, acdb_tx_id);
1404 }
1405
1406 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001407}
1408
1409int platform_switch_voice_call_device_post(void *platform,
1410 snd_device_t out_snd_device,
1411 snd_device_t in_snd_device)
1412{
1413 struct platform_data *my_data = (struct platform_data *)platform;
1414 int acdb_rx_id, acdb_tx_id;
1415
1416 if (my_data->acdb_send_voice_cal == NULL) {
1417 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1418 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001419 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1420 audio_extn_spkr_prot_is_enabled())
1421 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1422
keunhui.park2f7306a2015-07-16 16:48:06 +09001423 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1424 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001425
1426 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1427 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1428 else
1429 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1430 acdb_rx_id, acdb_tx_id);
1431 }
1432
1433 return 0;
1434}
1435
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001436int platform_switch_voice_call_usecase_route_post(void *platform,
1437 snd_device_t out_snd_device,
1438 snd_device_t in_snd_device)
1439{
1440 struct platform_data *my_data = (struct platform_data *)platform;
1441 int acdb_rx_id, acdb_tx_id;
1442 int ret = 0;
1443
1444 if (my_data->csd == NULL)
1445 return ret;
1446
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001447 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1448 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001449 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001450 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001451 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001452
keunhui.park2f7306a2015-07-16 16:48:06 +09001453 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001454
1455 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1456 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1457 my_data->adev->acdb_settings);
1458 if (ret < 0) {
1459 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1460 }
1461 } else {
1462 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1463 acdb_rx_id, acdb_tx_id);
1464 }
1465
1466 return ret;
1467}
1468
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001469int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001470{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001471 struct platform_data *my_data = (struct platform_data *)platform;
1472 int ret = 0;
1473
1474 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001475 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001476 if (ret < 0) {
1477 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1478 }
1479 }
1480 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001481}
1482
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001483int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001484{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001485 struct platform_data *my_data = (struct platform_data *)platform;
1486 int ret = 0;
1487
1488 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001489 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001490 if (ret < 0) {
1491 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1492 }
1493 }
1494 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001495}
1496
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001497int platform_get_sample_rate(void *platform, uint32_t *rate)
1498{
1499 struct platform_data *my_data = (struct platform_data *)platform;
1500 int ret = 0;
1501
1502 if (my_data->csd != NULL) {
1503 ret = my_data->csd->get_sample_rate(rate);
1504 if (ret < 0) {
1505 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1506 }
1507 }
1508 return ret;
1509}
1510
vivek mehtab6506412015-08-07 16:55:17 -07001511void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1512 snd_device_t snd_device,
1513 bool enable)
1514{
1515 const char* name;
1516 switch (snd_device) {
1517 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1518 if (enable)
1519 name = "spkr-gain-in-headphone-combo";
1520 else
1521 name = "speaker-gain-default";
1522 break;
1523 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1524 if (enable)
1525 name = "spkr-gain-in-line-combo";
1526 else
1527 name = "speaker-gain-default";
1528 break;
1529 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1530 if (enable)
1531 name = "spkr-safe-gain-in-headphone-combo";
1532 else
1533 name = "speaker-safe-gain-default";
1534 break;
1535 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1536 if (enable)
1537 name = "spkr-safe-gain-in-line-combo";
1538 else
1539 name = "speaker-safe-gain-default";
1540 break;
1541 default:
1542 return;
1543 }
1544
1545 audio_route_apply_and_update_path(adev->audio_route, name);
1546}
1547
Eric Laurentb23d5282013-05-14 15:27:20 -07001548int platform_set_voice_volume(void *platform, int volume)
1549{
1550 struct platform_data *my_data = (struct platform_data *)platform;
1551 struct audio_device *adev = my_data->adev;
1552 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001553 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001554 int vol_index = 0, ret = 0;
1555 uint32_t set_values[ ] = {0,
1556 ALL_SESSION_VSID,
1557 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001558
1559 // Voice volume levels are mapped to adsp volume levels as follows.
1560 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1561 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001562 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001563 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001564
1565 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1566 if (!ctl) {
1567 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1568 __func__, mixer_ctl_name);
1569 return -EINVAL;
1570 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001571 ALOGV("Setting voice volume index: %d", set_values[0]);
1572 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1573
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001574 if (my_data->csd != NULL) {
1575 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1576 DEFAULT_VOLUME_RAMP_DURATION_MS);
1577 if (ret < 0) {
1578 ALOGE("%s: csd_volume error %d", __func__, ret);
1579 }
1580 }
1581 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001582}
1583
1584int platform_set_mic_mute(void *platform, bool state)
1585{
1586 struct platform_data *my_data = (struct platform_data *)platform;
1587 struct audio_device *adev = my_data->adev;
1588 struct mixer_ctl *ctl;
1589 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001590 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001591 uint32_t set_values[ ] = {0,
1592 ALL_SESSION_VSID,
1593 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001594
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001595 if (adev->mode != AUDIO_MODE_IN_CALL)
1596 return 0;
1597
1598 set_values[0] = state;
1599 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1600 if (!ctl) {
1601 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1602 __func__, mixer_ctl_name);
1603 return -EINVAL;
1604 }
1605 ALOGV("Setting voice mute state: %d", state);
1606 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1607
1608 if (my_data->csd != NULL) {
1609 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1610 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001611 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001612 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001613 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001614 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001615 return ret;
1616}
Eric Laurentb23d5282013-05-14 15:27:20 -07001617
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001618int platform_set_device_mute(void *platform, bool state, char *dir)
1619{
1620 struct platform_data *my_data = (struct platform_data *)platform;
1621 struct audio_device *adev = my_data->adev;
1622 struct mixer_ctl *ctl;
1623 char *mixer_ctl_name = NULL;
1624 int ret = 0;
1625 uint32_t set_values[ ] = {0,
1626 ALL_SESSION_VSID,
1627 0};
1628 if(dir == NULL) {
1629 ALOGE("%s: Invalid direction:%s", __func__, dir);
1630 return -EINVAL;
1631 }
1632
1633 if (!strncmp("rx", dir, sizeof("rx"))) {
1634 mixer_ctl_name = "Voice Rx Device Mute";
1635 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1636 mixer_ctl_name = "Voice Tx Device Mute";
1637 } else {
1638 return -EINVAL;
1639 }
1640
1641 set_values[0] = state;
1642 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1643 if (!ctl) {
1644 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1645 __func__, mixer_ctl_name);
1646 return -EINVAL;
1647 }
1648
1649 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1650 __func__,state, mixer_ctl_name);
1651 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1652
1653 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001654}
1655
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001656bool platform_can_split_snd_device(snd_device_t snd_device,
1657 int *num_devices,
1658 snd_device_t *new_snd_devices)
1659{
1660 bool status = false;
1661
1662 if (NULL == num_devices || NULL == new_snd_devices) {
1663 ALOGE("%s: NULL pointer ..", __func__);
1664 return false;
1665 }
1666
1667 /*
1668 * If wired headset/headphones/line devices share the same backend
1669 * with speaker/earpiece this routine returns false.
1670 */
1671 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1672 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1673 *num_devices = 2;
1674 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1675 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1676 status = true;
1677 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1678 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1679 *num_devices = 2;
1680 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1681 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1682 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001683 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1684 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1685 *num_devices = 2;
1686 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1687 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1688 status = true;
1689 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1690 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1691 *num_devices = 2;
1692 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1693 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1694 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001695 }
1696 return status;
1697}
1698
Eric Laurentb23d5282013-05-14 15:27:20 -07001699snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1700{
1701 struct platform_data *my_data = (struct platform_data *)platform;
1702 struct audio_device *adev = my_data->adev;
1703 audio_mode_t mode = adev->mode;
1704 snd_device_t snd_device = SND_DEVICE_NONE;
1705
1706 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1707 if (devices == AUDIO_DEVICE_NONE ||
1708 devices & AUDIO_DEVICE_BIT_IN) {
1709 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1710 goto exit;
1711 }
1712
Eric Laurent1b491552015-09-15 17:52:41 -07001713 if (popcount(devices) == 2) {
1714 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1715 AUDIO_DEVICE_OUT_SPEAKER) ||
1716 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1717 AUDIO_DEVICE_OUT_SPEAKER)) {
1718 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
1719 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1720 AUDIO_DEVICE_OUT_SPEAKER)) {
1721 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
1722 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1723 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1724 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1725 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1726 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1727 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1728 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1729 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
1730 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1731 AUDIO_DEVICE_OUT_SPEAKER)) {
1732 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1733 } else {
1734 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1735 goto exit;
1736 }
1737 if (snd_device != SND_DEVICE_NONE) {
1738 goto exit;
1739 }
1740 }
1741
1742 if (popcount(devices) != 1) {
1743 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1744 goto exit;
1745 }
1746
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001747 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001748 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001749 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1750 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001751 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001752 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001753 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001754 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001755 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001756 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001757 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001758 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001759 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001760 else {
1761 if (devices & AUDIO_DEVICE_OUT_LINE)
1762 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1763 else
1764 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1765 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001766 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001767 if (adev->bt_wb_speech_enabled) {
1768 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1769 } else {
1770 snd_device = SND_DEVICE_OUT_BT_SCO;
1771 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001772 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001773 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1774 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001775 if(adev->voice.hac)
1776 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1777 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001778 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1779 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001780 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001781 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1782 snd_device = SND_DEVICE_OUT_VOICE_TX;
1783
Eric Laurentb23d5282013-05-14 15:27:20 -07001784 if (snd_device != SND_DEVICE_NONE) {
1785 goto exit;
1786 }
1787 }
1788
Eric Laurentb23d5282013-05-14 15:27:20 -07001789 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1790 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1791 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001792 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1793 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001794 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1795 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001796 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001797 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001798 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1799 else
1800 snd_device = SND_DEVICE_OUT_SPEAKER;
1801 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001802 if (adev->bt_wb_speech_enabled) {
1803 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1804 } else {
1805 snd_device = SND_DEVICE_OUT_BT_SCO;
1806 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001807 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1808 snd_device = SND_DEVICE_OUT_HDMI ;
1809 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001810 /*HAC support for voice-ish audio (eg visual voicemail)*/
1811 if(adev->voice.hac)
1812 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1813 else
1814 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001815 } else {
1816 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1817 }
1818exit:
1819 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1820 return snd_device;
1821}
1822
1823snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1824{
1825 struct platform_data *my_data = (struct platform_data *)platform;
1826 struct audio_device *adev = my_data->adev;
1827 audio_source_t source = (adev->active_input == NULL) ?
1828 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1829
1830 audio_mode_t mode = adev->mode;
1831 audio_devices_t in_device = ((adev->active_input == NULL) ?
1832 AUDIO_DEVICE_NONE : adev->active_input->device)
1833 & ~AUDIO_DEVICE_BIT_IN;
1834 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1835 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1836 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001837 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001838
vivek mehtadae44712015-07-27 14:13:18 -07001839 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
1840 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001841 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001842 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001843 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001844 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1845 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001846 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001847 case TTY_MODE_FULL:
1848 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1849 break;
1850 case TTY_MODE_VCO:
1851 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1852 break;
1853 case TTY_MODE_HCO:
1854 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1855 break;
1856 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001857 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001858 }
1859 goto exit;
1860 }
1861 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001862 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001863 if (my_data->fluence_in_voice_call == false) {
1864 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1865 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001866 if (is_operator_tmus())
1867 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001868 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001869 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001870 }
1871 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1872 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1873 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001874 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001875 if (adev->bluetooth_nrec)
1876 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1877 else
1878 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001879 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001880 if (adev->bluetooth_nrec)
1881 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1882 else
1883 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001884 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001885 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehtadae44712015-07-27 14:13:18 -07001886 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
1887 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1888 out_device & AUDIO_DEVICE_OUT_LINE) {
1889 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
1890 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
1891 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1892 } else {
1893 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1894 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001895 }
vivek mehtac0903392015-08-10 23:39:23 -07001896
1897 //select default
1898 if (snd_device == SND_DEVICE_NONE) {
1899 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
1900 }
vivek mehtadae44712015-07-27 14:13:18 -07001901 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001902 snd_device = SND_DEVICE_IN_VOICE_RX;
vivek mehtadae44712015-07-27 14:13:18 -07001903 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001904 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1905 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1906 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1907 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1908 }
1909 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1910 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehtadae44712015-07-27 14:13:18 -07001911 if (my_data->fluence_in_voice_rec && channel_count == 1) {
1912 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
1913 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
1914 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
1915 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
1916 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
1917 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
1918 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
1919 (my_data->fluence_type == FLUENCE_ENABLE)) &&
1920 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001921 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
vivek mehtadae44712015-07-27 14:13:18 -07001922 }
1923 platform_set_echo_reference(adev, true, out_device);
1924 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
1925 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
1926 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1927 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
1928 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
1929 snd_device = SND_DEVICE_IN_THREE_MIC;
1930 } else if (((int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
1931 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
1932 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001933 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001934 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001935 if (adev->active_input->enable_ns)
1936 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1937 else
1938 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001939 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07001940 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1941 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001942 }
1943 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001944 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07001945 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1946 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001947 if (adev->active_input->enable_aec &&
1948 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001949 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001950 if (my_data->fluence_in_spkr_mode &&
1951 my_data->fluence_in_voice_comm &&
vivek mehtadae44712015-07-27 14:13:18 -07001952 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001953 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
vivek mehtadae44712015-07-27 14:13:18 -07001954 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001955 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
vivek mehtadae44712015-07-27 14:13:18 -07001956 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001957 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001958 if (my_data->fluence_in_voice_comm &&
vivek mehtadae44712015-07-27 14:13:18 -07001959 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001960 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
vivek mehtadae44712015-07-27 14:13:18 -07001961 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001962 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
vivek mehtadae44712015-07-27 14:13:18 -07001963 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001964 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1965 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001966 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001967 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001968 } else if (adev->active_input->enable_aec) {
1969 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1970 if (my_data->fluence_in_spkr_mode &&
1971 my_data->fluence_in_voice_comm &&
vivek mehtadae44712015-07-27 14:13:18 -07001972 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001973 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
vivek mehtadae44712015-07-27 14:13:18 -07001974 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001975 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
vivek mehtadae44712015-07-27 14:13:18 -07001976 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001977 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1978 if (my_data->fluence_in_voice_comm &&
vivek mehtadae44712015-07-27 14:13:18 -07001979 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001980 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
vivek mehtadae44712015-07-27 14:13:18 -07001981 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001982 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
vivek mehtadae44712015-07-27 14:13:18 -07001983 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001984 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1985 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
1986 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001987 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001988 } else if (adev->active_input->enable_ns) {
1989 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1990 if (my_data->fluence_in_spkr_mode &&
1991 my_data->fluence_in_voice_comm &&
vivek mehtadae44712015-07-27 14:13:18 -07001992 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001993 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
vivek mehtadae44712015-07-27 14:13:18 -07001994 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001995 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
vivek mehtadae44712015-07-27 14:13:18 -07001996 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001997 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1998 if (my_data->fluence_in_voice_comm &&
vivek mehtadae44712015-07-27 14:13:18 -07001999 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002000 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
vivek mehtadae44712015-07-27 14:13:18 -07002001 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002002 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
vivek mehtadae44712015-07-27 14:13:18 -07002003 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002004 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002005 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002006 }
2007 } else if (source == AUDIO_SOURCE_DEFAULT) {
2008 goto exit;
2009 }
2010
2011
2012 if (snd_device != SND_DEVICE_NONE) {
2013 goto exit;
2014 }
2015
2016 if (in_device != AUDIO_DEVICE_NONE &&
2017 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2018 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2019 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehtadae44712015-07-27 14:13:18 -07002020 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
2021 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
2022 snd_device = SND_DEVICE_IN_QUAD_MIC;
2023 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
2024 (int)channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
2025 snd_device = SND_DEVICE_IN_THREE_MIC;
2026 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2027 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002028 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
vivek mehtadae44712015-07-27 14:13:18 -07002029 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2030 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002031 snd_device = SND_DEVICE_IN_HANDSET_MIC;
vivek mehtadae44712015-07-27 14:13:18 -07002032 } else {
2033 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2034 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2035 my_data->source_mic_type, channel_count, channel_mask);
2036 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2037 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002038 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
vivek mehtadae44712015-07-27 14:13:18 -07002039 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2040 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002041 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
vivek mehtadae44712015-07-27 14:13:18 -07002042 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2043 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002044 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
vivek mehtadae44712015-07-27 14:13:18 -07002045 } else {
2046 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2047 " no combination found .. setting to mono", __func__,
2048 my_data->source_mic_type, channel_count);
2049 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2050 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002051 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2052 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2053 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002054 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002055 if (adev->bluetooth_nrec)
2056 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2057 else
2058 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002059 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002060 if (adev->bluetooth_nrec)
2061 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2062 else
2063 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002064 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002065 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2066 snd_device = SND_DEVICE_IN_HDMI_MIC;
2067 } else {
2068 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2069 ALOGW("%s: Using default handset-mic", __func__);
2070 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2071 }
2072 } else {
2073 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2074 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2075 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2076 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002077 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002078 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002079 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002080 out_device & AUDIO_DEVICE_OUT_LINE) {
vivek mehtadae44712015-07-27 14:13:18 -07002081 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2082 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002083 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
vivek mehtadae44712015-07-27 14:13:18 -07002084 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2085 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002086 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
vivek mehtadae44712015-07-27 14:13:18 -07002087 } else {
2088 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2089 " no combination found .. setting to mono", __func__,
2090 my_data->source_mic_type, channel_count);
2091 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2092 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002093 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002094 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002095 if (adev->bluetooth_nrec)
2096 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2097 else
2098 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002099 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002100 if (adev->bluetooth_nrec)
2101 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2102 else
2103 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002104 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002105 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2106 snd_device = SND_DEVICE_IN_HDMI_MIC;
2107 } else {
2108 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2109 ALOGW("%s: Using default handset-mic", __func__);
2110 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2111 }
2112 }
2113exit:
2114 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2115 return snd_device;
2116}
2117
2118int platform_set_hdmi_channels(void *platform, int channel_count)
2119{
2120 struct platform_data *my_data = (struct platform_data *)platform;
2121 struct audio_device *adev = my_data->adev;
2122 struct mixer_ctl *ctl;
2123 const char *channel_cnt_str = NULL;
2124 const char *mixer_ctl_name = "HDMI_RX Channels";
2125 switch (channel_count) {
2126 case 8:
2127 channel_cnt_str = "Eight"; break;
2128 case 7:
2129 channel_cnt_str = "Seven"; break;
2130 case 6:
2131 channel_cnt_str = "Six"; break;
2132 case 5:
2133 channel_cnt_str = "Five"; break;
2134 case 4:
2135 channel_cnt_str = "Four"; break;
2136 case 3:
2137 channel_cnt_str = "Three"; break;
2138 default:
2139 channel_cnt_str = "Two"; break;
2140 }
2141 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2142 if (!ctl) {
2143 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2144 __func__, mixer_ctl_name);
2145 return -EINVAL;
2146 }
2147 ALOGV("HDMI channel count: %s", channel_cnt_str);
2148 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2149 return 0;
2150}
2151
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002152int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002153{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002154 struct platform_data *my_data = (struct platform_data *)platform;
2155 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002156 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2157 char *sad = block;
2158 int num_audio_blocks;
2159 int channel_count;
2160 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002161 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002162
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002163 struct mixer_ctl *ctl;
2164
2165 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2166 if (!ctl) {
2167 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2168 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002169 return 0;
2170 }
2171
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002172 mixer_ctl_update(ctl);
2173
2174 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002175
2176 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002177 if (count > (int)sizeof(block))
2178 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002179
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002180 ret = mixer_ctl_get_array(ctl, block, count);
2181 if (ret != 0) {
2182 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2183 return 0;
2184 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002185
2186 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002187 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002188
2189 for (i = 0; i < num_audio_blocks; i++) {
2190 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002191 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2192 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002193 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002194 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002195
2196 channel_count = (sad[0] & 0x7) + 1;
2197 if (channel_count > max_channels)
2198 max_channels = channel_count;
2199
2200 /* Advance to next block */
2201 sad += 3;
2202 }
2203
2204 return max_channels;
2205}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002206
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002207int platform_set_incall_recording_session_id(void *platform,
2208 uint32_t session_id, int rec_mode)
2209{
2210 int ret = 0;
2211 struct platform_data *my_data = (struct platform_data *)platform;
2212 struct audio_device *adev = my_data->adev;
2213 struct mixer_ctl *ctl;
2214 const char *mixer_ctl_name = "Voc VSID";
2215 int num_ctl_values;
2216 int i;
2217
2218 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2219 if (!ctl) {
2220 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2221 __func__, mixer_ctl_name);
2222 ret = -EINVAL;
2223 } else {
2224 num_ctl_values = mixer_ctl_get_num_values(ctl);
2225 for (i = 0; i < num_ctl_values; i++) {
2226 if (mixer_ctl_set_value(ctl, i, session_id)) {
2227 ALOGV("Error: invalid session_id: %x", session_id);
2228 ret = -EINVAL;
2229 break;
2230 }
2231 }
2232 }
2233
2234 if (my_data->csd != NULL) {
2235 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2236 if (ret < 0) {
2237 ALOGE("%s: csd_client_start_record failed, error %d",
2238 __func__, ret);
2239 }
2240 }
2241
2242 return ret;
2243}
2244
2245int platform_stop_incall_recording_usecase(void *platform)
2246{
2247 int ret = 0;
2248 struct platform_data *my_data = (struct platform_data *)platform;
2249
2250 if (my_data->csd != NULL) {
2251 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2252 if (ret < 0) {
2253 ALOGE("%s: csd_client_stop_record failed, error %d",
2254 __func__, ret);
2255 }
2256 }
2257
2258 return ret;
2259}
2260
2261int platform_start_incall_music_usecase(void *platform)
2262{
2263 int ret = 0;
2264 struct platform_data *my_data = (struct platform_data *)platform;
2265
2266 if (my_data->csd != NULL) {
2267 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2268 if (ret < 0) {
2269 ALOGE("%s: csd_client_start_playback failed, error %d",
2270 __func__, ret);
2271 }
2272 }
2273
2274 return ret;
2275}
2276
2277int platform_stop_incall_music_usecase(void *platform)
2278{
2279 int ret = 0;
2280 struct platform_data *my_data = (struct platform_data *)platform;
2281
2282 if (my_data->csd != NULL) {
2283 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2284 if (ret < 0) {
2285 ALOGE("%s: csd_client_stop_playback failed, error %d",
2286 __func__, ret);
2287 }
2288 }
2289
2290 return ret;
2291}
2292
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002293int platform_set_parameters(void *platform, struct str_parms *parms)
2294{
2295 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002296 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002297 char *kv_pairs = str_parms_to_str(parms);
2298 int ret = 0, err;
2299
2300 if (kv_pairs == NULL) {
2301 ret = -EINVAL;
2302 ALOGE("%s: key-value pair is NULL",__func__);
2303 goto done;
2304 }
2305
2306 ALOGV("%s: enter: %s", __func__, kv_pairs);
2307
2308 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2309 value, sizeof(value));
2310 if (err >= 0) {
2311 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2312 my_data->snd_card_name = strdup(value);
2313 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2314 }
2315
keunhui.park2f7306a2015-07-16 16:48:06 +09002316 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2317 value, sizeof(value));
2318 if (err >= 0) {
2319 struct operator_info *info;
2320 char *str = value;
2321 char *name;
2322
2323 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2324 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2325 name = strtok(str, ";");
2326 info->name = strdup(name);
2327 info->mccmnc = strdup(str + strlen(name) + 1);
2328
2329 list_add_tail(&operator_info_list, &info->list);
2330 ALOGD("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
2331 }
vivek mehtadae44712015-07-27 14:13:18 -07002332
2333 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002334 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
vivek mehtadae44712015-07-27 14:13:18 -07002335 value, sizeof(value));
2336 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002337 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
vivek mehtadae44712015-07-27 14:13:18 -07002338 my_data->max_mic_count = atoi(value);
2339 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
vivek mehtadae44712015-07-27 14:13:18 -07002340 }
2341
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002342done:
2343 ALOGV("%s: exit with code(%d)", __func__, ret);
2344 if (kv_pairs != NULL)
2345 free(kv_pairs);
2346
2347 return ret;
2348}
2349
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002350/* Delay in Us */
2351int64_t platform_render_latency(audio_usecase_t usecase)
2352{
2353 switch (usecase) {
2354 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2355 return DEEP_BUFFER_PLATFORM_DELAY;
2356 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2357 return LOW_LATENCY_PLATFORM_DELAY;
2358 default:
2359 return 0;
2360 }
2361}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002362
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002363int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2364 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002365{
2366 int ret = 0;
2367
2368 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2369 ALOGE("%s: Invalid snd_device = %d",
2370 __func__, device);
2371 ret = -EINVAL;
2372 goto done;
2373 }
2374
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002375 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2376 platform_get_snd_device_name(device),
2377 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2378 if (backend_tag_table[device]) {
2379 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002380 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002381 backend_tag_table[device] = strdup(backend_tag);
2382
2383 if (hw_interface != NULL) {
2384 if (hw_interface_table[device])
2385 free(hw_interface_table[device]);
2386 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2387 hw_interface_table[device] = strdup(hw_interface);
2388 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002389done:
2390 return ret;
2391}
2392
2393int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2394{
2395 int ret = 0;
2396 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2397 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2398 ret = -EINVAL;
2399 goto done;
2400 }
2401
2402 if ((type != 0) && (type != 1)) {
2403 ALOGE("%s: invalid usecase type", __func__);
2404 ret = -EINVAL;
2405 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002406 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002407 pcm_device_table[usecase][type] = pcm_id;
2408done:
2409 return ret;
2410}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002411
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002412#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2413int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2414 // backup_gain: gain to try to set in case of an error during ramp
2415 int start_gain, end_gain, step, backup_gain, i;
2416 bool error = false;
2417 const struct mixer_ctl *ctl;
2418 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2419 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2420 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2421 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2422 if (!ctl_left || !ctl_right) {
2423 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2424 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2425 return -EINVAL;
2426 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2427 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2428 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2429 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2430 return -EINVAL;
2431 }
2432 if (ramp_up) {
2433 start_gain = 0;
2434 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2435 step = +1;
2436 backup_gain = end_gain;
2437 } else {
2438 // using same gain on left and right
2439 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2440 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2441 end_gain = 0;
2442 step = -1;
2443 backup_gain = start_gain;
2444 }
2445 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2446 //ALOGV("setting speaker gain to %d", i);
2447 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2448 ALOGE("%s: error setting %s to %d during gain ramp",
2449 __func__, mixer_ctl_name_gain_left, i);
2450 error = true;
2451 break;
2452 }
2453 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2454 ALOGE("%s: error setting %s to %d during gain ramp",
2455 __func__, mixer_ctl_name_gain_right, i);
2456 error = true;
2457 break;
2458 }
2459 usleep(1000);
2460 }
2461 if (error) {
2462 // an error occured during the ramp, let's still try to go back to a safe volume
2463 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2464 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2465 }
2466 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2467 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2468 }
2469 }
2470 return start_gain;
2471}
2472
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002473int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2474{
2475 // only update if there is active pcm playback on speaker
2476 struct audio_usecase *usecase;
2477 struct listnode *node;
2478 struct platform_data *my_data = (struct platform_data *)adev->platform;
2479
2480 if (my_data->speaker_lr_swap != swap_channels) {
2481 my_data->speaker_lr_swap = swap_channels;
2482
2483 list_for_each(node, &adev->usecase_list) {
2484 usecase = node_to_item(node, struct audio_usecase, list);
2485 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002486 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2487 /*
2488 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2489 * to perform device switch to disable the current backend to
2490 * enable it with new acdb data.
2491 */
2492 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2493 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002494 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002495 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002496 if (initial_skpr_gain != -EINVAL) {
2497 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2498 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002499 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002500 const char *mixer_path;
2501 if (swap_channels) {
2502 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2503 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2504 } else {
2505 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2506 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2507 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002508 }
2509 break;
2510 }
2511 }
2512 }
2513 return 0;
2514}