blob: 7b1fa75c0380975ad8d4d013c6f36624215ca44a [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 */
Bryce Lee93be0a52015-08-10 23:23:55 +000016
Eric Laurentb23d5282013-05-14 15:27:20 -070017#define LOG_TAG "msm8974_platform"
18/*#define LOG_NDEBUG 0*/
19#define LOG_NDDEBUG 0
20
21#include <stdlib.h>
22#include <dlfcn.h>
23#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070024#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070025#include <cutils/properties.h>
26#include <audio_hw.h>
27#include <platform_api.h>
28#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070029#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070030#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070031
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070032#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -070033#define MIXER_XML_PATH_WCD9330 "/system/etc/mixer_paths_wcd9330.xml"
Eric Laurentb23d5282013-05-14 15:27:20 -070034#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070035#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090036#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070037
Bryce Lee93be0a52015-08-10 23:23:55 +000038#define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */
39#define DUALMIC_CONFIG_ENDFIRE 1
40#define DUALMIC_CONFIG_BROADSIDE 2
Eric Laurentb23d5282013-05-14 15:27:20 -070041
42/*
Eric Laurentb23d5282013-05-14 15:27:20 -070043 * This file will have a maximum of 38 bytes:
44 *
45 * 4 bytes: number of audio blocks
46 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
47 * Maximum 10 * 3 bytes: SAD blocks
48 */
49#define MAX_SAD_BLOCKS 10
50#define SAD_BLOCK_SIZE 3
51
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090052#define MAX_CVD_VERSION_STRING_SIZE 100
53
Eric Laurentb23d5282013-05-14 15:27:20 -070054/* EDID format ID for LPCM audio */
55#define EDID_FORMAT_LPCM 1
56
sangwoo1b9f4b32013-06-21 18:22:55 -070057/* Retry for delay in FW loading*/
58#define RETRY_NUMBER 10
59#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070060#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070061
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070062#define MAX_SND_CARD_NAME_LEN 31
63
vivek mehta1a9b7c02015-06-25 11:49:38 -070064#define DEFAULT_APP_TYPE_RX_PATH 0x11130
65
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090066#define TOSTRING_(x) #x
67#define TOSTRING(x) TOSTRING_(x)
68
Eric Laurentb23d5282013-05-14 15:27:20 -070069struct audio_block_header
70{
71 int reserved;
72 int length;
73};
74
vivek mehta1a9b7c02015-06-25 11:49:38 -070075enum {
76 CAL_MODE_SEND = 0x1,
77 CAL_MODE_PERSIST = 0x2,
78 CAL_MODE_RTAC = 0x4
79};
80
keunhui.park2f7306a2015-07-16 16:48:06 +090081#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
82
83struct operator_info {
84 struct listnode list;
85 char *name;
86 char *mccmnc;
87};
88
89struct operator_specific_device {
90 struct listnode list;
91 char *operator;
92 char *mixer_path;
93 int acdb_id;
94};
95
96static struct listnode operator_info_list;
97static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
98
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070099/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700100typedef void (*acdb_deallocate_t)();
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900101typedef int (*acdb_init_v2_cvd_t)(char *, char *);
102typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -0700103typedef int (*acdb_init_t)();
104typedef void (*acdb_send_audio_cal_t)(int, int);
105typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700106typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700107typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700108
109/* Audio calibration related functions */
110struct platform_data {
111 struct audio_device *adev;
112 bool fluence_in_spkr_mode;
113 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700114 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700115 bool fluence_in_voice_rec;
Bryce Lee93be0a52015-08-10 23:23:55 +0000116 int dualmic_config;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700117 bool speaker_lr_swap;
118
Eric Laurentb23d5282013-05-14 15:27:20 -0700119 void *acdb_handle;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700120 acdb_deallocate_t acdb_deallocate;
121 acdb_send_audio_cal_t acdb_send_audio_cal;
122 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700123 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700124 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700125 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800126 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700127
128 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900129 int max_vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -0700130};
131
Haynes Mathew George98c95622014-06-20 19:14:25 -0700132static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700133 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
134 DEEP_BUFFER_PCM_DEVICE},
135 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
136 LOWLATENCY_PCM_DEVICE},
137 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
138 MULTIMEDIA2_PCM_DEVICE},
139 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
140 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamandaf78a4d92015-04-24 15:18:23 -0700141 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA3_PCM_DEVICE,
142 MULTIMEDIA3_PCM_DEVICE},
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700143 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
144 AUDIO_RECORD_PCM_DEVICE},
145 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
146 LOWLATENCY_PCM_DEVICE},
147 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
148 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700149 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
150 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
151 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
152 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
153 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
154 AUDIO_RECORD_PCM_DEVICE},
155 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
156 AUDIO_RECORD_PCM_DEVICE},
157 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
158 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800159 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700160
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700161 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
162 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
163
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700164 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
165 AFE_PROXY_RECORD_PCM_DEVICE},
166 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
167 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800168 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700169
Eric Laurentb23d5282013-05-14 15:27:20 -0700170};
171
172/* Array to store sound devices */
173static const char * const device_table[SND_DEVICE_MAX] = {
174 [SND_DEVICE_NONE] = "none",
175 /* Playback sound devices */
176 [SND_DEVICE_OUT_HANDSET] = "handset",
177 [SND_DEVICE_OUT_SPEAKER] = "speaker",
178 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700179 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700180 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500181 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700182 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700183 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500184 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700185 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700186 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500187 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700188 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
189 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500190 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700191 [SND_DEVICE_OUT_HDMI] = "hdmi",
192 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
193 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700194 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700195 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
196 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
197 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
198 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700199 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700200 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
201 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Eric Laurentb23d5282013-05-14 15:27:20 -0700202
203 /* Capture sound devices */
204 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700205 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700206 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
207 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
208 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
209 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
210 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
211 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
212 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
213
214 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
215 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
216 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
217 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
218 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
219 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
220 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
221 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
222 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
223
224 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500225 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700226
Eric Laurentb23d5282013-05-14 15:27:20 -0700227 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
228 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700229 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700230 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700231 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700232 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700233
234 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
235 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
236 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
237 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
238 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700239 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
240 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
241 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700242
Eric Laurentb23d5282013-05-14 15:27:20 -0700243 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700244 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
245 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
246 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700247
248 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700249
250 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Eric Laurentb23d5282013-05-14 15:27:20 -0700251};
252
253/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700254static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700255 [SND_DEVICE_NONE] = -1,
256 [SND_DEVICE_OUT_HANDSET] = 7,
257 [SND_DEVICE_OUT_SPEAKER] = 15,
258 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700259 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700260 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500261 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700262 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700263 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500264 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700265 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700266 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
267 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500268 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700269 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500270 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700271 [SND_DEVICE_OUT_HDMI] = 18,
272 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
273 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700274 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700275 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
277 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
278 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700279 [SND_DEVICE_OUT_VOICE_TX] = 45,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700280 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
281 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Eric Laurentb23d5282013-05-14 15:27:20 -0700282
283 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700284 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
285 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
286 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
287 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
288 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
289 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
290 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
291 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
292
293 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
294 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
295 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
296 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
297 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
298 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
299 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
300 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
301 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
302
Eric Laurentb23d5282013-05-14 15:27:20 -0700303 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500304 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700305
Eric Laurentb23d5282013-05-14 15:27:20 -0700306 [SND_DEVICE_IN_HDMI_MIC] = 4,
307 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700308 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700309 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700310 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700311 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700312
313 [SND_DEVICE_IN_VOICE_DMIC] = 41,
314 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
315 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
316 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
317 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
Eric Laurentb23d5282013-05-14 15:27:20 -0700318 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
319 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
320 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700321
Eric Laurentb23d5282013-05-14 15:27:20 -0700322 [SND_DEVICE_IN_VOICE_REC_MIC] = 62,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700323 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
324 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
325 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700326
327 [SND_DEVICE_IN_VOICE_RX] = 44,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700328
329 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Eric Laurentb23d5282013-05-14 15:27:20 -0700330};
331
Haynes Mathew George98c95622014-06-20 19:14:25 -0700332struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700333 char name[100];
334 unsigned int index;
335};
336
337#define TO_NAME_INDEX(X) #X, X
338
Haynes Mathew George98c95622014-06-20 19:14:25 -0700339/* Used to get index from parsed string */
340static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
341 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700342 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
343 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
344 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700345 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700346 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500347 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700348 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700349 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500350 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700351 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700352 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
353 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
354 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500355 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700356 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
357 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
358 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
359 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700360 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500361 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700362 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
363 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
364 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700365
366 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700367 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
368 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700369 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700370 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700371 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
372 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
373 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
374 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
375 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
376 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
377 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
378
379 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700380 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700381 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
382 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
383 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
384 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
385 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
386 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
387 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
388
389 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700390 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700391
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700392 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
393 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700394 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700395 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700396 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700397 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700398
399 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
400 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
401 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
402 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
403 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700404 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
405 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
406 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700407
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700408 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700409 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
410 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
411 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700412
413 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700414};
415
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700416static char * backend_tag_table[SND_DEVICE_MAX] = {0};
417static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700418
419static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
420 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
421 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
422 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
423 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
424 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
425 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
426 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
427 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
428 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
429 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
430 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
431 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
432 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
433 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
434 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700435};
436
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700437#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
438#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
439
Eric Laurentb23d5282013-05-14 15:27:20 -0700440static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
441static bool is_tmus = false;
442
443static void check_operator()
444{
445 char value[PROPERTY_VALUE_MAX];
446 int mccmnc;
447 property_get("gsm.sim.operator.numeric",value,"0");
448 mccmnc = atoi(value);
449 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
450 switch(mccmnc) {
451 /* TMUS MCC(310), MNC(490, 260, 026) */
452 case 310490:
453 case 310260:
454 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900455 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
456 case 310800:
457 case 310660:
458 case 310580:
459 case 310310:
460 case 310270:
461 case 310250:
462 case 310240:
463 case 310230:
464 case 310220:
465 case 310210:
466 case 310200:
467 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700468 is_tmus = true;
469 break;
470 }
471}
472
473bool is_operator_tmus()
474{
475 pthread_once(&check_op_once_ctl, check_operator);
476 return is_tmus;
477}
478
keunhui.park2f7306a2015-07-16 16:48:06 +0900479static char *get_current_operator()
480{
481 struct listnode *node;
482 struct operator_info *info_item;
483 char mccmnc[PROPERTY_VALUE_MAX];
484 char *ret = NULL;
485
486 property_get("gsm.sim.operator.numeric",mccmnc,"0");
487
488 list_for_each(node, &operator_info_list) {
489 info_item = node_to_item(node, struct operator_info, list);
490 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
491 ret = info_item->name;
492 }
493 }
494
495 return ret;
496}
497
498static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
499{
500 struct listnode *node;
501 struct operator_specific_device *ret = NULL;
502 struct operator_specific_device *device_item;
503 char *operator_name;
504
505 operator_name = get_current_operator();
506 if (operator_name == NULL)
507 return ret;
508
509 list_for_each(node, operator_specific_device_table[snd_device]) {
510 device_item = node_to_item(node, struct operator_specific_device, list);
511 if (strcmp(operator_name, device_item->operator) == 0) {
512 ret = device_item;
513 }
514 }
515
516 return ret;
517}
518
519
520static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
521{
522 struct operator_specific_device *device;
523 int ret = acdb_device_table[snd_device];
524
525 device = get_operator_specific_device(snd_device);
526 if (device != NULL)
527 ret = device->acdb_id;
528
529 return ret;
530}
531
532static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
533{
534 struct operator_specific_device *device;
535 const char *ret = device_table[snd_device];
536
537 device = get_operator_specific_device(snd_device);
538 if (device != NULL)
539 ret = device->mixer_path;
540
541 return ret;
542}
543
vivek mehta1a9b7c02015-06-25 11:49:38 -0700544bool platform_send_gain_dep_cal(void *platform, int level)
545{
546 bool ret_val = false;
547 struct platform_data *my_data = (struct platform_data *)platform;
548 struct audio_device *adev = my_data->adev;
549 int acdb_dev_id, app_type;
550 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
551 int mode = CAL_MODE_RTAC;
552 struct listnode *node;
553 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700554
555 if (my_data->acdb_send_gain_dep_cal == NULL) {
556 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
557 return ret_val;
558 }
559
560 if (!voice_is_in_call(adev)) {
561 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
562 __func__, level);
563 app_type = DEFAULT_APP_TYPE_RX_PATH;
564
565 // find the current active sound device
566 list_for_each(node, &adev->usecase_list) {
567 usecase = node_to_item(node, struct audio_usecase, list);
568
569 if (usecase != NULL &&
570 usecase->type == PCM_PLAYBACK &&
571 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
572
573 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700574 if (audio_extn_spkr_prot_is_enabled()) {
575 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
576 } else {
577 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
578 }
579
vivek mehta1a9b7c02015-06-25 11:49:38 -0700580 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
581 acdb_dev_type, mode, level)) {
582 // set ret_val true if at least one calibration is set successfully
583 ret_val = true;
584 } else {
585 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
586 }
587 } else {
588 ALOGW("%s: Usecase list is empty", __func__);
589 }
590 }
591 } else {
592 ALOGW("%s: Voice call in progress .. ignore setting new cal",
593 __func__);
594 }
595 return ret_val;
596}
597
Eric Laurentcefbbac2014-09-04 13:54:10 -0500598void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700599{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800600 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500601 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700602
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800603 if (strcmp(my_data->ec_ref_mixer_path, "")) {
604 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
605 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500606 }
607
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800608 if (enable) {
609 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
610 if (out_device != AUDIO_DEVICE_NONE) {
611 snd_device = platform_get_output_snd_device(adev->platform, out_device);
612 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
613 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500614
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800615 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
616 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
617 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700618}
619
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700620static struct csd_data *open_csd_client(bool i2s_ext_modem)
621{
622 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
623
624 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
625 if (csd->csd_client == NULL) {
626 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
627 goto error;
628 } else {
629 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
630
631 csd->deinit = (deinit_t)dlsym(csd->csd_client,
632 "csd_client_deinit");
633 if (csd->deinit == NULL) {
634 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
635 dlerror());
636 goto error;
637 }
638 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
639 "csd_client_disable_device");
640 if (csd->disable_device == NULL) {
641 ALOGE("%s: dlsym error %s for csd_client_disable_device",
642 __func__, dlerror());
643 goto error;
644 }
645 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
646 "csd_client_enable_device_config");
647 if (csd->enable_device_config == NULL) {
648 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
649 __func__, dlerror());
650 goto error;
651 }
652 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
653 "csd_client_enable_device");
654 if (csd->enable_device == NULL) {
655 ALOGE("%s: dlsym error %s for csd_client_enable_device",
656 __func__, dlerror());
657 goto error;
658 }
659 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
660 "csd_client_start_voice");
661 if (csd->start_voice == NULL) {
662 ALOGE("%s: dlsym error %s for csd_client_start_voice",
663 __func__, dlerror());
664 goto error;
665 }
666 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
667 "csd_client_stop_voice");
668 if (csd->stop_voice == NULL) {
669 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
670 __func__, dlerror());
671 goto error;
672 }
673 csd->volume = (volume_t)dlsym(csd->csd_client,
674 "csd_client_volume");
675 if (csd->volume == NULL) {
676 ALOGE("%s: dlsym error %s for csd_client_volume",
677 __func__, dlerror());
678 goto error;
679 }
680 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
681 "csd_client_mic_mute");
682 if (csd->mic_mute == NULL) {
683 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
684 __func__, dlerror());
685 goto error;
686 }
687 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
688 "csd_client_slow_talk");
689 if (csd->slow_talk == NULL) {
690 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
691 __func__, dlerror());
692 goto error;
693 }
694 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
695 "csd_client_start_playback");
696 if (csd->start_playback == NULL) {
697 ALOGE("%s: dlsym error %s for csd_client_start_playback",
698 __func__, dlerror());
699 goto error;
700 }
701 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
702 "csd_client_stop_playback");
703 if (csd->stop_playback == NULL) {
704 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
705 __func__, dlerror());
706 goto error;
707 }
708 csd->start_record = (start_record_t)dlsym(csd->csd_client,
709 "csd_client_start_record");
710 if (csd->start_record == NULL) {
711 ALOGE("%s: dlsym error %s for csd_client_start_record",
712 __func__, dlerror());
713 goto error;
714 }
715 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
716 "csd_client_stop_record");
717 if (csd->stop_record == NULL) {
718 ALOGE("%s: dlsym error %s for csd_client_stop_record",
719 __func__, dlerror());
720 goto error;
721 }
722
723 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
724 "csd_client_get_sample_rate");
725 if (csd->get_sample_rate == NULL) {
726 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
727 __func__, dlerror());
728
729 goto error;
730 }
731
732 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
733
734 if (csd->init == NULL) {
735 ALOGE("%s: dlsym error %s for csd_client_init",
736 __func__, dlerror());
737 goto error;
738 } else {
739 csd->init(i2s_ext_modem);
740 }
741 }
742 return csd;
743
744error:
745 free(csd);
746 csd = NULL;
747 return csd;
748}
749
750void close_csd_client(struct csd_data *csd)
751{
752 if (csd != NULL) {
753 csd->deinit();
754 dlclose(csd->csd_client);
755 free(csd);
756 csd = NULL;
757 }
758}
759
760static void platform_csd_init(struct platform_data *my_data)
761{
762#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700763 int32_t modems, (*count_modems)(void);
764 const char *name = "libdetectmodem.so";
765 const char *func = "count_modems";
766 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700767
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700768 my_data->csd = NULL;
769
770 void *lib = dlopen(name, RTLD_NOW);
771 error = dlerror();
772 if (!lib) {
773 ALOGE("%s: could not find %s: %s", __func__, name, error);
774 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700775 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700776
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700777 count_modems = NULL;
778 *(void **)(&count_modems) = dlsym(lib, func);
779 error = dlerror();
780 if (!count_modems) {
781 ALOGE("%s: could not find symbol %s in %s: %s",
782 __func__, func, name, error);
783 goto done;
784 }
785
786 modems = count_modems();
787 if (modems < 0) {
788 ALOGE("%s: count_modems failed\n", __func__);
789 goto done;
790 }
791
792 ALOGD("%s: num_modems %d\n", __func__, modems);
793 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700794 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700795
796done:
797 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700798#else
799 my_data->csd = NULL;
800#endif
801}
802
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700803static void set_platform_defaults(struct platform_data * my_data __unused)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700804{
805 int32_t dev;
806 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700807 backend_tag_table[dev] = NULL;
808 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900809 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700810 }
811
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700812 // To overwrite these go to the audio_platform_info.xml file.
813 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700814 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700815 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
816 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
817 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
818 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
819 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700820 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700821 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
822 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700823
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700824 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
825 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
826 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
827 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
828 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
829 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
830 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700831 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700832 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700833 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700834 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
835 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
836 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
837 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
838 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
839 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
840 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
841 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
842 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
843 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
844 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
845 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
846 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
847 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
848 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
849 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700850}
851
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900852void get_cvd_version(char *cvd_version, struct audio_device *adev)
853{
854 struct mixer_ctl *ctl;
855 int count;
856 int ret = 0;
857
858 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
859 if (!ctl) {
860 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
861 goto done;
862 }
863 mixer_ctl_update(ctl);
864
865 count = mixer_ctl_get_num_values(ctl);
866 if (count > MAX_CVD_VERSION_STRING_SIZE)
867 count = MAX_CVD_VERSION_STRING_SIZE - 1;
868
869 ret = mixer_ctl_get_array(ctl, cvd_version, count);
870 if (ret != 0) {
871 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
872 goto done;
873 }
874
875done:
876 return;
877}
878
Eric Laurentb23d5282013-05-14 15:27:20 -0700879void *platform_init(struct audio_device *adev)
880{
881 char value[PROPERTY_VALUE_MAX];
882 struct platform_data *my_data;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700883 int retry_num = 0, snd_card_num = 0;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700884 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900885 char *cvd_version = NULL;
sangwoo1b9f4b32013-06-21 18:22:55 -0700886
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700887 my_data = calloc(1, sizeof(struct platform_data));
888
889 my_data->adev = adev;
890
keunhui.park2f7306a2015-07-16 16:48:06 +0900891 list_init(&operator_info_list);
892
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700893 set_platform_defaults(my_data);
894
895 /* Initialize platform specific ids and/or backends*/
896 platform_info_init(my_data);
897
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700898 while (snd_card_num < MAX_SND_CARD) {
899 adev->mixer = mixer_open(snd_card_num);
sangwoo1b9f4b32013-06-21 18:22:55 -0700900
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700901 while (!adev->mixer && retry_num < RETRY_NUMBER) {
902 usleep(RETRY_US);
903 adev->mixer = mixer_open(snd_card_num);
904 retry_num++;
905 }
906
907 if (!adev->mixer) {
908 ALOGE("%s: Unable to open the mixer card: %d", __func__,
909 snd_card_num);
910 retry_num = 0;
911 snd_card_num++;
912 continue;
913 }
914
915 snd_card_name = mixer_get_name(adev->mixer);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700916
917 /* validate the sound card name */
918 if (my_data->snd_card_name != NULL &&
919 strncmp(snd_card_name, my_data->snd_card_name, MAX_SND_CARD_NAME_LEN) != 0) {
920 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
921 __func__, snd_card_name, my_data->snd_card_name);
922 retry_num = 0;
923 snd_card_num++;
924 continue;
925 }
926
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700927 ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
928
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -0700929 if (!strncmp(snd_card_name, "msm8226-tomtom-snd-card",
930 sizeof("msm8226-tomtom-snd-card"))) {
931 ALOGD("%s: Call MIXER_XML_PATH_WCD9330", __func__);
932 adev->audio_route = audio_route_init(snd_card_num,
933 MIXER_XML_PATH_WCD9330);
934 } else {
935 adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH);
936 }
937
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700938 if (!adev->audio_route) {
939 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700940 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700941 }
942 adev->snd_card = snd_card_num;
943 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
944 break;
sangwoo1b9f4b32013-06-21 18:22:55 -0700945 }
946
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700947 if (snd_card_num >= MAX_SND_CARD) {
948 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700949 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -0700950 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700951
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900952 //set max volume step for voice call
953 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
954 my_data->max_vol_index = atoi(value);
955
Bryce Lee93be0a52015-08-10 23:23:55 +0000956 my_data->dualmic_config = DUALMIC_CONFIG_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700957 my_data->fluence_in_spkr_mode = false;
958 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700959 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -0700960 my_data->fluence_in_voice_rec = false;
961
Bryce Lee93be0a52015-08-10 23:23:55 +0000962 property_get("persist.audio.dualmic.config",value,"");
963 if (!strcmp("broadside", value)) {
964 ALOGE("%s: Unsupported dualmic configuration", __func__);
965 } else if (!strcmp("endfire", value)) {
966 my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700967 }
968
Bryce Lee93be0a52015-08-10 23:23:55 +0000969 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -0700970 property_get("persist.audio.fluence.voicecall",value,"");
971 if (!strcmp("true", value)) {
972 my_data->fluence_in_voice_call = true;
973 }
974
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700975 property_get("persist.audio.fluence.voicecomm",value,"");
976 if (!strcmp("true", value)) {
977 my_data->fluence_in_voice_comm = true;
978 }
979
Eric Laurentb23d5282013-05-14 15:27:20 -0700980 property_get("persist.audio.fluence.voicerec",value,"");
981 if (!strcmp("true", value)) {
982 my_data->fluence_in_voice_rec = true;
983 }
984
985 property_get("persist.audio.fluence.speaker",value,"");
986 if (!strcmp("true", value)) {
987 my_data->fluence_in_spkr_mode = true;
988 }
989 }
990
991 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
992 if (my_data->acdb_handle == NULL) {
993 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
994 } else {
995 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
996 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
997 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700998 if (!my_data->acdb_deallocate)
999 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1000 __func__, LIB_ACDB_LOADER);
1001
Eric Laurentb23d5282013-05-14 15:27:20 -07001002 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1003 "acdb_loader_send_audio_cal");
1004 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001005 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001006 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001007
Eric Laurentb23d5282013-05-14 15:27:20 -07001008 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1009 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001010 if (!my_data->acdb_send_voice_cal)
1011 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1012 __func__, LIB_ACDB_LOADER);
1013
1014 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1015 "acdb_loader_reload_vocvoltable");
1016 if (!my_data->acdb_reload_vocvoltable)
1017 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1018 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001019
1020 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1021 "acdb_loader_send_gain_dep_cal");
1022 if (!my_data->acdb_send_gain_dep_cal)
1023 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1024 __func__, LIB_ACDB_LOADER);
1025
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001026#if defined (PLATFORM_MSM8994)
1027 acdb_init_v2_cvd_t acdb_init;
1028 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1029 "acdb_loader_init_v2");
1030 if (acdb_init == NULL) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001031 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001032 goto acdb_init_fail;
1033 }
1034
1035 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1036 get_cvd_version(cvd_version, adev);
1037 if (!cvd_version)
1038 ALOGE("failed to allocate cvd_version");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001039 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001040 acdb_init((char *)snd_card_name, cvd_version);
1041 free(cvd_version);
1042#elif defined (PLATFORM_MSM8084)
1043 acdb_init_v2_t acdb_init;
1044 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1045 "acdb_loader_init_v2");
1046 if (acdb_init == NULL) {
1047 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
1048 goto acdb_init_fail;
1049 }
1050 acdb_init((char *)snd_card_name);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001051#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001052 acdb_init_t acdb_init;
1053 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001054 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001055 if (acdb_init == NULL)
Eric Laurentb23d5282013-05-14 15:27:20 -07001056 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
1057 else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001058 acdb_init();
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001059#endif
Eric Laurentb23d5282013-05-14 15:27:20 -07001060 }
1061
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001062acdb_init_fail:
1063
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001064 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001065
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001066 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1067
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001068 /* load csd client */
1069 platform_csd_init(my_data);
1070
Eric Laurentb23d5282013-05-14 15:27:20 -07001071 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001072
1073init_failed:
1074 if (my_data)
1075 free(my_data);
1076 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001077}
1078
1079void platform_deinit(void *platform)
1080{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001081 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001082 struct operator_info *info_item;
1083 struct operator_specific_device *device_item;
1084 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001085
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001086 struct platform_data *my_data = (struct platform_data *)platform;
1087 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001088
1089 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1090 if (backend_tag_table[dev])
1091 free(backend_tag_table[dev]);
1092 if (hw_interface_table[dev])
1093 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001094 if (operator_specific_device_table[dev]) {
1095 while (!list_empty(operator_specific_device_table[dev])) {
1096 node = list_head(operator_specific_device_table[dev]);
1097 list_remove(node);
1098 device_item = node_to_item(node, struct operator_specific_device, list);
1099 free(device_item->operator);
1100 free(device_item->mixer_path);
1101 free(device_item);
1102 }
1103 free(operator_specific_device_table[dev]);
1104 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001105 }
1106
1107 if (my_data->snd_card_name)
1108 free(my_data->snd_card_name);
1109
keunhui.park2f7306a2015-07-16 16:48:06 +09001110 while (!list_empty(&operator_info_list)) {
1111 node = list_head(&operator_info_list);
1112 list_remove(node);
1113 info_item = node_to_item(node, struct operator_info, list);
1114 free(info_item->name);
1115 free(info_item->mccmnc);
1116 free(info_item);
1117 }
1118
Eric Laurentb23d5282013-05-14 15:27:20 -07001119 free(platform);
1120}
1121
1122const char *platform_get_snd_device_name(snd_device_t snd_device)
1123{
keunhui.park2f7306a2015-07-16 16:48:06 +09001124 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1125 if (operator_specific_device_table[snd_device] != NULL) {
1126 return get_operator_specific_device_mixer_path(snd_device);
1127 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001128 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001129 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001130 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001131}
1132
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001133void platform_add_backend_name(void *platform, char *mixer_path,
1134 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001135{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001136 struct platform_data *my_data = (struct platform_data *)platform;
1137
Haynes Mathew George98c95622014-06-20 19:14:25 -07001138 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1139 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1140 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001141 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001142
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001143 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001144
1145 if (suffix != NULL) {
1146 strcat(mixer_path, " ");
1147 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001148 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001149}
1150
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001151bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1152{
1153 bool result = true;
1154
1155 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1156 platform_get_snd_device_name(snd_device1),
1157 platform_get_snd_device_name(snd_device2));
1158
1159 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1160 ALOGE("%s: Invalid snd_device = %s", __func__,
1161 platform_get_snd_device_name(snd_device1));
1162 return false;
1163 }
1164 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1165 ALOGE("%s: Invalid snd_device = %s", __func__,
1166 platform_get_snd_device_name(snd_device2));
1167 return false;
1168 }
1169 const char * be_itf1 = hw_interface_table[snd_device1];
1170 const char * be_itf2 = hw_interface_table[snd_device2];
1171
1172 if (NULL != be_itf1 && NULL != be_itf2) {
1173 if (0 != strcmp(be_itf1, be_itf2))
1174 result = false;
1175 }
1176
1177 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1178 return result;
1179}
1180
Eric Laurentb23d5282013-05-14 15:27:20 -07001181int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1182{
1183 int device_id;
1184 if (device_type == PCM_PLAYBACK)
1185 device_id = pcm_device_table[usecase][0];
1186 else
1187 device_id = pcm_device_table[usecase][1];
1188 return device_id;
1189}
1190
Haynes Mathew George98c95622014-06-20 19:14:25 -07001191static int find_index(const struct name_to_index * table, int32_t len,
1192 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001193{
1194 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001195 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001196
Haynes Mathew George98c95622014-06-20 19:14:25 -07001197 if (table == NULL) {
1198 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001199 ret = -ENODEV;
1200 goto done;
1201 }
1202
Haynes Mathew George98c95622014-06-20 19:14:25 -07001203 if (name == NULL) {
1204 ALOGE("null key");
1205 ret = -ENODEV;
1206 goto done;
1207 }
1208
1209 for (i=0; i < len; i++) {
1210 if (!strcmp(table[i].name, name)) {
1211 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001212 goto done;
1213 }
1214 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001215 ALOGE("%s: Could not find index for name = %s",
1216 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001217 ret = -ENODEV;
1218done:
1219 return ret;
1220}
1221
Haynes Mathew George98c95622014-06-20 19:14:25 -07001222int platform_get_snd_device_index(char *device_name)
1223{
1224 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1225}
1226
1227int platform_get_usecase_index(const char *usecase_name)
1228{
1229 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1230}
1231
keunhui.park2f7306a2015-07-16 16:48:06 +09001232void platform_add_operator_specific_device(snd_device_t snd_device,
1233 const char *operator,
1234 const char *mixer_path,
1235 unsigned int acdb_id)
1236{
1237 struct operator_specific_device *device;
1238
1239 if (operator_specific_device_table[snd_device] == NULL) {
1240 operator_specific_device_table[snd_device] =
1241 (struct listnode *)calloc(1, sizeof(struct listnode));
1242 list_init(operator_specific_device_table[snd_device]);
1243 }
1244
1245 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1246
1247 device->operator = strdup(operator);
1248 device->mixer_path = strdup(mixer_path);
1249 device->acdb_id = acdb_id;
1250
1251 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1252
1253 ALOGD("%s : deivce[%s] -> operator[%s] mixer_path[%s] acdb_id [%d]", __func__,
1254 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1255
1256}
1257
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001258int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1259{
1260 int ret = 0;
1261
1262 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1263 ALOGE("%s: Invalid snd_device = %d",
1264 __func__, snd_device);
1265 ret = -EINVAL;
1266 goto done;
1267 }
1268
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001269 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1270 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001271 acdb_device_table[snd_device] = acdb_id;
1272done:
1273 return ret;
1274}
1275
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001276int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1277{
1278 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1279 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1280 return -EINVAL;
1281 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001282
1283 if (operator_specific_device_table[snd_device] != NULL)
1284 return get_operator_specific_device_acdb_id(snd_device);
1285 else
1286 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001287}
1288
Eric Laurentb23d5282013-05-14 15:27:20 -07001289int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1290{
1291 struct platform_data *my_data = (struct platform_data *)platform;
1292 int acdb_dev_id, acdb_dev_type;
1293
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001294 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001295 if (acdb_dev_id < 0) {
1296 ALOGE("%s: Could not find acdb id for device(%d)",
1297 __func__, snd_device);
1298 return -EINVAL;
1299 }
1300 if (my_data->acdb_send_audio_cal) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001301 ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001302 __func__, snd_device, acdb_dev_id);
1303 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1304 snd_device < SND_DEVICE_OUT_END)
1305 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1306 else
1307 acdb_dev_type = ACDB_DEV_TYPE_IN;
1308 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1309 }
1310 return 0;
1311}
1312
1313int platform_switch_voice_call_device_pre(void *platform)
1314{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001315 struct platform_data *my_data = (struct platform_data *)platform;
1316 int ret = 0;
1317
1318 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001319 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001320 /* This must be called before disabling mixer controls on APQ side */
1321 ret = my_data->csd->disable_device();
1322 if (ret < 0) {
1323 ALOGE("%s: csd_client_disable_device, failed, error %d",
1324 __func__, ret);
1325 }
1326 }
1327 return ret;
1328}
1329
1330int platform_switch_voice_call_enable_device_config(void *platform,
1331 snd_device_t out_snd_device,
1332 snd_device_t in_snd_device)
1333{
1334 struct platform_data *my_data = (struct platform_data *)platform;
1335 int acdb_rx_id, acdb_tx_id;
1336 int ret = 0;
1337
1338 if (my_data->csd == NULL)
1339 return ret;
1340
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001341 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1342 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001343 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001344 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001345 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001346
keunhui.park2f7306a2015-07-16 16:48:06 +09001347 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001348
1349 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1350 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1351 if (ret < 0) {
1352 ALOGE("%s: csd_enable_device_config, failed, error %d",
1353 __func__, ret);
1354 }
1355 } else {
1356 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1357 acdb_rx_id, acdb_tx_id);
1358 }
1359
1360 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001361}
1362
1363int platform_switch_voice_call_device_post(void *platform,
1364 snd_device_t out_snd_device,
1365 snd_device_t in_snd_device)
1366{
1367 struct platform_data *my_data = (struct platform_data *)platform;
1368 int acdb_rx_id, acdb_tx_id;
1369
1370 if (my_data->acdb_send_voice_cal == NULL) {
1371 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1372 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001373 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1374 audio_extn_spkr_prot_is_enabled())
1375 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1376
keunhui.park2f7306a2015-07-16 16:48:06 +09001377 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1378 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001379
1380 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1381 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1382 else
1383 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1384 acdb_rx_id, acdb_tx_id);
1385 }
1386
1387 return 0;
1388}
1389
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001390int platform_switch_voice_call_usecase_route_post(void *platform,
1391 snd_device_t out_snd_device,
1392 snd_device_t in_snd_device)
1393{
1394 struct platform_data *my_data = (struct platform_data *)platform;
1395 int acdb_rx_id, acdb_tx_id;
1396 int ret = 0;
1397
1398 if (my_data->csd == NULL)
1399 return ret;
1400
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001401 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1402 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001403 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001404 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001405 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001406
keunhui.park2f7306a2015-07-16 16:48:06 +09001407 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001408
1409 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1410 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1411 my_data->adev->acdb_settings);
1412 if (ret < 0) {
1413 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1414 }
1415 } else {
1416 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1417 acdb_rx_id, acdb_tx_id);
1418 }
1419
1420 return ret;
1421}
1422
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001423int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001424{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001425 struct platform_data *my_data = (struct platform_data *)platform;
1426 int ret = 0;
1427
1428 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001429 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001430 if (ret < 0) {
1431 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1432 }
1433 }
1434 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001435}
1436
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001437int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001438{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001439 struct platform_data *my_data = (struct platform_data *)platform;
1440 int ret = 0;
1441
1442 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001443 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001444 if (ret < 0) {
1445 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1446 }
1447 }
1448 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001449}
1450
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001451int platform_get_sample_rate(void *platform, uint32_t *rate)
1452{
1453 struct platform_data *my_data = (struct platform_data *)platform;
1454 int ret = 0;
1455
1456 if (my_data->csd != NULL) {
1457 ret = my_data->csd->get_sample_rate(rate);
1458 if (ret < 0) {
1459 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1460 }
1461 }
1462 return ret;
1463}
1464
Eric Laurentb23d5282013-05-14 15:27:20 -07001465int platform_set_voice_volume(void *platform, int volume)
1466{
1467 struct platform_data *my_data = (struct platform_data *)platform;
1468 struct audio_device *adev = my_data->adev;
1469 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001470 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001471 int vol_index = 0, ret = 0;
1472 uint32_t set_values[ ] = {0,
1473 ALL_SESSION_VSID,
1474 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001475
1476 // Voice volume levels are mapped to adsp volume levels as follows.
1477 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1478 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001479 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001480 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001481
1482 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1483 if (!ctl) {
1484 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1485 __func__, mixer_ctl_name);
1486 return -EINVAL;
1487 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001488 ALOGV("Setting voice volume index: %d", set_values[0]);
1489 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1490
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001491 if (my_data->csd != NULL) {
1492 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1493 DEFAULT_VOLUME_RAMP_DURATION_MS);
1494 if (ret < 0) {
1495 ALOGE("%s: csd_volume error %d", __func__, ret);
1496 }
1497 }
1498 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001499}
1500
1501int platform_set_mic_mute(void *platform, bool state)
1502{
1503 struct platform_data *my_data = (struct platform_data *)platform;
1504 struct audio_device *adev = my_data->adev;
1505 struct mixer_ctl *ctl;
1506 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001507 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001508 uint32_t set_values[ ] = {0,
1509 ALL_SESSION_VSID,
1510 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001511
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001512 if (adev->mode != AUDIO_MODE_IN_CALL)
1513 return 0;
1514
1515 set_values[0] = state;
1516 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1517 if (!ctl) {
1518 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1519 __func__, mixer_ctl_name);
1520 return -EINVAL;
1521 }
1522 ALOGV("Setting voice mute state: %d", state);
1523 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1524
1525 if (my_data->csd != NULL) {
1526 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1527 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001528 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001529 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001530 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001531 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001532 return ret;
1533}
Eric Laurentb23d5282013-05-14 15:27:20 -07001534
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001535int platform_set_device_mute(void *platform, bool state, char *dir)
1536{
1537 struct platform_data *my_data = (struct platform_data *)platform;
1538 struct audio_device *adev = my_data->adev;
1539 struct mixer_ctl *ctl;
1540 char *mixer_ctl_name = NULL;
1541 int ret = 0;
1542 uint32_t set_values[ ] = {0,
1543 ALL_SESSION_VSID,
1544 0};
1545 if(dir == NULL) {
1546 ALOGE("%s: Invalid direction:%s", __func__, dir);
1547 return -EINVAL;
1548 }
1549
1550 if (!strncmp("rx", dir, sizeof("rx"))) {
1551 mixer_ctl_name = "Voice Rx Device Mute";
1552 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1553 mixer_ctl_name = "Voice Tx Device Mute";
1554 } else {
1555 return -EINVAL;
1556 }
1557
1558 set_values[0] = state;
1559 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1560 if (!ctl) {
1561 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1562 __func__, mixer_ctl_name);
1563 return -EINVAL;
1564 }
1565
1566 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1567 __func__,state, mixer_ctl_name);
1568 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1569
1570 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001571}
1572
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001573bool platform_can_split_snd_device(snd_device_t snd_device,
1574 int *num_devices,
1575 snd_device_t *new_snd_devices)
1576{
1577 bool status = false;
1578
1579 if (NULL == num_devices || NULL == new_snd_devices) {
1580 ALOGE("%s: NULL pointer ..", __func__);
1581 return false;
1582 }
1583
1584 /*
1585 * If wired headset/headphones/line devices share the same backend
1586 * with speaker/earpiece this routine returns false.
1587 */
1588 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
1589 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
1590 *num_devices = 2;
1591 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1592 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1593 status = true;
1594 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
1595 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
1596 *num_devices = 2;
1597 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
1598 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1599 status = true;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001600 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
1601 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
1602 *num_devices = 2;
1603 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1604 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
1605 status = true;
1606 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
1607 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
1608 *num_devices = 2;
1609 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
1610 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
1611 status = true;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001612 }
1613 return status;
1614}
1615
Eric Laurentb23d5282013-05-14 15:27:20 -07001616snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
1617{
1618 struct platform_data *my_data = (struct platform_data *)platform;
1619 struct audio_device *adev = my_data->adev;
1620 audio_mode_t mode = adev->mode;
1621 snd_device_t snd_device = SND_DEVICE_NONE;
1622
1623 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
1624 if (devices == AUDIO_DEVICE_NONE ||
1625 devices & AUDIO_DEVICE_BIT_IN) {
1626 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
1627 goto exit;
1628 }
1629
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001630 if (voice_is_in_call(adev) || adev->enable_voicerx) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001631 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001632 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1633 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001634 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001635 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07001636 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001637 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001638 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001639 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001640 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05001641 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07001642 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001643 else {
1644 if (devices & AUDIO_DEVICE_OUT_LINE)
1645 snd_device = SND_DEVICE_OUT_VOICE_LINE;
1646 else
1647 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
1648 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001649 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001650 if (adev->bt_wb_speech_enabled) {
1651 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1652 } else {
1653 snd_device = SND_DEVICE_OUT_BT_SCO;
1654 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001655 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001656 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
1657 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001658 if(adev->voice.hac)
1659 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1660 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07001661 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
1662 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05001663 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001664 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
1665 snd_device = SND_DEVICE_OUT_VOICE_TX;
1666
Eric Laurentb23d5282013-05-14 15:27:20 -07001667 if (snd_device != SND_DEVICE_NONE) {
1668 goto exit;
1669 }
1670 }
1671
1672 if (popcount(devices) == 2) {
1673 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001674 AUDIO_DEVICE_OUT_SPEAKER) ||
1675 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1676 AUDIO_DEVICE_OUT_SPEAKER)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001677 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Eric Laurent744996b2014-10-01 11:40:40 -05001678 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1679 AUDIO_DEVICE_OUT_SPEAKER)) {
1680 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001681 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
1682 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
1683 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
1684 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1685 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
1686 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
1687 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
1688 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001689 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
1690 AUDIO_DEVICE_OUT_SPEAKER)) {
1691 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
1692 } else {
1693 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
1694 goto exit;
1695 }
1696 if (snd_device != SND_DEVICE_NONE) {
1697 goto exit;
1698 }
1699 }
1700
1701 if (popcount(devices) != 1) {
1702 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
1703 goto exit;
1704 }
1705
1706 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1707 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1708 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001709 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
1710 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001711 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
1712 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001713 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07001714 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07001715 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
1716 else
1717 snd_device = SND_DEVICE_OUT_SPEAKER;
1718 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001719 if (adev->bt_wb_speech_enabled) {
1720 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
1721 } else {
1722 snd_device = SND_DEVICE_OUT_BT_SCO;
1723 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001724 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1725 snd_device = SND_DEVICE_OUT_HDMI ;
1726 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05001727 /*HAC support for voice-ish audio (eg visual voicemail)*/
1728 if(adev->voice.hac)
1729 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
1730 else
1731 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07001732 } else {
1733 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
1734 }
1735exit:
1736 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
1737 return snd_device;
1738}
1739
1740snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
1741{
1742 struct platform_data *my_data = (struct platform_data *)platform;
1743 struct audio_device *adev = my_data->adev;
1744 audio_source_t source = (adev->active_input == NULL) ?
1745 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
1746
1747 audio_mode_t mode = adev->mode;
1748 audio_devices_t in_device = ((adev->active_input == NULL) ?
1749 AUDIO_DEVICE_NONE : adev->active_input->device)
1750 & ~AUDIO_DEVICE_BIT_IN;
1751 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1752 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
1753 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001754 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07001755
Bryce Lee93be0a52015-08-10 23:23:55 +00001756 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
1757 __func__, out_device, in_device);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001758 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001759 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001760 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001761 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
1762 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001763 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001764 case TTY_MODE_FULL:
1765 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
1766 break;
1767 case TTY_MODE_VCO:
1768 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
1769 break;
1770 case TTY_MODE_HCO:
1771 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
1772 break;
1773 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001774 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07001775 }
1776 goto exit;
1777 }
1778 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001779 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001780 if (my_data->fluence_in_voice_call == false) {
1781 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1782 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001783 if (is_operator_tmus())
1784 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001785 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001786 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001787 }
1788 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1789 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
1790 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001791 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001792 if (adev->bluetooth_nrec)
1793 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1794 else
1795 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001796 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001797 if (adev->bluetooth_nrec)
1798 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1799 else
1800 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001801 }
Eric Laurentb991fb02014-08-29 15:23:17 -05001802 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Bryce Lee93be0a52015-08-10 23:23:55 +00001803 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
1804 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1805 out_device & AUDIO_DEVICE_OUT_LINE) {
1806 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
1807 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1808 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
1809 } else {
1810 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001811 }
Bryce Lee93be0a52015-08-10 23:23:55 +00001812 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07001813 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurentb23d5282013-05-14 15:27:20 -07001814 } else if (source == AUDIO_SOURCE_CAMCORDER) {
1815 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
1816 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1817 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
1818 }
1819 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
1820 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Bryce Lee93be0a52015-08-10 23:23:55 +00001821 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
1822 if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
1823 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
1824 else if (my_data->fluence_in_voice_rec &&
1825 adev->active_input->enable_ns)
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001826 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001827 }
Bryce Lee93be0a52015-08-10 23:23:55 +00001828
Eric Laurentb23d5282013-05-14 15:27:20 -07001829 if (snd_device == SND_DEVICE_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001830 if (adev->active_input->enable_ns)
1831 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
1832 else
1833 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001834 }
1835 }
1836 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001837 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07001838 in_device = AUDIO_DEVICE_IN_BACK_MIC;
1839 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001840 if (adev->active_input->enable_aec &&
1841 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001842 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001843 if (my_data->fluence_in_spkr_mode &&
1844 my_data->fluence_in_voice_comm &&
Bryce Lee93be0a52015-08-10 23:23:55 +00001845 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001846 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Bryce Lee93be0a52015-08-10 23:23:55 +00001847 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001848 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07001849 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001850 if (my_data->fluence_in_voice_comm &&
Bryce Lee93be0a52015-08-10 23:23:55 +00001851 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001852 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Bryce Lee93be0a52015-08-10 23:23:55 +00001853 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001854 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001855 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1856 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001857 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001858 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001859 } else if (adev->active_input->enable_aec) {
1860 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1861 if (my_data->fluence_in_spkr_mode &&
1862 my_data->fluence_in_voice_comm &&
Bryce Lee93be0a52015-08-10 23:23:55 +00001863 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001864 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Bryce Lee93be0a52015-08-10 23:23:55 +00001865 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001866 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
1867 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1868 if (my_data->fluence_in_voice_comm &&
Bryce Lee93be0a52015-08-10 23:23:55 +00001869 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001870 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Bryce Lee93be0a52015-08-10 23:23:55 +00001871 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001872 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05001873 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1874 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
1875 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08001876 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001877 } else if (adev->active_input->enable_ns) {
1878 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
1879 if (my_data->fluence_in_spkr_mode &&
1880 my_data->fluence_in_voice_comm &&
Bryce Lee93be0a52015-08-10 23:23:55 +00001881 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001882 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Bryce Lee93be0a52015-08-10 23:23:55 +00001883 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001884 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
1885 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
1886 if (my_data->fluence_in_voice_comm &&
Bryce Lee93be0a52015-08-10 23:23:55 +00001887 my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001888 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Bryce Lee93be0a52015-08-10 23:23:55 +00001889 } else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001890 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
1891 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05001892 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001893 }
1894 } else if (source == AUDIO_SOURCE_DEFAULT) {
1895 goto exit;
1896 }
1897
1898
1899 if (snd_device != SND_DEVICE_NONE) {
1900 goto exit;
1901 }
1902
1903 if (in_device != AUDIO_DEVICE_NONE &&
1904 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
1905 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
1906 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Bryce Lee93be0a52015-08-10 23:23:55 +00001907 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE &&
1908 channel_count == 2)
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001909 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Bryce Lee93be0a52015-08-10 23:23:55 +00001910 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001911 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001912 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Bryce Lee93be0a52015-08-10 23:23:55 +00001913 if (my_data->dualmic_config != DUALMIC_CONFIG_NONE &&
1914 channel_count == 2)
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001915 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Bryce Lee93be0a52015-08-10 23:23:55 +00001916 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001917 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001918 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
1919 snd_device = SND_DEVICE_IN_HEADSET_MIC;
1920 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001921 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001922 if (adev->bluetooth_nrec)
1923 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1924 else
1925 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001926 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001927 if (adev->bluetooth_nrec)
1928 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1929 else
1930 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001931 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001932 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
1933 snd_device = SND_DEVICE_IN_HDMI_MIC;
1934 } else {
1935 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
1936 ALOGW("%s: Using default handset-mic", __func__);
1937 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1938 }
1939 } else {
1940 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
1941 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1942 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
1943 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001944 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07001945 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001946 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05001947 out_device & AUDIO_DEVICE_OUT_LINE) {
Bryce Lee93be0a52015-08-10 23:23:55 +00001948 if (channel_count == 2)
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001949 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Bryce Lee93be0a52015-08-10 23:23:55 +00001950 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001951 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07001952 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001953 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001954 if (adev->bluetooth_nrec)
1955 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
1956 else
1957 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001958 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001959 if (adev->bluetooth_nrec)
1960 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
1961 else
1962 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07001963 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001964 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
1965 snd_device = SND_DEVICE_IN_HDMI_MIC;
1966 } else {
1967 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
1968 ALOGW("%s: Using default handset-mic", __func__);
1969 snd_device = SND_DEVICE_IN_HANDSET_MIC;
1970 }
1971 }
1972exit:
1973 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
1974 return snd_device;
1975}
1976
1977int platform_set_hdmi_channels(void *platform, int channel_count)
1978{
1979 struct platform_data *my_data = (struct platform_data *)platform;
1980 struct audio_device *adev = my_data->adev;
1981 struct mixer_ctl *ctl;
1982 const char *channel_cnt_str = NULL;
1983 const char *mixer_ctl_name = "HDMI_RX Channels";
1984 switch (channel_count) {
1985 case 8:
1986 channel_cnt_str = "Eight"; break;
1987 case 7:
1988 channel_cnt_str = "Seven"; break;
1989 case 6:
1990 channel_cnt_str = "Six"; break;
1991 case 5:
1992 channel_cnt_str = "Five"; break;
1993 case 4:
1994 channel_cnt_str = "Four"; break;
1995 case 3:
1996 channel_cnt_str = "Three"; break;
1997 default:
1998 channel_cnt_str = "Two"; break;
1999 }
2000 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2001 if (!ctl) {
2002 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2003 __func__, mixer_ctl_name);
2004 return -EINVAL;
2005 }
2006 ALOGV("HDMI channel count: %s", channel_cnt_str);
2007 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2008 return 0;
2009}
2010
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002011int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002012{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002013 struct platform_data *my_data = (struct platform_data *)platform;
2014 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002015 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2016 char *sad = block;
2017 int num_audio_blocks;
2018 int channel_count;
2019 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002020 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002021
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002022 struct mixer_ctl *ctl;
2023
2024 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2025 if (!ctl) {
2026 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2027 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002028 return 0;
2029 }
2030
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002031 mixer_ctl_update(ctl);
2032
2033 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002034
2035 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002036 if (count > (int)sizeof(block))
2037 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002038
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002039 ret = mixer_ctl_get_array(ctl, block, count);
2040 if (ret != 0) {
2041 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2042 return 0;
2043 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002044
2045 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002046 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002047
2048 for (i = 0; i < num_audio_blocks; i++) {
2049 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002050 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2051 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002052 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002053 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002054
2055 channel_count = (sad[0] & 0x7) + 1;
2056 if (channel_count > max_channels)
2057 max_channels = channel_count;
2058
2059 /* Advance to next block */
2060 sad += 3;
2061 }
2062
2063 return max_channels;
2064}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002065
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002066int platform_set_incall_recording_session_id(void *platform,
2067 uint32_t session_id, int rec_mode)
2068{
2069 int ret = 0;
2070 struct platform_data *my_data = (struct platform_data *)platform;
2071 struct audio_device *adev = my_data->adev;
2072 struct mixer_ctl *ctl;
2073 const char *mixer_ctl_name = "Voc VSID";
2074 int num_ctl_values;
2075 int i;
2076
2077 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2078 if (!ctl) {
2079 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2080 __func__, mixer_ctl_name);
2081 ret = -EINVAL;
2082 } else {
2083 num_ctl_values = mixer_ctl_get_num_values(ctl);
2084 for (i = 0; i < num_ctl_values; i++) {
2085 if (mixer_ctl_set_value(ctl, i, session_id)) {
2086 ALOGV("Error: invalid session_id: %x", session_id);
2087 ret = -EINVAL;
2088 break;
2089 }
2090 }
2091 }
2092
2093 if (my_data->csd != NULL) {
2094 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2095 if (ret < 0) {
2096 ALOGE("%s: csd_client_start_record failed, error %d",
2097 __func__, ret);
2098 }
2099 }
2100
2101 return ret;
2102}
2103
2104int platform_stop_incall_recording_usecase(void *platform)
2105{
2106 int ret = 0;
2107 struct platform_data *my_data = (struct platform_data *)platform;
2108
2109 if (my_data->csd != NULL) {
2110 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2111 if (ret < 0) {
2112 ALOGE("%s: csd_client_stop_record failed, error %d",
2113 __func__, ret);
2114 }
2115 }
2116
2117 return ret;
2118}
2119
2120int platform_start_incall_music_usecase(void *platform)
2121{
2122 int ret = 0;
2123 struct platform_data *my_data = (struct platform_data *)platform;
2124
2125 if (my_data->csd != NULL) {
2126 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2127 if (ret < 0) {
2128 ALOGE("%s: csd_client_start_playback failed, error %d",
2129 __func__, ret);
2130 }
2131 }
2132
2133 return ret;
2134}
2135
2136int platform_stop_incall_music_usecase(void *platform)
2137{
2138 int ret = 0;
2139 struct platform_data *my_data = (struct platform_data *)platform;
2140
2141 if (my_data->csd != NULL) {
2142 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2143 if (ret < 0) {
2144 ALOGE("%s: csd_client_stop_playback failed, error %d",
2145 __func__, ret);
2146 }
2147 }
2148
2149 return ret;
2150}
2151
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002152int platform_set_parameters(void *platform, struct str_parms *parms)
2153{
2154 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002155 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002156 char *kv_pairs = str_parms_to_str(parms);
2157 int ret = 0, err;
2158
2159 if (kv_pairs == NULL) {
2160 ret = -EINVAL;
2161 ALOGE("%s: key-value pair is NULL",__func__);
2162 goto done;
2163 }
2164
2165 ALOGV("%s: enter: %s", __func__, kv_pairs);
2166
2167 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2168 value, sizeof(value));
2169 if (err >= 0) {
2170 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2171 my_data->snd_card_name = strdup(value);
2172 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2173 }
2174
keunhui.park2f7306a2015-07-16 16:48:06 +09002175 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2176 value, sizeof(value));
2177 if (err >= 0) {
2178 struct operator_info *info;
2179 char *str = value;
2180 char *name;
2181
2182 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2183 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2184 name = strtok(str, ";");
2185 info->name = strdup(name);
2186 info->mccmnc = strdup(str + strlen(name) + 1);
2187
2188 list_add_tail(&operator_info_list, &info->list);
2189 ALOGD("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
2190 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002191done:
2192 ALOGV("%s: exit with code(%d)", __func__, ret);
2193 if (kv_pairs != NULL)
2194 free(kv_pairs);
2195
2196 return ret;
2197}
2198
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002199/* Delay in Us */
2200int64_t platform_render_latency(audio_usecase_t usecase)
2201{
2202 switch (usecase) {
2203 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2204 return DEEP_BUFFER_PLATFORM_DELAY;
2205 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2206 return LOW_LATENCY_PLATFORM_DELAY;
2207 default:
2208 return 0;
2209 }
2210}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002211
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002212int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2213 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002214{
2215 int ret = 0;
2216
2217 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2218 ALOGE("%s: Invalid snd_device = %d",
2219 __func__, device);
2220 ret = -EINVAL;
2221 goto done;
2222 }
2223
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002224 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2225 platform_get_snd_device_name(device),
2226 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2227 if (backend_tag_table[device]) {
2228 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002229 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002230 backend_tag_table[device] = strdup(backend_tag);
2231
2232 if (hw_interface != NULL) {
2233 if (hw_interface_table[device])
2234 free(hw_interface_table[device]);
2235 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2236 hw_interface_table[device] = strdup(hw_interface);
2237 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002238done:
2239 return ret;
2240}
2241
2242int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2243{
2244 int ret = 0;
2245 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2246 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2247 ret = -EINVAL;
2248 goto done;
2249 }
2250
2251 if ((type != 0) && (type != 1)) {
2252 ALOGE("%s: invalid usecase type", __func__);
2253 ret = -EINVAL;
2254 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002255 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002256 pcm_device_table[usecase][type] = pcm_id;
2257done:
2258 return ret;
2259}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002260
2261int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2262{
2263 // only update if there is active pcm playback on speaker
2264 struct audio_usecase *usecase;
2265 struct listnode *node;
2266 struct platform_data *my_data = (struct platform_data *)adev->platform;
2267
2268 if (my_data->speaker_lr_swap != swap_channels) {
2269 my_data->speaker_lr_swap = swap_channels;
2270
2271 list_for_each(node, &adev->usecase_list) {
2272 usecase = node_to_item(node, struct audio_usecase, list);
2273 if (usecase->type == PCM_PLAYBACK &&
2274 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2275 const char *mixer_path;
2276 if (swap_channels) {
2277 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2278 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2279 } else {
2280 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2281 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2282 }
2283 break;
2284 }
2285 }
2286 }
2287 return 0;
2288}