blob: b9812b164f27c47b69861262c492f42c40d9d863 [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
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700168 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
169 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700170 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
171 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
172 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
173 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800174 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
175 VOICEMMODE1_CALL_PCM_DEVICE},
176 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
177 VOICEMMODE2_CALL_PCM_DEVICE},
178
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700179 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
180 AUDIO_RECORD_PCM_DEVICE},
181 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
182 AUDIO_RECORD_PCM_DEVICE},
183 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
184 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800185 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700186
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700187 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
188 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
189
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700190 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
191 AFE_PROXY_RECORD_PCM_DEVICE},
192 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
193 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800194 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700195
Eric Laurentb23d5282013-05-14 15:27:20 -0700196};
197
198/* Array to store sound devices */
199static const char * const device_table[SND_DEVICE_MAX] = {
200 [SND_DEVICE_NONE] = "none",
201 /* Playback sound devices */
202 [SND_DEVICE_OUT_HANDSET] = "handset",
203 [SND_DEVICE_OUT_SPEAKER] = "speaker",
204 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700205 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700206 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500207 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700208 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700209 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500210 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700211 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700212 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500213 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700214 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
215 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500216 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217 [SND_DEVICE_OUT_HDMI] = "hdmi",
218 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
219 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700220 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
222 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
223 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
224 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800225 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
226 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700227 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700228 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700229 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700230 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700231 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700232 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700233 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
234 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700235 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800236 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
237 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700238
239 /* Capture sound devices */
240 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700241 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700242 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
243 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
244 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
245 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
246 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
247 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
248 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
249
250 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
251 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
252 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
253 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
254 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
255 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
256 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
257 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
258 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
259
260 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500261 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700262
Eric Laurentb23d5282013-05-14 15:27:20 -0700263 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
264 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700265 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700266 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700267 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700268 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700269
270 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
271 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
272 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
273 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700274 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700275 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700276 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
277 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
278 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800279 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
280 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700281
Eric Laurentb23d5282013-05-14 15:27:20 -0700282 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700283 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700284 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700285 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700286 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
287 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700288 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700289 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
290 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
291 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
292 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700293 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700294
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700295 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700296 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
297 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
298 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
299 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800300
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700301 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700302
Prashant Malanic92c5962015-08-11 15:10:18 -0700303 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
304 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700305 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700306 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
307 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700308 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
309 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700310};
311
312/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700313static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700314 [SND_DEVICE_NONE] = -1,
315 [SND_DEVICE_OUT_HANDSET] = 7,
316 [SND_DEVICE_OUT_SPEAKER] = 15,
317 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700318 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700319 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500320 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700321 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700322 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500323 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700324 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700325 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
326 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500327 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700328 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500329 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700330 [SND_DEVICE_OUT_HDMI] = 18,
331 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
332 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700333 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700334 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700335 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
336 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
337 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800338 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
339 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700340 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700341 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700342 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700343 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700344 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700345 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700346 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
347 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700348 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700349
350 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700351 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
352 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
353 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
354 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
355 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
356 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
357 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
358 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
359
360 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
361 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
362 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
363 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
364 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
365 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
366 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
367 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
368 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
369
rago90fb9612015-12-02 11:37:53 -0800370 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500371 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700372
Eric Laurentb23d5282013-05-14 15:27:20 -0700373 [SND_DEVICE_IN_HDMI_MIC] = 4,
374 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700375 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700376 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700377 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700378 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700379
380 [SND_DEVICE_IN_VOICE_DMIC] = 41,
381 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
382 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700383 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700384 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800385 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700386 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
387 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
388 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800389 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
390 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700391
rago90fb9612015-12-02 11:37:53 -0800392 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700393 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700394 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700395 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700396 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
397 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800398 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
399
400 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
401 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700402 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
403 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
404 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700405
406 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700407 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700408 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
409 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
410 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
411 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700412 [SND_DEVICE_IN_THREE_MIC] = 46,
413 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700414 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700415 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
416 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700417 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
418 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700419};
420
David Linee3fe402017-03-13 10:00:42 -0700421// Platform specific backend bit width table
422static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
423
Haynes Mathew George98c95622014-06-20 19:14:25 -0700424struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700425 char name[100];
426 unsigned int index;
427};
428
429#define TO_NAME_INDEX(X) #X, X
430
Haynes Mathew George98c95622014-06-20 19:14:25 -0700431/* Used to get index from parsed string */
432static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
433 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700434 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
435 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
436 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700437 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700438 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500439 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700440 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700441 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500442 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700443 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700444 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
445 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700446 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700447 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500448 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700449 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
450 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
451 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
452 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700453 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500454 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
456 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
457 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800458 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
459 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800460 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
461 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700462 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700463 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700464 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700465 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700466 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700467 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800469
470 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700471 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700472 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700473 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
474 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
475 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
476 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
477 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
478 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
479 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
480
481 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700482 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700483 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
484 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
485 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
486 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
488 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
490
491 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700492 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700493
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700494 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
495 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700496 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700497 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700498 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700499 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700500
501 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
503 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700504 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700505 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
506 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
508 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
509 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800510 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
511 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
512
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700513
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700514 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700515 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700516 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700518 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700521 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
523 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
524 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
525 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700526
rago90fb9612015-12-02 11:37:53 -0800527 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
528 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700529 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
530 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
531 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800532
Prashant Malanic92c5962015-08-11 15:10:18 -0700533 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700535 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700536 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700538 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
539 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700540};
541
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700542static char * backend_tag_table[SND_DEVICE_MAX] = {0};
543static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700544
545static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
546 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
547 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800548 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700549 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700550 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
551 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800552 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700553 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
554 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800555 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700556 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
557 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
558 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
559 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
560 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800561 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
562 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700563 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
564 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
565 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
566 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800567 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
568 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
569 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
570 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
571 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700572};
573
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800574static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
575 {TO_NAME_INDEX(PCM_PLAYBACK)},
576 {TO_NAME_INDEX(PCM_CAPTURE)},
577 {TO_NAME_INDEX(VOICE_CALL)},
578 {TO_NAME_INDEX(PCM_HFP_CALL)},
579};
580
581struct app_type_entry {
582 int uc_type;
583 int bit_width;
584 int app_type;
585 int max_rate;
586 struct listnode node; // membership in app_type_entry_list;
587};
588
589static struct listnode app_type_entry_list;
590
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700591#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
592#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800593#define ULL_PLATFORM_DELAY (3*1000LL)
594#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700595
Eric Laurentb23d5282013-05-14 15:27:20 -0700596static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
597static bool is_tmus = false;
598
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800599static int init_be_dai_name_table(struct audio_device *adev);
600
Eric Laurentb23d5282013-05-14 15:27:20 -0700601static void check_operator()
602{
603 char value[PROPERTY_VALUE_MAX];
604 int mccmnc;
605 property_get("gsm.sim.operator.numeric",value,"0");
606 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700607 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700608 switch(mccmnc) {
609 /* TMUS MCC(310), MNC(490, 260, 026) */
610 case 310490:
611 case 310260:
612 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900613 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
614 case 310800:
615 case 310660:
616 case 310580:
617 case 310310:
618 case 310270:
619 case 310250:
620 case 310240:
621 case 310230:
622 case 310220:
623 case 310210:
624 case 310200:
625 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700626 is_tmus = true;
627 break;
628 }
629}
630
631bool is_operator_tmus()
632{
633 pthread_once(&check_op_once_ctl, check_operator);
634 return is_tmus;
635}
636
keunhui.park2f7306a2015-07-16 16:48:06 +0900637static char *get_current_operator()
638{
639 struct listnode *node;
640 struct operator_info *info_item;
641 char mccmnc[PROPERTY_VALUE_MAX];
642 char *ret = NULL;
643
Tom Cherry7fea2042016-11-10 18:05:59 -0800644 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900645
646 list_for_each(node, &operator_info_list) {
647 info_item = node_to_item(node, struct operator_info, list);
648 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
649 ret = info_item->name;
650 }
651 }
652
653 return ret;
654}
655
656static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
657{
658 struct listnode *node;
659 struct operator_specific_device *ret = NULL;
660 struct operator_specific_device *device_item;
661 char *operator_name;
662
663 operator_name = get_current_operator();
664 if (operator_name == NULL)
665 return ret;
666
667 list_for_each(node, operator_specific_device_table[snd_device]) {
668 device_item = node_to_item(node, struct operator_specific_device, list);
669 if (strcmp(operator_name, device_item->operator) == 0) {
670 ret = device_item;
671 }
672 }
673
674 return ret;
675}
676
677
678static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
679{
680 struct operator_specific_device *device;
681 int ret = acdb_device_table[snd_device];
682
683 device = get_operator_specific_device(snd_device);
684 if (device != NULL)
685 ret = device->acdb_id;
686
687 return ret;
688}
689
690static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
691{
692 struct operator_specific_device *device;
693 const char *ret = device_table[snd_device];
694
695 device = get_operator_specific_device(snd_device);
696 if (device != NULL)
697 ret = device->mixer_path;
698
699 return ret;
700}
701
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800702inline bool platform_supports_app_type_cfg()
703{
704#ifdef PLATFORM_MSM8998
705 return true;
706#else
707 return false;
708#endif
709}
710
vivek mehta1a9b7c02015-06-25 11:49:38 -0700711bool platform_send_gain_dep_cal(void *platform, int level)
712{
713 bool ret_val = false;
714 struct platform_data *my_data = (struct platform_data *)platform;
715 struct audio_device *adev = my_data->adev;
716 int acdb_dev_id, app_type;
717 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
718 int mode = CAL_MODE_RTAC;
719 struct listnode *node;
720 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700721
722 if (my_data->acdb_send_gain_dep_cal == NULL) {
723 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
724 return ret_val;
725 }
726
727 if (!voice_is_in_call(adev)) {
728 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
729 __func__, level);
730 app_type = DEFAULT_APP_TYPE_RX_PATH;
731
732 // find the current active sound device
733 list_for_each(node, &adev->usecase_list) {
734 usecase = node_to_item(node, struct audio_usecase, list);
735
736 if (usecase != NULL &&
737 usecase->type == PCM_PLAYBACK &&
738 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
739
740 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700741 if (audio_extn_spkr_prot_is_enabled()) {
742 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
743 } else {
744 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
745 }
746
vivek mehta1a9b7c02015-06-25 11:49:38 -0700747 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
748 acdb_dev_type, mode, level)) {
749 // set ret_val true if at least one calibration is set successfully
750 ret_val = true;
751 } else {
752 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
753 }
754 } else {
755 ALOGW("%s: Usecase list is empty", __func__);
756 }
757 }
758 } else {
759 ALOGW("%s: Voice call in progress .. ignore setting new cal",
760 __func__);
761 }
762 return ret_val;
763}
764
Eric Laurentcefbbac2014-09-04 13:54:10 -0500765void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700766{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800767 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500768 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700769
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800770 if (strcmp(my_data->ec_ref_mixer_path, "")) {
771 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
772 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500773 }
774
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800775 if (enable) {
776 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
777 if (out_device != AUDIO_DEVICE_NONE) {
778 snd_device = platform_get_output_snd_device(adev->platform, out_device);
779 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
780 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500781
Joe Onorato188b6222016-03-01 11:02:27 -0800782 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800783 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
784 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700785}
786
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700787static struct csd_data *open_csd_client(bool i2s_ext_modem)
788{
789 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
790
791 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
792 if (csd->csd_client == NULL) {
793 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
794 goto error;
795 } else {
796 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
797
798 csd->deinit = (deinit_t)dlsym(csd->csd_client,
799 "csd_client_deinit");
800 if (csd->deinit == NULL) {
801 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
802 dlerror());
803 goto error;
804 }
805 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
806 "csd_client_disable_device");
807 if (csd->disable_device == NULL) {
808 ALOGE("%s: dlsym error %s for csd_client_disable_device",
809 __func__, dlerror());
810 goto error;
811 }
812 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
813 "csd_client_enable_device_config");
814 if (csd->enable_device_config == NULL) {
815 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
816 __func__, dlerror());
817 goto error;
818 }
819 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
820 "csd_client_enable_device");
821 if (csd->enable_device == NULL) {
822 ALOGE("%s: dlsym error %s for csd_client_enable_device",
823 __func__, dlerror());
824 goto error;
825 }
826 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
827 "csd_client_start_voice");
828 if (csd->start_voice == NULL) {
829 ALOGE("%s: dlsym error %s for csd_client_start_voice",
830 __func__, dlerror());
831 goto error;
832 }
833 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
834 "csd_client_stop_voice");
835 if (csd->stop_voice == NULL) {
836 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
837 __func__, dlerror());
838 goto error;
839 }
840 csd->volume = (volume_t)dlsym(csd->csd_client,
841 "csd_client_volume");
842 if (csd->volume == NULL) {
843 ALOGE("%s: dlsym error %s for csd_client_volume",
844 __func__, dlerror());
845 goto error;
846 }
847 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
848 "csd_client_mic_mute");
849 if (csd->mic_mute == NULL) {
850 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
851 __func__, dlerror());
852 goto error;
853 }
854 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
855 "csd_client_slow_talk");
856 if (csd->slow_talk == NULL) {
857 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
858 __func__, dlerror());
859 goto error;
860 }
861 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
862 "csd_client_start_playback");
863 if (csd->start_playback == NULL) {
864 ALOGE("%s: dlsym error %s for csd_client_start_playback",
865 __func__, dlerror());
866 goto error;
867 }
868 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
869 "csd_client_stop_playback");
870 if (csd->stop_playback == NULL) {
871 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
872 __func__, dlerror());
873 goto error;
874 }
875 csd->start_record = (start_record_t)dlsym(csd->csd_client,
876 "csd_client_start_record");
877 if (csd->start_record == NULL) {
878 ALOGE("%s: dlsym error %s for csd_client_start_record",
879 __func__, dlerror());
880 goto error;
881 }
882 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
883 "csd_client_stop_record");
884 if (csd->stop_record == NULL) {
885 ALOGE("%s: dlsym error %s for csd_client_stop_record",
886 __func__, dlerror());
887 goto error;
888 }
889
890 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
891 "csd_client_get_sample_rate");
892 if (csd->get_sample_rate == NULL) {
893 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
894 __func__, dlerror());
895
896 goto error;
897 }
898
899 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
900
901 if (csd->init == NULL) {
902 ALOGE("%s: dlsym error %s for csd_client_init",
903 __func__, dlerror());
904 goto error;
905 } else {
906 csd->init(i2s_ext_modem);
907 }
908 }
909 return csd;
910
911error:
912 free(csd);
913 csd = NULL;
914 return csd;
915}
916
917void close_csd_client(struct csd_data *csd)
918{
919 if (csd != NULL) {
920 csd->deinit();
921 dlclose(csd->csd_client);
922 free(csd);
923 csd = NULL;
924 }
925}
926
927static void platform_csd_init(struct platform_data *my_data)
928{
929#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700930 int32_t modems, (*count_modems)(void);
931 const char *name = "libdetectmodem.so";
932 const char *func = "count_modems";
933 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700934
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700935 my_data->csd = NULL;
936
937 void *lib = dlopen(name, RTLD_NOW);
938 error = dlerror();
939 if (!lib) {
940 ALOGE("%s: could not find %s: %s", __func__, name, error);
941 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700942 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700943
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700944 count_modems = NULL;
945 *(void **)(&count_modems) = dlsym(lib, func);
946 error = dlerror();
947 if (!count_modems) {
948 ALOGE("%s: could not find symbol %s in %s: %s",
949 __func__, func, name, error);
950 goto done;
951 }
952
953 modems = count_modems();
954 if (modems < 0) {
955 ALOGE("%s: count_modems failed\n", __func__);
956 goto done;
957 }
958
Eric Laurent2bafff12016-03-17 12:17:23 -0700959 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700960 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700961 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700962
963done:
964 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700965#else
966 my_data->csd = NULL;
967#endif
968}
969
Eric Laurentc6333382015-09-14 12:43:44 -0700970static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700971{
972 int32_t dev;
973 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700974 backend_tag_table[dev] = NULL;
975 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900976 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700977 }
978
David Linee3fe402017-03-13 10:00:42 -0700979 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
980 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
981 }
982
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700983 // To overwrite these go to the audio_platform_info.xml file.
984 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700985 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700986 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
987 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
988 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
989 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
990 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700991 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700992 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
993 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700994
David Linee3fe402017-03-13 10:00:42 -0700995 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700996 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -0700997 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700998 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -0700999 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1000 strdup("speaker-and-usb-headphones");
1001 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001002 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1003 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1004 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1005 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001006 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1007 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1008 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1009 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1010 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1011 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1012 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001013 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001014 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001015 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001016 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1017 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1018 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1019 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1020 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1021 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1022 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1023 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1024 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1025 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1026 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1027 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1028 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001029 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001030 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001031 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001032 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001033 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001034 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1035 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1036 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -07001037
1038 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001039}
1040
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001041void get_cvd_version(char *cvd_version, struct audio_device *adev)
1042{
1043 struct mixer_ctl *ctl;
1044 int count;
1045 int ret = 0;
1046
1047 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1048 if (!ctl) {
1049 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1050 goto done;
1051 }
1052 mixer_ctl_update(ctl);
1053
1054 count = mixer_ctl_get_num_values(ctl);
1055 if (count > MAX_CVD_VERSION_STRING_SIZE)
1056 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1057
1058 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1059 if (ret != 0) {
1060 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1061 goto done;
1062 }
1063
1064done:
1065 return;
1066}
1067
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001068static int platform_acdb_init(void *platform)
1069{
1070 struct platform_data *my_data = (struct platform_data *)platform;
1071 struct audio_device *adev = my_data->adev;
1072
1073 if (!my_data->acdb_init) {
1074 ALOGE("%s: no acdb_init fn provided", __func__);
1075 return -1;
1076 }
1077
1078 if (my_data->acdb_initialized) {
1079 ALOGW("acdb is already initialized");
1080 return 0;
1081 }
1082
Thierry Strudel92232b42017-01-26 10:51:48 -08001083#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001084 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1085 if (!cvd_version)
1086 ALOGE("failed to allocate cvd_version");
1087 else {
1088 get_cvd_version(cvd_version, adev);
1089 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1090 free(cvd_version);
1091 }
1092#elif defined (PLATFORM_MSM8084)
1093 my_data->acdb_init((char *)my_data->snd_card_name);
1094#else
1095 my_data->acdb_init();
1096#endif
1097 my_data->acdb_initialized = true;
1098 return 0;
1099}
1100
David Linee3fe402017-03-13 10:00:42 -07001101static void
1102platform_backend_config_init(struct platform_data *pdata)
1103{
1104 int i;
1105
1106 /* initialize backend config */
1107 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1108 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1109 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1110 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1111
1112 if (i > MAX_RX_CODEC_BACKENDS)
1113 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1114
1115 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1116 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1117 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1118 }
1119
1120 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1121 strdup("SLIM_0_RX Format");
1122 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1123 strdup("SLIM_0_RX SampleRate");
1124
1125 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1126 strdup("SLIM_0_TX Format");
1127 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1128 strdup("SLIM_0_TX SampleRate");
1129
1130 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1131 strdup("USB_AUDIO_TX Format");
1132 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1133 strdup("USB_AUDIO_TX SampleRate");
1134 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1135 strdup("USB_AUDIO_TX Channels");
1136
1137 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1138 strdup("SLIM_6_RX Format");
1139 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1140 strdup("SLIM_6_RX SampleRate");
1141
1142 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1143 strdup("USB_AUDIO_RX Format");
1144 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1145 strdup("USB_AUDIO_RX SampleRate");
1146
1147 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1148 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1149 strdup("USB_AUDIO_RX Channels");
1150}
1151
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001152static int
1153platform_backend_app_type_cfg_init(struct platform_data *pdata,
1154 struct mixer *mixer)
1155{
1156 size_t app_type_cfg[128] = {0};
1157 int length, num_app_types = 0;
1158 struct mixer_ctl *ctl = NULL;
1159
1160 const char *mixer_ctl_name = "App Type Config";
1161 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1162 if (!ctl) {
1163 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1164 return -1;
1165 }
1166
1167 length = 1; // reserve index 0 for number of app types
1168
1169 struct listnode *node;
1170 struct app_type_entry *entry;
1171 list_for_each(node, &app_type_entry_list) {
1172 entry = node_to_item(node, struct app_type_entry, node);
1173 app_type_cfg[length++] = entry->app_type;
1174 app_type_cfg[length++] = entry->max_rate;
1175 app_type_cfg[length++] = entry->bit_width;
1176 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1177 num_app_types += 1;
1178 }
1179
1180 // default for capture
1181 int t;
1182 platform_get_default_app_type_v2(pdata,
1183 PCM_CAPTURE,
1184 &t);
1185 app_type_cfg[length++] = t;
1186 app_type_cfg[length++] = 48000;
1187 app_type_cfg[length++] = 16;
1188 num_app_types += 1;
1189
1190 if (num_app_types) {
1191 app_type_cfg[0] = num_app_types;
1192 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1193 ALOGE("Failed to set app type cfg");
1194 }
1195 }
1196 return 0;
1197}
1198
Eric Laurentb23d5282013-05-14 15:27:20 -07001199void *platform_init(struct audio_device *adev)
1200{
1201 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001202 struct platform_data *my_data = NULL;
1203 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1204 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001205 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001206 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001207 char *snd_internal_name = NULL;
1208 char *tmp = NULL;
1209 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001210 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1211 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001212 my_data = calloc(1, sizeof(struct platform_data));
1213
1214 my_data->adev = adev;
1215
keunhui.park2f7306a2015-07-16 16:48:06 +09001216 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001217 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001218
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001219 set_platform_defaults(my_data);
1220
vivek mehta0fb11312017-05-15 19:35:32 -07001221 // audio_extn_utils_get_snd_card_num does
1222 // - open mixer and get snd card name
1223 // - parse platform info xml file and check for valid snd card name
1224 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001225
vivek mehta0fb11312017-05-15 19:35:32 -07001226 snd_card_num = audio_extn_utils_get_snd_card_num();
1227 if (-1 == snd_card_num) {
1228 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1229 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001230 }
1231
vivek mehta0fb11312017-05-15 19:35:32 -07001232 adev->mixer = mixer_open(snd_card_num);
1233 snd_card_name = mixer_get_name(adev->mixer);
1234 my_data->hw_info = hw_info_init(snd_card_name);
1235
1236 audio_extn_set_snd_card_split(snd_card_name);
1237 snd_split_handle = audio_extn_get_snd_card_split();
1238
1239 /* Get the codec internal name from the sound card and/or form factor
1240 * name and form the mixer paths and platfor info file name dynamically.
1241 * This is generic way of picking any codec and forma factor name based
1242 * mixer and platform info files in future with no code change.
1243
1244 * current code extends and looks for any of the exteneded mixer path and
1245 * platform info file present based on codec and form factor.
1246
1247 * order of picking appropriate file is
1248 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1249 * <ii> mixer_paths_<codec_name>.xml, if file not present
1250 * <iii> mixer_paths.xml
1251
1252 * same order is followed for audio_platform_info.xml as well
1253 */
1254
1255 // need to carryforward old file name
1256 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1257 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1258 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1259 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1260 } else {
1261
1262 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1263 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1264 snd_split_handle->form_factor);
1265 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1266 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1267 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1268 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1269
1270 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1271 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1272 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1273 audio_extn_utils_resolve_config_file(mixer_xml_file);
1274 }
1275 }
1276 }
1277
1278 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1279
1280 /* Initialize platform specific ids and/or backends*/
1281 platform_info_init(platform_info_file, my_data);
1282
1283 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1284 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1285
1286 if (!adev->audio_route) {
1287 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1288 mixer_close(adev->mixer);
1289 adev->mixer = NULL;
1290 hw_info_deinit(my_data->hw_info);
1291 my_data->hw_info = NULL;
1292 goto init_failed;
1293 }
1294 adev->snd_card = snd_card_num;
1295 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1296
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001297 //set max volume step for voice call
1298 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1299 my_data->max_vol_index = atoi(value);
1300
vivek mehta65ad12d2015-08-13 18:32:48 -07001301 property_get("persist.audio.dualmic.config",value,"");
1302 if (!strcmp("endfire", value)) {
1303 dual_mic_config = true;
1304 }
1305
Prashant Malanic92c5962015-08-11 15:10:18 -07001306 my_data->source_mic_type = SOURCE_DUAL_MIC;
1307
Eric Laurentb23d5282013-05-14 15:27:20 -07001308 my_data->fluence_in_spkr_mode = false;
1309 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001310 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001311 my_data->fluence_in_voice_rec = false;
1312
vivek mehta65ad12d2015-08-13 18:32:48 -07001313 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001314 if (!strcmp("fluencepro", value)) {
1315 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001316 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001317 my_data->fluence_type = FLUENCE_ENABLE;
1318 } else if (!strcmp("none", value)) {
1319 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001320 }
1321
Prashant Malanic92c5962015-08-11 15:10:18 -07001322 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001323 property_get("persist.audio.fluence.voicecall",value,"");
1324 if (!strcmp("true", value)) {
1325 my_data->fluence_in_voice_call = true;
1326 }
1327
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001328 property_get("persist.audio.fluence.voicecomm",value,"");
1329 if (!strcmp("true", value)) {
1330 my_data->fluence_in_voice_comm = true;
1331 }
1332
Eric Laurentb23d5282013-05-14 15:27:20 -07001333 property_get("persist.audio.fluence.voicerec",value,"");
1334 if (!strcmp("true", value)) {
1335 my_data->fluence_in_voice_rec = true;
1336 }
1337
1338 property_get("persist.audio.fluence.speaker",value,"");
1339 if (!strcmp("true", value)) {
1340 my_data->fluence_in_spkr_mode = true;
1341 }
1342 }
1343
Prashant Malanic92c5962015-08-11 15:10:18 -07001344 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1345 switch (my_data->max_mic_count) {
1346 case 4:
1347 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1348 case 3:
1349 my_data->source_mic_type |= SOURCE_THREE_MIC;
1350 case 2:
1351 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1352 case 1:
1353 my_data->source_mic_type |= SOURCE_MONO_MIC;
1354 break;
1355 default:
1356 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1357 __func__, my_data->max_mic_count);
1358 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1359 break;
1360 }
1361
1362 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1363 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1364 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1365 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1366 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1367
Eric Laurentb23d5282013-05-14 15:27:20 -07001368 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1369 if (my_data->acdb_handle == NULL) {
1370 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1371 } else {
1372 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1373 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1374 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001375 if (!my_data->acdb_deallocate)
1376 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1377 __func__, LIB_ACDB_LOADER);
1378
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001379 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1380 "acdb_loader_send_audio_cal_v3");
1381 if (!my_data->acdb_send_audio_cal_v3)
1382 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1383 __func__, LIB_ACDB_LOADER);
1384
Eric Laurentb23d5282013-05-14 15:27:20 -07001385 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1386 "acdb_loader_send_audio_cal");
1387 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001388 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001389 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001390
Eric Laurentb23d5282013-05-14 15:27:20 -07001391 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1392 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001393 if (!my_data->acdb_send_voice_cal)
1394 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1395 __func__, LIB_ACDB_LOADER);
1396
1397 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1398 "acdb_loader_reload_vocvoltable");
1399 if (!my_data->acdb_reload_vocvoltable)
1400 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1401 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001402
1403 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1404 "acdb_loader_send_gain_dep_cal");
1405 if (!my_data->acdb_send_gain_dep_cal)
1406 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1407 __func__, LIB_ACDB_LOADER);
1408
Thierry Strudel92232b42017-01-26 10:51:48 -08001409#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001410 acdb_init_v2_cvd_t acdb_init_local;
1411 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001412 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001413 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001414 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1415 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001416
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001417#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001418 acdb_init_v2_t acdb_init_local;
1419 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001420 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001421 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001422 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1423 dlerror());
1424
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001425#else
vivek mehta0fb11312017-05-15 19:35:32 -07001426 acdb_init_t acdb_init_local;
1427 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001428 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001429 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001430 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1431 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001432#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001433 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001434
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001435 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1436 dlsym(my_data->acdb_handle,
1437 "acdb_loader_send_common_custom_topology");
1438
1439 if (!my_data->acdb_send_custom_top)
1440 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1441 __func__, LIB_ACDB_LOADER);
1442
vivek mehta0fb11312017-05-15 19:35:32 -07001443 int result = acdb_init(adev->snd_card);
1444 if (!result) {
1445 my_data->acdb_initialized = true;
1446 ALOGD("ACDB initialized");
1447 } else {
1448 my_data->acdb_initialized = false;
1449 ALOGD("ACDB initialization failed");
1450 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001451 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001452
David Linee3fe402017-03-13 10:00:42 -07001453 /* init usb */
1454 audio_extn_usb_init(adev);
1455
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001456 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001457
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001458 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1459
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001460 /* load csd client */
1461 platform_csd_init(my_data);
1462
David Linee3fe402017-03-13 10:00:42 -07001463 platform_backend_config_init(my_data);
1464
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001465 init_be_dai_name_table(adev);
1466
1467 if (platform_supports_app_type_cfg())
1468 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1469
Eric Laurentb23d5282013-05-14 15:27:20 -07001470 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001471
1472init_failed:
1473 if (my_data)
1474 free(my_data);
1475 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001476}
1477
1478void platform_deinit(void *platform)
1479{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001480 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001481 struct operator_info *info_item;
1482 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001483 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001484 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001485
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001486 struct platform_data *my_data = (struct platform_data *)platform;
1487 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001488
vivek mehtade4849c2016-03-03 17:23:38 -08001489 hw_info_deinit(my_data->hw_info);
1490
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001491 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1492 if (backend_tag_table[dev])
1493 free(backend_tag_table[dev]);
1494 if (hw_interface_table[dev])
1495 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001496 if (operator_specific_device_table[dev]) {
1497 while (!list_empty(operator_specific_device_table[dev])) {
1498 node = list_head(operator_specific_device_table[dev]);
1499 list_remove(node);
1500 device_item = node_to_item(node, struct operator_specific_device, list);
1501 free(device_item->operator);
1502 free(device_item->mixer_path);
1503 free(device_item);
1504 }
1505 free(operator_specific_device_table[dev]);
1506 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001507 }
1508
1509 if (my_data->snd_card_name)
1510 free(my_data->snd_card_name);
1511
keunhui.park2f7306a2015-07-16 16:48:06 +09001512 while (!list_empty(&operator_info_list)) {
1513 node = list_head(&operator_info_list);
1514 list_remove(node);
1515 info_item = node_to_item(node, struct operator_info, list);
1516 free(info_item->name);
1517 free(info_item->mccmnc);
1518 free(info_item);
1519 }
1520
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001521 while (!list_empty(&app_type_entry_list)) {
1522 node = list_head(&app_type_entry_list);
1523 list_remove(node);
1524 ap = node_to_item(node, struct app_type_entry, node);
1525 free(ap);
1526 }
1527
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001528 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001529 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001530
1531 /* deinit usb */
1532 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001533}
1534
1535const char *platform_get_snd_device_name(snd_device_t snd_device)
1536{
keunhui.park2f7306a2015-07-16 16:48:06 +09001537 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1538 if (operator_specific_device_table[snd_device] != NULL) {
1539 return get_operator_specific_device_mixer_path(snd_device);
1540 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001541 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001542 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001543 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001544}
1545
vivek mehtade4849c2016-03-03 17:23:38 -08001546int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1547 char *device_name)
1548{
1549 struct platform_data *my_data = (struct platform_data *)platform;
1550
David Benjamin1565f992016-09-21 12:10:34 -04001551 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001552 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001553 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1554 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001555 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1556 if (operator_specific_device_table[snd_device] != NULL) {
1557 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1558 DEVICE_NAME_MAX_SIZE);
1559 } else {
1560 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1561 }
1562 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1563 } else {
1564 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1565 }
1566
1567 return 0;
1568}
1569
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001570void platform_add_backend_name(void *platform, char *mixer_path,
1571 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001572{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001573 struct platform_data *my_data = (struct platform_data *)platform;
1574
Haynes Mathew George98c95622014-06-20 19:14:25 -07001575 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1576 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1577 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001578 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001579
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001580 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001581
1582 if (suffix != NULL) {
1583 strcat(mixer_path, " ");
1584 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001585 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001586}
1587
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001588bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1589{
1590 bool result = true;
1591
1592 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1593 platform_get_snd_device_name(snd_device1),
1594 platform_get_snd_device_name(snd_device2));
1595
1596 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1597 ALOGE("%s: Invalid snd_device = %s", __func__,
1598 platform_get_snd_device_name(snd_device1));
1599 return false;
1600 }
1601 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1602 ALOGE("%s: Invalid snd_device = %s", __func__,
1603 platform_get_snd_device_name(snd_device2));
1604 return false;
1605 }
1606 const char * be_itf1 = hw_interface_table[snd_device1];
1607 const char * be_itf2 = hw_interface_table[snd_device2];
1608
1609 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001610 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001611 result = false;
1612 }
1613
1614 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1615 return result;
1616}
1617
Eric Laurentb23d5282013-05-14 15:27:20 -07001618int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1619{
1620 int device_id;
1621 if (device_type == PCM_PLAYBACK)
1622 device_id = pcm_device_table[usecase][0];
1623 else
1624 device_id = pcm_device_table[usecase][1];
1625 return device_id;
1626}
1627
Haynes Mathew George98c95622014-06-20 19:14:25 -07001628static int find_index(const struct name_to_index * table, int32_t len,
1629 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001630{
1631 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001632 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001633
Haynes Mathew George98c95622014-06-20 19:14:25 -07001634 if (table == NULL) {
1635 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001636 ret = -ENODEV;
1637 goto done;
1638 }
1639
Haynes Mathew George98c95622014-06-20 19:14:25 -07001640 if (name == NULL) {
1641 ALOGE("null key");
1642 ret = -ENODEV;
1643 goto done;
1644 }
1645
1646 for (i=0; i < len; i++) {
1647 if (!strcmp(table[i].name, name)) {
1648 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001649 goto done;
1650 }
1651 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001652 ALOGE("%s: Could not find index for name = %s",
1653 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001654 ret = -ENODEV;
1655done:
1656 return ret;
1657}
1658
Haynes Mathew George98c95622014-06-20 19:14:25 -07001659int platform_get_snd_device_index(char *device_name)
1660{
1661 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1662}
1663
1664int platform_get_usecase_index(const char *usecase_name)
1665{
1666 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1667}
1668
keunhui.park2f7306a2015-07-16 16:48:06 +09001669void platform_add_operator_specific_device(snd_device_t snd_device,
1670 const char *operator,
1671 const char *mixer_path,
1672 unsigned int acdb_id)
1673{
1674 struct operator_specific_device *device;
1675
1676 if (operator_specific_device_table[snd_device] == NULL) {
1677 operator_specific_device_table[snd_device] =
1678 (struct listnode *)calloc(1, sizeof(struct listnode));
1679 list_init(operator_specific_device_table[snd_device]);
1680 }
1681
1682 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1683
1684 device->operator = strdup(operator);
1685 device->mixer_path = strdup(mixer_path);
1686 device->acdb_id = acdb_id;
1687
1688 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1689
Eric Laurent2bafff12016-03-17 12:17:23 -07001690 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001691 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1692
1693}
1694
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001695int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1696{
1697 int ret = 0;
1698
1699 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1700 ALOGE("%s: Invalid snd_device = %d",
1701 __func__, snd_device);
1702 ret = -EINVAL;
1703 goto done;
1704 }
1705
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001706 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1707 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001708 acdb_device_table[snd_device] = acdb_id;
1709done:
1710 return ret;
1711}
1712
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001713int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1714{
1715 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1716 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1717 return -EINVAL;
1718 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001719
1720 if (operator_specific_device_table[snd_device] != NULL)
1721 return get_operator_specific_device_acdb_id(snd_device);
1722 else
1723 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001724}
1725
David Linee3fe402017-03-13 10:00:42 -07001726static int platform_get_backend_index(snd_device_t snd_device)
1727{
1728 int32_t port = DEFAULT_CODEC_BACKEND;
1729
1730 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1731 if (backend_tag_table[snd_device] != NULL) {
1732 if (strncmp(backend_tag_table[snd_device], "headphones",
1733 sizeof("headphones")) == 0)
1734 port = HEADPHONE_BACKEND;
1735 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1736 port = HDMI_RX_BACKEND;
1737 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1738 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1739 port = USB_AUDIO_RX_BACKEND;
1740 }
1741 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1742 port = DEFAULT_CODEC_TX_BACKEND;
1743 if (backend_tag_table[snd_device] != NULL) {
1744 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1745 port = USB_AUDIO_TX_BACKEND;
1746 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1747 port = BT_SCO_TX_BACKEND;
1748 }
1749 } else {
1750 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1751 }
1752
1753 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1754
1755 return port;
1756}
1757
Eric Laurentb23d5282013-05-14 15:27:20 -07001758int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1759{
1760 struct platform_data *my_data = (struct platform_data *)platform;
1761 int acdb_dev_id, acdb_dev_type;
1762
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001763 if (platform_supports_app_type_cfg()) // use v2 instead
1764 return -ENOSYS;
1765
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001766 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001767 if (acdb_dev_id < 0) {
1768 ALOGE("%s: Could not find acdb id for device(%d)",
1769 __func__, snd_device);
1770 return -EINVAL;
1771 }
1772 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001773 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001774 __func__, snd_device, acdb_dev_id);
1775 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1776 snd_device < SND_DEVICE_OUT_END)
1777 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1778 else
1779 acdb_dev_type = ACDB_DEV_TYPE_IN;
1780 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1781 }
1782 return 0;
1783}
1784
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001785int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1786 int app_type, int sample_rate)
1787{
1788 struct platform_data *my_data = (struct platform_data *)platform;
1789 int acdb_dev_id, acdb_dev_type;
1790 int snd_device = SND_DEVICE_OUT_SPEAKER;
1791 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1792 int i, num_devices = 1;
1793
1794 if (!platform_supports_app_type_cfg()) // use v1 instead
1795 return -ENOSYS;
1796
1797 if (usecase->type == PCM_PLAYBACK)
1798 snd_device = usecase->out_snd_device;
1799 else if (usecase->type == PCM_CAPTURE)
1800 snd_device = usecase->in_snd_device;
1801
1802 // skipped over get_spkr_prot_device
1803 acdb_dev_id = acdb_device_table[snd_device];
1804 if (acdb_dev_id < 0) {
1805 ALOGE("%s: Could not find acdb id for device(%d)",
1806 __func__, snd_device);
1807 return -EINVAL;
1808 }
1809
1810 if (platform_can_split_snd_device(snd_device,
1811 &num_devices, new_snd_device) < 0) {
1812 new_snd_device[0] = snd_device;
1813 }
1814
1815 for (i = 0; i < num_devices; i++) {
1816 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1817 if (acdb_dev_id < 0) {
1818 ALOGE("%s: Could not find acdb id for device(%d)",
1819 __func__, new_snd_device[i]);
1820 return -EINVAL;
1821 }
1822 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1823 __func__, new_snd_device[i], acdb_dev_id);
1824 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1825 new_snd_device[i] < SND_DEVICE_OUT_END)
1826 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1827 else
1828 acdb_dev_type = ACDB_DEV_TYPE_IN;
1829
1830 if (my_data->acdb_send_audio_cal_v3) {
1831 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1832 app_type, sample_rate, i);
1833 } else if (my_data->acdb_send_audio_cal) {
1834 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1835 }
1836 }
1837
1838 return 0;
1839}
1840
1841
Eric Laurentb23d5282013-05-14 15:27:20 -07001842int platform_switch_voice_call_device_pre(void *platform)
1843{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001844 struct platform_data *my_data = (struct platform_data *)platform;
1845 int ret = 0;
1846
1847 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001848 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001849 /* This must be called before disabling mixer controls on APQ side */
1850 ret = my_data->csd->disable_device();
1851 if (ret < 0) {
1852 ALOGE("%s: csd_client_disable_device, failed, error %d",
1853 __func__, ret);
1854 }
1855 }
1856 return ret;
1857}
1858
1859int platform_switch_voice_call_enable_device_config(void *platform,
1860 snd_device_t out_snd_device,
1861 snd_device_t in_snd_device)
1862{
1863 struct platform_data *my_data = (struct platform_data *)platform;
1864 int acdb_rx_id, acdb_tx_id;
1865 int ret = 0;
1866
1867 if (my_data->csd == NULL)
1868 return ret;
1869
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001870 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1871 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001872 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001873 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001874 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001875
keunhui.park2f7306a2015-07-16 16:48:06 +09001876 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001877
1878 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1879 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1880 if (ret < 0) {
1881 ALOGE("%s: csd_enable_device_config, failed, error %d",
1882 __func__, ret);
1883 }
1884 } else {
1885 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1886 acdb_rx_id, acdb_tx_id);
1887 }
1888
1889 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001890}
1891
1892int platform_switch_voice_call_device_post(void *platform,
1893 snd_device_t out_snd_device,
1894 snd_device_t in_snd_device)
1895{
1896 struct platform_data *my_data = (struct platform_data *)platform;
1897 int acdb_rx_id, acdb_tx_id;
1898
1899 if (my_data->acdb_send_voice_cal == NULL) {
1900 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1901 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001902 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1903 audio_extn_spkr_prot_is_enabled())
1904 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1905
keunhui.park2f7306a2015-07-16 16:48:06 +09001906 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1907 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001908
1909 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1910 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1911 else
1912 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1913 acdb_rx_id, acdb_tx_id);
1914 }
1915
1916 return 0;
1917}
1918
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001919int platform_switch_voice_call_usecase_route_post(void *platform,
1920 snd_device_t out_snd_device,
1921 snd_device_t in_snd_device)
1922{
1923 struct platform_data *my_data = (struct platform_data *)platform;
1924 int acdb_rx_id, acdb_tx_id;
1925 int ret = 0;
1926
1927 if (my_data->csd == NULL)
1928 return ret;
1929
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001930 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1931 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001932 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001933 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001934 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001935
keunhui.park2f7306a2015-07-16 16:48:06 +09001936 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001937
1938 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1939 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1940 my_data->adev->acdb_settings);
1941 if (ret < 0) {
1942 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1943 }
1944 } else {
1945 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1946 acdb_rx_id, acdb_tx_id);
1947 }
1948
1949 return ret;
1950}
1951
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001952int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001953{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001954 struct platform_data *my_data = (struct platform_data *)platform;
1955 int ret = 0;
1956
1957 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001958 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001959 if (ret < 0) {
1960 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1961 }
1962 }
1963 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001964}
1965
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001966int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001967{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001968 struct platform_data *my_data = (struct platform_data *)platform;
1969 int ret = 0;
1970
1971 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001972 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001973 if (ret < 0) {
1974 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1975 }
1976 }
1977 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001978}
1979
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001980int platform_get_sample_rate(void *platform, uint32_t *rate)
1981{
1982 struct platform_data *my_data = (struct platform_data *)platform;
1983 int ret = 0;
1984
1985 if (my_data->csd != NULL) {
1986 ret = my_data->csd->get_sample_rate(rate);
1987 if (ret < 0) {
1988 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1989 }
1990 }
1991 return ret;
1992}
1993
vivek mehtab6506412015-08-07 16:55:17 -07001994void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1995 snd_device_t snd_device,
1996 bool enable)
1997{
1998 const char* name;
1999 switch (snd_device) {
2000 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2001 if (enable)
2002 name = "spkr-gain-in-headphone-combo";
2003 else
2004 name = "speaker-gain-default";
2005 break;
2006 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2007 if (enable)
2008 name = "spkr-gain-in-line-combo";
2009 else
2010 name = "speaker-gain-default";
2011 break;
2012 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2013 if (enable)
2014 name = "spkr-safe-gain-in-headphone-combo";
2015 else
2016 name = "speaker-safe-gain-default";
2017 break;
2018 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2019 if (enable)
2020 name = "spkr-safe-gain-in-line-combo";
2021 else
2022 name = "speaker-safe-gain-default";
2023 break;
2024 default:
2025 return;
2026 }
2027
2028 audio_route_apply_and_update_path(adev->audio_route, name);
2029}
2030
Eric Laurentb23d5282013-05-14 15:27:20 -07002031int platform_set_voice_volume(void *platform, int volume)
2032{
2033 struct platform_data *my_data = (struct platform_data *)platform;
2034 struct audio_device *adev = my_data->adev;
2035 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002036 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002037 int vol_index = 0, ret = 0;
2038 uint32_t set_values[ ] = {0,
2039 ALL_SESSION_VSID,
2040 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002041
2042 // Voice volume levels are mapped to adsp volume levels as follows.
2043 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2044 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002045 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002046 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002047
2048 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2049 if (!ctl) {
2050 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2051 __func__, mixer_ctl_name);
2052 return -EINVAL;
2053 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002054 ALOGV("Setting voice volume index: %d", set_values[0]);
2055 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2056
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002057 if (my_data->csd != NULL) {
2058 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2059 DEFAULT_VOLUME_RAMP_DURATION_MS);
2060 if (ret < 0) {
2061 ALOGE("%s: csd_volume error %d", __func__, ret);
2062 }
2063 }
2064 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002065}
2066
2067int platform_set_mic_mute(void *platform, bool state)
2068{
2069 struct platform_data *my_data = (struct platform_data *)platform;
2070 struct audio_device *adev = my_data->adev;
2071 struct mixer_ctl *ctl;
2072 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002073 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002074 uint32_t set_values[ ] = {0,
2075 ALL_SESSION_VSID,
2076 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002077
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002078 if (adev->mode != AUDIO_MODE_IN_CALL &&
2079 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002080 return 0;
2081
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002082 if (adev->enable_hfp)
2083 mixer_ctl_name = "HFP Tx Mute";
2084
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002085 set_values[0] = state;
2086 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2087 if (!ctl) {
2088 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2089 __func__, mixer_ctl_name);
2090 return -EINVAL;
2091 }
2092 ALOGV("Setting voice mute state: %d", state);
2093 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2094
2095 if (my_data->csd != NULL) {
2096 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2097 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002098 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002099 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002100 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002101 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002102 return ret;
2103}
Eric Laurentb23d5282013-05-14 15:27:20 -07002104
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002105int platform_set_device_mute(void *platform, bool state, char *dir)
2106{
2107 struct platform_data *my_data = (struct platform_data *)platform;
2108 struct audio_device *adev = my_data->adev;
2109 struct mixer_ctl *ctl;
2110 char *mixer_ctl_name = NULL;
2111 int ret = 0;
2112 uint32_t set_values[ ] = {0,
2113 ALL_SESSION_VSID,
2114 0};
2115 if(dir == NULL) {
2116 ALOGE("%s: Invalid direction:%s", __func__, dir);
2117 return -EINVAL;
2118 }
2119
2120 if (!strncmp("rx", dir, sizeof("rx"))) {
2121 mixer_ctl_name = "Voice Rx Device Mute";
2122 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2123 mixer_ctl_name = "Voice Tx Device Mute";
2124 } else {
2125 return -EINVAL;
2126 }
2127
2128 set_values[0] = state;
2129 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2130 if (!ctl) {
2131 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2132 __func__, mixer_ctl_name);
2133 return -EINVAL;
2134 }
2135
2136 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2137 __func__,state, mixer_ctl_name);
2138 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2139
2140 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002141}
2142
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002143int platform_can_split_snd_device(snd_device_t snd_device,
2144 int *num_devices,
2145 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002146{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002147 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002148 if (NULL == num_devices || NULL == new_snd_devices) {
2149 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002150 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002151 }
2152
2153 /*
2154 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002155 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002156 */
2157 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2158 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2159 *num_devices = 2;
2160 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2161 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002162 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002163 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2164 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2165 *num_devices = 2;
2166 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2167 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002168 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002169 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2170 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2171 *num_devices = 2;
2172 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2173 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002174 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002175 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2176 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2177 *num_devices = 2;
2178 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2179 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002180 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002181 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2182 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2183 SND_DEVICE_OUT_BT_SCO)) {
2184 *num_devices = 2;
2185 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2186 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2187 ret = 0;
2188 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2189 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2190 SND_DEVICE_OUT_BT_SCO_WB)) {
2191 *num_devices = 2;
2192 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2193 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2194 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002195 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2196 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2197 *num_devices = 2;
2198 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2199 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2200 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002201 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002202 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002203}
2204
Eric Laurentb23d5282013-05-14 15:27:20 -07002205snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2206{
2207 struct platform_data *my_data = (struct platform_data *)platform;
2208 struct audio_device *adev = my_data->adev;
2209 audio_mode_t mode = adev->mode;
2210 snd_device_t snd_device = SND_DEVICE_NONE;
2211
2212 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2213 if (devices == AUDIO_DEVICE_NONE ||
2214 devices & AUDIO_DEVICE_BIT_IN) {
2215 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2216 goto exit;
2217 }
2218
Eric Laurent1b491552015-09-15 17:52:41 -07002219 if (popcount(devices) == 2) {
2220 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2221 AUDIO_DEVICE_OUT_SPEAKER) ||
2222 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2223 AUDIO_DEVICE_OUT_SPEAKER)) {
2224 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2225 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2226 AUDIO_DEVICE_OUT_SPEAKER)) {
2227 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2228 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2229 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2230 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2231 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2232 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2233 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2234 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2235 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2236 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2237 AUDIO_DEVICE_OUT_SPEAKER)) {
2238 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002239 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2240 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2241 snd_device = adev->bt_wb_speech_enabled ?
2242 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2243 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
David Linee3fe402017-03-13 10:00:42 -07002244 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2245 AUDIO_DEVICE_OUT_SPEAKER)) {
2246 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002247 } else {
2248 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2249 goto exit;
2250 }
2251 if (snd_device != SND_DEVICE_NONE) {
2252 goto exit;
2253 }
2254 }
2255
2256 if (popcount(devices) != 1) {
2257 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2258 goto exit;
2259 }
2260
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302261 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002262 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002263 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2264 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002265 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002266 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002267 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002268 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002269 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002270 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002271 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002272 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002273 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002274 else {
2275 if (devices & AUDIO_DEVICE_OUT_LINE)
2276 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2277 else
2278 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2279 }
vivek mehtaa6b79742017-03-09 15:40:43 -08002280 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2281 if (voice_is_in_call(adev)) {
2282 switch (adev->voice.tty_mode) {
2283 case TTY_MODE_FULL:
2284 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2285 break;
2286 case TTY_MODE_VCO:
2287 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2288 break;
2289 case TTY_MODE_HCO:
2290 // since Hearing will be on handset\speaker, use existing device
2291 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2292 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002293 case TTY_MODE_OFF:
2294 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002295 default:
2296 ALOGE("%s: Invalid TTY mode (%#x)",
2297 __func__, adev->voice.tty_mode);
2298 }
2299 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002300 if (snd_device == SND_DEVICE_NONE) {
2301 snd_device = audio_extn_usb_is_capture_supported() ?
2302 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2303 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2304 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002305 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002306 if (adev->bt_wb_speech_enabled) {
2307 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2308 } else {
2309 snd_device = SND_DEVICE_OUT_BT_SCO;
2310 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002311 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002312 if (!adev->enable_hfp) {
2313 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2314 } else {
2315 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2316 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002317 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002318 if(adev->voice.hac)
2319 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2320 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002321 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2322 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002323 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002324 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2325 snd_device = SND_DEVICE_OUT_VOICE_TX;
2326
Eric Laurentb23d5282013-05-14 15:27:20 -07002327 if (snd_device != SND_DEVICE_NONE) {
2328 goto exit;
2329 }
2330 }
2331
Eric Laurentb23d5282013-05-14 15:27:20 -07002332 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2333 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2334 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002335 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2336 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002337 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2338 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002339 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002340 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002341 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2342 else
2343 snd_device = SND_DEVICE_OUT_SPEAKER;
2344 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002345 if (adev->bt_wb_speech_enabled) {
2346 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2347 } else {
2348 snd_device = SND_DEVICE_OUT_BT_SCO;
2349 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002350 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2351 snd_device = SND_DEVICE_OUT_HDMI ;
David Linee3fe402017-03-13 10:00:42 -07002352 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2353 if (audio_extn_usb_is_capture_supported())
2354 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2355 else
2356 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2357 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002358 /*HAC support for voice-ish audio (eg visual voicemail)*/
2359 if(adev->voice.hac)
2360 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2361 else
2362 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002363 } else {
2364 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2365 }
2366exit:
2367 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2368 return snd_device;
2369}
2370
2371snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2372{
2373 struct platform_data *my_data = (struct platform_data *)platform;
2374 struct audio_device *adev = my_data->adev;
2375 audio_source_t source = (adev->active_input == NULL) ?
2376 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2377
2378 audio_mode_t mode = adev->mode;
2379 audio_devices_t in_device = ((adev->active_input == NULL) ?
2380 AUDIO_DEVICE_NONE : adev->active_input->device)
2381 & ~AUDIO_DEVICE_BIT_IN;
2382 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2383 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2384 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002385 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002386
Prashant Malanic92c5962015-08-11 15:10:18 -07002387 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2388 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002389 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2390 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002391 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002392 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002393 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2394 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002395 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002396 case TTY_MODE_FULL:
2397 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2398 break;
2399 case TTY_MODE_VCO:
2400 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2401 break;
2402 case TTY_MODE_HCO:
2403 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2404 break;
2405 default:
2406 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2407 }
2408 goto exit;
2409 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2410 switch (adev->voice.tty_mode) {
2411 case TTY_MODE_FULL:
2412 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2413 break;
2414 case TTY_MODE_VCO:
2415 // since voice will be captured from handset mic, use existing device
2416 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2417 break;
2418 case TTY_MODE_HCO:
2419 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2420 break;
2421 default:
2422 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002423 }
2424 goto exit;
2425 }
2426 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002427 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002428 if (my_data->fluence_in_voice_call == false) {
2429 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2430 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002431 if (is_operator_tmus())
2432 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002433 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002434 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002435 }
2436 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2437 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2438 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002439 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002440 if (adev->bluetooth_nrec)
2441 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2442 else
2443 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002444 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002445 if (adev->bluetooth_nrec)
2446 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2447 else
2448 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002449 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002450 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002451 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2452 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2453 out_device & AUDIO_DEVICE_OUT_LINE) {
2454 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2455 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2456 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2457 } else {
2458 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2459 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002460 }
vivek mehtafe121d52015-08-10 23:39:23 -07002461
2462 //select default
2463 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002464 if (!adev->enable_hfp) {
2465 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2466 } else {
2467 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2468 platform_set_echo_reference(adev, true, out_device);
2469 }
vivek mehtafe121d52015-08-10 23:39:23 -07002470 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002471 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002472 snd_device = SND_DEVICE_IN_VOICE_RX;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002473 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2474 if (audio_extn_usb_is_capture_supported()) {
2475 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2476 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002477 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002478 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2479 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2480 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2481 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2482 }
2483 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2484 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002485 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2486 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2487 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002488 if (adev->active_input->enable_aec)
2489 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2490 else
2491 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002492 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2493 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002494 if (adev->active_input->enable_aec)
2495 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2496 else
2497 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002498 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2499 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2500 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002501 if (adev->active_input->enable_aec)
2502 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2503 else
2504 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002505 }
2506 platform_set_echo_reference(adev, true, out_device);
2507 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2508 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2509 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002510 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002511 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2512 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002513 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002514 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2515 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002516 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002517 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002518 if (adev->active_input->enable_aec) {
2519 if (adev->active_input->enable_ns) {
2520 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2521 } else {
2522 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2523 }
vivek mehta733c1df2016-04-04 15:09:24 -07002524 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002525 } else if (adev->active_input->enable_ns) {
2526 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2527 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002528 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002529 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002530 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002531 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2532 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002533 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2534 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002535 }
rago90fb9612015-12-02 11:37:53 -08002536 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2537 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002538 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2539 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2540 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2541 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002542 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002543 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2544 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002545 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002546 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2547 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2548 } else {
2549 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2550 }
rago90fb9612015-12-02 11:37:53 -08002551 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2552 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002553 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2554 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002555 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002556 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002557 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002558 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002559 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2560 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002561 if (adev->active_input->enable_aec &&
2562 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002563 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002564 if (my_data->fluence_in_spkr_mode &&
2565 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002566 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002567 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002568 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002569 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002570 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002571 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002572 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002573 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002574 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002575 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002576 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002577 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002578 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2579 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002580 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2581 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002582 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002583 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002584 } else if (adev->active_input->enable_aec) {
2585 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2586 if (my_data->fluence_in_spkr_mode &&
2587 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002588 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002589 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002590 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002591 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002592 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002593 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2594 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002595 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002596 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002597 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002598 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002599 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002600 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2601 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002602 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2603 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002604 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002605 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002606 } else if (adev->active_input->enable_ns) {
2607 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2608 if (my_data->fluence_in_spkr_mode &&
2609 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002610 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002611 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002612 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002613 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002614 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002615 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2616 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002617 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002618 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002619 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002620 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002621 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002622 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002623 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002624 }
2625 } else if (source == AUDIO_SOURCE_DEFAULT) {
2626 goto exit;
2627 }
2628
2629
2630 if (snd_device != SND_DEVICE_NONE) {
2631 goto exit;
2632 }
2633
2634 if (in_device != AUDIO_DEVICE_NONE &&
2635 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2636 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2637 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002638 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002639 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002640 snd_device = SND_DEVICE_IN_QUAD_MIC;
2641 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002642 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002643 snd_device = SND_DEVICE_IN_THREE_MIC;
2644 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2645 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002646 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002647 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2648 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002649 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002650 } else {
2651 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2652 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2653 my_data->source_mic_type, channel_count, channel_mask);
2654 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2655 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002656 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002657 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2658 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002659 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002660 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2661 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002662 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002663 } else {
2664 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2665 " no combination found .. setting to mono", __func__,
2666 my_data->source_mic_type, channel_count);
2667 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2668 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002669 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2670 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2671 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002672 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002673 if (adev->bluetooth_nrec)
2674 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2675 else
2676 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002677 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002678 if (adev->bluetooth_nrec)
2679 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2680 else
2681 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002682 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002683 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2684 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002685 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2686 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002687 } else {
2688 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2689 ALOGW("%s: Using default handset-mic", __func__);
2690 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2691 }
2692 } else {
2693 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2694 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2695 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2696 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002697 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002698 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002699 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002700 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002701 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2702 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002703 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002704 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2705 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002706 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002707 } else {
2708 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2709 " no combination found .. setting to mono", __func__,
2710 my_data->source_mic_type, channel_count);
2711 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2712 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002713 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002714 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002715 if (adev->bluetooth_nrec)
2716 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2717 else
2718 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002719 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002720 if (adev->bluetooth_nrec)
2721 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2722 else
2723 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002724 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002725 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2726 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002727 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2728 if (audio_extn_usb_is_capture_supported())
2729 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2730 else
2731 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002732 } else {
2733 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2734 ALOGW("%s: Using default handset-mic", __func__);
2735 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2736 }
2737 }
2738exit:
2739 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2740 return snd_device;
2741}
2742
2743int platform_set_hdmi_channels(void *platform, int channel_count)
2744{
2745 struct platform_data *my_data = (struct platform_data *)platform;
2746 struct audio_device *adev = my_data->adev;
2747 struct mixer_ctl *ctl;
2748 const char *channel_cnt_str = NULL;
2749 const char *mixer_ctl_name = "HDMI_RX Channels";
2750 switch (channel_count) {
2751 case 8:
2752 channel_cnt_str = "Eight"; break;
2753 case 7:
2754 channel_cnt_str = "Seven"; break;
2755 case 6:
2756 channel_cnt_str = "Six"; break;
2757 case 5:
2758 channel_cnt_str = "Five"; break;
2759 case 4:
2760 channel_cnt_str = "Four"; break;
2761 case 3:
2762 channel_cnt_str = "Three"; break;
2763 default:
2764 channel_cnt_str = "Two"; break;
2765 }
2766 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2767 if (!ctl) {
2768 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2769 __func__, mixer_ctl_name);
2770 return -EINVAL;
2771 }
2772 ALOGV("HDMI channel count: %s", channel_cnt_str);
2773 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2774 return 0;
2775}
2776
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002777int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002778{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002779 struct platform_data *my_data = (struct platform_data *)platform;
2780 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002781 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2782 char *sad = block;
2783 int num_audio_blocks;
2784 int channel_count;
2785 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002786 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002787
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002788 struct mixer_ctl *ctl;
2789
2790 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2791 if (!ctl) {
2792 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2793 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002794 return 0;
2795 }
2796
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002797 mixer_ctl_update(ctl);
2798
2799 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002800
2801 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002802 if (count > (int)sizeof(block))
2803 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002804
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002805 ret = mixer_ctl_get_array(ctl, block, count);
2806 if (ret != 0) {
2807 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2808 return 0;
2809 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002810
2811 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002812 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002813
2814 for (i = 0; i < num_audio_blocks; i++) {
2815 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002816 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2817 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002818 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002819 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002820
2821 channel_count = (sad[0] & 0x7) + 1;
2822 if (channel_count > max_channels)
2823 max_channels = channel_count;
2824
2825 /* Advance to next block */
2826 sad += 3;
2827 }
2828
2829 return max_channels;
2830}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002831
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002832int platform_set_incall_recording_session_id(void *platform,
2833 uint32_t session_id, int rec_mode)
2834{
2835 int ret = 0;
2836 struct platform_data *my_data = (struct platform_data *)platform;
2837 struct audio_device *adev = my_data->adev;
2838 struct mixer_ctl *ctl;
2839 const char *mixer_ctl_name = "Voc VSID";
2840 int num_ctl_values;
2841 int i;
2842
2843 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2844 if (!ctl) {
2845 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2846 __func__, mixer_ctl_name);
2847 ret = -EINVAL;
2848 } else {
2849 num_ctl_values = mixer_ctl_get_num_values(ctl);
2850 for (i = 0; i < num_ctl_values; i++) {
2851 if (mixer_ctl_set_value(ctl, i, session_id)) {
2852 ALOGV("Error: invalid session_id: %x", session_id);
2853 ret = -EINVAL;
2854 break;
2855 }
2856 }
2857 }
2858
2859 if (my_data->csd != NULL) {
2860 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2861 if (ret < 0) {
2862 ALOGE("%s: csd_client_start_record failed, error %d",
2863 __func__, ret);
2864 }
2865 }
2866
2867 return ret;
2868}
2869
2870int platform_stop_incall_recording_usecase(void *platform)
2871{
2872 int ret = 0;
2873 struct platform_data *my_data = (struct platform_data *)platform;
2874
2875 if (my_data->csd != NULL) {
2876 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2877 if (ret < 0) {
2878 ALOGE("%s: csd_client_stop_record failed, error %d",
2879 __func__, ret);
2880 }
2881 }
2882
2883 return ret;
2884}
2885
2886int platform_start_incall_music_usecase(void *platform)
2887{
2888 int ret = 0;
2889 struct platform_data *my_data = (struct platform_data *)platform;
2890
2891 if (my_data->csd != NULL) {
2892 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2893 if (ret < 0) {
2894 ALOGE("%s: csd_client_start_playback failed, error %d",
2895 __func__, ret);
2896 }
2897 }
2898
2899 return ret;
2900}
2901
2902int platform_stop_incall_music_usecase(void *platform)
2903{
2904 int ret = 0;
2905 struct platform_data *my_data = (struct platform_data *)platform;
2906
2907 if (my_data->csd != NULL) {
2908 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2909 if (ret < 0) {
2910 ALOGE("%s: csd_client_stop_playback failed, error %d",
2911 __func__, ret);
2912 }
2913 }
2914
2915 return ret;
2916}
2917
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002918int platform_set_parameters(void *platform, struct str_parms *parms)
2919{
2920 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002921 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002922 char *kv_pairs = str_parms_to_str(parms);
2923 int ret = 0, err;
2924
2925 if (kv_pairs == NULL) {
2926 ret = -EINVAL;
2927 ALOGE("%s: key-value pair is NULL",__func__);
2928 goto done;
2929 }
2930
2931 ALOGV("%s: enter: %s", __func__, kv_pairs);
2932
2933 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2934 value, sizeof(value));
2935 if (err >= 0) {
2936 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2937 my_data->snd_card_name = strdup(value);
2938 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2939 }
2940
keunhui.park2f7306a2015-07-16 16:48:06 +09002941 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2942 value, sizeof(value));
2943 if (err >= 0) {
2944 struct operator_info *info;
2945 char *str = value;
2946 char *name;
2947
2948 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2949 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2950 name = strtok(str, ";");
2951 info->name = strdup(name);
2952 info->mccmnc = strdup(str + strlen(name) + 1);
2953
2954 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002955 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002956 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002957
2958 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002959 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002960 value, sizeof(value));
2961 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002962 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002963 my_data->max_mic_count = atoi(value);
2964 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002965 }
2966
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002967done:
2968 ALOGV("%s: exit with code(%d)", __func__, ret);
2969 if (kv_pairs != NULL)
2970 free(kv_pairs);
2971
2972 return ret;
2973}
2974
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002975/* Delay in Us */
2976int64_t platform_render_latency(audio_usecase_t usecase)
2977{
2978 switch (usecase) {
2979 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2980 return DEEP_BUFFER_PLATFORM_DELAY;
2981 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2982 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002983 case USECASE_AUDIO_PLAYBACK_ULL:
2984 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002985 case USECASE_AUDIO_PLAYBACK_MMAP:
2986 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002987 default:
2988 return 0;
2989 }
2990}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002991
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002992int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2993 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002994{
2995 int ret = 0;
2996
2997 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2998 ALOGE("%s: Invalid snd_device = %d",
2999 __func__, device);
3000 ret = -EINVAL;
3001 goto done;
3002 }
3003
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003004 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3005 platform_get_snd_device_name(device),
3006 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3007 if (backend_tag_table[device]) {
3008 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003009 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003010 backend_tag_table[device] = strdup(backend_tag);
3011
3012 if (hw_interface != NULL) {
3013 if (hw_interface_table[device])
3014 free(hw_interface_table[device]);
3015 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3016 hw_interface_table[device] = strdup(hw_interface);
3017 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003018done:
3019 return ret;
3020}
3021
3022int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3023{
3024 int ret = 0;
3025 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3026 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3027 ret = -EINVAL;
3028 goto done;
3029 }
3030
3031 if ((type != 0) && (type != 1)) {
3032 ALOGE("%s: invalid usecase type", __func__);
3033 ret = -EINVAL;
3034 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003035 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003036 pcm_device_table[usecase][type] = pcm_id;
3037done:
3038 return ret;
3039}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003040
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003041#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3042int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3043 // backup_gain: gain to try to set in case of an error during ramp
3044 int start_gain, end_gain, step, backup_gain, i;
3045 bool error = false;
3046 const struct mixer_ctl *ctl;
3047 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3048 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3049 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3050 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3051 if (!ctl_left || !ctl_right) {
3052 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3053 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3054 return -EINVAL;
3055 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3056 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3057 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3058 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3059 return -EINVAL;
3060 }
3061 if (ramp_up) {
3062 start_gain = 0;
3063 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3064 step = +1;
3065 backup_gain = end_gain;
3066 } else {
3067 // using same gain on left and right
3068 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3069 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3070 end_gain = 0;
3071 step = -1;
3072 backup_gain = start_gain;
3073 }
3074 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3075 //ALOGV("setting speaker gain to %d", i);
3076 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3077 ALOGE("%s: error setting %s to %d during gain ramp",
3078 __func__, mixer_ctl_name_gain_left, i);
3079 error = true;
3080 break;
3081 }
3082 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3083 ALOGE("%s: error setting %s to %d during gain ramp",
3084 __func__, mixer_ctl_name_gain_right, i);
3085 error = true;
3086 break;
3087 }
3088 usleep(1000);
3089 }
3090 if (error) {
3091 // an error occured during the ramp, let's still try to go back to a safe volume
3092 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3093 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3094 }
3095 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3096 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3097 }
3098 }
3099 return start_gain;
3100}
3101
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003102int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
3103{
3104 // only update if there is active pcm playback on speaker
3105 struct audio_usecase *usecase;
3106 struct listnode *node;
3107 struct platform_data *my_data = (struct platform_data *)adev->platform;
3108
3109 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003110
3111 // do not swap channels in audio modes with concurrent capture and playback
3112 // as this may break the echo reference
3113 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3114 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3115 return 0;
3116 }
3117
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003118 my_data->speaker_lr_swap = swap_channels;
3119
3120 list_for_each(node, &adev->usecase_list) {
3121 usecase = node_to_item(node, struct audio_usecase, list);
3122 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003123 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3124 /*
3125 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3126 * to perform device switch to disable the current backend to
3127 * enable it with new acdb data.
3128 */
3129 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3130 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003131 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003132 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003133 if (initial_skpr_gain != -EINVAL) {
3134 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3135 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003136 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003137 const char *mixer_path;
3138 if (swap_channels) {
3139 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3140 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3141 } else {
3142 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3143 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3144 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003145 }
3146 break;
3147 }
3148 }
3149 }
3150 return 0;
3151}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003152
3153static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3154static int num_gain_tbl_entry = 0;
3155
3156bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3157
3158 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3159 if (num_gain_tbl_entry == -1) {
3160 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3161 __func__);
3162 return false;
3163 }
3164
3165 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3166 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3167 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3168 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3169 return false;
3170 }
3171
3172 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3173 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3174 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3175 return false;
3176 }
3177
3178 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3179 ++num_gain_tbl_entry;
3180
3181 return true;
3182}
3183
3184int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3185 int table_size) {
3186 int itt = 0;
3187 ALOGV("platform_get_gain_level_mapping called ");
3188
3189 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3190 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3191 return 0;
3192 }
3193
3194 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3195 mapping_tbl[itt] = tbl_mapping[itt];
3196 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3197 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3198 }
3199
3200 return num_gain_tbl_entry;
3201}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003202
3203int platform_snd_card_update(void *platform, card_status_t status)
3204{
3205 struct platform_data *my_data = (struct platform_data *)platform;
3206 struct audio_device *adev = my_data->adev;
3207
3208 if (status == CARD_STATUS_ONLINE) {
3209 if (my_data->acdb_send_custom_top)
3210 my_data->acdb_send_custom_top();
3211 }
3212 return 0;
3213}
David Linee3fe402017-03-13 10:00:42 -07003214
3215/*
3216 * configures afe with bit width and Sample Rate
3217 */
3218static int platform_set_backend_cfg(const struct audio_device* adev,
3219 snd_device_t snd_device,
3220 const struct audio_backend_cfg *backend_cfg)
3221{
3222
3223 int ret = 0;
3224 const int backend_idx = platform_get_backend_index(snd_device);
3225 struct platform_data *my_data = (struct platform_data *)adev->platform;
3226 const unsigned int bit_width = backend_cfg->bit_width;
3227 const unsigned int sample_rate = backend_cfg->sample_rate;
3228 const unsigned int channels = backend_cfg->channels;
3229 const audio_format_t format = backend_cfg->format;
3230 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3231
3232
3233 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3234 ", backend_idx %d device (%s)", __func__, bit_width,
3235 sample_rate, channels, backend_idx,
3236 platform_get_snd_device_name(snd_device));
3237
3238 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3239 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3240
3241 struct mixer_ctl *ctl = NULL;
3242 ctl = mixer_get_ctl_by_name(adev->mixer,
3243 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3244 if (!ctl) {
3245 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3246 __func__,
3247 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3248 return -EINVAL;
3249 }
3250
3251 if (bit_width == 24) {
3252 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3253 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3254 else
3255 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3256 } else if (bit_width == 32) {
3257 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3258 } else {
3259 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3260 }
3261 if ( ret < 0) {
3262 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3263 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3264 } else {
3265 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3266 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3267 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3268 }
3269 /* set the ret as 0 and not pass back to upper layer */
3270 ret = 0;
3271 }
3272
3273 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3274 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3275 char *rate_str = NULL;
3276 struct mixer_ctl *ctl = NULL;
3277
3278 switch (sample_rate) {
3279 case 32000:
3280 if (passthrough_enabled) {
3281 rate_str = "KHZ_32";
3282 break;
3283 }
3284 case 8000:
3285 case 11025:
3286 case 16000:
3287 case 22050:
3288 case 48000:
3289 rate_str = "KHZ_48";
3290 break;
3291 case 44100:
3292 rate_str = "KHZ_44P1";
3293 break;
3294 case 64000:
3295 case 96000:
3296 rate_str = "KHZ_96";
3297 break;
3298 case 88200:
3299 rate_str = "KHZ_88P2";
3300 break;
3301 case 176400:
3302 rate_str = "KHZ_176P4";
3303 break;
3304 case 192000:
3305 rate_str = "KHZ_192";
3306 break;
3307 case 352800:
3308 rate_str = "KHZ_352P8";
3309 break;
3310 case 384000:
3311 rate_str = "KHZ_384";
3312 break;
3313 case 144000:
3314 if (passthrough_enabled) {
3315 rate_str = "KHZ_144";
3316 break;
3317 }
3318 default:
3319 rate_str = "KHZ_48";
3320 break;
3321 }
3322
3323 ctl = mixer_get_ctl_by_name(adev->mixer,
3324 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3325 if(!ctl) {
3326 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3327 __func__,
3328 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3329 return -EINVAL;
3330 }
3331
3332 ALOGD("%s:becf: afe: %s set to %s", __func__,
3333 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3334 mixer_ctl_set_enum_by_string(ctl, rate_str);
3335 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3336 }
3337 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3338 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3339 struct mixer_ctl *ctl = NULL;
3340 char *channel_cnt_str = NULL;
3341
3342 switch (channels) {
3343 case 8:
3344 channel_cnt_str = "Eight"; break;
3345 case 7:
3346 channel_cnt_str = "Seven"; break;
3347 case 6:
3348 channel_cnt_str = "Six"; break;
3349 case 5:
3350 channel_cnt_str = "Five"; break;
3351 case 4:
3352 channel_cnt_str = "Four"; break;
3353 case 3:
3354 channel_cnt_str = "Three"; break;
3355 case 1:
3356 channel_cnt_str = "One"; break;
3357 case 2:
3358 default:
3359 channel_cnt_str = "Two"; break;
3360 }
3361
3362 ctl = mixer_get_ctl_by_name(adev->mixer,
3363 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3364 if (!ctl) {
3365 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3366 __func__,
3367 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3368 return -EINVAL;
3369 }
3370 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3371 my_data->current_backend_cfg[backend_idx].channels = channels;
3372
3373 // skip EDID configuration for HDMI backend
3374
3375 ALOGD("%s:becf: afe: %s set to %s", __func__,
3376 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3377 channel_cnt_str);
3378 }
3379
3380 // skip set ext_display format mixer control
3381 return ret;
3382}
3383
3384static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3385{
3386 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3387 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3388 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3389 }
3390
3391 return backend_bit_width_table[snd_device];
3392}
3393
3394/*
3395 * return backend_idx on which voice call is active
3396 */
3397static int platform_get_voice_call_backend(struct audio_device* adev)
3398{
3399 struct audio_usecase *uc = NULL;
3400 struct listnode *node;
3401 snd_device_t out_snd_device = SND_DEVICE_NONE;
3402
3403 int backend_idx = -1;
3404
3405 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3406 list_for_each(node, &adev->usecase_list) {
3407 uc = node_to_item(node, struct audio_usecase, list);
3408 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3409 out_snd_device = platform_get_output_snd_device(adev->platform,
3410 uc->stream.out->devices);
3411 backend_idx = platform_get_backend_index(out_snd_device);
3412 break;
3413 }
3414 }
3415 }
3416 return backend_idx;
3417}
3418
3419/*
3420 * goes through all the current usecases and picks the highest
3421 * bitwidth & samplerate
3422 */
3423static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3424 int backend_idx,
3425 struct audio_backend_cfg *backend_cfg)
3426{
3427 bool backend_change = false;
3428 unsigned int bit_width;
3429 unsigned int sample_rate;
3430 unsigned int channels;
3431 struct platform_data *my_data = (struct platform_data *)adev->platform;
3432
3433 bit_width = backend_cfg->bit_width;
3434 sample_rate = backend_cfg->sample_rate;
3435 channels = backend_cfg->channels;
3436
3437 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3438 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3439 sample_rate, channels);
3440
3441 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3442 // default backend
3443 // force routing is not required here, caller will do it anyway
3444 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3445 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3446 "for unprocessed/camera source", __func__);
3447 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3448 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3449 }
3450
3451 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3452 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3453 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3454 __func__, bit_width, sample_rate, channels);
3455 }
3456
3457 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3458 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3459
3460 // Force routing if the expected bitwdith or samplerate
3461 // is not same as current backend comfiguration
3462 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3463 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3464 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3465 backend_cfg->bit_width = bit_width;
3466 backend_cfg->sample_rate= sample_rate;
3467 backend_cfg->channels = channels;
3468 backend_change = true;
3469 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3470 "new sample rate: %d new channel: %d",
3471 __func__, backend_cfg->bit_width,
3472 backend_cfg->sample_rate, backend_cfg->channels);
3473 }
3474
3475 return backend_change;
3476}
3477
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003478static void pick_playback_cfg_for_uc(struct audio_device *adev,
3479 struct audio_usecase *usecase,
3480 snd_device_t snd_device,
3481 unsigned int *bit_width,
3482 unsigned int *sample_rate,
3483 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003484{
3485 int i =0;
3486 struct listnode *node;
3487 list_for_each(node, &adev->usecase_list) {
3488 struct audio_usecase *uc;
3489 uc = node_to_item(node, struct audio_usecase, list);
3490 struct stream_out *out = (struct stream_out*) uc->stream.out;
3491 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3492 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3493 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3494 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3495 uc->id, out->sample_rate,
3496 pcm_format_to_bits(out->config.format), out_channels,
3497 platform_get_snd_device_name(uc->out_snd_device));
3498
3499 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3500 if (*bit_width < pcm_format_to_bits(out->config.format))
3501 *bit_width = pcm_format_to_bits(out->config.format);
3502 if (*sample_rate < out->sample_rate)
3503 *sample_rate = out->sample_rate;
3504 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3505 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3506 if (*channels < out_channels)
3507 *channels = out_channels;
3508 }
3509 }
3510 }
3511 return;
3512}
3513
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003514static void headset_is_config_supported(unsigned int *bit_width,
3515 unsigned int *sample_rate,
3516 unsigned int *channels) {
3517 switch (*bit_width) {
3518 case 16:
3519 case 24:
3520 break;
3521 default:
3522 *bit_width = 16;
3523 break;
3524 }
3525
3526 if (*sample_rate > 192000) {
3527 *sample_rate = 192000;
3528 }
3529
3530 if (*channels > 2) {
3531 *channels = 2;
3532 }
3533}
3534
David Linee3fe402017-03-13 10:00:42 -07003535static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3536 struct audio_usecase* usecase,
3537 snd_device_t snd_device,
3538 struct audio_backend_cfg *backend_cfg)
3539{
3540 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003541 unsigned int bit_width;
3542 unsigned int sample_rate;
3543 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003544 int backend_idx = DEFAULT_CODEC_BACKEND;
3545 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003546
3547 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3548 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3549 backend_change = false;
3550 return backend_change;
3551 }
3552
3553 backend_idx = platform_get_backend_index(snd_device);
3554 bit_width = backend_cfg->bit_width;
3555 sample_rate = backend_cfg->sample_rate;
3556 channels = backend_cfg->channels;
3557
3558 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3559 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3560 sample_rate, channels, backend_idx, usecase->id,
3561 platform_get_snd_device_name(snd_device));
3562
3563 if (backend_idx == platform_get_voice_call_backend(adev)) {
3564 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3565 __func__);
3566 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3567 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3568 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3569 } else {
3570 /*
3571 * The backend should be configured at highest bit width and/or
3572 * sample rate amongst all playback usecases.
3573 * If the selected sample rate and/or bit width differ with
3574 * current backend sample rate and/or bit width, then, we set the
3575 * backend re-configuration flag.
3576 *
3577 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3578 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003579 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3580 &bit_width,
3581 &sample_rate,
3582 &channels);
David Linee3fe402017-03-13 10:00:42 -07003583 }
3584
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003585 switch (backend_idx) {
3586 case USB_AUDIO_RX_BACKEND:
3587 audio_extn_usb_is_config_supported(&bit_width,
3588 &sample_rate, &channels, true);
3589 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3590 __func__, bit_width, sample_rate, channels);
3591 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003592 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003593 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3594 break;
3595 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003596 default:
3597 bit_width = platform_get_snd_device_bit_width(snd_device);
3598 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3599 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3600 break;
David Linee3fe402017-03-13 10:00:42 -07003601 }
3602
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003603 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3604 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003605 __func__, backend_idx , bit_width, sample_rate);
3606
3607 // Force routing if the expected bitwdith or samplerate
3608 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003609 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3610 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3611 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003612 backend_cfg->bit_width = bit_width;
3613 backend_cfg->sample_rate = sample_rate;
3614 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003615 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003616 backend_change = true;
3617 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3618 "new sample rate: %d new channels: %d",
3619 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3620 }
3621
3622 return backend_change;
3623}
3624
3625bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3626 struct audio_usecase *usecase, snd_device_t snd_device)
3627{
3628 int backend_idx = DEFAULT_CODEC_BACKEND;
3629 int new_snd_devices[SND_DEVICE_OUT_END];
3630 int i, num_devices = 1;
3631 bool ret = false;
3632 struct platform_data *my_data = (struct platform_data *)adev->platform;
3633 struct audio_backend_cfg backend_cfg;
3634
3635 backend_idx = platform_get_backend_index(snd_device);
3636
3637 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3638 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3639 backend_cfg.format = usecase->stream.out->format;
3640 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3641 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3642 backend_cfg.passthrough_enabled = false;
3643
3644 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3645 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3646 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3647 platform_get_snd_device_name(snd_device));
3648
3649 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3650 new_snd_devices[0] = snd_device;
3651
3652 for (i = 0; i < num_devices; i++) {
3653 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3654 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3655 &backend_cfg))) {
3656 platform_set_backend_cfg(adev, new_snd_devices[i],
3657 &backend_cfg);
3658 ret = true;
3659 }
3660 }
3661 return ret;
3662}
3663
3664bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3665 struct audio_usecase *usecase, snd_device_t snd_device)
3666{
3667 int backend_idx = platform_get_backend_index(snd_device);
3668 int ret = 0;
3669 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003670 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003671
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003672 if (usecase->type == PCM_CAPTURE) {
3673 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003674 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3675 } else {
3676 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3677 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3678 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3679 backend_cfg.channels = 1;
3680 }
3681
3682 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3683 ", backend_idx %d usecase = %d device (%s)", __func__,
3684 backend_cfg.bit_width,
3685 backend_cfg.sample_rate,
3686 backend_cfg.channels,
3687 backend_idx, usecase->id,
3688 platform_get_snd_device_name(snd_device));
3689
3690 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3691 ret = platform_set_backend_cfg(adev, snd_device,
3692 &backend_cfg);
3693 if(!ret)
3694 return true;
3695 }
3696
3697 return false;
3698}
3699
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003700static int max_be_dai_names = 0;
3701static const struct be_dai_name_struct *be_dai_name_table;
3702
3703/*
3704 * Retrieves the be_dai_name_table from kernel to enable a mapping
3705 * between sound device hw interfaces and backend IDs. This allows HAL to
3706 * specify the backend a specific calibration is needed for.
3707 */
3708static int init_be_dai_name_table(struct audio_device *adev)
3709{
3710 const char *mixer_ctl_name = "Backend DAI Name Table";
3711 struct mixer_ctl *ctl;
3712 int i, j, ret, size;
3713 bool valid_hw_interface;
3714
3715 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3716 if (!ctl) {
3717 ALOGE("%s: Could not get ctl for mixer name %s\n",
3718 __func__, mixer_ctl_name);
3719 ret = -EINVAL;
3720 goto done;
3721 }
3722
3723 mixer_ctl_update(ctl);
3724
3725 size = mixer_ctl_get_num_values(ctl);
3726 if (size <= 0){
3727 ALOGE("%s: Failed to get %s size %d\n",
3728 __func__, mixer_ctl_name, size);
3729 ret = -EFAULT;
3730 goto done;
3731 }
3732
3733 posix_memalign((void **)&be_dai_name_table, 32, size);
3734 if (be_dai_name_table == NULL) {
3735 ALOGE("%s: Failed to allocate memory for %s\n",
3736 __func__, mixer_ctl_name);
3737 ret = -ENOMEM;
3738 goto freeMem;
3739 }
3740
3741 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3742 if (ret) {
3743 ALOGE("%s: Failed to get %s, ret %d\n",
3744 __func__, mixer_ctl_name, ret);
3745 ret = -EFAULT;
3746 goto freeMem;
3747 }
3748
3749 if (be_dai_name_table != NULL) {
3750 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3751 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3752 __func__, mixer_ctl_name, max_be_dai_names);
3753 ret = 0;
3754 } else {
3755 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3756 ret = -EFAULT;
3757 goto freeMem;
3758 }
3759
3760 /*
3761 * Validate all sound devices have a valid backend set to catch
3762 * errors for uncommon sound devices
3763 */
3764 for (i = 0; i < SND_DEVICE_MAX; i++) {
3765 valid_hw_interface = false;
3766
3767 if (hw_interface_table[i] == NULL) {
3768 ALOGW("%s: sound device %s has no hw interface set\n",
3769 __func__, platform_get_snd_device_name(i));
3770 continue;
3771 }
3772
3773 for (j = 0; j < max_be_dai_names; j++) {
3774 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3775 == 0) {
3776 valid_hw_interface = true;
3777 break;
3778 }
3779 }
3780 if (!valid_hw_interface)
3781 ALOGD("%s: sound device %s does not have a valid hw interface set "
3782 "(disregard for combo devices) %s\n",
3783 __func__, platform_get_snd_device_name(i),
3784 hw_interface_table[i]);
3785 }
3786
3787 goto done;
3788
3789freeMem:
3790 if (be_dai_name_table) {
3791 free((void *)be_dai_name_table);
3792 be_dai_name_table = NULL;
3793 }
3794
3795done:
3796 return ret;
3797}
3798
3799int platform_get_snd_device_backend_index(snd_device_t device)
3800{
3801 int i, be_dai_id;
3802 const char * hw_interface_name = NULL;
3803
3804 ALOGV("%s: enter with device %d\n", __func__, device);
3805
3806 if ((device <= SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3807 ALOGE("%s: Invalid snd_device = %d",
3808 __func__, device);
3809 be_dai_id = -EINVAL;
3810 goto done;
3811 }
3812
3813 /* Get string value of necessary backend for device */
3814 hw_interface_name = hw_interface_table[device];
3815 if (hw_interface_name == NULL) {
3816 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3817 be_dai_id = -EINVAL;
3818 goto done;
3819 }
3820
3821 /* Check if be dai name table was retrieved successfully */
3822 if (be_dai_name_table == NULL) {
3823 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3824 be_dai_id = -EFAULT;
3825 goto done;
3826 }
3827
3828 /* Get backend ID for device specified */
3829 for (i = 0; i < max_be_dai_names; i++) {
3830 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3831 be_dai_id = be_dai_name_table[i].be_id;
3832 goto done;
3833 }
3834 }
3835 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3836 be_dai_id = -EINVAL;
3837 goto done;
3838
3839done:
3840 return be_dai_id;
3841}
3842
3843void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3844 unsigned int stream_sr, int* sample_rate)
3845{
3846 struct platform_data* my_data = (struct platform_data *)platform;
3847 int backend_idx = platform_get_backend_index(snd_device);
3848 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3849 /*
3850 *Check if device SR is multiple of 8K or 11.025 Khz
3851 *check if the stream SR is multiple of same base, if yes
3852 *then have copp SR equal to stream SR, this ensures that
3853 *post processing happens at stream SR, else have
3854 *copp SR equal to device SR.
3855 */
3856 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3857 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3858 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3859 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
3860 *sample_rate = device_sr;
3861 } else
3862 *sample_rate = stream_sr;
3863
3864 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
3865 , *sample_rate);
3866
3867}
3868
3869// called from info parser
3870void platform_add_app_type(int bw, const char *uc_type,
3871 int app_type, int max_rate) {
3872 struct app_type_entry *ap =
3873 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
3874
3875 if (!ap) {
3876 ALOGE("%s failed to allocate mem for app type", __func__);
3877 return;
3878 }
3879
3880 ap->uc_type = -1;
3881 for (int i=0; i<USECASE_TYPE_MAX; i++) {
3882 if (!strcmp(uc_type, usecase_type_index[i].name)) {
3883 ap->uc_type = usecase_type_index[i].index;
3884 break;
3885 }
3886 }
3887
3888 if (ap->uc_type == -1) {
3889 free(ap);
3890 return;
3891 }
3892
3893 ALOGI("%s bw %d uc %s app_type %d max_rate %d",
3894 __func__, bw, uc_type, app_type, max_rate);
3895 ap->bit_width = bw;
3896 ap->app_type = app_type;
3897 ap->max_rate = max_rate;
3898 list_add_tail(&app_type_entry_list, &ap->node);
3899}
3900
3901
3902int platform_get_default_app_type_v2(void *platform __unused,
3903 usecase_type_t type,
3904 int *app_type )
3905{
3906 if (type == PCM_PLAYBACK)
3907 *app_type = DEFAULT_APP_TYPE_RX_PATH;
3908 else
3909 *app_type = DEFAULT_APP_TYPE_TX_PATH;
3910 return 0;
3911}
3912
3913int platform_get_app_type_v2(void *platform, usecase_type_t uc_type,
3914 int bw, int sr __unused,
3915 int *app_type)
3916{
3917 struct listnode *node;
3918 struct app_type_entry *entry;
3919 *app_type = -1;
3920 list_for_each(node, &app_type_entry_list) {
3921 entry = node_to_item(node, struct app_type_entry, node);
3922 if (entry->bit_width == bw &&
3923 entry->uc_type == uc_type) {
3924 *app_type = entry->app_type;
3925 break;
3926 }
3927 }
3928
3929 if (*app_type == -1) {
3930 return platform_get_default_app_type_v2(platform, uc_type, app_type);
3931 }
3932 return 0;
3933}