blob: 02512ea88743cd252511a543fb368bd6c5d8d6f1 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
22#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070023#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/properties.h>
25#include <audio_hw.h>
26#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070027#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070028#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
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090032#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
33#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080034#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
35#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
36
Eric Laurentb23d5282013-05-14 15:27:20 -070037#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070038#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090039#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070040
Eric Laurentf9583c32016-03-28 13:50:50 -070041#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070042
43/*
Eric Laurentb23d5282013-05-14 15:27:20 -070044 * This file will have a maximum of 38 bytes:
45 *
46 * 4 bytes: number of audio blocks
47 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
48 * Maximum 10 * 3 bytes: SAD blocks
49 */
50#define MAX_SAD_BLOCKS 10
51#define SAD_BLOCK_SIZE 3
52
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090053#define MAX_CVD_VERSION_STRING_SIZE 100
54
Eric Laurentb23d5282013-05-14 15:27:20 -070055/* EDID format ID for LPCM audio */
56#define EDID_FORMAT_LPCM 1
57
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070058#define MAX_SND_CARD_NAME_LEN 31
59
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080060#define DEFAULT_APP_TYPE_RX_PATH 69936
61#define DEFAULT_APP_TYPE_TX_PATH 69938
vivek mehta1a9b7c02015-06-25 11:49:38 -070062
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090063#define TOSTRING_(x) #x
64#define TOSTRING(x) TOSTRING_(x)
65
Eric Laurentb23d5282013-05-14 15:27:20 -070066struct audio_block_header
67{
68 int reserved;
69 int length;
70};
71
vivek mehta1a9b7c02015-06-25 11:49:38 -070072enum {
73 CAL_MODE_SEND = 0x1,
74 CAL_MODE_PERSIST = 0x2,
75 CAL_MODE_RTAC = 0x4
76};
77
keunhui.park2f7306a2015-07-16 16:48:06 +090078#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
79
80struct operator_info {
81 struct listnode list;
82 char *name;
83 char *mccmnc;
84};
85
86struct operator_specific_device {
87 struct listnode list;
88 char *operator;
89 char *mixer_path;
90 int acdb_id;
91};
92
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080093#define BE_DAI_NAME_MAX_LENGTH 24
94struct be_dai_name_struct {
95 unsigned int be_id;
96 char be_name[BE_DAI_NAME_MAX_LENGTH];
97};
98
keunhui.park2f7306a2015-07-16 16:48:06 +090099static struct listnode operator_info_list;
100static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
101
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700102/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800103typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700104
Eric Laurentb23d5282013-05-14 15:27:20 -0700105struct platform_data {
106 struct audio_device *adev;
107 bool fluence_in_spkr_mode;
108 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700109 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700110 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700111 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
112 int fluence_type;
113 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700114 bool speaker_lr_swap;
115
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800117#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700118 acdb_init_v2_cvd_t acdb_init;
119#elif defined (PLATFORM_MSM8084)
120 acdb_init_v2_t acdb_init;
121#else
122 acdb_init_t acdb_init;
123#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700124 acdb_deallocate_t acdb_deallocate;
125 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800126 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700127 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700128 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700129 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700130 acdb_send_custom_top_t acdb_send_custom_top;
131 bool acdb_initialized;
132
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700133 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800134 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700135
David Linee3fe402017-03-13 10:00:42 -0700136 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700137 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900138 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700139 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800140
141 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700142};
143
Haynes Mathew George98c95622014-06-20 19:14:25 -0700144static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700145 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
146 DEEP_BUFFER_PCM_DEVICE},
147 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
148 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800149 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700150 MULTIMEDIA2_PCM_DEVICE},
151 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
152 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700153 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
154 MULTIMEDIA2_PCM_DEVICE},
155 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
156 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800157 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
158 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700159
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700160 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
161 AUDIO_RECORD_PCM_DEVICE},
162 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
163 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700164
Eric Laurent0e46adf2016-12-16 12:49:24 -0800165 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
166 MMAP_RECORD_PCM_DEVICE},
167
Haynes Mathew George569b7482017-05-08 14:44:27 -0700168 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
169 MULTIMEDIA2_PCM_DEVICE},
170
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700171 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
172 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700173 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
174 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
175 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
176 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800177 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
178 VOICEMMODE1_CALL_PCM_DEVICE},
179 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
180 VOICEMMODE2_CALL_PCM_DEVICE},
181
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700182 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
183 AUDIO_RECORD_PCM_DEVICE},
184 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
185 AUDIO_RECORD_PCM_DEVICE},
186 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
187 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800188 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700189
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700190 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
191 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
192
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700193 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
194 AFE_PROXY_RECORD_PCM_DEVICE},
195 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
196 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800197 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700198
Eric Laurentb23d5282013-05-14 15:27:20 -0700199};
200
201/* Array to store sound devices */
202static const char * const device_table[SND_DEVICE_MAX] = {
203 [SND_DEVICE_NONE] = "none",
204 /* Playback sound devices */
205 [SND_DEVICE_OUT_HANDSET] = "handset",
206 [SND_DEVICE_OUT_SPEAKER] = "speaker",
207 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700208 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700209 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500210 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700211 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700212 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500213 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700214 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700215 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500216 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
218 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500219 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700220 [SND_DEVICE_OUT_HDMI] = "hdmi",
221 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
222 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700223 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
225 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
226 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
227 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800228 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
229 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700230 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700231 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700232 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700233 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700234 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700235 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700236 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
237 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700238 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800239 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
240 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700241
242 /* Capture sound devices */
243 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700244 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700245 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
246 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
247 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
248 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
249 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
250 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
251 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
252
253 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
254 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
255 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
256 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
257 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
258 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
259 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
260 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
261 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
262
263 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500264 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700265
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
267 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700268 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700269 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700270 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700271 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700272
273 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
274 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
275 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
276 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700277 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700278 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700279 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
280 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
281 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800282 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
283 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700284
Eric Laurentb23d5282013-05-14 15:27:20 -0700285 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700286 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700287 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700288 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700289 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
290 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700291 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700292 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
293 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
294 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
295 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700296 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700297
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700298 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700299 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
300 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
301 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
302 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800303
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700304 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700305
Prashant Malanic92c5962015-08-11 15:10:18 -0700306 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
307 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700308 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700309 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
310 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700311 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
312 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700313};
314
315/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700316static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700317 [SND_DEVICE_NONE] = -1,
318 [SND_DEVICE_OUT_HANDSET] = 7,
319 [SND_DEVICE_OUT_SPEAKER] = 15,
320 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700321 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700322 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500323 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700324 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700325 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500326 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700327 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700328 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
329 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500330 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700331 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500332 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700333 [SND_DEVICE_OUT_HDMI] = 18,
334 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
335 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700336 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700337 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700338 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
339 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
340 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800341 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
342 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700343 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700344 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700345 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700346 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700347 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700348 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700349 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
350 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700351 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700352
353 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700354 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
355 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
356 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
357 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
358 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
359 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
360 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
361 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
362
363 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
364 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
365 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
366 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
367 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
368 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
369 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
370 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
371 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
372
rago90fb9612015-12-02 11:37:53 -0800373 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500374 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700375
Eric Laurentb23d5282013-05-14 15:27:20 -0700376 [SND_DEVICE_IN_HDMI_MIC] = 4,
377 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700378 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700379 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700380 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700381 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700382
383 [SND_DEVICE_IN_VOICE_DMIC] = 41,
384 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
385 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700386 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700387 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800388 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700389 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
390 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
391 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800392 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
393 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700394
rago90fb9612015-12-02 11:37:53 -0800395 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700396 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700397 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700398 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700399 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
400 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800401 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
402
403 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
404 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700405 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
406 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
407 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700408
409 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700410 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700411 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
412 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
413 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
414 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700415 [SND_DEVICE_IN_THREE_MIC] = 46,
416 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700417 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700418 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
419 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700420 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
421 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700422};
423
David Linee3fe402017-03-13 10:00:42 -0700424// Platform specific backend bit width table
425static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
426
Haynes Mathew George98c95622014-06-20 19:14:25 -0700427struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700428 char name[100];
429 unsigned int index;
430};
431
432#define TO_NAME_INDEX(X) #X, X
433
Haynes Mathew George98c95622014-06-20 19:14:25 -0700434/* Used to get index from parsed string */
435static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
436 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700437 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
438 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
439 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700440 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700441 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500442 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700443 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700444 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500445 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700446 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700447 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
448 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700449 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700450 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500451 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700452 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
453 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
454 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
455 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700456 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500457 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
459 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
460 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800461 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
462 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800463 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
464 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700465 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700466 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700467 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700469 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700470 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
471 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800472
473 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700474 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700475 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700476 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
477 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
478 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
479 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
480 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
481 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
482 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
483
484 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700485 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700486 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
488 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
490 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
491 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
492 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
493
494 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700495 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700496
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700497 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
498 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700499 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700500 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700501 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700502 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700503
504 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
505 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
506 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700508 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
509 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700510 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
511 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
512 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800513 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
514 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
515
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700516
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700518 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700523 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700524 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700525 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
528 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700529
rago90fb9612015-12-02 11:37:53 -0800530 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
531 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800535
Prashant Malanic92c5962015-08-11 15:10:18 -0700536 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700538 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700539 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700543};
544
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700545static char * backend_tag_table[SND_DEVICE_MAX] = {0};
546static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700547
548static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
549 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
550 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800551 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700552 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700553 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
554 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800555 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700556 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
557 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800558 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700559 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700560 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
561 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
562 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
563 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
564 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800565 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
566 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700567 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
568 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
569 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
570 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800571 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
572 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
573 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
574 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
575 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700576};
577
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800578static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
579 {TO_NAME_INDEX(PCM_PLAYBACK)},
580 {TO_NAME_INDEX(PCM_CAPTURE)},
581 {TO_NAME_INDEX(VOICE_CALL)},
582 {TO_NAME_INDEX(PCM_HFP_CALL)},
583};
584
585struct app_type_entry {
586 int uc_type;
587 int bit_width;
588 int app_type;
589 int max_rate;
590 struct listnode node; // membership in app_type_entry_list;
591};
592
593static struct listnode app_type_entry_list;
594
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700595#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
596#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800597#define ULL_PLATFORM_DELAY (3*1000LL)
598#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700599
Eric Laurentb23d5282013-05-14 15:27:20 -0700600static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
601static bool is_tmus = false;
602
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800603static int init_be_dai_name_table(struct audio_device *adev);
604
Eric Laurentb23d5282013-05-14 15:27:20 -0700605static void check_operator()
606{
607 char value[PROPERTY_VALUE_MAX];
608 int mccmnc;
609 property_get("gsm.sim.operator.numeric",value,"0");
610 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700611 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700612 switch(mccmnc) {
613 /* TMUS MCC(310), MNC(490, 260, 026) */
614 case 310490:
615 case 310260:
616 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900617 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
618 case 310800:
619 case 310660:
620 case 310580:
621 case 310310:
622 case 310270:
623 case 310250:
624 case 310240:
625 case 310230:
626 case 310220:
627 case 310210:
628 case 310200:
629 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700630 is_tmus = true;
631 break;
632 }
633}
634
635bool is_operator_tmus()
636{
637 pthread_once(&check_op_once_ctl, check_operator);
638 return is_tmus;
639}
640
keunhui.park2f7306a2015-07-16 16:48:06 +0900641static char *get_current_operator()
642{
643 struct listnode *node;
644 struct operator_info *info_item;
645 char mccmnc[PROPERTY_VALUE_MAX];
646 char *ret = NULL;
647
Tom Cherry7fea2042016-11-10 18:05:59 -0800648 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900649
650 list_for_each(node, &operator_info_list) {
651 info_item = node_to_item(node, struct operator_info, list);
652 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
653 ret = info_item->name;
654 }
655 }
656
657 return ret;
658}
659
660static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
661{
662 struct listnode *node;
663 struct operator_specific_device *ret = NULL;
664 struct operator_specific_device *device_item;
665 char *operator_name;
666
667 operator_name = get_current_operator();
668 if (operator_name == NULL)
669 return ret;
670
671 list_for_each(node, operator_specific_device_table[snd_device]) {
672 device_item = node_to_item(node, struct operator_specific_device, list);
673 if (strcmp(operator_name, device_item->operator) == 0) {
674 ret = device_item;
675 }
676 }
677
678 return ret;
679}
680
681
682static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
683{
684 struct operator_specific_device *device;
685 int ret = acdb_device_table[snd_device];
686
687 device = get_operator_specific_device(snd_device);
688 if (device != NULL)
689 ret = device->acdb_id;
690
691 return ret;
692}
693
694static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
695{
696 struct operator_specific_device *device;
697 const char *ret = device_table[snd_device];
698
699 device = get_operator_specific_device(snd_device);
700 if (device != NULL)
701 ret = device->mixer_path;
702
703 return ret;
704}
705
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800706inline bool platform_supports_app_type_cfg()
707{
708#ifdef PLATFORM_MSM8998
709 return true;
710#else
711 return false;
712#endif
713}
714
vivek mehta1a9b7c02015-06-25 11:49:38 -0700715bool platform_send_gain_dep_cal(void *platform, int level)
716{
717 bool ret_val = false;
718 struct platform_data *my_data = (struct platform_data *)platform;
719 struct audio_device *adev = my_data->adev;
720 int acdb_dev_id, app_type;
721 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
722 int mode = CAL_MODE_RTAC;
723 struct listnode *node;
724 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700725
726 if (my_data->acdb_send_gain_dep_cal == NULL) {
727 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
728 return ret_val;
729 }
730
731 if (!voice_is_in_call(adev)) {
732 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
733 __func__, level);
734 app_type = DEFAULT_APP_TYPE_RX_PATH;
735
736 // find the current active sound device
737 list_for_each(node, &adev->usecase_list) {
738 usecase = node_to_item(node, struct audio_usecase, list);
739
740 if (usecase != NULL &&
741 usecase->type == PCM_PLAYBACK &&
742 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
743
744 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700745 if (audio_extn_spkr_prot_is_enabled()) {
746 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
747 } else {
748 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
749 }
750
vivek mehta1a9b7c02015-06-25 11:49:38 -0700751 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
752 acdb_dev_type, mode, level)) {
753 // set ret_val true if at least one calibration is set successfully
754 ret_val = true;
755 } else {
756 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
757 }
758 } else {
759 ALOGW("%s: Usecase list is empty", __func__);
760 }
761 }
762 } else {
763 ALOGW("%s: Voice call in progress .. ignore setting new cal",
764 __func__);
765 }
766 return ret_val;
767}
768
Eric Laurentcefbbac2014-09-04 13:54:10 -0500769void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700770{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800771 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500772 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700773
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800774 if (strcmp(my_data->ec_ref_mixer_path, "")) {
775 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
776 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500777 }
778
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800779 if (enable) {
780 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
781 if (out_device != AUDIO_DEVICE_NONE) {
782 snd_device = platform_get_output_snd_device(adev->platform, out_device);
783 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
784 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500785
Joe Onorato188b6222016-03-01 11:02:27 -0800786 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800787 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
788 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700789}
790
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700791static struct csd_data *open_csd_client(bool i2s_ext_modem)
792{
793 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
794
795 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
796 if (csd->csd_client == NULL) {
797 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
798 goto error;
799 } else {
800 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
801
802 csd->deinit = (deinit_t)dlsym(csd->csd_client,
803 "csd_client_deinit");
804 if (csd->deinit == NULL) {
805 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
806 dlerror());
807 goto error;
808 }
809 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
810 "csd_client_disable_device");
811 if (csd->disable_device == NULL) {
812 ALOGE("%s: dlsym error %s for csd_client_disable_device",
813 __func__, dlerror());
814 goto error;
815 }
816 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
817 "csd_client_enable_device_config");
818 if (csd->enable_device_config == NULL) {
819 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
820 __func__, dlerror());
821 goto error;
822 }
823 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
824 "csd_client_enable_device");
825 if (csd->enable_device == NULL) {
826 ALOGE("%s: dlsym error %s for csd_client_enable_device",
827 __func__, dlerror());
828 goto error;
829 }
830 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
831 "csd_client_start_voice");
832 if (csd->start_voice == NULL) {
833 ALOGE("%s: dlsym error %s for csd_client_start_voice",
834 __func__, dlerror());
835 goto error;
836 }
837 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
838 "csd_client_stop_voice");
839 if (csd->stop_voice == NULL) {
840 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
841 __func__, dlerror());
842 goto error;
843 }
844 csd->volume = (volume_t)dlsym(csd->csd_client,
845 "csd_client_volume");
846 if (csd->volume == NULL) {
847 ALOGE("%s: dlsym error %s for csd_client_volume",
848 __func__, dlerror());
849 goto error;
850 }
851 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
852 "csd_client_mic_mute");
853 if (csd->mic_mute == NULL) {
854 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
855 __func__, dlerror());
856 goto error;
857 }
858 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
859 "csd_client_slow_talk");
860 if (csd->slow_talk == NULL) {
861 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
862 __func__, dlerror());
863 goto error;
864 }
865 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
866 "csd_client_start_playback");
867 if (csd->start_playback == NULL) {
868 ALOGE("%s: dlsym error %s for csd_client_start_playback",
869 __func__, dlerror());
870 goto error;
871 }
872 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
873 "csd_client_stop_playback");
874 if (csd->stop_playback == NULL) {
875 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
876 __func__, dlerror());
877 goto error;
878 }
879 csd->start_record = (start_record_t)dlsym(csd->csd_client,
880 "csd_client_start_record");
881 if (csd->start_record == NULL) {
882 ALOGE("%s: dlsym error %s for csd_client_start_record",
883 __func__, dlerror());
884 goto error;
885 }
886 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
887 "csd_client_stop_record");
888 if (csd->stop_record == NULL) {
889 ALOGE("%s: dlsym error %s for csd_client_stop_record",
890 __func__, dlerror());
891 goto error;
892 }
893
894 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
895 "csd_client_get_sample_rate");
896 if (csd->get_sample_rate == NULL) {
897 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
898 __func__, dlerror());
899
900 goto error;
901 }
902
903 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
904
905 if (csd->init == NULL) {
906 ALOGE("%s: dlsym error %s for csd_client_init",
907 __func__, dlerror());
908 goto error;
909 } else {
910 csd->init(i2s_ext_modem);
911 }
912 }
913 return csd;
914
915error:
916 free(csd);
917 csd = NULL;
918 return csd;
919}
920
921void close_csd_client(struct csd_data *csd)
922{
923 if (csd != NULL) {
924 csd->deinit();
925 dlclose(csd->csd_client);
926 free(csd);
927 csd = NULL;
928 }
929}
930
931static void platform_csd_init(struct platform_data *my_data)
932{
933#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700934 int32_t modems, (*count_modems)(void);
935 const char *name = "libdetectmodem.so";
936 const char *func = "count_modems";
937 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700938
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700939 my_data->csd = NULL;
940
941 void *lib = dlopen(name, RTLD_NOW);
942 error = dlerror();
943 if (!lib) {
944 ALOGE("%s: could not find %s: %s", __func__, name, error);
945 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700946 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700947
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700948 count_modems = NULL;
949 *(void **)(&count_modems) = dlsym(lib, func);
950 error = dlerror();
951 if (!count_modems) {
952 ALOGE("%s: could not find symbol %s in %s: %s",
953 __func__, func, name, error);
954 goto done;
955 }
956
957 modems = count_modems();
958 if (modems < 0) {
959 ALOGE("%s: count_modems failed\n", __func__);
960 goto done;
961 }
962
Eric Laurent2bafff12016-03-17 12:17:23 -0700963 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700964 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700965 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700966
967done:
968 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700969#else
970 my_data->csd = NULL;
971#endif
972}
973
Eric Laurentc6333382015-09-14 12:43:44 -0700974static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700975{
976 int32_t dev;
977 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700978 backend_tag_table[dev] = NULL;
979 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900980 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700981 }
982
David Linee3fe402017-03-13 10:00:42 -0700983 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
984 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
985 }
986
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700987 // To overwrite these go to the audio_platform_info.xml file.
988 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700989 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700990 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
991 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
992 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
993 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
994 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700995 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700996 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
997 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700998
David Linee3fe402017-03-13 10:00:42 -0700999 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001000 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001001 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001002 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001003 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1004 strdup("speaker-and-usb-headphones");
1005 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001006 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1007 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1008 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1009 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001010 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1011 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1012 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1013 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1014 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1015 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1016 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001017 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001018 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001019 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001020 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1021 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1022 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1023 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1024 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1025 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1026 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1027 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1028 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1029 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1030 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1031 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1032 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001033 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001034 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1035 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001036 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001037 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001038 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001039 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001040 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1041 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1042 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001043 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1044 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1045 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1046 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1047 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1048 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1049 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
1050 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1051 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1052 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1053 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1054 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001055
1056 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001057}
1058
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001059void get_cvd_version(char *cvd_version, struct audio_device *adev)
1060{
1061 struct mixer_ctl *ctl;
1062 int count;
1063 int ret = 0;
1064
1065 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1066 if (!ctl) {
1067 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1068 goto done;
1069 }
1070 mixer_ctl_update(ctl);
1071
1072 count = mixer_ctl_get_num_values(ctl);
1073 if (count > MAX_CVD_VERSION_STRING_SIZE)
1074 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1075
1076 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1077 if (ret != 0) {
1078 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1079 goto done;
1080 }
1081
1082done:
1083 return;
1084}
1085
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001086static int platform_acdb_init(void *platform)
1087{
1088 struct platform_data *my_data = (struct platform_data *)platform;
1089 struct audio_device *adev = my_data->adev;
1090
1091 if (!my_data->acdb_init) {
1092 ALOGE("%s: no acdb_init fn provided", __func__);
1093 return -1;
1094 }
1095
1096 if (my_data->acdb_initialized) {
1097 ALOGW("acdb is already initialized");
1098 return 0;
1099 }
1100
Thierry Strudel92232b42017-01-26 10:51:48 -08001101#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001102 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1103 if (!cvd_version)
1104 ALOGE("failed to allocate cvd_version");
1105 else {
1106 get_cvd_version(cvd_version, adev);
1107 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1108 free(cvd_version);
1109 }
1110#elif defined (PLATFORM_MSM8084)
1111 my_data->acdb_init((char *)my_data->snd_card_name);
1112#else
1113 my_data->acdb_init();
1114#endif
1115 my_data->acdb_initialized = true;
1116 return 0;
1117}
1118
David Linee3fe402017-03-13 10:00:42 -07001119static void
1120platform_backend_config_init(struct platform_data *pdata)
1121{
1122 int i;
1123
1124 /* initialize backend config */
1125 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1126 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1127 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1128 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1129
1130 if (i > MAX_RX_CODEC_BACKENDS)
1131 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1132
1133 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1134 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1135 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1136 }
1137
1138 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1139 strdup("SLIM_0_RX Format");
1140 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1141 strdup("SLIM_0_RX SampleRate");
1142
1143 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1144 strdup("SLIM_0_TX Format");
1145 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1146 strdup("SLIM_0_TX SampleRate");
1147
1148 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1149 strdup("USB_AUDIO_TX Format");
1150 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1151 strdup("USB_AUDIO_TX SampleRate");
1152 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1153 strdup("USB_AUDIO_TX Channels");
1154
1155 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1156 strdup("SLIM_6_RX Format");
1157 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1158 strdup("SLIM_6_RX SampleRate");
1159
1160 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1161 strdup("USB_AUDIO_RX Format");
1162 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1163 strdup("USB_AUDIO_RX SampleRate");
1164
1165 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1166 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1167 strdup("USB_AUDIO_RX Channels");
1168}
1169
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001170static int
1171platform_backend_app_type_cfg_init(struct platform_data *pdata,
1172 struct mixer *mixer)
1173{
1174 size_t app_type_cfg[128] = {0};
1175 int length, num_app_types = 0;
1176 struct mixer_ctl *ctl = NULL;
1177
1178 const char *mixer_ctl_name = "App Type Config";
1179 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1180 if (!ctl) {
1181 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1182 return -1;
1183 }
1184
1185 length = 1; // reserve index 0 for number of app types
1186
1187 struct listnode *node;
1188 struct app_type_entry *entry;
1189 list_for_each(node, &app_type_entry_list) {
1190 entry = node_to_item(node, struct app_type_entry, node);
1191 app_type_cfg[length++] = entry->app_type;
1192 app_type_cfg[length++] = entry->max_rate;
1193 app_type_cfg[length++] = entry->bit_width;
1194 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1195 num_app_types += 1;
1196 }
1197
1198 // default for capture
1199 int t;
1200 platform_get_default_app_type_v2(pdata,
1201 PCM_CAPTURE,
1202 &t);
1203 app_type_cfg[length++] = t;
1204 app_type_cfg[length++] = 48000;
1205 app_type_cfg[length++] = 16;
1206 num_app_types += 1;
1207
1208 if (num_app_types) {
1209 app_type_cfg[0] = num_app_types;
1210 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1211 ALOGE("Failed to set app type cfg");
1212 }
1213 }
1214 return 0;
1215}
1216
Eric Laurentb23d5282013-05-14 15:27:20 -07001217void *platform_init(struct audio_device *adev)
1218{
1219 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001220 struct platform_data *my_data = NULL;
1221 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1222 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001223 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001224 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001225 char *snd_internal_name = NULL;
1226 char *tmp = NULL;
1227 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001228 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1229 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001230 my_data = calloc(1, sizeof(struct platform_data));
1231
1232 my_data->adev = adev;
1233
keunhui.park2f7306a2015-07-16 16:48:06 +09001234 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001235 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001236
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001237 set_platform_defaults(my_data);
1238
vivek mehta0fb11312017-05-15 19:35:32 -07001239 // audio_extn_utils_get_snd_card_num does
1240 // - open mixer and get snd card name
1241 // - parse platform info xml file and check for valid snd card name
1242 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001243
vivek mehta0fb11312017-05-15 19:35:32 -07001244 snd_card_num = audio_extn_utils_get_snd_card_num();
1245 if (-1 == snd_card_num) {
1246 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1247 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001248 }
1249
vivek mehta0fb11312017-05-15 19:35:32 -07001250 adev->mixer = mixer_open(snd_card_num);
1251 snd_card_name = mixer_get_name(adev->mixer);
1252 my_data->hw_info = hw_info_init(snd_card_name);
1253
1254 audio_extn_set_snd_card_split(snd_card_name);
1255 snd_split_handle = audio_extn_get_snd_card_split();
1256
1257 /* Get the codec internal name from the sound card and/or form factor
1258 * name and form the mixer paths and platfor info file name dynamically.
1259 * This is generic way of picking any codec and forma factor name based
1260 * mixer and platform info files in future with no code change.
1261
1262 * current code extends and looks for any of the exteneded mixer path and
1263 * platform info file present based on codec and form factor.
1264
1265 * order of picking appropriate file is
1266 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1267 * <ii> mixer_paths_<codec_name>.xml, if file not present
1268 * <iii> mixer_paths.xml
1269
1270 * same order is followed for audio_platform_info.xml as well
1271 */
1272
1273 // need to carryforward old file name
1274 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1275 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1276 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1277 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1278 } else {
1279
1280 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1281 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1282 snd_split_handle->form_factor);
1283 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1284 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1285 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1286 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1287
1288 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1289 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1290 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1291 audio_extn_utils_resolve_config_file(mixer_xml_file);
1292 }
1293 }
1294 }
1295
1296 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1297
1298 /* Initialize platform specific ids and/or backends*/
1299 platform_info_init(platform_info_file, my_data);
1300
1301 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1302 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1303
1304 if (!adev->audio_route) {
1305 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1306 mixer_close(adev->mixer);
1307 adev->mixer = NULL;
1308 hw_info_deinit(my_data->hw_info);
1309 my_data->hw_info = NULL;
1310 goto init_failed;
1311 }
1312 adev->snd_card = snd_card_num;
1313 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1314
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001315 //set max volume step for voice call
1316 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1317 my_data->max_vol_index = atoi(value);
1318
vivek mehta65ad12d2015-08-13 18:32:48 -07001319 property_get("persist.audio.dualmic.config",value,"");
1320 if (!strcmp("endfire", value)) {
1321 dual_mic_config = true;
1322 }
1323
Prashant Malanic92c5962015-08-11 15:10:18 -07001324 my_data->source_mic_type = SOURCE_DUAL_MIC;
1325
Eric Laurentb23d5282013-05-14 15:27:20 -07001326 my_data->fluence_in_spkr_mode = false;
1327 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001328 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001329 my_data->fluence_in_voice_rec = false;
1330
vivek mehta65ad12d2015-08-13 18:32:48 -07001331 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001332 if (!strcmp("fluencepro", value)) {
1333 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001334 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001335 my_data->fluence_type = FLUENCE_ENABLE;
1336 } else if (!strcmp("none", value)) {
1337 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001338 }
1339
Prashant Malanic92c5962015-08-11 15:10:18 -07001340 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001341 property_get("persist.audio.fluence.voicecall",value,"");
1342 if (!strcmp("true", value)) {
1343 my_data->fluence_in_voice_call = true;
1344 }
1345
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001346 property_get("persist.audio.fluence.voicecomm",value,"");
1347 if (!strcmp("true", value)) {
1348 my_data->fluence_in_voice_comm = true;
1349 }
1350
Eric Laurentb23d5282013-05-14 15:27:20 -07001351 property_get("persist.audio.fluence.voicerec",value,"");
1352 if (!strcmp("true", value)) {
1353 my_data->fluence_in_voice_rec = true;
1354 }
1355
1356 property_get("persist.audio.fluence.speaker",value,"");
1357 if (!strcmp("true", value)) {
1358 my_data->fluence_in_spkr_mode = true;
1359 }
1360 }
1361
Prashant Malanic92c5962015-08-11 15:10:18 -07001362 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1363 switch (my_data->max_mic_count) {
1364 case 4:
1365 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1366 case 3:
1367 my_data->source_mic_type |= SOURCE_THREE_MIC;
1368 case 2:
1369 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1370 case 1:
1371 my_data->source_mic_type |= SOURCE_MONO_MIC;
1372 break;
1373 default:
1374 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1375 __func__, my_data->max_mic_count);
1376 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1377 break;
1378 }
1379
1380 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1381 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1382 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1383 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1384 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1385
Eric Laurentb23d5282013-05-14 15:27:20 -07001386 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1387 if (my_data->acdb_handle == NULL) {
1388 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1389 } else {
1390 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1391 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1392 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001393 if (!my_data->acdb_deallocate)
1394 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1395 __func__, LIB_ACDB_LOADER);
1396
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001397 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1398 "acdb_loader_send_audio_cal_v3");
1399 if (!my_data->acdb_send_audio_cal_v3)
1400 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1401 __func__, LIB_ACDB_LOADER);
1402
Eric Laurentb23d5282013-05-14 15:27:20 -07001403 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1404 "acdb_loader_send_audio_cal");
1405 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001406 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001407 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001408
Eric Laurentb23d5282013-05-14 15:27:20 -07001409 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1410 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001411 if (!my_data->acdb_send_voice_cal)
1412 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1413 __func__, LIB_ACDB_LOADER);
1414
1415 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1416 "acdb_loader_reload_vocvoltable");
1417 if (!my_data->acdb_reload_vocvoltable)
1418 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1419 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001420
1421 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1422 "acdb_loader_send_gain_dep_cal");
1423 if (!my_data->acdb_send_gain_dep_cal)
1424 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1425 __func__, LIB_ACDB_LOADER);
1426
Thierry Strudel92232b42017-01-26 10:51:48 -08001427#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001428 acdb_init_v2_cvd_t acdb_init_local;
1429 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001430 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001431 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001432 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1433 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001434
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001435#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001436 acdb_init_v2_t acdb_init_local;
1437 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001438 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001439 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001440 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1441 dlerror());
1442
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001443#else
vivek mehta0fb11312017-05-15 19:35:32 -07001444 acdb_init_t acdb_init_local;
1445 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001446 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001447 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001448 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1449 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001450#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001451 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001452
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001453 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1454 dlsym(my_data->acdb_handle,
1455 "acdb_loader_send_common_custom_topology");
1456
1457 if (!my_data->acdb_send_custom_top)
1458 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1459 __func__, LIB_ACDB_LOADER);
1460
vivek mehta0fb11312017-05-15 19:35:32 -07001461 int result = acdb_init(adev->snd_card);
1462 if (!result) {
1463 my_data->acdb_initialized = true;
1464 ALOGD("ACDB initialized");
1465 } else {
1466 my_data->acdb_initialized = false;
1467 ALOGD("ACDB initialization failed");
1468 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001469 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001470
David Linee3fe402017-03-13 10:00:42 -07001471 /* init usb */
1472 audio_extn_usb_init(adev);
1473
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001474 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001475
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001476 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1477
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001478 /* load csd client */
1479 platform_csd_init(my_data);
1480
David Linee3fe402017-03-13 10:00:42 -07001481 platform_backend_config_init(my_data);
1482
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001483 init_be_dai_name_table(adev);
1484
1485 if (platform_supports_app_type_cfg())
1486 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1487
Eric Laurentb23d5282013-05-14 15:27:20 -07001488 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001489
1490init_failed:
1491 if (my_data)
1492 free(my_data);
1493 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001494}
1495
1496void platform_deinit(void *platform)
1497{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001498 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001499 struct operator_info *info_item;
1500 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001501 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001502 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001503
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001504 struct platform_data *my_data = (struct platform_data *)platform;
1505 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001506
vivek mehtade4849c2016-03-03 17:23:38 -08001507 hw_info_deinit(my_data->hw_info);
1508
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001509 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1510 if (backend_tag_table[dev])
1511 free(backend_tag_table[dev]);
1512 if (hw_interface_table[dev])
1513 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001514 if (operator_specific_device_table[dev]) {
1515 while (!list_empty(operator_specific_device_table[dev])) {
1516 node = list_head(operator_specific_device_table[dev]);
1517 list_remove(node);
1518 device_item = node_to_item(node, struct operator_specific_device, list);
1519 free(device_item->operator);
1520 free(device_item->mixer_path);
1521 free(device_item);
1522 }
1523 free(operator_specific_device_table[dev]);
1524 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001525 }
1526
1527 if (my_data->snd_card_name)
1528 free(my_data->snd_card_name);
1529
keunhui.park2f7306a2015-07-16 16:48:06 +09001530 while (!list_empty(&operator_info_list)) {
1531 node = list_head(&operator_info_list);
1532 list_remove(node);
1533 info_item = node_to_item(node, struct operator_info, list);
1534 free(info_item->name);
1535 free(info_item->mccmnc);
1536 free(info_item);
1537 }
1538
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001539 while (!list_empty(&app_type_entry_list)) {
1540 node = list_head(&app_type_entry_list);
1541 list_remove(node);
1542 ap = node_to_item(node, struct app_type_entry, node);
1543 free(ap);
1544 }
1545
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001546 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001547 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001548
1549 /* deinit usb */
1550 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001551}
1552
1553const char *platform_get_snd_device_name(snd_device_t snd_device)
1554{
keunhui.park2f7306a2015-07-16 16:48:06 +09001555 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1556 if (operator_specific_device_table[snd_device] != NULL) {
1557 return get_operator_specific_device_mixer_path(snd_device);
1558 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001559 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001560 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001561 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001562}
1563
vivek mehtade4849c2016-03-03 17:23:38 -08001564int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1565 char *device_name)
1566{
1567 struct platform_data *my_data = (struct platform_data *)platform;
1568
David Benjamin1565f992016-09-21 12:10:34 -04001569 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001570 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001571 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1572 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001573 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1574 if (operator_specific_device_table[snd_device] != NULL) {
1575 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1576 DEVICE_NAME_MAX_SIZE);
1577 } else {
1578 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1579 }
1580 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1581 } else {
1582 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1583 }
1584
1585 return 0;
1586}
1587
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001588void platform_add_backend_name(void *platform, char *mixer_path,
1589 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001590{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001591 struct platform_data *my_data = (struct platform_data *)platform;
1592
Haynes Mathew George98c95622014-06-20 19:14:25 -07001593 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1594 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1595 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001596 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001597
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001598 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001599
1600 if (suffix != NULL) {
1601 strcat(mixer_path, " ");
1602 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001603 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001604}
1605
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001606bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1607{
1608 bool result = true;
1609
1610 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1611 platform_get_snd_device_name(snd_device1),
1612 platform_get_snd_device_name(snd_device2));
1613
1614 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1615 ALOGE("%s: Invalid snd_device = %s", __func__,
1616 platform_get_snd_device_name(snd_device1));
1617 return false;
1618 }
1619 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1620 ALOGE("%s: Invalid snd_device = %s", __func__,
1621 platform_get_snd_device_name(snd_device2));
1622 return false;
1623 }
1624 const char * be_itf1 = hw_interface_table[snd_device1];
1625 const char * be_itf2 = hw_interface_table[snd_device2];
1626
1627 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001628 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001629 result = false;
1630 }
1631
1632 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1633 return result;
1634}
1635
Eric Laurentb23d5282013-05-14 15:27:20 -07001636int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1637{
1638 int device_id;
1639 if (device_type == PCM_PLAYBACK)
1640 device_id = pcm_device_table[usecase][0];
1641 else
1642 device_id = pcm_device_table[usecase][1];
1643 return device_id;
1644}
1645
Haynes Mathew George98c95622014-06-20 19:14:25 -07001646static int find_index(const struct name_to_index * table, int32_t len,
1647 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001648{
1649 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001650 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001651
Haynes Mathew George98c95622014-06-20 19:14:25 -07001652 if (table == NULL) {
1653 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001654 ret = -ENODEV;
1655 goto done;
1656 }
1657
Haynes Mathew George98c95622014-06-20 19:14:25 -07001658 if (name == NULL) {
1659 ALOGE("null key");
1660 ret = -ENODEV;
1661 goto done;
1662 }
1663
1664 for (i=0; i < len; i++) {
1665 if (!strcmp(table[i].name, name)) {
1666 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001667 goto done;
1668 }
1669 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001670 ALOGE("%s: Could not find index for name = %s",
1671 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001672 ret = -ENODEV;
1673done:
1674 return ret;
1675}
1676
Haynes Mathew George98c95622014-06-20 19:14:25 -07001677int platform_get_snd_device_index(char *device_name)
1678{
1679 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1680}
1681
1682int platform_get_usecase_index(const char *usecase_name)
1683{
1684 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1685}
1686
keunhui.park2f7306a2015-07-16 16:48:06 +09001687void platform_add_operator_specific_device(snd_device_t snd_device,
1688 const char *operator,
1689 const char *mixer_path,
1690 unsigned int acdb_id)
1691{
1692 struct operator_specific_device *device;
1693
1694 if (operator_specific_device_table[snd_device] == NULL) {
1695 operator_specific_device_table[snd_device] =
1696 (struct listnode *)calloc(1, sizeof(struct listnode));
1697 list_init(operator_specific_device_table[snd_device]);
1698 }
1699
1700 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1701
1702 device->operator = strdup(operator);
1703 device->mixer_path = strdup(mixer_path);
1704 device->acdb_id = acdb_id;
1705
1706 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1707
Eric Laurent2bafff12016-03-17 12:17:23 -07001708 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001709 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1710
1711}
1712
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001713int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1714{
1715 int ret = 0;
1716
1717 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1718 ALOGE("%s: Invalid snd_device = %d",
1719 __func__, snd_device);
1720 ret = -EINVAL;
1721 goto done;
1722 }
1723
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001724 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1725 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001726 acdb_device_table[snd_device] = acdb_id;
1727done:
1728 return ret;
1729}
1730
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001731int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1732{
1733 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1734 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1735 return -EINVAL;
1736 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001737
1738 if (operator_specific_device_table[snd_device] != NULL)
1739 return get_operator_specific_device_acdb_id(snd_device);
1740 else
1741 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001742}
1743
David Linee3fe402017-03-13 10:00:42 -07001744static int platform_get_backend_index(snd_device_t snd_device)
1745{
1746 int32_t port = DEFAULT_CODEC_BACKEND;
1747
1748 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1749 if (backend_tag_table[snd_device] != NULL) {
1750 if (strncmp(backend_tag_table[snd_device], "headphones",
1751 sizeof("headphones")) == 0)
1752 port = HEADPHONE_BACKEND;
1753 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1754 port = HDMI_RX_BACKEND;
1755 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1756 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1757 port = USB_AUDIO_RX_BACKEND;
1758 }
1759 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1760 port = DEFAULT_CODEC_TX_BACKEND;
1761 if (backend_tag_table[snd_device] != NULL) {
1762 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1763 port = USB_AUDIO_TX_BACKEND;
1764 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1765 port = BT_SCO_TX_BACKEND;
1766 }
1767 } else {
1768 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1769 }
1770
1771 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1772
1773 return port;
1774}
1775
Eric Laurentb23d5282013-05-14 15:27:20 -07001776int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1777{
1778 struct platform_data *my_data = (struct platform_data *)platform;
1779 int acdb_dev_id, acdb_dev_type;
1780
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001781 if (platform_supports_app_type_cfg()) // use v2 instead
1782 return -ENOSYS;
1783
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001784 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001785 if (acdb_dev_id < 0) {
1786 ALOGE("%s: Could not find acdb id for device(%d)",
1787 __func__, snd_device);
1788 return -EINVAL;
1789 }
1790 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001791 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001792 __func__, snd_device, acdb_dev_id);
1793 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1794 snd_device < SND_DEVICE_OUT_END)
1795 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1796 else
1797 acdb_dev_type = ACDB_DEV_TYPE_IN;
1798 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1799 }
1800 return 0;
1801}
1802
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001803int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1804 int app_type, int sample_rate)
1805{
1806 struct platform_data *my_data = (struct platform_data *)platform;
1807 int acdb_dev_id, acdb_dev_type;
1808 int snd_device = SND_DEVICE_OUT_SPEAKER;
1809 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1810 int i, num_devices = 1;
1811
1812 if (!platform_supports_app_type_cfg()) // use v1 instead
1813 return -ENOSYS;
1814
1815 if (usecase->type == PCM_PLAYBACK)
1816 snd_device = usecase->out_snd_device;
1817 else if (usecase->type == PCM_CAPTURE)
1818 snd_device = usecase->in_snd_device;
1819
1820 // skipped over get_spkr_prot_device
1821 acdb_dev_id = acdb_device_table[snd_device];
1822 if (acdb_dev_id < 0) {
1823 ALOGE("%s: Could not find acdb id for device(%d)",
1824 __func__, snd_device);
1825 return -EINVAL;
1826 }
1827
1828 if (platform_can_split_snd_device(snd_device,
1829 &num_devices, new_snd_device) < 0) {
1830 new_snd_device[0] = snd_device;
1831 }
1832
1833 for (i = 0; i < num_devices; i++) {
1834 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1835 if (acdb_dev_id < 0) {
1836 ALOGE("%s: Could not find acdb id for device(%d)",
1837 __func__, new_snd_device[i]);
1838 return -EINVAL;
1839 }
1840 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1841 __func__, new_snd_device[i], acdb_dev_id);
1842 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1843 new_snd_device[i] < SND_DEVICE_OUT_END)
1844 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1845 else
1846 acdb_dev_type = ACDB_DEV_TYPE_IN;
1847
1848 if (my_data->acdb_send_audio_cal_v3) {
1849 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1850 app_type, sample_rate, i);
1851 } else if (my_data->acdb_send_audio_cal) {
1852 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1853 }
1854 }
1855
1856 return 0;
1857}
1858
1859
Eric Laurentb23d5282013-05-14 15:27:20 -07001860int platform_switch_voice_call_device_pre(void *platform)
1861{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001862 struct platform_data *my_data = (struct platform_data *)platform;
1863 int ret = 0;
1864
1865 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001866 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001867 /* This must be called before disabling mixer controls on APQ side */
1868 ret = my_data->csd->disable_device();
1869 if (ret < 0) {
1870 ALOGE("%s: csd_client_disable_device, failed, error %d",
1871 __func__, ret);
1872 }
1873 }
1874 return ret;
1875}
1876
1877int platform_switch_voice_call_enable_device_config(void *platform,
1878 snd_device_t out_snd_device,
1879 snd_device_t in_snd_device)
1880{
1881 struct platform_data *my_data = (struct platform_data *)platform;
1882 int acdb_rx_id, acdb_tx_id;
1883 int ret = 0;
1884
1885 if (my_data->csd == NULL)
1886 return ret;
1887
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001888 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1889 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001890 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001891 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001892 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001893
keunhui.park2f7306a2015-07-16 16:48:06 +09001894 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001895
1896 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1897 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1898 if (ret < 0) {
1899 ALOGE("%s: csd_enable_device_config, failed, error %d",
1900 __func__, ret);
1901 }
1902 } else {
1903 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1904 acdb_rx_id, acdb_tx_id);
1905 }
1906
1907 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001908}
1909
1910int platform_switch_voice_call_device_post(void *platform,
1911 snd_device_t out_snd_device,
1912 snd_device_t in_snd_device)
1913{
1914 struct platform_data *my_data = (struct platform_data *)platform;
1915 int acdb_rx_id, acdb_tx_id;
1916
1917 if (my_data->acdb_send_voice_cal == NULL) {
1918 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1919 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001920 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1921 audio_extn_spkr_prot_is_enabled())
1922 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1923
keunhui.park2f7306a2015-07-16 16:48:06 +09001924 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1925 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001926
1927 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1928 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1929 else
1930 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1931 acdb_rx_id, acdb_tx_id);
1932 }
1933
1934 return 0;
1935}
1936
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001937int platform_switch_voice_call_usecase_route_post(void *platform,
1938 snd_device_t out_snd_device,
1939 snd_device_t in_snd_device)
1940{
1941 struct platform_data *my_data = (struct platform_data *)platform;
1942 int acdb_rx_id, acdb_tx_id;
1943 int ret = 0;
1944
1945 if (my_data->csd == NULL)
1946 return ret;
1947
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001948 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1949 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001950 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001951 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001952 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001953
keunhui.park2f7306a2015-07-16 16:48:06 +09001954 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001955
1956 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1957 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1958 my_data->adev->acdb_settings);
1959 if (ret < 0) {
1960 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1961 }
1962 } else {
1963 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1964 acdb_rx_id, acdb_tx_id);
1965 }
1966
1967 return ret;
1968}
1969
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001970int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001971{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001972 struct platform_data *my_data = (struct platform_data *)platform;
1973 int ret = 0;
1974
1975 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001976 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001977 if (ret < 0) {
1978 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1979 }
1980 }
1981 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001982}
1983
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001984int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001985{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001986 struct platform_data *my_data = (struct platform_data *)platform;
1987 int ret = 0;
1988
1989 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001990 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001991 if (ret < 0) {
1992 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1993 }
1994 }
1995 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001996}
1997
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001998int platform_get_sample_rate(void *platform, uint32_t *rate)
1999{
2000 struct platform_data *my_data = (struct platform_data *)platform;
2001 int ret = 0;
2002
2003 if (my_data->csd != NULL) {
2004 ret = my_data->csd->get_sample_rate(rate);
2005 if (ret < 0) {
2006 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2007 }
2008 }
2009 return ret;
2010}
2011
vivek mehtab6506412015-08-07 16:55:17 -07002012void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2013 snd_device_t snd_device,
2014 bool enable)
2015{
2016 const char* name;
2017 switch (snd_device) {
2018 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2019 if (enable)
2020 name = "spkr-gain-in-headphone-combo";
2021 else
2022 name = "speaker-gain-default";
2023 break;
2024 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2025 if (enable)
2026 name = "spkr-gain-in-line-combo";
2027 else
2028 name = "speaker-gain-default";
2029 break;
2030 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2031 if (enable)
2032 name = "spkr-safe-gain-in-headphone-combo";
2033 else
2034 name = "speaker-safe-gain-default";
2035 break;
2036 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2037 if (enable)
2038 name = "spkr-safe-gain-in-line-combo";
2039 else
2040 name = "speaker-safe-gain-default";
2041 break;
2042 default:
2043 return;
2044 }
2045
2046 audio_route_apply_and_update_path(adev->audio_route, name);
2047}
2048
Eric Laurentb23d5282013-05-14 15:27:20 -07002049int platform_set_voice_volume(void *platform, int volume)
2050{
2051 struct platform_data *my_data = (struct platform_data *)platform;
2052 struct audio_device *adev = my_data->adev;
2053 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002054 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002055 int vol_index = 0, ret = 0;
2056 uint32_t set_values[ ] = {0,
2057 ALL_SESSION_VSID,
2058 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002059
2060 // Voice volume levels are mapped to adsp volume levels as follows.
2061 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2062 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002063 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002064 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002065
2066 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2067 if (!ctl) {
2068 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2069 __func__, mixer_ctl_name);
2070 return -EINVAL;
2071 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002072 ALOGV("Setting voice volume index: %d", set_values[0]);
2073 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2074
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002075 if (my_data->csd != NULL) {
2076 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2077 DEFAULT_VOLUME_RAMP_DURATION_MS);
2078 if (ret < 0) {
2079 ALOGE("%s: csd_volume error %d", __func__, ret);
2080 }
2081 }
2082 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002083}
2084
2085int platform_set_mic_mute(void *platform, bool state)
2086{
2087 struct platform_data *my_data = (struct platform_data *)platform;
2088 struct audio_device *adev = my_data->adev;
2089 struct mixer_ctl *ctl;
2090 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002091 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002092 uint32_t set_values[ ] = {0,
2093 ALL_SESSION_VSID,
2094 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002095
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002096 if (adev->mode != AUDIO_MODE_IN_CALL &&
2097 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002098 return 0;
2099
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002100 if (adev->enable_hfp)
2101 mixer_ctl_name = "HFP Tx Mute";
2102
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002103 set_values[0] = state;
2104 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2105 if (!ctl) {
2106 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2107 __func__, mixer_ctl_name);
2108 return -EINVAL;
2109 }
2110 ALOGV("Setting voice mute state: %d", state);
2111 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2112
2113 if (my_data->csd != NULL) {
2114 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2115 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002116 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002117 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002118 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002119 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002120 return ret;
2121}
Eric Laurentb23d5282013-05-14 15:27:20 -07002122
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002123int platform_set_device_mute(void *platform, bool state, char *dir)
2124{
2125 struct platform_data *my_data = (struct platform_data *)platform;
2126 struct audio_device *adev = my_data->adev;
2127 struct mixer_ctl *ctl;
2128 char *mixer_ctl_name = NULL;
2129 int ret = 0;
2130 uint32_t set_values[ ] = {0,
2131 ALL_SESSION_VSID,
2132 0};
2133 if(dir == NULL) {
2134 ALOGE("%s: Invalid direction:%s", __func__, dir);
2135 return -EINVAL;
2136 }
2137
2138 if (!strncmp("rx", dir, sizeof("rx"))) {
2139 mixer_ctl_name = "Voice Rx Device Mute";
2140 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2141 mixer_ctl_name = "Voice Tx Device Mute";
2142 } else {
2143 return -EINVAL;
2144 }
2145
2146 set_values[0] = state;
2147 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2148 if (!ctl) {
2149 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2150 __func__, mixer_ctl_name);
2151 return -EINVAL;
2152 }
2153
2154 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2155 __func__,state, mixer_ctl_name);
2156 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2157
2158 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002159}
2160
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002161int platform_can_split_snd_device(snd_device_t snd_device,
2162 int *num_devices,
2163 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002164{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002165 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002166 if (NULL == num_devices || NULL == new_snd_devices) {
2167 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002168 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002169 }
2170
2171 /*
2172 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002173 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002174 */
2175 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2176 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2177 *num_devices = 2;
2178 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2179 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002180 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002181 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2182 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2183 *num_devices = 2;
2184 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2185 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002186 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002187 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2188 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2189 *num_devices = 2;
2190 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2191 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002192 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002193 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2194 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2195 *num_devices = 2;
2196 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2197 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002198 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002199 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2200 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2201 SND_DEVICE_OUT_BT_SCO)) {
2202 *num_devices = 2;
2203 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2204 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2205 ret = 0;
2206 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2207 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2208 SND_DEVICE_OUT_BT_SCO_WB)) {
2209 *num_devices = 2;
2210 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2211 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2212 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002213 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2214 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2215 *num_devices = 2;
2216 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2217 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2218 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002219 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002220 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002221}
2222
Eric Laurentb23d5282013-05-14 15:27:20 -07002223snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2224{
2225 struct platform_data *my_data = (struct platform_data *)platform;
2226 struct audio_device *adev = my_data->adev;
2227 audio_mode_t mode = adev->mode;
2228 snd_device_t snd_device = SND_DEVICE_NONE;
2229
2230 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2231 if (devices == AUDIO_DEVICE_NONE ||
2232 devices & AUDIO_DEVICE_BIT_IN) {
2233 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2234 goto exit;
2235 }
2236
Eric Laurent1b491552015-09-15 17:52:41 -07002237 if (popcount(devices) == 2) {
2238 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2239 AUDIO_DEVICE_OUT_SPEAKER) ||
2240 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2241 AUDIO_DEVICE_OUT_SPEAKER)) {
2242 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2243 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2244 AUDIO_DEVICE_OUT_SPEAKER)) {
2245 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2246 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2247 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2248 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2249 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2250 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2251 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2252 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2253 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2254 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2255 AUDIO_DEVICE_OUT_SPEAKER)) {
2256 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002257 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2258 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2259 snd_device = adev->bt_wb_speech_enabled ?
2260 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2261 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
David Linee3fe402017-03-13 10:00:42 -07002262 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2263 AUDIO_DEVICE_OUT_SPEAKER)) {
2264 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002265 } else {
2266 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2267 goto exit;
2268 }
2269 if (snd_device != SND_DEVICE_NONE) {
2270 goto exit;
2271 }
2272 }
2273
2274 if (popcount(devices) != 1) {
2275 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2276 goto exit;
2277 }
2278
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302279 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002280 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002281 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2282 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002283 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002284 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002285 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002286 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002287 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002288 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002289 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002290 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002291 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002292 else {
2293 if (devices & AUDIO_DEVICE_OUT_LINE)
2294 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2295 else
2296 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2297 }
vivek mehtaa6b79742017-03-09 15:40:43 -08002298 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2299 if (voice_is_in_call(adev)) {
2300 switch (adev->voice.tty_mode) {
2301 case TTY_MODE_FULL:
2302 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2303 break;
2304 case TTY_MODE_VCO:
2305 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2306 break;
2307 case TTY_MODE_HCO:
2308 // since Hearing will be on handset\speaker, use existing device
2309 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2310 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002311 case TTY_MODE_OFF:
2312 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002313 default:
2314 ALOGE("%s: Invalid TTY mode (%#x)",
2315 __func__, adev->voice.tty_mode);
2316 }
2317 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002318 if (snd_device == SND_DEVICE_NONE) {
2319 snd_device = audio_extn_usb_is_capture_supported() ?
2320 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2321 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2322 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002323 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002324 if (adev->bt_wb_speech_enabled) {
2325 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2326 } else {
2327 snd_device = SND_DEVICE_OUT_BT_SCO;
2328 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002329 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002330 if (!adev->enable_hfp) {
2331 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2332 } else {
2333 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2334 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002335 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002336 if(adev->voice.hac)
2337 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2338 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002339 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2340 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002341 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002342 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2343 snd_device = SND_DEVICE_OUT_VOICE_TX;
2344
Eric Laurentb23d5282013-05-14 15:27:20 -07002345 if (snd_device != SND_DEVICE_NONE) {
2346 goto exit;
2347 }
2348 }
2349
Eric Laurentb23d5282013-05-14 15:27:20 -07002350 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2351 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2352 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002353 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2354 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002355 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2356 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002357 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002358 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002359 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2360 else
2361 snd_device = SND_DEVICE_OUT_SPEAKER;
2362 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002363 if (adev->bt_wb_speech_enabled) {
2364 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2365 } else {
2366 snd_device = SND_DEVICE_OUT_BT_SCO;
2367 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002368 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2369 snd_device = SND_DEVICE_OUT_HDMI ;
David Linee3fe402017-03-13 10:00:42 -07002370 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2371 if (audio_extn_usb_is_capture_supported())
2372 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2373 else
2374 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2375 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002376 /*HAC support for voice-ish audio (eg visual voicemail)*/
2377 if(adev->voice.hac)
2378 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2379 else
2380 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002381 } else {
2382 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2383 }
2384exit:
2385 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2386 return snd_device;
2387}
2388
2389snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2390{
2391 struct platform_data *my_data = (struct platform_data *)platform;
2392 struct audio_device *adev = my_data->adev;
2393 audio_source_t source = (adev->active_input == NULL) ?
2394 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2395
2396 audio_mode_t mode = adev->mode;
2397 audio_devices_t in_device = ((adev->active_input == NULL) ?
2398 AUDIO_DEVICE_NONE : adev->active_input->device)
2399 & ~AUDIO_DEVICE_BIT_IN;
2400 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2401 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2402 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002403 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002404
Prashant Malanic92c5962015-08-11 15:10:18 -07002405 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2406 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002407 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2408 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002409 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002410 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002411 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2412 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002413 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002414 case TTY_MODE_FULL:
2415 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2416 break;
2417 case TTY_MODE_VCO:
2418 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2419 break;
2420 case TTY_MODE_HCO:
2421 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2422 break;
2423 default:
2424 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2425 }
2426 goto exit;
2427 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2428 switch (adev->voice.tty_mode) {
2429 case TTY_MODE_FULL:
2430 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2431 break;
2432 case TTY_MODE_VCO:
2433 // since voice will be captured from handset mic, use existing device
2434 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2435 break;
2436 case TTY_MODE_HCO:
2437 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2438 break;
2439 default:
2440 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002441 }
2442 goto exit;
2443 }
2444 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002445 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002446 if (my_data->fluence_in_voice_call == false) {
2447 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2448 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002449 if (is_operator_tmus())
2450 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002451 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002452 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002453 }
2454 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2455 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2456 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002457 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002458 if (adev->bluetooth_nrec)
2459 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2460 else
2461 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002462 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002463 if (adev->bluetooth_nrec)
2464 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2465 else
2466 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002467 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002468 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002469 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2470 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2471 out_device & AUDIO_DEVICE_OUT_LINE) {
2472 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2473 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2474 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2475 } else {
2476 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2477 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002478 }
vivek mehtafe121d52015-08-10 23:39:23 -07002479
2480 //select default
2481 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002482 if (!adev->enable_hfp) {
2483 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2484 } else {
2485 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2486 platform_set_echo_reference(adev, true, out_device);
2487 }
vivek mehtafe121d52015-08-10 23:39:23 -07002488 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002489 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002490 snd_device = SND_DEVICE_IN_VOICE_RX;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002491 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2492 if (audio_extn_usb_is_capture_supported()) {
2493 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2494 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002495 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002496 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2497 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2498 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2499 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2500 }
2501 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2502 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002503 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2504 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2505 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002506 if (adev->active_input->enable_aec)
2507 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2508 else
2509 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002510 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2511 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002512 if (adev->active_input->enable_aec)
2513 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2514 else
2515 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002516 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2517 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2518 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002519 if (adev->active_input->enable_aec)
2520 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2521 else
2522 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002523 }
2524 platform_set_echo_reference(adev, true, out_device);
2525 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2526 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2527 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002528 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002529 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2530 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002531 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002532 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2533 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002534 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002535 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002536 if (adev->active_input->enable_aec) {
2537 if (adev->active_input->enable_ns) {
2538 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2539 } else {
2540 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2541 }
vivek mehta733c1df2016-04-04 15:09:24 -07002542 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002543 } else if (adev->active_input->enable_ns) {
2544 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2545 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002546 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002547 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002548 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002549 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2550 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002551 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2552 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002553 }
rago90fb9612015-12-02 11:37:53 -08002554 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2555 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002556 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2557 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2558 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2559 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002560 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002561 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2562 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002563 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002564 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2565 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2566 } else {
2567 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2568 }
rago90fb9612015-12-02 11:37:53 -08002569 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2570 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002571 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2572 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002573 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002574 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002575 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002576 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002577 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2578 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002579 if (adev->active_input->enable_aec &&
2580 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002581 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002582 if (my_data->fluence_in_spkr_mode &&
2583 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002584 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002585 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002586 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002587 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002588 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002589 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002590 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002591 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002592 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002593 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002594 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002595 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002596 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2597 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002598 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2599 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002600 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002601 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002602 } else if (adev->active_input->enable_aec) {
2603 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2604 if (my_data->fluence_in_spkr_mode &&
2605 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002606 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002607 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002608 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002609 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002610 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002611 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2612 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002613 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002614 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002615 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002616 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002617 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002618 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2619 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002620 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2621 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002622 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002623 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002624 } else if (adev->active_input->enable_ns) {
2625 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2626 if (my_data->fluence_in_spkr_mode &&
2627 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002628 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002629 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002630 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002631 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002632 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002633 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2634 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002635 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002636 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002637 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002638 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002639 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002640 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002641 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002642 }
2643 } else if (source == AUDIO_SOURCE_DEFAULT) {
2644 goto exit;
2645 }
2646
2647
2648 if (snd_device != SND_DEVICE_NONE) {
2649 goto exit;
2650 }
2651
2652 if (in_device != AUDIO_DEVICE_NONE &&
2653 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2654 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2655 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002656 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002657 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002658 snd_device = SND_DEVICE_IN_QUAD_MIC;
2659 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002660 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002661 snd_device = SND_DEVICE_IN_THREE_MIC;
2662 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2663 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002664 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002665 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2666 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002667 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002668 } else {
2669 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2670 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2671 my_data->source_mic_type, channel_count, channel_mask);
2672 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2673 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002674 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002675 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2676 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002677 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002678 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2679 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002680 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002681 } else {
2682 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2683 " no combination found .. setting to mono", __func__,
2684 my_data->source_mic_type, channel_count);
2685 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2686 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002687 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2688 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2689 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002690 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002691 if (adev->bluetooth_nrec)
2692 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2693 else
2694 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002695 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002696 if (adev->bluetooth_nrec)
2697 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2698 else
2699 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002700 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002701 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2702 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002703 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2704 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002705 } else {
2706 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2707 ALOGW("%s: Using default handset-mic", __func__);
2708 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2709 }
2710 } else {
2711 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2712 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2713 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2714 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002715 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002716 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002717 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002718 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002719 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2720 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002721 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002722 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2723 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002724 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002725 } else {
2726 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2727 " no combination found .. setting to mono", __func__,
2728 my_data->source_mic_type, channel_count);
2729 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2730 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002731 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002732 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002733 if (adev->bluetooth_nrec)
2734 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2735 else
2736 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002737 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002738 if (adev->bluetooth_nrec)
2739 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2740 else
2741 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002742 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002743 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2744 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002745 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2746 if (audio_extn_usb_is_capture_supported())
2747 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2748 else
2749 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002750 } else {
2751 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2752 ALOGW("%s: Using default handset-mic", __func__);
2753 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2754 }
2755 }
2756exit:
2757 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2758 return snd_device;
2759}
2760
2761int platform_set_hdmi_channels(void *platform, int channel_count)
2762{
2763 struct platform_data *my_data = (struct platform_data *)platform;
2764 struct audio_device *adev = my_data->adev;
2765 struct mixer_ctl *ctl;
2766 const char *channel_cnt_str = NULL;
2767 const char *mixer_ctl_name = "HDMI_RX Channels";
2768 switch (channel_count) {
2769 case 8:
2770 channel_cnt_str = "Eight"; break;
2771 case 7:
2772 channel_cnt_str = "Seven"; break;
2773 case 6:
2774 channel_cnt_str = "Six"; break;
2775 case 5:
2776 channel_cnt_str = "Five"; break;
2777 case 4:
2778 channel_cnt_str = "Four"; break;
2779 case 3:
2780 channel_cnt_str = "Three"; break;
2781 default:
2782 channel_cnt_str = "Two"; break;
2783 }
2784 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2785 if (!ctl) {
2786 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2787 __func__, mixer_ctl_name);
2788 return -EINVAL;
2789 }
2790 ALOGV("HDMI channel count: %s", channel_cnt_str);
2791 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2792 return 0;
2793}
2794
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002795int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002796{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002797 struct platform_data *my_data = (struct platform_data *)platform;
2798 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002799 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2800 char *sad = block;
2801 int num_audio_blocks;
2802 int channel_count;
2803 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002804 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002805
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002806 struct mixer_ctl *ctl;
2807
2808 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2809 if (!ctl) {
2810 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2811 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002812 return 0;
2813 }
2814
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002815 mixer_ctl_update(ctl);
2816
2817 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002818
2819 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002820 if (count > (int)sizeof(block))
2821 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002822
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002823 ret = mixer_ctl_get_array(ctl, block, count);
2824 if (ret != 0) {
2825 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2826 return 0;
2827 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002828
2829 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002830 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002831
2832 for (i = 0; i < num_audio_blocks; i++) {
2833 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002834 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2835 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002836 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002837 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002838
2839 channel_count = (sad[0] & 0x7) + 1;
2840 if (channel_count > max_channels)
2841 max_channels = channel_count;
2842
2843 /* Advance to next block */
2844 sad += 3;
2845 }
2846
2847 return max_channels;
2848}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002849
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002850int platform_set_incall_recording_session_id(void *platform,
2851 uint32_t session_id, int rec_mode)
2852{
2853 int ret = 0;
2854 struct platform_data *my_data = (struct platform_data *)platform;
2855 struct audio_device *adev = my_data->adev;
2856 struct mixer_ctl *ctl;
2857 const char *mixer_ctl_name = "Voc VSID";
2858 int num_ctl_values;
2859 int i;
2860
2861 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2862 if (!ctl) {
2863 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2864 __func__, mixer_ctl_name);
2865 ret = -EINVAL;
2866 } else {
2867 num_ctl_values = mixer_ctl_get_num_values(ctl);
2868 for (i = 0; i < num_ctl_values; i++) {
2869 if (mixer_ctl_set_value(ctl, i, session_id)) {
2870 ALOGV("Error: invalid session_id: %x", session_id);
2871 ret = -EINVAL;
2872 break;
2873 }
2874 }
2875 }
2876
2877 if (my_data->csd != NULL) {
2878 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2879 if (ret < 0) {
2880 ALOGE("%s: csd_client_start_record failed, error %d",
2881 __func__, ret);
2882 }
2883 }
2884
2885 return ret;
2886}
2887
2888int platform_stop_incall_recording_usecase(void *platform)
2889{
2890 int ret = 0;
2891 struct platform_data *my_data = (struct platform_data *)platform;
2892
2893 if (my_data->csd != NULL) {
2894 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2895 if (ret < 0) {
2896 ALOGE("%s: csd_client_stop_record failed, error %d",
2897 __func__, ret);
2898 }
2899 }
2900
2901 return ret;
2902}
2903
2904int platform_start_incall_music_usecase(void *platform)
2905{
2906 int ret = 0;
2907 struct platform_data *my_data = (struct platform_data *)platform;
2908
2909 if (my_data->csd != NULL) {
2910 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2911 if (ret < 0) {
2912 ALOGE("%s: csd_client_start_playback failed, error %d",
2913 __func__, ret);
2914 }
2915 }
2916
2917 return ret;
2918}
2919
2920int platform_stop_incall_music_usecase(void *platform)
2921{
2922 int ret = 0;
2923 struct platform_data *my_data = (struct platform_data *)platform;
2924
2925 if (my_data->csd != NULL) {
2926 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2927 if (ret < 0) {
2928 ALOGE("%s: csd_client_stop_playback failed, error %d",
2929 __func__, ret);
2930 }
2931 }
2932
2933 return ret;
2934}
2935
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002936int platform_set_parameters(void *platform, struct str_parms *parms)
2937{
2938 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002939 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002940 char *kv_pairs = str_parms_to_str(parms);
2941 int ret = 0, err;
2942
2943 if (kv_pairs == NULL) {
2944 ret = -EINVAL;
2945 ALOGE("%s: key-value pair is NULL",__func__);
2946 goto done;
2947 }
2948
2949 ALOGV("%s: enter: %s", __func__, kv_pairs);
2950
2951 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2952 value, sizeof(value));
2953 if (err >= 0) {
2954 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2955 my_data->snd_card_name = strdup(value);
2956 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2957 }
2958
keunhui.park2f7306a2015-07-16 16:48:06 +09002959 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2960 value, sizeof(value));
2961 if (err >= 0) {
2962 struct operator_info *info;
2963 char *str = value;
2964 char *name;
2965
2966 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2967 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2968 name = strtok(str, ";");
2969 info->name = strdup(name);
2970 info->mccmnc = strdup(str + strlen(name) + 1);
2971
2972 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002973 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002974 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002975
2976 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002977 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002978 value, sizeof(value));
2979 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002980 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002981 my_data->max_mic_count = atoi(value);
2982 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002983 }
2984
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002985done:
2986 ALOGV("%s: exit with code(%d)", __func__, ret);
2987 if (kv_pairs != NULL)
2988 free(kv_pairs);
2989
2990 return ret;
2991}
2992
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002993/* Delay in Us */
2994int64_t platform_render_latency(audio_usecase_t usecase)
2995{
2996 switch (usecase) {
2997 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2998 return DEEP_BUFFER_PLATFORM_DELAY;
2999 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3000 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003001 case USECASE_AUDIO_PLAYBACK_ULL:
3002 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003003 case USECASE_AUDIO_PLAYBACK_MMAP:
3004 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003005 default:
3006 return 0;
3007 }
3008}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003009
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003010int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3011 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003012{
3013 int ret = 0;
3014
3015 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3016 ALOGE("%s: Invalid snd_device = %d",
3017 __func__, device);
3018 ret = -EINVAL;
3019 goto done;
3020 }
3021
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003022 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3023 platform_get_snd_device_name(device),
3024 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3025 if (backend_tag_table[device]) {
3026 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003027 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003028 backend_tag_table[device] = strdup(backend_tag);
3029
3030 if (hw_interface != NULL) {
3031 if (hw_interface_table[device])
3032 free(hw_interface_table[device]);
3033 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3034 hw_interface_table[device] = strdup(hw_interface);
3035 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003036done:
3037 return ret;
3038}
3039
3040int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3041{
3042 int ret = 0;
3043 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3044 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3045 ret = -EINVAL;
3046 goto done;
3047 }
3048
3049 if ((type != 0) && (type != 1)) {
3050 ALOGE("%s: invalid usecase type", __func__);
3051 ret = -EINVAL;
3052 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003053 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003054 pcm_device_table[usecase][type] = pcm_id;
3055done:
3056 return ret;
3057}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003058
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003059#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3060int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3061 // backup_gain: gain to try to set in case of an error during ramp
3062 int start_gain, end_gain, step, backup_gain, i;
3063 bool error = false;
3064 const struct mixer_ctl *ctl;
3065 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3066 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3067 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3068 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3069 if (!ctl_left || !ctl_right) {
3070 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3071 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3072 return -EINVAL;
3073 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3074 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3075 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3076 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3077 return -EINVAL;
3078 }
3079 if (ramp_up) {
3080 start_gain = 0;
3081 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3082 step = +1;
3083 backup_gain = end_gain;
3084 } else {
3085 // using same gain on left and right
3086 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3087 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3088 end_gain = 0;
3089 step = -1;
3090 backup_gain = start_gain;
3091 }
3092 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3093 //ALOGV("setting speaker gain to %d", i);
3094 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3095 ALOGE("%s: error setting %s to %d during gain ramp",
3096 __func__, mixer_ctl_name_gain_left, i);
3097 error = true;
3098 break;
3099 }
3100 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3101 ALOGE("%s: error setting %s to %d during gain ramp",
3102 __func__, mixer_ctl_name_gain_right, i);
3103 error = true;
3104 break;
3105 }
3106 usleep(1000);
3107 }
3108 if (error) {
3109 // an error occured during the ramp, let's still try to go back to a safe volume
3110 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3111 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3112 }
3113 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3114 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3115 }
3116 }
3117 return start_gain;
3118}
3119
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003120int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
3121{
3122 // only update if there is active pcm playback on speaker
3123 struct audio_usecase *usecase;
3124 struct listnode *node;
3125 struct platform_data *my_data = (struct platform_data *)adev->platform;
3126
3127 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003128
3129 // do not swap channels in audio modes with concurrent capture and playback
3130 // as this may break the echo reference
3131 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3132 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3133 return 0;
3134 }
3135
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003136 my_data->speaker_lr_swap = swap_channels;
3137
3138 list_for_each(node, &adev->usecase_list) {
3139 usecase = node_to_item(node, struct audio_usecase, list);
3140 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003141 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3142 /*
3143 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3144 * to perform device switch to disable the current backend to
3145 * enable it with new acdb data.
3146 */
3147 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3148 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003149 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003150 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003151 if (initial_skpr_gain != -EINVAL) {
3152 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3153 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003154 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003155 const char *mixer_path;
3156 if (swap_channels) {
3157 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3158 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3159 } else {
3160 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3161 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3162 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003163 }
3164 break;
3165 }
3166 }
3167 }
3168 return 0;
3169}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003170
3171static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3172static int num_gain_tbl_entry = 0;
3173
3174bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3175
3176 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3177 if (num_gain_tbl_entry == -1) {
3178 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3179 __func__);
3180 return false;
3181 }
3182
3183 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3184 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3185 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3186 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3187 return false;
3188 }
3189
3190 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3191 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3192 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3193 return false;
3194 }
3195
3196 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3197 ++num_gain_tbl_entry;
3198
3199 return true;
3200}
3201
3202int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3203 int table_size) {
3204 int itt = 0;
3205 ALOGV("platform_get_gain_level_mapping called ");
3206
3207 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3208 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3209 return 0;
3210 }
3211
3212 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3213 mapping_tbl[itt] = tbl_mapping[itt];
3214 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3215 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3216 }
3217
3218 return num_gain_tbl_entry;
3219}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003220
3221int platform_snd_card_update(void *platform, card_status_t status)
3222{
3223 struct platform_data *my_data = (struct platform_data *)platform;
3224 struct audio_device *adev = my_data->adev;
3225
3226 if (status == CARD_STATUS_ONLINE) {
3227 if (my_data->acdb_send_custom_top)
3228 my_data->acdb_send_custom_top();
3229 }
3230 return 0;
3231}
David Linee3fe402017-03-13 10:00:42 -07003232
3233/*
3234 * configures afe with bit width and Sample Rate
3235 */
3236static int platform_set_backend_cfg(const struct audio_device* adev,
3237 snd_device_t snd_device,
3238 const struct audio_backend_cfg *backend_cfg)
3239{
3240
3241 int ret = 0;
3242 const int backend_idx = platform_get_backend_index(snd_device);
3243 struct platform_data *my_data = (struct platform_data *)adev->platform;
3244 const unsigned int bit_width = backend_cfg->bit_width;
3245 const unsigned int sample_rate = backend_cfg->sample_rate;
3246 const unsigned int channels = backend_cfg->channels;
3247 const audio_format_t format = backend_cfg->format;
3248 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3249
3250
3251 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3252 ", backend_idx %d device (%s)", __func__, bit_width,
3253 sample_rate, channels, backend_idx,
3254 platform_get_snd_device_name(snd_device));
3255
3256 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3257 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3258
3259 struct mixer_ctl *ctl = NULL;
3260 ctl = mixer_get_ctl_by_name(adev->mixer,
3261 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3262 if (!ctl) {
3263 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3264 __func__,
3265 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3266 return -EINVAL;
3267 }
3268
3269 if (bit_width == 24) {
3270 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3271 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3272 else
3273 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3274 } else if (bit_width == 32) {
3275 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3276 } else {
3277 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3278 }
3279 if ( ret < 0) {
3280 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3281 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3282 } else {
3283 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3284 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3285 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3286 }
3287 /* set the ret as 0 and not pass back to upper layer */
3288 ret = 0;
3289 }
3290
3291 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3292 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3293 char *rate_str = NULL;
3294 struct mixer_ctl *ctl = NULL;
3295
3296 switch (sample_rate) {
3297 case 32000:
3298 if (passthrough_enabled) {
3299 rate_str = "KHZ_32";
3300 break;
3301 }
3302 case 8000:
3303 case 11025:
3304 case 16000:
3305 case 22050:
3306 case 48000:
3307 rate_str = "KHZ_48";
3308 break;
3309 case 44100:
3310 rate_str = "KHZ_44P1";
3311 break;
3312 case 64000:
3313 case 96000:
3314 rate_str = "KHZ_96";
3315 break;
3316 case 88200:
3317 rate_str = "KHZ_88P2";
3318 break;
3319 case 176400:
3320 rate_str = "KHZ_176P4";
3321 break;
3322 case 192000:
3323 rate_str = "KHZ_192";
3324 break;
3325 case 352800:
3326 rate_str = "KHZ_352P8";
3327 break;
3328 case 384000:
3329 rate_str = "KHZ_384";
3330 break;
3331 case 144000:
3332 if (passthrough_enabled) {
3333 rate_str = "KHZ_144";
3334 break;
3335 }
3336 default:
3337 rate_str = "KHZ_48";
3338 break;
3339 }
3340
3341 ctl = mixer_get_ctl_by_name(adev->mixer,
3342 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3343 if(!ctl) {
3344 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3345 __func__,
3346 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3347 return -EINVAL;
3348 }
3349
3350 ALOGD("%s:becf: afe: %s set to %s", __func__,
3351 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3352 mixer_ctl_set_enum_by_string(ctl, rate_str);
3353 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3354 }
3355 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3356 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3357 struct mixer_ctl *ctl = NULL;
3358 char *channel_cnt_str = NULL;
3359
3360 switch (channels) {
3361 case 8:
3362 channel_cnt_str = "Eight"; break;
3363 case 7:
3364 channel_cnt_str = "Seven"; break;
3365 case 6:
3366 channel_cnt_str = "Six"; break;
3367 case 5:
3368 channel_cnt_str = "Five"; break;
3369 case 4:
3370 channel_cnt_str = "Four"; break;
3371 case 3:
3372 channel_cnt_str = "Three"; break;
3373 case 1:
3374 channel_cnt_str = "One"; break;
3375 case 2:
3376 default:
3377 channel_cnt_str = "Two"; break;
3378 }
3379
3380 ctl = mixer_get_ctl_by_name(adev->mixer,
3381 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3382 if (!ctl) {
3383 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3384 __func__,
3385 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3386 return -EINVAL;
3387 }
3388 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3389 my_data->current_backend_cfg[backend_idx].channels = channels;
3390
3391 // skip EDID configuration for HDMI backend
3392
3393 ALOGD("%s:becf: afe: %s set to %s", __func__,
3394 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3395 channel_cnt_str);
3396 }
3397
3398 // skip set ext_display format mixer control
3399 return ret;
3400}
3401
3402static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3403{
3404 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3405 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3406 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3407 }
3408
3409 return backend_bit_width_table[snd_device];
3410}
3411
3412/*
3413 * return backend_idx on which voice call is active
3414 */
3415static int platform_get_voice_call_backend(struct audio_device* adev)
3416{
3417 struct audio_usecase *uc = NULL;
3418 struct listnode *node;
3419 snd_device_t out_snd_device = SND_DEVICE_NONE;
3420
3421 int backend_idx = -1;
3422
3423 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3424 list_for_each(node, &adev->usecase_list) {
3425 uc = node_to_item(node, struct audio_usecase, list);
3426 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3427 out_snd_device = platform_get_output_snd_device(adev->platform,
3428 uc->stream.out->devices);
3429 backend_idx = platform_get_backend_index(out_snd_device);
3430 break;
3431 }
3432 }
3433 }
3434 return backend_idx;
3435}
3436
3437/*
3438 * goes through all the current usecases and picks the highest
3439 * bitwidth & samplerate
3440 */
3441static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3442 int backend_idx,
3443 struct audio_backend_cfg *backend_cfg)
3444{
3445 bool backend_change = false;
3446 unsigned int bit_width;
3447 unsigned int sample_rate;
3448 unsigned int channels;
3449 struct platform_data *my_data = (struct platform_data *)adev->platform;
3450
3451 bit_width = backend_cfg->bit_width;
3452 sample_rate = backend_cfg->sample_rate;
3453 channels = backend_cfg->channels;
3454
3455 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3456 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3457 sample_rate, channels);
3458
3459 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3460 // default backend
3461 // force routing is not required here, caller will do it anyway
3462 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3463 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3464 "for unprocessed/camera source", __func__);
3465 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3466 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3467 }
3468
3469 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3470 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3471 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3472 __func__, bit_width, sample_rate, channels);
3473 }
3474
3475 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3476 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3477
3478 // Force routing if the expected bitwdith or samplerate
3479 // is not same as current backend comfiguration
3480 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3481 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3482 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3483 backend_cfg->bit_width = bit_width;
3484 backend_cfg->sample_rate= sample_rate;
3485 backend_cfg->channels = channels;
3486 backend_change = true;
3487 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3488 "new sample rate: %d new channel: %d",
3489 __func__, backend_cfg->bit_width,
3490 backend_cfg->sample_rate, backend_cfg->channels);
3491 }
3492
3493 return backend_change;
3494}
3495
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003496static void pick_playback_cfg_for_uc(struct audio_device *adev,
3497 struct audio_usecase *usecase,
3498 snd_device_t snd_device,
3499 unsigned int *bit_width,
3500 unsigned int *sample_rate,
3501 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003502{
3503 int i =0;
3504 struct listnode *node;
3505 list_for_each(node, &adev->usecase_list) {
3506 struct audio_usecase *uc;
3507 uc = node_to_item(node, struct audio_usecase, list);
3508 struct stream_out *out = (struct stream_out*) uc->stream.out;
3509 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3510 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3511 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3512 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3513 uc->id, out->sample_rate,
3514 pcm_format_to_bits(out->config.format), out_channels,
3515 platform_get_snd_device_name(uc->out_snd_device));
3516
3517 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3518 if (*bit_width < pcm_format_to_bits(out->config.format))
3519 *bit_width = pcm_format_to_bits(out->config.format);
3520 if (*sample_rate < out->sample_rate)
3521 *sample_rate = out->sample_rate;
3522 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3523 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3524 if (*channels < out_channels)
3525 *channels = out_channels;
3526 }
3527 }
3528 }
3529 return;
3530}
3531
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003532static void headset_is_config_supported(unsigned int *bit_width,
3533 unsigned int *sample_rate,
3534 unsigned int *channels) {
3535 switch (*bit_width) {
3536 case 16:
3537 case 24:
3538 break;
3539 default:
3540 *bit_width = 16;
3541 break;
3542 }
3543
3544 if (*sample_rate > 192000) {
3545 *sample_rate = 192000;
3546 }
3547
3548 if (*channels > 2) {
3549 *channels = 2;
3550 }
3551}
3552
David Linee3fe402017-03-13 10:00:42 -07003553static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3554 struct audio_usecase* usecase,
3555 snd_device_t snd_device,
3556 struct audio_backend_cfg *backend_cfg)
3557{
3558 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003559 unsigned int bit_width;
3560 unsigned int sample_rate;
3561 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003562 int backend_idx = DEFAULT_CODEC_BACKEND;
3563 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003564
3565 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3566 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3567 backend_change = false;
3568 return backend_change;
3569 }
3570
3571 backend_idx = platform_get_backend_index(snd_device);
3572 bit_width = backend_cfg->bit_width;
3573 sample_rate = backend_cfg->sample_rate;
3574 channels = backend_cfg->channels;
3575
3576 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3577 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3578 sample_rate, channels, backend_idx, usecase->id,
3579 platform_get_snd_device_name(snd_device));
3580
3581 if (backend_idx == platform_get_voice_call_backend(adev)) {
3582 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3583 __func__);
3584 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3585 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3586 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3587 } else {
3588 /*
3589 * The backend should be configured at highest bit width and/or
3590 * sample rate amongst all playback usecases.
3591 * If the selected sample rate and/or bit width differ with
3592 * current backend sample rate and/or bit width, then, we set the
3593 * backend re-configuration flag.
3594 *
3595 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3596 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003597 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3598 &bit_width,
3599 &sample_rate,
3600 &channels);
David Linee3fe402017-03-13 10:00:42 -07003601 }
3602
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003603 switch (backend_idx) {
3604 case USB_AUDIO_RX_BACKEND:
3605 audio_extn_usb_is_config_supported(&bit_width,
3606 &sample_rate, &channels, true);
3607 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3608 __func__, bit_width, sample_rate, channels);
3609 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003610 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003611 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3612 break;
3613 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003614 default:
3615 bit_width = platform_get_snd_device_bit_width(snd_device);
3616 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3617 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3618 break;
David Linee3fe402017-03-13 10:00:42 -07003619 }
3620
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003621 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3622 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003623 __func__, backend_idx , bit_width, sample_rate);
3624
3625 // Force routing if the expected bitwdith or samplerate
3626 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003627 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3628 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3629 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003630 backend_cfg->bit_width = bit_width;
3631 backend_cfg->sample_rate = sample_rate;
3632 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003633 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003634 backend_change = true;
3635 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3636 "new sample rate: %d new channels: %d",
3637 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3638 }
3639
3640 return backend_change;
3641}
3642
3643bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3644 struct audio_usecase *usecase, snd_device_t snd_device)
3645{
3646 int backend_idx = DEFAULT_CODEC_BACKEND;
3647 int new_snd_devices[SND_DEVICE_OUT_END];
3648 int i, num_devices = 1;
3649 bool ret = false;
3650 struct platform_data *my_data = (struct platform_data *)adev->platform;
3651 struct audio_backend_cfg backend_cfg;
3652
3653 backend_idx = platform_get_backend_index(snd_device);
3654
3655 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3656 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3657 backend_cfg.format = usecase->stream.out->format;
3658 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3659 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3660 backend_cfg.passthrough_enabled = false;
3661
3662 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3663 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3664 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3665 platform_get_snd_device_name(snd_device));
3666
3667 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3668 new_snd_devices[0] = snd_device;
3669
3670 for (i = 0; i < num_devices; i++) {
3671 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3672 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3673 &backend_cfg))) {
3674 platform_set_backend_cfg(adev, new_snd_devices[i],
3675 &backend_cfg);
3676 ret = true;
3677 }
3678 }
3679 return ret;
3680}
3681
3682bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3683 struct audio_usecase *usecase, snd_device_t snd_device)
3684{
3685 int backend_idx = platform_get_backend_index(snd_device);
3686 int ret = 0;
3687 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003688 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003689
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003690 if (usecase->type == PCM_CAPTURE) {
3691 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003692 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3693 } else {
3694 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3695 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3696 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3697 backend_cfg.channels = 1;
3698 }
3699
3700 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3701 ", backend_idx %d usecase = %d device (%s)", __func__,
3702 backend_cfg.bit_width,
3703 backend_cfg.sample_rate,
3704 backend_cfg.channels,
3705 backend_idx, usecase->id,
3706 platform_get_snd_device_name(snd_device));
3707
3708 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3709 ret = platform_set_backend_cfg(adev, snd_device,
3710 &backend_cfg);
3711 if(!ret)
3712 return true;
3713 }
3714
3715 return false;
3716}
3717
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003718static int max_be_dai_names = 0;
3719static const struct be_dai_name_struct *be_dai_name_table;
3720
3721/*
3722 * Retrieves the be_dai_name_table from kernel to enable a mapping
3723 * between sound device hw interfaces and backend IDs. This allows HAL to
3724 * specify the backend a specific calibration is needed for.
3725 */
3726static int init_be_dai_name_table(struct audio_device *adev)
3727{
3728 const char *mixer_ctl_name = "Backend DAI Name Table";
3729 struct mixer_ctl *ctl;
3730 int i, j, ret, size;
3731 bool valid_hw_interface;
3732
3733 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3734 if (!ctl) {
3735 ALOGE("%s: Could not get ctl for mixer name %s\n",
3736 __func__, mixer_ctl_name);
3737 ret = -EINVAL;
3738 goto done;
3739 }
3740
3741 mixer_ctl_update(ctl);
3742
3743 size = mixer_ctl_get_num_values(ctl);
3744 if (size <= 0){
3745 ALOGE("%s: Failed to get %s size %d\n",
3746 __func__, mixer_ctl_name, size);
3747 ret = -EFAULT;
3748 goto done;
3749 }
3750
3751 posix_memalign((void **)&be_dai_name_table, 32, size);
3752 if (be_dai_name_table == NULL) {
3753 ALOGE("%s: Failed to allocate memory for %s\n",
3754 __func__, mixer_ctl_name);
3755 ret = -ENOMEM;
3756 goto freeMem;
3757 }
3758
3759 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3760 if (ret) {
3761 ALOGE("%s: Failed to get %s, ret %d\n",
3762 __func__, mixer_ctl_name, ret);
3763 ret = -EFAULT;
3764 goto freeMem;
3765 }
3766
3767 if (be_dai_name_table != NULL) {
3768 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3769 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3770 __func__, mixer_ctl_name, max_be_dai_names);
3771 ret = 0;
3772 } else {
3773 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3774 ret = -EFAULT;
3775 goto freeMem;
3776 }
3777
3778 /*
3779 * Validate all sound devices have a valid backend set to catch
3780 * errors for uncommon sound devices
3781 */
3782 for (i = 0; i < SND_DEVICE_MAX; i++) {
3783 valid_hw_interface = false;
3784
3785 if (hw_interface_table[i] == NULL) {
3786 ALOGW("%s: sound device %s has no hw interface set\n",
3787 __func__, platform_get_snd_device_name(i));
3788 continue;
3789 }
3790
3791 for (j = 0; j < max_be_dai_names; j++) {
3792 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3793 == 0) {
3794 valid_hw_interface = true;
3795 break;
3796 }
3797 }
3798 if (!valid_hw_interface)
3799 ALOGD("%s: sound device %s does not have a valid hw interface set "
3800 "(disregard for combo devices) %s\n",
3801 __func__, platform_get_snd_device_name(i),
3802 hw_interface_table[i]);
3803 }
3804
3805 goto done;
3806
3807freeMem:
3808 if (be_dai_name_table) {
3809 free((void *)be_dai_name_table);
3810 be_dai_name_table = NULL;
3811 }
3812
3813done:
3814 return ret;
3815}
3816
3817int platform_get_snd_device_backend_index(snd_device_t device)
3818{
3819 int i, be_dai_id;
3820 const char * hw_interface_name = NULL;
3821
3822 ALOGV("%s: enter with device %d\n", __func__, device);
3823
3824 if ((device <= SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3825 ALOGE("%s: Invalid snd_device = %d",
3826 __func__, device);
3827 be_dai_id = -EINVAL;
3828 goto done;
3829 }
3830
3831 /* Get string value of necessary backend for device */
3832 hw_interface_name = hw_interface_table[device];
3833 if (hw_interface_name == NULL) {
3834 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3835 be_dai_id = -EINVAL;
3836 goto done;
3837 }
3838
3839 /* Check if be dai name table was retrieved successfully */
3840 if (be_dai_name_table == NULL) {
3841 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3842 be_dai_id = -EFAULT;
3843 goto done;
3844 }
3845
3846 /* Get backend ID for device specified */
3847 for (i = 0; i < max_be_dai_names; i++) {
3848 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3849 be_dai_id = be_dai_name_table[i].be_id;
3850 goto done;
3851 }
3852 }
3853 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3854 be_dai_id = -EINVAL;
3855 goto done;
3856
3857done:
3858 return be_dai_id;
3859}
3860
3861void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3862 unsigned int stream_sr, int* sample_rate)
3863{
3864 struct platform_data* my_data = (struct platform_data *)platform;
3865 int backend_idx = platform_get_backend_index(snd_device);
3866 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3867 /*
3868 *Check if device SR is multiple of 8K or 11.025 Khz
3869 *check if the stream SR is multiple of same base, if yes
3870 *then have copp SR equal to stream SR, this ensures that
3871 *post processing happens at stream SR, else have
3872 *copp SR equal to device SR.
3873 */
3874 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3875 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3876 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3877 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
3878 *sample_rate = device_sr;
3879 } else
3880 *sample_rate = stream_sr;
3881
3882 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
3883 , *sample_rate);
3884
3885}
3886
3887// called from info parser
3888void platform_add_app_type(int bw, const char *uc_type,
3889 int app_type, int max_rate) {
3890 struct app_type_entry *ap =
3891 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
3892
3893 if (!ap) {
3894 ALOGE("%s failed to allocate mem for app type", __func__);
3895 return;
3896 }
3897
3898 ap->uc_type = -1;
3899 for (int i=0; i<USECASE_TYPE_MAX; i++) {
3900 if (!strcmp(uc_type, usecase_type_index[i].name)) {
3901 ap->uc_type = usecase_type_index[i].index;
3902 break;
3903 }
3904 }
3905
3906 if (ap->uc_type == -1) {
3907 free(ap);
3908 return;
3909 }
3910
3911 ALOGI("%s bw %d uc %s app_type %d max_rate %d",
3912 __func__, bw, uc_type, app_type, max_rate);
3913 ap->bit_width = bw;
3914 ap->app_type = app_type;
3915 ap->max_rate = max_rate;
3916 list_add_tail(&app_type_entry_list, &ap->node);
3917}
3918
3919
3920int platform_get_default_app_type_v2(void *platform __unused,
3921 usecase_type_t type,
3922 int *app_type )
3923{
3924 if (type == PCM_PLAYBACK)
3925 *app_type = DEFAULT_APP_TYPE_RX_PATH;
3926 else
3927 *app_type = DEFAULT_APP_TYPE_TX_PATH;
3928 return 0;
3929}
3930
3931int platform_get_app_type_v2(void *platform, usecase_type_t uc_type,
3932 int bw, int sr __unused,
3933 int *app_type)
3934{
3935 struct listnode *node;
3936 struct app_type_entry *entry;
3937 *app_type = -1;
3938 list_for_each(node, &app_type_entry_list) {
3939 entry = node_to_item(node, struct app_type_entry, node);
3940 if (entry->bit_width == bw &&
3941 entry->uc_type == uc_type) {
3942 *app_type = entry->app_type;
3943 break;
3944 }
3945 }
3946
3947 if (*app_type == -1) {
3948 return platform_get_default_app_type_v2(platform, uc_type, app_type);
3949 }
3950 return 0;
3951}