blob: cfe2b3d5fc0240b2c39724fb1491c3f2dfa26273 [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
vivek mehtaa68fea62017-06-08 19:04:02 -0700199 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
200 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
201 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
202 AUDIO_RECORD_VOIP_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700203};
204
205/* Array to store sound devices */
206static const char * const device_table[SND_DEVICE_MAX] = {
207 [SND_DEVICE_NONE] = "none",
208 /* Playback sound devices */
209 [SND_DEVICE_OUT_HANDSET] = "handset",
210 [SND_DEVICE_OUT_SPEAKER] = "speaker",
211 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700212 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700213 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500214 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700215 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700216 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500217 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700218 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700219 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500220 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
222 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500223 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 [SND_DEVICE_OUT_HDMI] = "hdmi",
225 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
226 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700227 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700228 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
229 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
230 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
231 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800232 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
233 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700234 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700235 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700236 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700237 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700238 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700239 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700240 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700241 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
242 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700243 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800244 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
245 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700246
247 /* Capture sound devices */
248 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700249 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700250 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
251 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
252 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
253 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
254 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
255 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
256 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
257
258 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
259 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
260 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
261 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
262 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
263 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
264 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
265 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
266 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
267
268 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500269 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700270
Eric Laurentb23d5282013-05-14 15:27:20 -0700271 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
272 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700273 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700274 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700275 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700277
278 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
279 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
280 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
281 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700282 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700283 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700284 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
285 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
286 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800287 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
288 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700289
Eric Laurentb23d5282013-05-14 15:27:20 -0700290 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700291 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700292 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700293 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700294 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
295 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700296 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700297 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
298 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
299 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
300 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700301 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700302
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700303 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700304 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
305 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
306 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
307 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800308
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700309 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700310
Prashant Malanic92c5962015-08-11 15:10:18 -0700311 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
312 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700313 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700314 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
315 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700316 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
317 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700318};
319
320/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700321static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700322 [SND_DEVICE_NONE] = -1,
323 [SND_DEVICE_OUT_HANDSET] = 7,
324 [SND_DEVICE_OUT_SPEAKER] = 15,
325 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700326 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700327 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500328 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700329 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700330 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500331 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700332 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700333 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
334 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500335 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700336 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500337 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700338 [SND_DEVICE_OUT_HDMI] = 18,
339 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
340 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700341 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700342 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700343 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
344 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
345 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800346 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
347 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700348 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700349 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700350 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700351 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700352 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700353 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700354 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700355 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
356 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700357 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700358
359 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700360 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
361 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
362 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
363 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
364 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
365 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
366 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
367 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
368
369 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
370 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
371 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
372 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
373 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
374 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
375 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
376 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
377 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
378
rago90fb9612015-12-02 11:37:53 -0800379 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500380 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700381
Eric Laurentb23d5282013-05-14 15:27:20 -0700382 [SND_DEVICE_IN_HDMI_MIC] = 4,
383 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700384 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700385 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700386 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700387 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700388
389 [SND_DEVICE_IN_VOICE_DMIC] = 41,
390 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
391 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700392 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700393 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800394 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700395 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
396 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
397 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800398 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
399 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700400
rago90fb9612015-12-02 11:37:53 -0800401 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700402 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700403 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700404 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700405 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
406 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800407 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
408
409 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
410 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700411 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
412 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
413 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700414
415 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700416 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700417 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
418 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
419 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
420 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700421 [SND_DEVICE_IN_THREE_MIC] = 46,
422 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700423 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700424 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
425 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700426 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
427 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700428};
429
David Linee3fe402017-03-13 10:00:42 -0700430// Platform specific backend bit width table
431static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
432
Haynes Mathew George98c95622014-06-20 19:14:25 -0700433struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700434 char name[100];
435 unsigned int index;
436};
437
438#define TO_NAME_INDEX(X) #X, X
439
Haynes Mathew George98c95622014-06-20 19:14:25 -0700440/* Used to get index from parsed string */
441static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
442 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700443 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
444 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
445 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700446 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700447 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500448 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700449 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700450 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500451 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700452 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700453 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
454 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700456 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500457 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
459 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
460 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
461 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700462 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500463 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700464 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
465 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
466 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800467 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
468 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800469 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
470 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700471 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700472 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700473 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700474 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700475 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700476 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700477 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
478 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800479
480 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700481 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700482 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700483 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
484 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
485 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
486 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
488 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
490
491 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700492 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700493 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
494 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
495 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
496 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
497 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
498 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
499 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
500
501 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700502 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700503
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700504 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
505 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700506 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700508 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700509 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700510
511 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
512 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
513 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700514 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700515 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
516 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
518 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
522
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700523
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700524 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700525 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700526 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700528 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700530 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700531 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700536
rago90fb9612015-12-02 11:37:53 -0800537 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700539 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800542
Prashant Malanic92c5962015-08-11 15:10:18 -0700543 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700545 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700546 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700548 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700550};
551
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700552static char * backend_tag_table[SND_DEVICE_MAX] = {0};
553static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700554
555static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
556 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
557 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800558 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700559 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700560 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
561 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800562 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700563 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
564 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800565 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700566 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700567 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
568 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
569 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
570 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
571 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800572 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
573 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700574 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
575 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
576 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
577 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800578 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
579 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
580 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
581 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
582 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700583 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
584 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700585};
586
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800587static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
588 {TO_NAME_INDEX(PCM_PLAYBACK)},
589 {TO_NAME_INDEX(PCM_CAPTURE)},
590 {TO_NAME_INDEX(VOICE_CALL)},
591 {TO_NAME_INDEX(PCM_HFP_CALL)},
592};
593
594struct app_type_entry {
595 int uc_type;
596 int bit_width;
597 int app_type;
598 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700599 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800600 struct listnode node; // membership in app_type_entry_list;
601};
602
603static struct listnode app_type_entry_list;
604
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700605#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
606#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800607#define ULL_PLATFORM_DELAY (3*1000LL)
608#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700609
Eric Laurentb23d5282013-05-14 15:27:20 -0700610static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
611static bool is_tmus = false;
612
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800613static int init_be_dai_name_table(struct audio_device *adev);
614
Eric Laurentb23d5282013-05-14 15:27:20 -0700615static void check_operator()
616{
617 char value[PROPERTY_VALUE_MAX];
618 int mccmnc;
619 property_get("gsm.sim.operator.numeric",value,"0");
620 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700621 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700622 switch(mccmnc) {
623 /* TMUS MCC(310), MNC(490, 260, 026) */
624 case 310490:
625 case 310260:
626 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900627 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
628 case 310800:
629 case 310660:
630 case 310580:
631 case 310310:
632 case 310270:
633 case 310250:
634 case 310240:
635 case 310230:
636 case 310220:
637 case 310210:
638 case 310200:
639 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700640 is_tmus = true;
641 break;
642 }
643}
644
645bool is_operator_tmus()
646{
647 pthread_once(&check_op_once_ctl, check_operator);
648 return is_tmus;
649}
650
keunhui.park2f7306a2015-07-16 16:48:06 +0900651static char *get_current_operator()
652{
653 struct listnode *node;
654 struct operator_info *info_item;
655 char mccmnc[PROPERTY_VALUE_MAX];
656 char *ret = NULL;
657
Tom Cherry7fea2042016-11-10 18:05:59 -0800658 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900659
660 list_for_each(node, &operator_info_list) {
661 info_item = node_to_item(node, struct operator_info, list);
662 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
663 ret = info_item->name;
664 }
665 }
666
667 return ret;
668}
669
670static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
671{
672 struct listnode *node;
673 struct operator_specific_device *ret = NULL;
674 struct operator_specific_device *device_item;
675 char *operator_name;
676
677 operator_name = get_current_operator();
678 if (operator_name == NULL)
679 return ret;
680
681 list_for_each(node, operator_specific_device_table[snd_device]) {
682 device_item = node_to_item(node, struct operator_specific_device, list);
683 if (strcmp(operator_name, device_item->operator) == 0) {
684 ret = device_item;
685 }
686 }
687
688 return ret;
689}
690
691
692static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
693{
694 struct operator_specific_device *device;
695 int ret = acdb_device_table[snd_device];
696
697 device = get_operator_specific_device(snd_device);
698 if (device != NULL)
699 ret = device->acdb_id;
700
701 return ret;
702}
703
704static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
705{
706 struct operator_specific_device *device;
707 const char *ret = device_table[snd_device];
708
709 device = get_operator_specific_device(snd_device);
710 if (device != NULL)
711 ret = device->mixer_path;
712
713 return ret;
714}
715
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800716inline bool platform_supports_app_type_cfg()
717{
718#ifdef PLATFORM_MSM8998
719 return true;
720#else
721 return false;
722#endif
723}
724
vivek mehta1a9b7c02015-06-25 11:49:38 -0700725bool platform_send_gain_dep_cal(void *platform, int level)
726{
727 bool ret_val = false;
728 struct platform_data *my_data = (struct platform_data *)platform;
729 struct audio_device *adev = my_data->adev;
730 int acdb_dev_id, app_type;
731 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
732 int mode = CAL_MODE_RTAC;
733 struct listnode *node;
734 struct audio_usecase *usecase;
vivek mehtaa68fea62017-06-08 19:04:02 -0700735 bool valid_uc_type = false;
736 bool valid_dev = false;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700737
738 if (my_data->acdb_send_gain_dep_cal == NULL) {
739 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
740 return ret_val;
741 }
742
743 if (!voice_is_in_call(adev)) {
744 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
745 __func__, level);
746 app_type = DEFAULT_APP_TYPE_RX_PATH;
747
748 // find the current active sound device
749 list_for_each(node, &adev->usecase_list) {
750 usecase = node_to_item(node, struct audio_usecase, list);
vivek mehtaa68fea62017-06-08 19:04:02 -0700751 valid_uc_type = usecase->type == PCM_PLAYBACK;
752 audio_devices_t dev = usecase->stream.out->devices;
753 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
754 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
755 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
756 if (usecase != NULL && valid_uc_type && valid_dev) {
757 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
758 if (audio_extn_spkr_prot_is_enabled()) {
vivek mehta4cb82982015-07-13 12:05:49 -0700759 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
vivek mehtaa68fea62017-06-08 19:04:02 -0700760 } else {
761 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
762 }
vivek mehta4cb82982015-07-13 12:05:49 -0700763
vivek mehtaa68fea62017-06-08 19:04:02 -0700764 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700765 acdb_dev_type, mode, level)) {
766 // set ret_val true if at least one calibration is set successfully
767 ret_val = true;
768 } else {
769 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
770 }
771 } else {
772 ALOGW("%s: Usecase list is empty", __func__);
773 }
774 }
775 } else {
776 ALOGW("%s: Voice call in progress .. ignore setting new cal",
777 __func__);
778 }
779 return ret_val;
780}
781
Eric Laurentcefbbac2014-09-04 13:54:10 -0500782void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700783{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800784 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500785 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700786
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800787 if (strcmp(my_data->ec_ref_mixer_path, "")) {
788 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
789 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500790 }
791
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800792 if (enable) {
793 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
794 if (out_device != AUDIO_DEVICE_NONE) {
795 snd_device = platform_get_output_snd_device(adev->platform, out_device);
796 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
797 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500798
Joe Onorato188b6222016-03-01 11:02:27 -0800799 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800800 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
801 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700802}
803
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700804static struct csd_data *open_csd_client(bool i2s_ext_modem)
805{
806 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
807
808 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
809 if (csd->csd_client == NULL) {
810 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
811 goto error;
812 } else {
813 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
814
815 csd->deinit = (deinit_t)dlsym(csd->csd_client,
816 "csd_client_deinit");
817 if (csd->deinit == NULL) {
818 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
819 dlerror());
820 goto error;
821 }
822 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
823 "csd_client_disable_device");
824 if (csd->disable_device == NULL) {
825 ALOGE("%s: dlsym error %s for csd_client_disable_device",
826 __func__, dlerror());
827 goto error;
828 }
829 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
830 "csd_client_enable_device_config");
831 if (csd->enable_device_config == NULL) {
832 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
833 __func__, dlerror());
834 goto error;
835 }
836 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
837 "csd_client_enable_device");
838 if (csd->enable_device == NULL) {
839 ALOGE("%s: dlsym error %s for csd_client_enable_device",
840 __func__, dlerror());
841 goto error;
842 }
843 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
844 "csd_client_start_voice");
845 if (csd->start_voice == NULL) {
846 ALOGE("%s: dlsym error %s for csd_client_start_voice",
847 __func__, dlerror());
848 goto error;
849 }
850 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
851 "csd_client_stop_voice");
852 if (csd->stop_voice == NULL) {
853 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
854 __func__, dlerror());
855 goto error;
856 }
857 csd->volume = (volume_t)dlsym(csd->csd_client,
858 "csd_client_volume");
859 if (csd->volume == NULL) {
860 ALOGE("%s: dlsym error %s for csd_client_volume",
861 __func__, dlerror());
862 goto error;
863 }
864 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
865 "csd_client_mic_mute");
866 if (csd->mic_mute == NULL) {
867 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
868 __func__, dlerror());
869 goto error;
870 }
871 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
872 "csd_client_slow_talk");
873 if (csd->slow_talk == NULL) {
874 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
875 __func__, dlerror());
876 goto error;
877 }
878 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
879 "csd_client_start_playback");
880 if (csd->start_playback == NULL) {
881 ALOGE("%s: dlsym error %s for csd_client_start_playback",
882 __func__, dlerror());
883 goto error;
884 }
885 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
886 "csd_client_stop_playback");
887 if (csd->stop_playback == NULL) {
888 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
889 __func__, dlerror());
890 goto error;
891 }
892 csd->start_record = (start_record_t)dlsym(csd->csd_client,
893 "csd_client_start_record");
894 if (csd->start_record == NULL) {
895 ALOGE("%s: dlsym error %s for csd_client_start_record",
896 __func__, dlerror());
897 goto error;
898 }
899 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
900 "csd_client_stop_record");
901 if (csd->stop_record == NULL) {
902 ALOGE("%s: dlsym error %s for csd_client_stop_record",
903 __func__, dlerror());
904 goto error;
905 }
906
907 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
908 "csd_client_get_sample_rate");
909 if (csd->get_sample_rate == NULL) {
910 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
911 __func__, dlerror());
912
913 goto error;
914 }
915
916 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
917
918 if (csd->init == NULL) {
919 ALOGE("%s: dlsym error %s for csd_client_init",
920 __func__, dlerror());
921 goto error;
922 } else {
923 csd->init(i2s_ext_modem);
924 }
925 }
926 return csd;
927
928error:
929 free(csd);
930 csd = NULL;
931 return csd;
932}
933
934void close_csd_client(struct csd_data *csd)
935{
936 if (csd != NULL) {
937 csd->deinit();
938 dlclose(csd->csd_client);
939 free(csd);
940 csd = NULL;
941 }
942}
943
944static void platform_csd_init(struct platform_data *my_data)
945{
946#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700947 int32_t modems, (*count_modems)(void);
948 const char *name = "libdetectmodem.so";
949 const char *func = "count_modems";
950 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700951
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700952 my_data->csd = NULL;
953
954 void *lib = dlopen(name, RTLD_NOW);
955 error = dlerror();
956 if (!lib) {
957 ALOGE("%s: could not find %s: %s", __func__, name, error);
958 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700959 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700960
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700961 count_modems = NULL;
962 *(void **)(&count_modems) = dlsym(lib, func);
963 error = dlerror();
964 if (!count_modems) {
965 ALOGE("%s: could not find symbol %s in %s: %s",
966 __func__, func, name, error);
967 goto done;
968 }
969
970 modems = count_modems();
971 if (modems < 0) {
972 ALOGE("%s: count_modems failed\n", __func__);
973 goto done;
974 }
975
Eric Laurent2bafff12016-03-17 12:17:23 -0700976 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700977 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700978 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700979
980done:
981 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700982#else
983 my_data->csd = NULL;
984#endif
985}
986
Eric Laurentc6333382015-09-14 12:43:44 -0700987static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700988{
989 int32_t dev;
990 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700991 backend_tag_table[dev] = NULL;
992 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900993 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700994 }
995
David Linee3fe402017-03-13 10:00:42 -0700996 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
997 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
998 }
999
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001000 // To overwrite these go to the audio_platform_info.xml file.
1001 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001002 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001003 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1004 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1005 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1006 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1007 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001008 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001009 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1010 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001011
David Linee3fe402017-03-13 10:00:42 -07001012 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001013 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001014 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001015 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001016 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1017 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001018 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1019 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001020 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001021 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1022 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1023 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1024 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001025 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1026 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1027 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1028 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1029 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1030 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1031 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001032 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001033 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001034 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001035 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1036 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1037 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1038 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1039 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1040 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1041 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1042 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1043 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1044 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1045 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1046 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1047 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001048 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001049 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1050 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001051 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001052 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001053 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001054 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001055 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001056 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1057 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1058 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001059 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1060 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1061 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1062 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1063 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1064 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1065 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
1066 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1067 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1068 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1069 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1070 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001071
1072 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001073}
1074
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001075void get_cvd_version(char *cvd_version, struct audio_device *adev)
1076{
1077 struct mixer_ctl *ctl;
1078 int count;
1079 int ret = 0;
1080
1081 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1082 if (!ctl) {
1083 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1084 goto done;
1085 }
1086 mixer_ctl_update(ctl);
1087
1088 count = mixer_ctl_get_num_values(ctl);
1089 if (count > MAX_CVD_VERSION_STRING_SIZE)
1090 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1091
1092 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1093 if (ret != 0) {
1094 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1095 goto done;
1096 }
1097
1098done:
1099 return;
1100}
1101
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001102static int platform_acdb_init(void *platform)
1103{
1104 struct platform_data *my_data = (struct platform_data *)platform;
1105 struct audio_device *adev = my_data->adev;
1106
1107 if (!my_data->acdb_init) {
1108 ALOGE("%s: no acdb_init fn provided", __func__);
1109 return -1;
1110 }
1111
1112 if (my_data->acdb_initialized) {
1113 ALOGW("acdb is already initialized");
1114 return 0;
1115 }
1116
Thierry Strudel92232b42017-01-26 10:51:48 -08001117#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001118 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1119 if (!cvd_version)
1120 ALOGE("failed to allocate cvd_version");
1121 else {
1122 get_cvd_version(cvd_version, adev);
1123 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1124 free(cvd_version);
1125 }
1126#elif defined (PLATFORM_MSM8084)
1127 my_data->acdb_init((char *)my_data->snd_card_name);
1128#else
1129 my_data->acdb_init();
1130#endif
1131 my_data->acdb_initialized = true;
1132 return 0;
1133}
1134
David Linee3fe402017-03-13 10:00:42 -07001135static void
1136platform_backend_config_init(struct platform_data *pdata)
1137{
1138 int i;
1139
1140 /* initialize backend config */
1141 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1142 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1143 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1144 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1145
1146 if (i > MAX_RX_CODEC_BACKENDS)
1147 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1148
1149 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1150 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1151 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1152 }
1153
1154 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1155 strdup("SLIM_0_RX Format");
1156 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1157 strdup("SLIM_0_RX SampleRate");
1158
1159 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1160 strdup("SLIM_0_TX Format");
1161 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1162 strdup("SLIM_0_TX SampleRate");
1163
1164 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1165 strdup("USB_AUDIO_TX Format");
1166 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1167 strdup("USB_AUDIO_TX SampleRate");
1168 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1169 strdup("USB_AUDIO_TX Channels");
1170
1171 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1172 strdup("SLIM_6_RX Format");
1173 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1174 strdup("SLIM_6_RX SampleRate");
1175
1176 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1177 strdup("USB_AUDIO_RX Format");
1178 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1179 strdup("USB_AUDIO_RX SampleRate");
1180
1181 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1182 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1183 strdup("USB_AUDIO_RX Channels");
1184}
1185
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001186static int
1187platform_backend_app_type_cfg_init(struct platform_data *pdata,
1188 struct mixer *mixer)
1189{
1190 size_t app_type_cfg[128] = {0};
1191 int length, num_app_types = 0;
1192 struct mixer_ctl *ctl = NULL;
1193
1194 const char *mixer_ctl_name = "App Type Config";
1195 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1196 if (!ctl) {
1197 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1198 return -1;
1199 }
1200
1201 length = 1; // reserve index 0 for number of app types
1202
1203 struct listnode *node;
1204 struct app_type_entry *entry;
1205 list_for_each(node, &app_type_entry_list) {
1206 entry = node_to_item(node, struct app_type_entry, node);
1207 app_type_cfg[length++] = entry->app_type;
1208 app_type_cfg[length++] = entry->max_rate;
1209 app_type_cfg[length++] = entry->bit_width;
1210 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1211 num_app_types += 1;
1212 }
1213
1214 // default for capture
1215 int t;
1216 platform_get_default_app_type_v2(pdata,
1217 PCM_CAPTURE,
1218 &t);
1219 app_type_cfg[length++] = t;
1220 app_type_cfg[length++] = 48000;
1221 app_type_cfg[length++] = 16;
1222 num_app_types += 1;
1223
1224 if (num_app_types) {
1225 app_type_cfg[0] = num_app_types;
1226 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1227 ALOGE("Failed to set app type cfg");
1228 }
1229 }
1230 return 0;
1231}
1232
Eric Laurentb23d5282013-05-14 15:27:20 -07001233void *platform_init(struct audio_device *adev)
1234{
1235 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001236 struct platform_data *my_data = NULL;
1237 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1238 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001239 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001240 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001241 char *snd_internal_name = NULL;
1242 char *tmp = NULL;
1243 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001244 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1245 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001246 my_data = calloc(1, sizeof(struct platform_data));
1247
1248 my_data->adev = adev;
1249
keunhui.park2f7306a2015-07-16 16:48:06 +09001250 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001251 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001252
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001253 set_platform_defaults(my_data);
1254
vivek mehta0fb11312017-05-15 19:35:32 -07001255 // audio_extn_utils_get_snd_card_num does
1256 // - open mixer and get snd card name
1257 // - parse platform info xml file and check for valid snd card name
1258 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001259
vivek mehta0fb11312017-05-15 19:35:32 -07001260 snd_card_num = audio_extn_utils_get_snd_card_num();
1261 if (-1 == snd_card_num) {
1262 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1263 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001264 }
1265
vivek mehta0fb11312017-05-15 19:35:32 -07001266 adev->mixer = mixer_open(snd_card_num);
1267 snd_card_name = mixer_get_name(adev->mixer);
1268 my_data->hw_info = hw_info_init(snd_card_name);
1269
1270 audio_extn_set_snd_card_split(snd_card_name);
1271 snd_split_handle = audio_extn_get_snd_card_split();
1272
1273 /* Get the codec internal name from the sound card and/or form factor
1274 * name and form the mixer paths and platfor info file name dynamically.
1275 * This is generic way of picking any codec and forma factor name based
1276 * mixer and platform info files in future with no code change.
1277
1278 * current code extends and looks for any of the exteneded mixer path and
1279 * platform info file present based on codec and form factor.
1280
1281 * order of picking appropriate file is
1282 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1283 * <ii> mixer_paths_<codec_name>.xml, if file not present
1284 * <iii> mixer_paths.xml
1285
1286 * same order is followed for audio_platform_info.xml as well
1287 */
1288
1289 // need to carryforward old file name
1290 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1291 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1292 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1293 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1294 } else {
1295
1296 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1297 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1298 snd_split_handle->form_factor);
1299 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1300 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1301 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1302 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1303
1304 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1305 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1306 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1307 audio_extn_utils_resolve_config_file(mixer_xml_file);
1308 }
1309 }
1310 }
1311
1312 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1313
1314 /* Initialize platform specific ids and/or backends*/
1315 platform_info_init(platform_info_file, my_data);
1316
1317 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1318 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1319
1320 if (!adev->audio_route) {
1321 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1322 mixer_close(adev->mixer);
1323 adev->mixer = NULL;
1324 hw_info_deinit(my_data->hw_info);
1325 my_data->hw_info = NULL;
1326 goto init_failed;
1327 }
1328 adev->snd_card = snd_card_num;
1329 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1330
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001331 //set max volume step for voice call
1332 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1333 my_data->max_vol_index = atoi(value);
1334
vivek mehta65ad12d2015-08-13 18:32:48 -07001335 property_get("persist.audio.dualmic.config",value,"");
1336 if (!strcmp("endfire", value)) {
1337 dual_mic_config = true;
1338 }
1339
Prashant Malanic92c5962015-08-11 15:10:18 -07001340 my_data->source_mic_type = SOURCE_DUAL_MIC;
1341
Eric Laurentb23d5282013-05-14 15:27:20 -07001342 my_data->fluence_in_spkr_mode = false;
1343 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001344 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001345 my_data->fluence_in_voice_rec = false;
1346
vivek mehta65ad12d2015-08-13 18:32:48 -07001347 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001348 if (!strcmp("fluencepro", value)) {
1349 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001350 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001351 my_data->fluence_type = FLUENCE_ENABLE;
1352 } else if (!strcmp("none", value)) {
1353 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001354 }
1355
Prashant Malanic92c5962015-08-11 15:10:18 -07001356 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001357 property_get("persist.audio.fluence.voicecall",value,"");
1358 if (!strcmp("true", value)) {
1359 my_data->fluence_in_voice_call = true;
1360 }
1361
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001362 property_get("persist.audio.fluence.voicecomm",value,"");
1363 if (!strcmp("true", value)) {
1364 my_data->fluence_in_voice_comm = true;
1365 }
1366
Eric Laurentb23d5282013-05-14 15:27:20 -07001367 property_get("persist.audio.fluence.voicerec",value,"");
1368 if (!strcmp("true", value)) {
1369 my_data->fluence_in_voice_rec = true;
1370 }
1371
1372 property_get("persist.audio.fluence.speaker",value,"");
1373 if (!strcmp("true", value)) {
1374 my_data->fluence_in_spkr_mode = true;
1375 }
1376 }
1377
Prashant Malanic92c5962015-08-11 15:10:18 -07001378 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1379 switch (my_data->max_mic_count) {
1380 case 4:
1381 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1382 case 3:
1383 my_data->source_mic_type |= SOURCE_THREE_MIC;
1384 case 2:
1385 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1386 case 1:
1387 my_data->source_mic_type |= SOURCE_MONO_MIC;
1388 break;
1389 default:
1390 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1391 __func__, my_data->max_mic_count);
1392 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1393 break;
1394 }
1395
1396 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1397 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1398 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1399 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1400 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1401
Eric Laurentb23d5282013-05-14 15:27:20 -07001402 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1403 if (my_data->acdb_handle == NULL) {
1404 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1405 } else {
1406 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1407 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1408 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001409 if (!my_data->acdb_deallocate)
1410 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1411 __func__, LIB_ACDB_LOADER);
1412
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001413 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1414 "acdb_loader_send_audio_cal_v3");
1415 if (!my_data->acdb_send_audio_cal_v3)
1416 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1417 __func__, LIB_ACDB_LOADER);
1418
Eric Laurentb23d5282013-05-14 15:27:20 -07001419 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1420 "acdb_loader_send_audio_cal");
1421 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001422 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001423 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001424
Eric Laurentb23d5282013-05-14 15:27:20 -07001425 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1426 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001427 if (!my_data->acdb_send_voice_cal)
1428 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1429 __func__, LIB_ACDB_LOADER);
1430
1431 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1432 "acdb_loader_reload_vocvoltable");
1433 if (!my_data->acdb_reload_vocvoltable)
1434 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1435 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001436
1437 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1438 "acdb_loader_send_gain_dep_cal");
1439 if (!my_data->acdb_send_gain_dep_cal)
1440 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1441 __func__, LIB_ACDB_LOADER);
1442
Thierry Strudel92232b42017-01-26 10:51:48 -08001443#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001444 acdb_init_v2_cvd_t acdb_init_local;
1445 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001446 "acdb_loader_init_v2");
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_v2", __func__,
1449 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001450
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001451#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001452 acdb_init_v2_t acdb_init_local;
1453 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001454 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001455 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001456 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1457 dlerror());
1458
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001459#else
vivek mehta0fb11312017-05-15 19:35:32 -07001460 acdb_init_t acdb_init_local;
1461 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001462 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001463 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001464 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1465 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001466#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001467 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001468
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001469 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1470 dlsym(my_data->acdb_handle,
1471 "acdb_loader_send_common_custom_topology");
1472
1473 if (!my_data->acdb_send_custom_top)
1474 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1475 __func__, LIB_ACDB_LOADER);
1476
vivek mehta0fb11312017-05-15 19:35:32 -07001477 int result = acdb_init(adev->snd_card);
1478 if (!result) {
1479 my_data->acdb_initialized = true;
1480 ALOGD("ACDB initialized");
1481 } else {
1482 my_data->acdb_initialized = false;
1483 ALOGD("ACDB initialization failed");
1484 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001485 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001486
David Linee3fe402017-03-13 10:00:42 -07001487 /* init usb */
1488 audio_extn_usb_init(adev);
1489
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001490 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001491
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001492 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1493
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001494 /* load csd client */
1495 platform_csd_init(my_data);
1496
David Linee3fe402017-03-13 10:00:42 -07001497 platform_backend_config_init(my_data);
1498
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001499 init_be_dai_name_table(adev);
1500
1501 if (platform_supports_app_type_cfg())
1502 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1503
Eric Laurentb23d5282013-05-14 15:27:20 -07001504 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001505
1506init_failed:
1507 if (my_data)
1508 free(my_data);
1509 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001510}
1511
1512void platform_deinit(void *platform)
1513{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001514 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001515 struct operator_info *info_item;
1516 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001517 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001518 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001519
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001520 struct platform_data *my_data = (struct platform_data *)platform;
1521 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001522
vivek mehtade4849c2016-03-03 17:23:38 -08001523 hw_info_deinit(my_data->hw_info);
1524
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001525 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1526 if (backend_tag_table[dev])
1527 free(backend_tag_table[dev]);
1528 if (hw_interface_table[dev])
1529 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001530 if (operator_specific_device_table[dev]) {
1531 while (!list_empty(operator_specific_device_table[dev])) {
1532 node = list_head(operator_specific_device_table[dev]);
1533 list_remove(node);
1534 device_item = node_to_item(node, struct operator_specific_device, list);
1535 free(device_item->operator);
1536 free(device_item->mixer_path);
1537 free(device_item);
1538 }
1539 free(operator_specific_device_table[dev]);
1540 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001541 }
1542
1543 if (my_data->snd_card_name)
1544 free(my_data->snd_card_name);
1545
keunhui.park2f7306a2015-07-16 16:48:06 +09001546 while (!list_empty(&operator_info_list)) {
1547 node = list_head(&operator_info_list);
1548 list_remove(node);
1549 info_item = node_to_item(node, struct operator_info, list);
1550 free(info_item->name);
1551 free(info_item->mccmnc);
1552 free(info_item);
1553 }
1554
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001555 while (!list_empty(&app_type_entry_list)) {
1556 node = list_head(&app_type_entry_list);
1557 list_remove(node);
1558 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001559 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001560 free(ap);
1561 }
1562
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001563 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001564 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001565
1566 /* deinit usb */
1567 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001568}
1569
1570const char *platform_get_snd_device_name(snd_device_t snd_device)
1571{
keunhui.park2f7306a2015-07-16 16:48:06 +09001572 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1573 if (operator_specific_device_table[snd_device] != NULL) {
1574 return get_operator_specific_device_mixer_path(snd_device);
1575 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001576 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001577 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001578 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001579}
1580
vivek mehtade4849c2016-03-03 17:23:38 -08001581int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1582 char *device_name)
1583{
1584 struct platform_data *my_data = (struct platform_data *)platform;
1585
David Benjamin1565f992016-09-21 12:10:34 -04001586 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001587 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001588 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1589 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001590 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1591 if (operator_specific_device_table[snd_device] != NULL) {
1592 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1593 DEVICE_NAME_MAX_SIZE);
1594 } else {
1595 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1596 }
1597 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1598 } else {
1599 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1600 }
1601
1602 return 0;
1603}
1604
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001605void platform_add_backend_name(void *platform, char *mixer_path,
1606 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001607{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001608 struct platform_data *my_data = (struct platform_data *)platform;
1609
Haynes Mathew George98c95622014-06-20 19:14:25 -07001610 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1611 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1612 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001613 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001614
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001615 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001616
1617 if (suffix != NULL) {
1618 strcat(mixer_path, " ");
1619 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001620 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001621}
1622
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001623bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1624{
1625 bool result = true;
1626
1627 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1628 platform_get_snd_device_name(snd_device1),
1629 platform_get_snd_device_name(snd_device2));
1630
1631 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1632 ALOGE("%s: Invalid snd_device = %s", __func__,
1633 platform_get_snd_device_name(snd_device1));
1634 return false;
1635 }
1636 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1637 ALOGE("%s: Invalid snd_device = %s", __func__,
1638 platform_get_snd_device_name(snd_device2));
1639 return false;
1640 }
1641 const char * be_itf1 = hw_interface_table[snd_device1];
1642 const char * be_itf2 = hw_interface_table[snd_device2];
1643
1644 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001645 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001646 result = false;
1647 }
1648
1649 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1650 return result;
1651}
1652
Eric Laurentb23d5282013-05-14 15:27:20 -07001653int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1654{
1655 int device_id;
1656 if (device_type == PCM_PLAYBACK)
1657 device_id = pcm_device_table[usecase][0];
1658 else
1659 device_id = pcm_device_table[usecase][1];
1660 return device_id;
1661}
1662
Haynes Mathew George98c95622014-06-20 19:14:25 -07001663static int find_index(const struct name_to_index * table, int32_t len,
1664 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001665{
1666 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001667 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001668
Haynes Mathew George98c95622014-06-20 19:14:25 -07001669 if (table == NULL) {
1670 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001671 ret = -ENODEV;
1672 goto done;
1673 }
1674
Haynes Mathew George98c95622014-06-20 19:14:25 -07001675 if (name == NULL) {
1676 ALOGE("null key");
1677 ret = -ENODEV;
1678 goto done;
1679 }
1680
1681 for (i=0; i < len; i++) {
1682 if (!strcmp(table[i].name, name)) {
1683 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001684 goto done;
1685 }
1686 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001687 ALOGE("%s: Could not find index for name = %s",
1688 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001689 ret = -ENODEV;
1690done:
1691 return ret;
1692}
1693
Haynes Mathew George98c95622014-06-20 19:14:25 -07001694int platform_get_snd_device_index(char *device_name)
1695{
1696 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1697}
1698
1699int platform_get_usecase_index(const char *usecase_name)
1700{
1701 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1702}
1703
keunhui.park2f7306a2015-07-16 16:48:06 +09001704void platform_add_operator_specific_device(snd_device_t snd_device,
1705 const char *operator,
1706 const char *mixer_path,
1707 unsigned int acdb_id)
1708{
1709 struct operator_specific_device *device;
1710
1711 if (operator_specific_device_table[snd_device] == NULL) {
1712 operator_specific_device_table[snd_device] =
1713 (struct listnode *)calloc(1, sizeof(struct listnode));
1714 list_init(operator_specific_device_table[snd_device]);
1715 }
1716
1717 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1718
1719 device->operator = strdup(operator);
1720 device->mixer_path = strdup(mixer_path);
1721 device->acdb_id = acdb_id;
1722
1723 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1724
Eric Laurent2bafff12016-03-17 12:17:23 -07001725 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001726 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1727
1728}
1729
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001730int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1731{
1732 int ret = 0;
1733
1734 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1735 ALOGE("%s: Invalid snd_device = %d",
1736 __func__, snd_device);
1737 ret = -EINVAL;
1738 goto done;
1739 }
1740
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001741 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1742 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001743 acdb_device_table[snd_device] = acdb_id;
1744done:
1745 return ret;
1746}
1747
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001748int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1749{
1750 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1751 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1752 return -EINVAL;
1753 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001754
1755 if (operator_specific_device_table[snd_device] != NULL)
1756 return get_operator_specific_device_acdb_id(snd_device);
1757 else
1758 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001759}
1760
David Linee3fe402017-03-13 10:00:42 -07001761static int platform_get_backend_index(snd_device_t snd_device)
1762{
1763 int32_t port = DEFAULT_CODEC_BACKEND;
1764
1765 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1766 if (backend_tag_table[snd_device] != NULL) {
1767 if (strncmp(backend_tag_table[snd_device], "headphones",
1768 sizeof("headphones")) == 0)
1769 port = HEADPHONE_BACKEND;
1770 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1771 port = HDMI_RX_BACKEND;
1772 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1773 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1774 port = USB_AUDIO_RX_BACKEND;
1775 }
1776 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1777 port = DEFAULT_CODEC_TX_BACKEND;
1778 if (backend_tag_table[snd_device] != NULL) {
1779 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1780 port = USB_AUDIO_TX_BACKEND;
1781 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1782 port = BT_SCO_TX_BACKEND;
1783 }
1784 } else {
1785 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1786 }
1787
1788 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1789
1790 return port;
1791}
1792
Eric Laurentb23d5282013-05-14 15:27:20 -07001793int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1794{
1795 struct platform_data *my_data = (struct platform_data *)platform;
1796 int acdb_dev_id, acdb_dev_type;
1797
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001798 if (platform_supports_app_type_cfg()) // use v2 instead
1799 return -ENOSYS;
1800
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001801 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001802 if (acdb_dev_id < 0) {
1803 ALOGE("%s: Could not find acdb id for device(%d)",
1804 __func__, snd_device);
1805 return -EINVAL;
1806 }
1807 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001808 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001809 __func__, snd_device, acdb_dev_id);
1810 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1811 snd_device < SND_DEVICE_OUT_END)
1812 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1813 else
1814 acdb_dev_type = ACDB_DEV_TYPE_IN;
1815 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1816 }
1817 return 0;
1818}
1819
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001820int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1821 int app_type, int sample_rate)
1822{
1823 struct platform_data *my_data = (struct platform_data *)platform;
1824 int acdb_dev_id, acdb_dev_type;
1825 int snd_device = SND_DEVICE_OUT_SPEAKER;
1826 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1827 int i, num_devices = 1;
1828
1829 if (!platform_supports_app_type_cfg()) // use v1 instead
1830 return -ENOSYS;
1831
1832 if (usecase->type == PCM_PLAYBACK)
1833 snd_device = usecase->out_snd_device;
1834 else if (usecase->type == PCM_CAPTURE)
1835 snd_device = usecase->in_snd_device;
1836
1837 // skipped over get_spkr_prot_device
1838 acdb_dev_id = acdb_device_table[snd_device];
1839 if (acdb_dev_id < 0) {
1840 ALOGE("%s: Could not find acdb id for device(%d)",
1841 __func__, snd_device);
1842 return -EINVAL;
1843 }
1844
1845 if (platform_can_split_snd_device(snd_device,
1846 &num_devices, new_snd_device) < 0) {
1847 new_snd_device[0] = snd_device;
1848 }
1849
1850 for (i = 0; i < num_devices; i++) {
1851 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1852 if (acdb_dev_id < 0) {
1853 ALOGE("%s: Could not find acdb id for device(%d)",
1854 __func__, new_snd_device[i]);
1855 return -EINVAL;
1856 }
1857 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1858 __func__, new_snd_device[i], acdb_dev_id);
1859 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1860 new_snd_device[i] < SND_DEVICE_OUT_END)
1861 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1862 else
1863 acdb_dev_type = ACDB_DEV_TYPE_IN;
1864
1865 if (my_data->acdb_send_audio_cal_v3) {
1866 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1867 app_type, sample_rate, i);
1868 } else if (my_data->acdb_send_audio_cal) {
1869 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1870 }
1871 }
1872
1873 return 0;
1874}
1875
1876
Eric Laurentb23d5282013-05-14 15:27:20 -07001877int platform_switch_voice_call_device_pre(void *platform)
1878{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001879 struct platform_data *my_data = (struct platform_data *)platform;
1880 int ret = 0;
1881
1882 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001883 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001884 /* This must be called before disabling mixer controls on APQ side */
1885 ret = my_data->csd->disable_device();
1886 if (ret < 0) {
1887 ALOGE("%s: csd_client_disable_device, failed, error %d",
1888 __func__, ret);
1889 }
1890 }
1891 return ret;
1892}
1893
1894int platform_switch_voice_call_enable_device_config(void *platform,
1895 snd_device_t out_snd_device,
1896 snd_device_t in_snd_device)
1897{
1898 struct platform_data *my_data = (struct platform_data *)platform;
1899 int acdb_rx_id, acdb_tx_id;
1900 int ret = 0;
1901
1902 if (my_data->csd == NULL)
1903 return ret;
1904
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001905 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1906 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001907 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001908 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001909 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001910
keunhui.park2f7306a2015-07-16 16:48:06 +09001911 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001912
1913 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1914 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1915 if (ret < 0) {
1916 ALOGE("%s: csd_enable_device_config, failed, error %d",
1917 __func__, ret);
1918 }
1919 } else {
1920 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1921 acdb_rx_id, acdb_tx_id);
1922 }
1923
1924 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001925}
1926
1927int platform_switch_voice_call_device_post(void *platform,
1928 snd_device_t out_snd_device,
1929 snd_device_t in_snd_device)
1930{
1931 struct platform_data *my_data = (struct platform_data *)platform;
1932 int acdb_rx_id, acdb_tx_id;
1933
1934 if (my_data->acdb_send_voice_cal == NULL) {
1935 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1936 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001937 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1938 audio_extn_spkr_prot_is_enabled())
1939 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1940
keunhui.park2f7306a2015-07-16 16:48:06 +09001941 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1942 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001943
1944 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1945 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1946 else
1947 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1948 acdb_rx_id, acdb_tx_id);
1949 }
1950
1951 return 0;
1952}
1953
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001954int platform_switch_voice_call_usecase_route_post(void *platform,
1955 snd_device_t out_snd_device,
1956 snd_device_t in_snd_device)
1957{
1958 struct platform_data *my_data = (struct platform_data *)platform;
1959 int acdb_rx_id, acdb_tx_id;
1960 int ret = 0;
1961
1962 if (my_data->csd == NULL)
1963 return ret;
1964
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001965 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1966 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001967 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001968 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001969 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001970
keunhui.park2f7306a2015-07-16 16:48:06 +09001971 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001972
1973 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1974 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1975 my_data->adev->acdb_settings);
1976 if (ret < 0) {
1977 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1978 }
1979 } else {
1980 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1981 acdb_rx_id, acdb_tx_id);
1982 }
1983
1984 return ret;
1985}
1986
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001987int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001988{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001989 struct platform_data *my_data = (struct platform_data *)platform;
1990 int ret = 0;
1991
1992 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001993 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001994 if (ret < 0) {
1995 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1996 }
1997 }
1998 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001999}
2000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002001int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002002{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002003 struct platform_data *my_data = (struct platform_data *)platform;
2004 int ret = 0;
2005
2006 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002007 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002008 if (ret < 0) {
2009 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2010 }
2011 }
2012 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002013}
2014
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002015int platform_get_sample_rate(void *platform, uint32_t *rate)
2016{
2017 struct platform_data *my_data = (struct platform_data *)platform;
2018 int ret = 0;
2019
2020 if (my_data->csd != NULL) {
2021 ret = my_data->csd->get_sample_rate(rate);
2022 if (ret < 0) {
2023 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2024 }
2025 }
2026 return ret;
2027}
2028
vivek mehtab6506412015-08-07 16:55:17 -07002029void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2030 snd_device_t snd_device,
2031 bool enable)
2032{
2033 const char* name;
2034 switch (snd_device) {
2035 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2036 if (enable)
2037 name = "spkr-gain-in-headphone-combo";
2038 else
2039 name = "speaker-gain-default";
2040 break;
2041 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2042 if (enable)
2043 name = "spkr-gain-in-line-combo";
2044 else
2045 name = "speaker-gain-default";
2046 break;
2047 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2048 if (enable)
2049 name = "spkr-safe-gain-in-headphone-combo";
2050 else
2051 name = "speaker-safe-gain-default";
2052 break;
2053 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2054 if (enable)
2055 name = "spkr-safe-gain-in-line-combo";
2056 else
2057 name = "speaker-safe-gain-default";
2058 break;
2059 default:
2060 return;
2061 }
2062
2063 audio_route_apply_and_update_path(adev->audio_route, name);
2064}
2065
Eric Laurentb23d5282013-05-14 15:27:20 -07002066int platform_set_voice_volume(void *platform, int volume)
2067{
2068 struct platform_data *my_data = (struct platform_data *)platform;
2069 struct audio_device *adev = my_data->adev;
2070 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002071 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002072 int vol_index = 0, ret = 0;
2073 uint32_t set_values[ ] = {0,
2074 ALL_SESSION_VSID,
2075 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002076
2077 // Voice volume levels are mapped to adsp volume levels as follows.
2078 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2079 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002080 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002081 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002082
2083 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2084 if (!ctl) {
2085 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2086 __func__, mixer_ctl_name);
2087 return -EINVAL;
2088 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002089 ALOGV("Setting voice volume index: %d", set_values[0]);
2090 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2091
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002092 if (my_data->csd != NULL) {
2093 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2094 DEFAULT_VOLUME_RAMP_DURATION_MS);
2095 if (ret < 0) {
2096 ALOGE("%s: csd_volume error %d", __func__, ret);
2097 }
2098 }
2099 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002100}
2101
2102int platform_set_mic_mute(void *platform, bool state)
2103{
2104 struct platform_data *my_data = (struct platform_data *)platform;
2105 struct audio_device *adev = my_data->adev;
2106 struct mixer_ctl *ctl;
2107 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002108 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002109 uint32_t set_values[ ] = {0,
2110 ALL_SESSION_VSID,
2111 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002112
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002113 if (adev->mode != AUDIO_MODE_IN_CALL &&
2114 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002115 return 0;
2116
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002117 if (adev->enable_hfp)
2118 mixer_ctl_name = "HFP Tx Mute";
2119
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002120 set_values[0] = state;
2121 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2122 if (!ctl) {
2123 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2124 __func__, mixer_ctl_name);
2125 return -EINVAL;
2126 }
2127 ALOGV("Setting voice mute state: %d", state);
2128 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2129
2130 if (my_data->csd != NULL) {
2131 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2132 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002133 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002134 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002135 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002136 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002137 return ret;
2138}
Eric Laurentb23d5282013-05-14 15:27:20 -07002139
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002140int platform_set_device_mute(void *platform, bool state, char *dir)
2141{
2142 struct platform_data *my_data = (struct platform_data *)platform;
2143 struct audio_device *adev = my_data->adev;
2144 struct mixer_ctl *ctl;
2145 char *mixer_ctl_name = NULL;
2146 int ret = 0;
2147 uint32_t set_values[ ] = {0,
2148 ALL_SESSION_VSID,
2149 0};
2150 if(dir == NULL) {
2151 ALOGE("%s: Invalid direction:%s", __func__, dir);
2152 return -EINVAL;
2153 }
2154
2155 if (!strncmp("rx", dir, sizeof("rx"))) {
2156 mixer_ctl_name = "Voice Rx Device Mute";
2157 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2158 mixer_ctl_name = "Voice Tx Device Mute";
2159 } else {
2160 return -EINVAL;
2161 }
2162
2163 set_values[0] = state;
2164 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2165 if (!ctl) {
2166 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2167 __func__, mixer_ctl_name);
2168 return -EINVAL;
2169 }
2170
2171 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2172 __func__,state, mixer_ctl_name);
2173 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2174
2175 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002176}
2177
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002178int platform_can_split_snd_device(snd_device_t snd_device,
2179 int *num_devices,
2180 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002181{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002182 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002183 if (NULL == num_devices || NULL == new_snd_devices) {
2184 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002185 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002186 }
2187
2188 /*
2189 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002190 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002191 */
2192 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2193 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2194 *num_devices = 2;
2195 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2196 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002197 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002198 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2199 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2200 *num_devices = 2;
2201 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2202 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002203 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002204 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2205 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2206 *num_devices = 2;
2207 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2208 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002209 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002210 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2211 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2212 *num_devices = 2;
2213 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2214 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002215 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002216 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2217 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2218 SND_DEVICE_OUT_BT_SCO)) {
2219 *num_devices = 2;
2220 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2221 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2222 ret = 0;
2223 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2224 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2225 SND_DEVICE_OUT_BT_SCO_WB)) {
2226 *num_devices = 2;
2227 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2228 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2229 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002230 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2231 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2232 *num_devices = 2;
2233 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2234 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2235 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002236 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2237 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2238 *num_devices = 2;
2239 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2240 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2241 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002242 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002243 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002244}
2245
Eric Laurentb23d5282013-05-14 15:27:20 -07002246snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2247{
2248 struct platform_data *my_data = (struct platform_data *)platform;
2249 struct audio_device *adev = my_data->adev;
2250 audio_mode_t mode = adev->mode;
2251 snd_device_t snd_device = SND_DEVICE_NONE;
2252
2253 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2254 if (devices == AUDIO_DEVICE_NONE ||
2255 devices & AUDIO_DEVICE_BIT_IN) {
2256 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2257 goto exit;
2258 }
2259
Eric Laurent1b491552015-09-15 17:52:41 -07002260 if (popcount(devices) == 2) {
2261 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2262 AUDIO_DEVICE_OUT_SPEAKER) ||
2263 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2264 AUDIO_DEVICE_OUT_SPEAKER)) {
2265 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2266 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2267 AUDIO_DEVICE_OUT_SPEAKER)) {
2268 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2269 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2270 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2271 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2272 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2273 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2274 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2275 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2276 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2277 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2278 AUDIO_DEVICE_OUT_SPEAKER)) {
2279 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002280 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2281 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2282 snd_device = adev->bt_wb_speech_enabled ?
2283 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2284 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002285 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2286 AUDIO_DEVICE_OUT_SPEAKER)) ||
2287 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2288 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002289 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002290 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2291 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2292 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002293 } else {
2294 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2295 goto exit;
2296 }
2297 if (snd_device != SND_DEVICE_NONE) {
2298 goto exit;
2299 }
2300 }
2301
2302 if (popcount(devices) != 1) {
2303 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2304 goto exit;
2305 }
2306
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302307 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002308 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002309 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2310 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002311 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002312 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002313 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002314 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002315 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002316 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002317 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002318 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002319 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002320 else {
2321 if (devices & AUDIO_DEVICE_OUT_LINE)
2322 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2323 else
2324 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2325 }
Eric Laurent99dab492017-06-17 15:19:08 -07002326 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002327 if (voice_is_in_call(adev)) {
2328 switch (adev->voice.tty_mode) {
2329 case TTY_MODE_FULL:
2330 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2331 break;
2332 case TTY_MODE_VCO:
2333 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2334 break;
2335 case TTY_MODE_HCO:
2336 // since Hearing will be on handset\speaker, use existing device
2337 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2338 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002339 case TTY_MODE_OFF:
2340 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002341 default:
2342 ALOGE("%s: Invalid TTY mode (%#x)",
2343 __func__, adev->voice.tty_mode);
2344 }
2345 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002346 if (snd_device == SND_DEVICE_NONE) {
2347 snd_device = audio_extn_usb_is_capture_supported() ?
2348 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2349 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2350 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002351 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002352 if (adev->bt_wb_speech_enabled) {
2353 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2354 } else {
2355 snd_device = SND_DEVICE_OUT_BT_SCO;
2356 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002357 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002358 if (!adev->enable_hfp) {
2359 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2360 } else {
2361 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2362 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002363 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002364 if(adev->voice.hac)
2365 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2366 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002367 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2368 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002369 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002370 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2371 snd_device = SND_DEVICE_OUT_VOICE_TX;
2372
Eric Laurentb23d5282013-05-14 15:27:20 -07002373 if (snd_device != SND_DEVICE_NONE) {
2374 goto exit;
2375 }
2376 }
2377
Eric Laurentb23d5282013-05-14 15:27:20 -07002378 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2379 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2380 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002381 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2382 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002383 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2384 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002385 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002386 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002387 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2388 else
2389 snd_device = SND_DEVICE_OUT_SPEAKER;
2390 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002391 if (adev->bt_wb_speech_enabled) {
2392 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2393 } else {
2394 snd_device = SND_DEVICE_OUT_BT_SCO;
2395 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002396 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2397 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002398 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002399 if (audio_extn_usb_is_capture_supported())
2400 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2401 else
2402 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2403 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002404 /*HAC support for voice-ish audio (eg visual voicemail)*/
2405 if(adev->voice.hac)
2406 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2407 else
2408 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002409 } else {
2410 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2411 }
2412exit:
2413 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2414 return snd_device;
2415}
2416
2417snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2418{
2419 struct platform_data *my_data = (struct platform_data *)platform;
2420 struct audio_device *adev = my_data->adev;
2421 audio_source_t source = (adev->active_input == NULL) ?
2422 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2423
2424 audio_mode_t mode = adev->mode;
2425 audio_devices_t in_device = ((adev->active_input == NULL) ?
2426 AUDIO_DEVICE_NONE : adev->active_input->device)
2427 & ~AUDIO_DEVICE_BIT_IN;
2428 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2429 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2430 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002431 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002432
Prashant Malanic92c5962015-08-11 15:10:18 -07002433 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2434 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002435 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2436 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002437 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002438 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002439 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2440 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002441 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002442 case TTY_MODE_FULL:
2443 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2444 break;
2445 case TTY_MODE_VCO:
2446 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2447 break;
2448 case TTY_MODE_HCO:
2449 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2450 break;
2451 default:
2452 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2453 }
2454 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002455 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002456 switch (adev->voice.tty_mode) {
2457 case TTY_MODE_FULL:
2458 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2459 break;
2460 case TTY_MODE_VCO:
2461 // since voice will be captured from handset mic, use existing device
2462 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2463 break;
2464 case TTY_MODE_HCO:
2465 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2466 break;
2467 default:
2468 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002469 }
2470 goto exit;
2471 }
2472 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002473 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002474 if (my_data->fluence_in_voice_call == false) {
2475 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2476 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002477 if (is_operator_tmus())
2478 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002479 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002480 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002481 }
2482 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2483 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2484 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002485 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002486 if (adev->bluetooth_nrec)
2487 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2488 else
2489 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002490 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002491 if (adev->bluetooth_nrec)
2492 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2493 else
2494 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002495 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002496 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002497 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2498 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2499 out_device & AUDIO_DEVICE_OUT_LINE) {
2500 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2501 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2502 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2503 } else {
2504 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2505 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002506 }
vivek mehtafe121d52015-08-10 23:39:23 -07002507
2508 //select default
2509 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002510 if (!adev->enable_hfp) {
2511 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2512 } else {
2513 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2514 platform_set_echo_reference(adev, true, out_device);
2515 }
vivek mehtafe121d52015-08-10 23:39:23 -07002516 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002517 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002518 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002519 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002520 if (audio_extn_usb_is_capture_supported()) {
2521 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2522 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002523 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002524 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2525 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2526 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2527 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2528 }
2529 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2530 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002531 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2532 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2533 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002534 if (adev->active_input->enable_aec)
2535 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2536 else
2537 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002538 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2539 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002540 if (adev->active_input->enable_aec)
2541 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2542 else
2543 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002544 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2545 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2546 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002547 if (adev->active_input->enable_aec)
2548 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2549 else
2550 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002551 }
2552 platform_set_echo_reference(adev, true, out_device);
2553 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2554 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2555 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002556 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002557 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2558 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002559 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002560 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2561 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002562 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002563 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002564 if (adev->active_input->enable_aec) {
2565 if (adev->active_input->enable_ns) {
2566 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2567 } else {
2568 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2569 }
vivek mehta733c1df2016-04-04 15:09:24 -07002570 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002571 } else if (adev->active_input->enable_ns) {
2572 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2573 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002574 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002575 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002576 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002577 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2578 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002579 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002580 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002581 }
rago90fb9612015-12-02 11:37:53 -08002582 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2583 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002584 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2585 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2586 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2587 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002588 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002589 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2590 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002591 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002592 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2593 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2594 } else {
2595 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2596 }
rago90fb9612015-12-02 11:37:53 -08002597 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2598 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002599 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002600 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002601 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002602 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002603 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002604 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002605 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2606 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002607 if (adev->active_input->enable_aec &&
2608 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002609 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002610 if (my_data->fluence_in_spkr_mode &&
2611 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002612 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002613 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002614 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002615 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002616 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002617 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002618 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002619 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002620 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002621 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002622 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002623 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002624 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2625 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002626 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002627 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002628 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002629 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002630 } else if (adev->active_input->enable_aec) {
2631 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2632 if (my_data->fluence_in_spkr_mode &&
2633 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002634 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002635 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002636 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002637 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002638 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002639 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2640 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002641 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002642 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002643 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002644 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002645 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002646 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2647 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002648 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002649 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002650 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002651 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002652 } else if (adev->active_input->enable_ns) {
2653 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2654 if (my_data->fluence_in_spkr_mode &&
2655 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002656 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002657 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002658 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002659 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002660 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002661 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2662 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002663 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002664 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002665 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002666 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002667 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002668 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002669 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002670 }
2671 } else if (source == AUDIO_SOURCE_DEFAULT) {
2672 goto exit;
2673 }
2674
2675
2676 if (snd_device != SND_DEVICE_NONE) {
2677 goto exit;
2678 }
2679
2680 if (in_device != AUDIO_DEVICE_NONE &&
2681 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2682 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2683 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002684 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002685 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002686 snd_device = SND_DEVICE_IN_QUAD_MIC;
2687 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002688 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002689 snd_device = SND_DEVICE_IN_THREE_MIC;
2690 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2691 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002692 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002693 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2694 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002695 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002696 } else {
2697 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2698 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2699 my_data->source_mic_type, channel_count, channel_mask);
2700 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2701 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002702 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002703 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2704 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002705 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002706 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2707 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002708 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002709 } else {
2710 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2711 " no combination found .. setting to mono", __func__,
2712 my_data->source_mic_type, channel_count);
2713 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2714 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002715 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2716 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2717 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002718 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002719 if (adev->bluetooth_nrec)
2720 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2721 else
2722 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002723 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002724 if (adev->bluetooth_nrec)
2725 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2726 else
2727 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002728 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002729 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2730 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002731 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002732 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002733 } else {
2734 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2735 ALOGW("%s: Using default handset-mic", __func__);
2736 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2737 }
2738 } else {
2739 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2740 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2741 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2742 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002743 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002744 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002745 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002746 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002747 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2748 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002749 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002750 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2751 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002752 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002753 } else {
2754 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2755 " no combination found .. setting to mono", __func__,
2756 my_data->source_mic_type, channel_count);
2757 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2758 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002759 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002760 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002761 if (adev->bluetooth_nrec)
2762 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2763 else
2764 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002765 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002766 if (adev->bluetooth_nrec)
2767 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2768 else
2769 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002770 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002771 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2772 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002773 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002774 if (audio_extn_usb_is_capture_supported())
2775 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2776 else
2777 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002778 } else {
2779 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2780 ALOGW("%s: Using default handset-mic", __func__);
2781 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2782 }
2783 }
2784exit:
2785 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2786 return snd_device;
2787}
2788
2789int platform_set_hdmi_channels(void *platform, int channel_count)
2790{
2791 struct platform_data *my_data = (struct platform_data *)platform;
2792 struct audio_device *adev = my_data->adev;
2793 struct mixer_ctl *ctl;
2794 const char *channel_cnt_str = NULL;
2795 const char *mixer_ctl_name = "HDMI_RX Channels";
2796 switch (channel_count) {
2797 case 8:
2798 channel_cnt_str = "Eight"; break;
2799 case 7:
2800 channel_cnt_str = "Seven"; break;
2801 case 6:
2802 channel_cnt_str = "Six"; break;
2803 case 5:
2804 channel_cnt_str = "Five"; break;
2805 case 4:
2806 channel_cnt_str = "Four"; break;
2807 case 3:
2808 channel_cnt_str = "Three"; break;
2809 default:
2810 channel_cnt_str = "Two"; break;
2811 }
2812 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2813 if (!ctl) {
2814 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2815 __func__, mixer_ctl_name);
2816 return -EINVAL;
2817 }
2818 ALOGV("HDMI channel count: %s", channel_cnt_str);
2819 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2820 return 0;
2821}
2822
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002823int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002824{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002825 struct platform_data *my_data = (struct platform_data *)platform;
2826 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002827 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2828 char *sad = block;
2829 int num_audio_blocks;
2830 int channel_count;
2831 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002832 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002833
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002834 struct mixer_ctl *ctl;
2835
2836 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2837 if (!ctl) {
2838 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2839 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002840 return 0;
2841 }
2842
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002843 mixer_ctl_update(ctl);
2844
2845 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002846
2847 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002848 if (count > (int)sizeof(block))
2849 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002850
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002851 ret = mixer_ctl_get_array(ctl, block, count);
2852 if (ret != 0) {
2853 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2854 return 0;
2855 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002856
2857 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002858 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002859
2860 for (i = 0; i < num_audio_blocks; i++) {
2861 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002862 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2863 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002864 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002865 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002866
2867 channel_count = (sad[0] & 0x7) + 1;
2868 if (channel_count > max_channels)
2869 max_channels = channel_count;
2870
2871 /* Advance to next block */
2872 sad += 3;
2873 }
2874
2875 return max_channels;
2876}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002877
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002878int platform_set_incall_recording_session_id(void *platform,
2879 uint32_t session_id, int rec_mode)
2880{
2881 int ret = 0;
2882 struct platform_data *my_data = (struct platform_data *)platform;
2883 struct audio_device *adev = my_data->adev;
2884 struct mixer_ctl *ctl;
2885 const char *mixer_ctl_name = "Voc VSID";
2886 int num_ctl_values;
2887 int i;
2888
2889 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2890 if (!ctl) {
2891 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2892 __func__, mixer_ctl_name);
2893 ret = -EINVAL;
2894 } else {
2895 num_ctl_values = mixer_ctl_get_num_values(ctl);
2896 for (i = 0; i < num_ctl_values; i++) {
2897 if (mixer_ctl_set_value(ctl, i, session_id)) {
2898 ALOGV("Error: invalid session_id: %x", session_id);
2899 ret = -EINVAL;
2900 break;
2901 }
2902 }
2903 }
2904
2905 if (my_data->csd != NULL) {
2906 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2907 if (ret < 0) {
2908 ALOGE("%s: csd_client_start_record failed, error %d",
2909 __func__, ret);
2910 }
2911 }
2912
2913 return ret;
2914}
2915
2916int platform_stop_incall_recording_usecase(void *platform)
2917{
2918 int ret = 0;
2919 struct platform_data *my_data = (struct platform_data *)platform;
2920
2921 if (my_data->csd != NULL) {
2922 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2923 if (ret < 0) {
2924 ALOGE("%s: csd_client_stop_record failed, error %d",
2925 __func__, ret);
2926 }
2927 }
2928
2929 return ret;
2930}
2931
2932int platform_start_incall_music_usecase(void *platform)
2933{
2934 int ret = 0;
2935 struct platform_data *my_data = (struct platform_data *)platform;
2936
2937 if (my_data->csd != NULL) {
2938 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2939 if (ret < 0) {
2940 ALOGE("%s: csd_client_start_playback failed, error %d",
2941 __func__, ret);
2942 }
2943 }
2944
2945 return ret;
2946}
2947
2948int platform_stop_incall_music_usecase(void *platform)
2949{
2950 int ret = 0;
2951 struct platform_data *my_data = (struct platform_data *)platform;
2952
2953 if (my_data->csd != NULL) {
2954 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2955 if (ret < 0) {
2956 ALOGE("%s: csd_client_stop_playback failed, error %d",
2957 __func__, ret);
2958 }
2959 }
2960
2961 return ret;
2962}
2963
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002964int platform_set_parameters(void *platform, struct str_parms *parms)
2965{
2966 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002967 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002968 char *kv_pairs = str_parms_to_str(parms);
2969 int ret = 0, err;
2970
2971 if (kv_pairs == NULL) {
2972 ret = -EINVAL;
2973 ALOGE("%s: key-value pair is NULL",__func__);
2974 goto done;
2975 }
2976
2977 ALOGV("%s: enter: %s", __func__, kv_pairs);
2978
2979 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2980 value, sizeof(value));
2981 if (err >= 0) {
2982 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2983 my_data->snd_card_name = strdup(value);
2984 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2985 }
2986
keunhui.park2f7306a2015-07-16 16:48:06 +09002987 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2988 value, sizeof(value));
2989 if (err >= 0) {
2990 struct operator_info *info;
2991 char *str = value;
2992 char *name;
2993
2994 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2995 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2996 name = strtok(str, ";");
2997 info->name = strdup(name);
2998 info->mccmnc = strdup(str + strlen(name) + 1);
2999
3000 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003001 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003002 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003003
3004 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003005 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003006 value, sizeof(value));
3007 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003008 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003009 my_data->max_mic_count = atoi(value);
3010 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003011 }
3012
vivek mehta90933872017-06-15 18:04:39 -07003013 // to-do: disable setting sidetone gain, will revist this later
3014 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003015done:
3016 ALOGV("%s: exit with code(%d)", __func__, ret);
3017 if (kv_pairs != NULL)
3018 free(kv_pairs);
3019
3020 return ret;
3021}
3022
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003023/* Delay in Us */
3024int64_t platform_render_latency(audio_usecase_t usecase)
3025{
3026 switch (usecase) {
3027 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3028 return DEEP_BUFFER_PLATFORM_DELAY;
3029 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3030 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003031 case USECASE_AUDIO_PLAYBACK_ULL:
3032 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003033 case USECASE_AUDIO_PLAYBACK_MMAP:
3034 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003035 default:
3036 return 0;
3037 }
3038}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003039
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003040int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3041 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003042{
3043 int ret = 0;
3044
3045 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3046 ALOGE("%s: Invalid snd_device = %d",
3047 __func__, device);
3048 ret = -EINVAL;
3049 goto done;
3050 }
3051
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003052 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3053 platform_get_snd_device_name(device),
3054 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3055 if (backend_tag_table[device]) {
3056 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003057 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003058 backend_tag_table[device] = strdup(backend_tag);
3059
3060 if (hw_interface != NULL) {
3061 if (hw_interface_table[device])
3062 free(hw_interface_table[device]);
3063 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3064 hw_interface_table[device] = strdup(hw_interface);
3065 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003066done:
3067 return ret;
3068}
3069
3070int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3071{
3072 int ret = 0;
3073 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3074 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3075 ret = -EINVAL;
3076 goto done;
3077 }
3078
3079 if ((type != 0) && (type != 1)) {
3080 ALOGE("%s: invalid usecase type", __func__);
3081 ret = -EINVAL;
3082 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003083 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3084 use_case_table[usecase],
3085 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003086 pcm_device_table[usecase][type] = pcm_id;
3087done:
3088 return ret;
3089}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003090
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003091#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3092int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3093 // backup_gain: gain to try to set in case of an error during ramp
3094 int start_gain, end_gain, step, backup_gain, i;
3095 bool error = false;
3096 const struct mixer_ctl *ctl;
3097 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3098 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3099 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3100 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3101 if (!ctl_left || !ctl_right) {
3102 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3103 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3104 return -EINVAL;
3105 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3106 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3107 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3108 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3109 return -EINVAL;
3110 }
3111 if (ramp_up) {
3112 start_gain = 0;
3113 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3114 step = +1;
3115 backup_gain = end_gain;
3116 } else {
3117 // using same gain on left and right
3118 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3119 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3120 end_gain = 0;
3121 step = -1;
3122 backup_gain = start_gain;
3123 }
3124 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3125 //ALOGV("setting speaker gain to %d", i);
3126 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3127 ALOGE("%s: error setting %s to %d during gain ramp",
3128 __func__, mixer_ctl_name_gain_left, i);
3129 error = true;
3130 break;
3131 }
3132 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3133 ALOGE("%s: error setting %s to %d during gain ramp",
3134 __func__, mixer_ctl_name_gain_right, i);
3135 error = true;
3136 break;
3137 }
3138 usleep(1000);
3139 }
3140 if (error) {
3141 // an error occured during the ramp, let's still try to go back to a safe volume
3142 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3143 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3144 }
3145 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3146 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3147 }
3148 }
3149 return start_gain;
3150}
3151
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003152int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
3153{
3154 // only update if there is active pcm playback on speaker
3155 struct audio_usecase *usecase;
3156 struct listnode *node;
3157 struct platform_data *my_data = (struct platform_data *)adev->platform;
3158
3159 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003160
3161 // do not swap channels in audio modes with concurrent capture and playback
3162 // as this may break the echo reference
3163 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3164 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3165 return 0;
3166 }
3167
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003168 my_data->speaker_lr_swap = swap_channels;
3169
3170 list_for_each(node, &adev->usecase_list) {
3171 usecase = node_to_item(node, struct audio_usecase, list);
3172 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003173 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3174 /*
3175 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3176 * to perform device switch to disable the current backend to
3177 * enable it with new acdb data.
3178 */
3179 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3180 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003181 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003182 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003183 if (initial_skpr_gain != -EINVAL) {
3184 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3185 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003186 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003187 const char *mixer_path;
3188 if (swap_channels) {
3189 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3190 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3191 } else {
3192 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3193 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3194 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003195 }
3196 break;
3197 }
3198 }
3199 }
3200 return 0;
3201}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003202
3203static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3204static int num_gain_tbl_entry = 0;
3205
3206bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3207
3208 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3209 if (num_gain_tbl_entry == -1) {
3210 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3211 __func__);
3212 return false;
3213 }
3214
3215 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3216 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3217 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3218 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3219 return false;
3220 }
3221
3222 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3223 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3224 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3225 return false;
3226 }
3227
3228 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3229 ++num_gain_tbl_entry;
3230
3231 return true;
3232}
3233
3234int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3235 int table_size) {
3236 int itt = 0;
3237 ALOGV("platform_get_gain_level_mapping called ");
3238
3239 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3240 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3241 return 0;
3242 }
3243
3244 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3245 mapping_tbl[itt] = tbl_mapping[itt];
3246 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3247 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3248 }
3249
3250 return num_gain_tbl_entry;
3251}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003252
3253int platform_snd_card_update(void *platform, card_status_t status)
3254{
3255 struct platform_data *my_data = (struct platform_data *)platform;
3256 struct audio_device *adev = my_data->adev;
3257
3258 if (status == CARD_STATUS_ONLINE) {
3259 if (my_data->acdb_send_custom_top)
3260 my_data->acdb_send_custom_top();
3261 }
3262 return 0;
3263}
David Linee3fe402017-03-13 10:00:42 -07003264
3265/*
3266 * configures afe with bit width and Sample Rate
3267 */
3268static int platform_set_backend_cfg(const struct audio_device* adev,
3269 snd_device_t snd_device,
3270 const struct audio_backend_cfg *backend_cfg)
3271{
3272
3273 int ret = 0;
3274 const int backend_idx = platform_get_backend_index(snd_device);
3275 struct platform_data *my_data = (struct platform_data *)adev->platform;
3276 const unsigned int bit_width = backend_cfg->bit_width;
3277 const unsigned int sample_rate = backend_cfg->sample_rate;
3278 const unsigned int channels = backend_cfg->channels;
3279 const audio_format_t format = backend_cfg->format;
3280 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3281
3282
3283 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3284 ", backend_idx %d device (%s)", __func__, bit_width,
3285 sample_rate, channels, backend_idx,
3286 platform_get_snd_device_name(snd_device));
3287
3288 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3289 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3290
3291 struct mixer_ctl *ctl = NULL;
3292 ctl = mixer_get_ctl_by_name(adev->mixer,
3293 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3294 if (!ctl) {
3295 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3296 __func__,
3297 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3298 return -EINVAL;
3299 }
3300
3301 if (bit_width == 24) {
3302 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3303 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3304 else
3305 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3306 } else if (bit_width == 32) {
3307 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3308 } else {
3309 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3310 }
3311 if ( ret < 0) {
3312 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3313 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3314 } else {
3315 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3316 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3317 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3318 }
3319 /* set the ret as 0 and not pass back to upper layer */
3320 ret = 0;
3321 }
3322
3323 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3324 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3325 char *rate_str = NULL;
3326 struct mixer_ctl *ctl = NULL;
3327
3328 switch (sample_rate) {
3329 case 32000:
3330 if (passthrough_enabled) {
3331 rate_str = "KHZ_32";
3332 break;
3333 }
3334 case 8000:
3335 case 11025:
3336 case 16000:
3337 case 22050:
3338 case 48000:
3339 rate_str = "KHZ_48";
3340 break;
3341 case 44100:
3342 rate_str = "KHZ_44P1";
3343 break;
3344 case 64000:
3345 case 96000:
3346 rate_str = "KHZ_96";
3347 break;
3348 case 88200:
3349 rate_str = "KHZ_88P2";
3350 break;
3351 case 176400:
3352 rate_str = "KHZ_176P4";
3353 break;
3354 case 192000:
3355 rate_str = "KHZ_192";
3356 break;
3357 case 352800:
3358 rate_str = "KHZ_352P8";
3359 break;
3360 case 384000:
3361 rate_str = "KHZ_384";
3362 break;
3363 case 144000:
3364 if (passthrough_enabled) {
3365 rate_str = "KHZ_144";
3366 break;
3367 }
3368 default:
3369 rate_str = "KHZ_48";
3370 break;
3371 }
3372
3373 ctl = mixer_get_ctl_by_name(adev->mixer,
3374 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3375 if(!ctl) {
3376 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3377 __func__,
3378 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3379 return -EINVAL;
3380 }
3381
3382 ALOGD("%s:becf: afe: %s set to %s", __func__,
3383 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3384 mixer_ctl_set_enum_by_string(ctl, rate_str);
3385 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3386 }
3387 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3388 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3389 struct mixer_ctl *ctl = NULL;
3390 char *channel_cnt_str = NULL;
3391
3392 switch (channels) {
3393 case 8:
3394 channel_cnt_str = "Eight"; break;
3395 case 7:
3396 channel_cnt_str = "Seven"; break;
3397 case 6:
3398 channel_cnt_str = "Six"; break;
3399 case 5:
3400 channel_cnt_str = "Five"; break;
3401 case 4:
3402 channel_cnt_str = "Four"; break;
3403 case 3:
3404 channel_cnt_str = "Three"; break;
3405 case 1:
3406 channel_cnt_str = "One"; break;
3407 case 2:
3408 default:
3409 channel_cnt_str = "Two"; break;
3410 }
3411
3412 ctl = mixer_get_ctl_by_name(adev->mixer,
3413 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3414 if (!ctl) {
3415 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3416 __func__,
3417 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3418 return -EINVAL;
3419 }
3420 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3421 my_data->current_backend_cfg[backend_idx].channels = channels;
3422
3423 // skip EDID configuration for HDMI backend
3424
3425 ALOGD("%s:becf: afe: %s set to %s", __func__,
3426 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3427 channel_cnt_str);
3428 }
3429
3430 // skip set ext_display format mixer control
3431 return ret;
3432}
3433
3434static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3435{
3436 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3437 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3438 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3439 }
3440
3441 return backend_bit_width_table[snd_device];
3442}
3443
3444/*
3445 * return backend_idx on which voice call is active
3446 */
3447static int platform_get_voice_call_backend(struct audio_device* adev)
3448{
3449 struct audio_usecase *uc = NULL;
3450 struct listnode *node;
3451 snd_device_t out_snd_device = SND_DEVICE_NONE;
3452
3453 int backend_idx = -1;
3454
3455 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3456 list_for_each(node, &adev->usecase_list) {
3457 uc = node_to_item(node, struct audio_usecase, list);
3458 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3459 out_snd_device = platform_get_output_snd_device(adev->platform,
3460 uc->stream.out->devices);
3461 backend_idx = platform_get_backend_index(out_snd_device);
3462 break;
3463 }
3464 }
3465 }
3466 return backend_idx;
3467}
3468
3469/*
3470 * goes through all the current usecases and picks the highest
3471 * bitwidth & samplerate
3472 */
3473static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3474 int backend_idx,
3475 struct audio_backend_cfg *backend_cfg)
3476{
3477 bool backend_change = false;
3478 unsigned int bit_width;
3479 unsigned int sample_rate;
3480 unsigned int channels;
3481 struct platform_data *my_data = (struct platform_data *)adev->platform;
3482
3483 bit_width = backend_cfg->bit_width;
3484 sample_rate = backend_cfg->sample_rate;
3485 channels = backend_cfg->channels;
3486
3487 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3488 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3489 sample_rate, channels);
3490
3491 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3492 // default backend
3493 // force routing is not required here, caller will do it anyway
3494 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3495 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3496 "for unprocessed/camera source", __func__);
3497 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3498 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3499 }
3500
3501 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3502 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3503 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3504 __func__, bit_width, sample_rate, channels);
3505 }
3506
3507 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3508 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3509
3510 // Force routing if the expected bitwdith or samplerate
3511 // is not same as current backend comfiguration
3512 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3513 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3514 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3515 backend_cfg->bit_width = bit_width;
3516 backend_cfg->sample_rate= sample_rate;
3517 backend_cfg->channels = channels;
3518 backend_change = true;
3519 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3520 "new sample rate: %d new channel: %d",
3521 __func__, backend_cfg->bit_width,
3522 backend_cfg->sample_rate, backend_cfg->channels);
3523 }
3524
3525 return backend_change;
3526}
3527
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003528static void pick_playback_cfg_for_uc(struct audio_device *adev,
3529 struct audio_usecase *usecase,
3530 snd_device_t snd_device,
3531 unsigned int *bit_width,
3532 unsigned int *sample_rate,
3533 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003534{
3535 int i =0;
3536 struct listnode *node;
3537 list_for_each(node, &adev->usecase_list) {
3538 struct audio_usecase *uc;
3539 uc = node_to_item(node, struct audio_usecase, list);
3540 struct stream_out *out = (struct stream_out*) uc->stream.out;
3541 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3542 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3543 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3544 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3545 uc->id, out->sample_rate,
3546 pcm_format_to_bits(out->config.format), out_channels,
3547 platform_get_snd_device_name(uc->out_snd_device));
3548
3549 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3550 if (*bit_width < pcm_format_to_bits(out->config.format))
3551 *bit_width = pcm_format_to_bits(out->config.format);
3552 if (*sample_rate < out->sample_rate)
3553 *sample_rate = out->sample_rate;
3554 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3555 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3556 if (*channels < out_channels)
3557 *channels = out_channels;
3558 }
3559 }
3560 }
3561 return;
3562}
3563
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003564static void headset_is_config_supported(unsigned int *bit_width,
3565 unsigned int *sample_rate,
3566 unsigned int *channels) {
3567 switch (*bit_width) {
3568 case 16:
3569 case 24:
3570 break;
3571 default:
3572 *bit_width = 16;
3573 break;
3574 }
3575
3576 if (*sample_rate > 192000) {
3577 *sample_rate = 192000;
3578 }
3579
3580 if (*channels > 2) {
3581 *channels = 2;
3582 }
3583}
3584
David Linee3fe402017-03-13 10:00:42 -07003585static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3586 struct audio_usecase* usecase,
3587 snd_device_t snd_device,
3588 struct audio_backend_cfg *backend_cfg)
3589{
3590 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003591 unsigned int bit_width;
3592 unsigned int sample_rate;
3593 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003594 int backend_idx = DEFAULT_CODEC_BACKEND;
3595 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003596
3597 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3598 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3599 backend_change = false;
3600 return backend_change;
3601 }
3602
3603 backend_idx = platform_get_backend_index(snd_device);
3604 bit_width = backend_cfg->bit_width;
3605 sample_rate = backend_cfg->sample_rate;
3606 channels = backend_cfg->channels;
3607
3608 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3609 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3610 sample_rate, channels, backend_idx, usecase->id,
3611 platform_get_snd_device_name(snd_device));
3612
3613 if (backend_idx == platform_get_voice_call_backend(adev)) {
3614 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3615 __func__);
3616 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3617 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3618 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3619 } else {
3620 /*
3621 * The backend should be configured at highest bit width and/or
3622 * sample rate amongst all playback usecases.
3623 * If the selected sample rate and/or bit width differ with
3624 * current backend sample rate and/or bit width, then, we set the
3625 * backend re-configuration flag.
3626 *
3627 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3628 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003629 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3630 &bit_width,
3631 &sample_rate,
3632 &channels);
David Linee3fe402017-03-13 10:00:42 -07003633 }
3634
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003635 switch (backend_idx) {
3636 case USB_AUDIO_RX_BACKEND:
3637 audio_extn_usb_is_config_supported(&bit_width,
3638 &sample_rate, &channels, true);
3639 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3640 __func__, bit_width, sample_rate, channels);
3641 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003642 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003643 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3644 break;
3645 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003646 default:
3647 bit_width = platform_get_snd_device_bit_width(snd_device);
3648 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3649 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3650 break;
David Linee3fe402017-03-13 10:00:42 -07003651 }
3652
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003653 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3654 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003655 __func__, backend_idx , bit_width, sample_rate);
3656
3657 // Force routing if the expected bitwdith or samplerate
3658 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003659 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3660 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3661 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003662 backend_cfg->bit_width = bit_width;
3663 backend_cfg->sample_rate = sample_rate;
3664 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003665 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003666 backend_change = true;
3667 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3668 "new sample rate: %d new channels: %d",
3669 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3670 }
3671
3672 return backend_change;
3673}
3674
3675bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3676 struct audio_usecase *usecase, snd_device_t snd_device)
3677{
3678 int backend_idx = DEFAULT_CODEC_BACKEND;
3679 int new_snd_devices[SND_DEVICE_OUT_END];
3680 int i, num_devices = 1;
3681 bool ret = false;
3682 struct platform_data *my_data = (struct platform_data *)adev->platform;
3683 struct audio_backend_cfg backend_cfg;
3684
3685 backend_idx = platform_get_backend_index(snd_device);
3686
3687 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3688 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3689 backend_cfg.format = usecase->stream.out->format;
3690 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3691 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3692 backend_cfg.passthrough_enabled = false;
3693
3694 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3695 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3696 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3697 platform_get_snd_device_name(snd_device));
3698
3699 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3700 new_snd_devices[0] = snd_device;
3701
3702 for (i = 0; i < num_devices; i++) {
3703 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3704 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3705 &backend_cfg))) {
3706 platform_set_backend_cfg(adev, new_snd_devices[i],
3707 &backend_cfg);
3708 ret = true;
3709 }
3710 }
3711 return ret;
3712}
3713
3714bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3715 struct audio_usecase *usecase, snd_device_t snd_device)
3716{
3717 int backend_idx = platform_get_backend_index(snd_device);
3718 int ret = 0;
3719 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003720 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003721
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003722 if (usecase->type == PCM_CAPTURE) {
3723 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003724 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3725 } else {
3726 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3727 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3728 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3729 backend_cfg.channels = 1;
3730 }
3731
3732 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3733 ", backend_idx %d usecase = %d device (%s)", __func__,
3734 backend_cfg.bit_width,
3735 backend_cfg.sample_rate,
3736 backend_cfg.channels,
3737 backend_idx, usecase->id,
3738 platform_get_snd_device_name(snd_device));
3739
3740 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3741 ret = platform_set_backend_cfg(adev, snd_device,
3742 &backend_cfg);
3743 if(!ret)
3744 return true;
3745 }
3746
3747 return false;
3748}
3749
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003750static int max_be_dai_names = 0;
3751static const struct be_dai_name_struct *be_dai_name_table;
3752
3753/*
3754 * Retrieves the be_dai_name_table from kernel to enable a mapping
3755 * between sound device hw interfaces and backend IDs. This allows HAL to
3756 * specify the backend a specific calibration is needed for.
3757 */
3758static int init_be_dai_name_table(struct audio_device *adev)
3759{
3760 const char *mixer_ctl_name = "Backend DAI Name Table";
3761 struct mixer_ctl *ctl;
3762 int i, j, ret, size;
3763 bool valid_hw_interface;
3764
3765 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3766 if (!ctl) {
3767 ALOGE("%s: Could not get ctl for mixer name %s\n",
3768 __func__, mixer_ctl_name);
3769 ret = -EINVAL;
3770 goto done;
3771 }
3772
3773 mixer_ctl_update(ctl);
3774
3775 size = mixer_ctl_get_num_values(ctl);
3776 if (size <= 0){
3777 ALOGE("%s: Failed to get %s size %d\n",
3778 __func__, mixer_ctl_name, size);
3779 ret = -EFAULT;
3780 goto done;
3781 }
3782
vivek mehtaa68fea62017-06-08 19:04:02 -07003783 be_dai_name_table =
3784 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003785 if (be_dai_name_table == NULL) {
3786 ALOGE("%s: Failed to allocate memory for %s\n",
3787 __func__, mixer_ctl_name);
3788 ret = -ENOMEM;
3789 goto freeMem;
3790 }
3791
3792 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3793 if (ret) {
3794 ALOGE("%s: Failed to get %s, ret %d\n",
3795 __func__, mixer_ctl_name, ret);
3796 ret = -EFAULT;
3797 goto freeMem;
3798 }
3799
3800 if (be_dai_name_table != NULL) {
3801 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3802 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3803 __func__, mixer_ctl_name, max_be_dai_names);
3804 ret = 0;
3805 } else {
3806 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3807 ret = -EFAULT;
3808 goto freeMem;
3809 }
3810
3811 /*
3812 * Validate all sound devices have a valid backend set to catch
3813 * errors for uncommon sound devices
3814 */
3815 for (i = 0; i < SND_DEVICE_MAX; i++) {
3816 valid_hw_interface = false;
3817
3818 if (hw_interface_table[i] == NULL) {
3819 ALOGW("%s: sound device %s has no hw interface set\n",
3820 __func__, platform_get_snd_device_name(i));
3821 continue;
3822 }
3823
3824 for (j = 0; j < max_be_dai_names; j++) {
3825 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3826 == 0) {
3827 valid_hw_interface = true;
3828 break;
3829 }
3830 }
3831 if (!valid_hw_interface)
3832 ALOGD("%s: sound device %s does not have a valid hw interface set "
3833 "(disregard for combo devices) %s\n",
3834 __func__, platform_get_snd_device_name(i),
3835 hw_interface_table[i]);
3836 }
3837
3838 goto done;
3839
3840freeMem:
3841 if (be_dai_name_table) {
3842 free((void *)be_dai_name_table);
3843 be_dai_name_table = NULL;
3844 }
3845
3846done:
3847 return ret;
3848}
3849
3850int platform_get_snd_device_backend_index(snd_device_t device)
3851{
3852 int i, be_dai_id;
3853 const char * hw_interface_name = NULL;
3854
3855 ALOGV("%s: enter with device %d\n", __func__, device);
3856
vivek mehtaa68fea62017-06-08 19:04:02 -07003857 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003858 ALOGE("%s: Invalid snd_device = %d",
3859 __func__, device);
3860 be_dai_id = -EINVAL;
3861 goto done;
3862 }
3863
3864 /* Get string value of necessary backend for device */
3865 hw_interface_name = hw_interface_table[device];
3866 if (hw_interface_name == NULL) {
3867 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3868 be_dai_id = -EINVAL;
3869 goto done;
3870 }
3871
3872 /* Check if be dai name table was retrieved successfully */
3873 if (be_dai_name_table == NULL) {
3874 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3875 be_dai_id = -EFAULT;
3876 goto done;
3877 }
3878
3879 /* Get backend ID for device specified */
3880 for (i = 0; i < max_be_dai_names; i++) {
3881 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3882 be_dai_id = be_dai_name_table[i].be_id;
3883 goto done;
3884 }
3885 }
3886 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3887 be_dai_id = -EINVAL;
3888 goto done;
3889
3890done:
3891 return be_dai_id;
3892}
3893
3894void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3895 unsigned int stream_sr, int* sample_rate)
3896{
3897 struct platform_data* my_data = (struct platform_data *)platform;
3898 int backend_idx = platform_get_backend_index(snd_device);
3899 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3900 /*
3901 *Check if device SR is multiple of 8K or 11.025 Khz
3902 *check if the stream SR is multiple of same base, if yes
3903 *then have copp SR equal to stream SR, this ensures that
3904 *post processing happens at stream SR, else have
3905 *copp SR equal to device SR.
3906 */
3907 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3908 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3909 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3910 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
3911 *sample_rate = device_sr;
3912 } else
3913 *sample_rate = stream_sr;
3914
3915 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
3916 , *sample_rate);
3917
3918}
3919
3920// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07003921void platform_add_app_type(const char *uc_type,
3922 const char *mode,
3923 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003924 int app_type, int max_rate) {
3925 struct app_type_entry *ap =
3926 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
3927
3928 if (!ap) {
3929 ALOGE("%s failed to allocate mem for app type", __func__);
3930 return;
3931 }
3932
3933 ap->uc_type = -1;
3934 for (int i=0; i<USECASE_TYPE_MAX; i++) {
3935 if (!strcmp(uc_type, usecase_type_index[i].name)) {
3936 ap->uc_type = usecase_type_index[i].index;
3937 break;
3938 }
3939 }
3940
3941 if (ap->uc_type == -1) {
3942 free(ap);
3943 return;
3944 }
3945
vivek mehtaa68fea62017-06-08 19:04:02 -07003946 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
3947 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003948 ap->bit_width = bw;
3949 ap->app_type = app_type;
3950 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07003951 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003952 list_add_tail(&app_type_entry_list, &ap->node);
3953}
3954
3955
3956int platform_get_default_app_type_v2(void *platform __unused,
3957 usecase_type_t type,
3958 int *app_type )
3959{
3960 if (type == PCM_PLAYBACK)
3961 *app_type = DEFAULT_APP_TYPE_RX_PATH;
3962 else
3963 *app_type = DEFAULT_APP_TYPE_TX_PATH;
3964 return 0;
3965}
3966
vivek mehtaa68fea62017-06-08 19:04:02 -07003967int platform_get_app_type_v2(void *platform,
3968 usecase_type_t uc_type,
3969 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003970 int bw, int sr __unused,
3971 int *app_type)
3972{
3973 struct listnode *node;
3974 struct app_type_entry *entry;
3975 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07003976
3977 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
3978 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003979 list_for_each(node, &app_type_entry_list) {
3980 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07003981 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
3982 __func__, entry->uc_type, entry->mode, entry->bit_width,
3983 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003984 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07003985 entry->uc_type == uc_type &&
3986 sr <= entry->max_rate &&
3987 entry->mode && !strcmp(mode, entry->mode)) {
3988 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003989 *app_type = entry->app_type;
3990 break;
3991 }
3992 }
3993
3994 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07003995 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003996 return platform_get_default_app_type_v2(platform, uc_type, app_type);
3997 }
3998 return 0;
3999}
vivek mehta90933872017-06-15 18:04:39 -07004000
4001int platform_set_sidetone(struct audio_device *adev,
4002 snd_device_t out_snd_device,
4003 bool enable, char *str)
4004{
4005 int ret;
4006 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4007 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4008 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4009 if (ret)
4010 ALOGI("%s: usb device %d does not support device sidetone\n",
4011 __func__, out_snd_device);
4012 } else {
4013 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4014 __func__, out_snd_device, str);
4015 if (enable)
4016 audio_route_apply_and_update_path(adev->audio_route, str);
4017 else
4018 audio_route_reset_and_update_path(adev->audio_route, str);
4019 }
4020 return 0;
4021}