blob: 66719bbb28f6b144220f2120edfb993a29689bb9 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
22#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070023#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/properties.h>
25#include <audio_hw.h>
26#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070027#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070028#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070029#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070030#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070031
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090032#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
33#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080034#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
35#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
36
Eric Laurentb23d5282013-05-14 15:27:20 -070037#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070038#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090039#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070040
Eric Laurentf9583c32016-03-28 13:50:50 -070041#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070042
43/*
Eric Laurentb23d5282013-05-14 15:27:20 -070044 * This file will have a maximum of 38 bytes:
45 *
46 * 4 bytes: number of audio blocks
47 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
48 * Maximum 10 * 3 bytes: SAD blocks
49 */
50#define MAX_SAD_BLOCKS 10
51#define SAD_BLOCK_SIZE 3
52
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090053#define MAX_CVD_VERSION_STRING_SIZE 100
54
Eric Laurentb23d5282013-05-14 15:27:20 -070055/* EDID format ID for LPCM audio */
56#define EDID_FORMAT_LPCM 1
57
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070058#define MAX_SND_CARD_NAME_LEN 31
59
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080060#define DEFAULT_APP_TYPE_RX_PATH 69936
61#define DEFAULT_APP_TYPE_TX_PATH 69938
vivek mehta1a9b7c02015-06-25 11:49:38 -070062
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090063#define TOSTRING_(x) #x
64#define TOSTRING(x) TOSTRING_(x)
65
Eric Laurentb23d5282013-05-14 15:27:20 -070066struct audio_block_header
67{
68 int reserved;
69 int length;
70};
71
vivek mehta1a9b7c02015-06-25 11:49:38 -070072enum {
73 CAL_MODE_SEND = 0x1,
74 CAL_MODE_PERSIST = 0x2,
75 CAL_MODE_RTAC = 0x4
76};
77
keunhui.park2f7306a2015-07-16 16:48:06 +090078#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
79
80struct operator_info {
81 struct listnode list;
82 char *name;
83 char *mccmnc;
84};
85
86struct operator_specific_device {
87 struct listnode list;
88 char *operator;
89 char *mixer_path;
90 int acdb_id;
91};
92
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080093#define BE_DAI_NAME_MAX_LENGTH 24
94struct be_dai_name_struct {
95 unsigned int be_id;
96 char be_name[BE_DAI_NAME_MAX_LENGTH];
97};
98
keunhui.park2f7306a2015-07-16 16:48:06 +090099static struct listnode operator_info_list;
100static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
101
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700102/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800103typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700104
Eric Laurentb23d5282013-05-14 15:27:20 -0700105struct platform_data {
106 struct audio_device *adev;
107 bool fluence_in_spkr_mode;
108 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700109 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700110 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700111 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
112 int fluence_type;
113 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700114 bool speaker_lr_swap;
115
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800117#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700118 acdb_init_v2_cvd_t acdb_init;
119#elif defined (PLATFORM_MSM8084)
120 acdb_init_v2_t acdb_init;
121#else
122 acdb_init_t acdb_init;
123#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700124 acdb_deallocate_t acdb_deallocate;
125 acdb_send_audio_cal_t acdb_send_audio_cal;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800126 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700127 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700128 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700129 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700130 acdb_send_custom_top_t acdb_send_custom_top;
131 bool acdb_initialized;
132
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700133 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800134 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700135
David Linee3fe402017-03-13 10:00:42 -0700136 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700137 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900138 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700139 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800140
141 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700142};
143
Haynes Mathew George98c95622014-06-20 19:14:25 -0700144static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700145 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
146 DEEP_BUFFER_PCM_DEVICE},
147 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
148 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800149 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700150 MULTIMEDIA2_PCM_DEVICE},
151 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
152 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700153 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
154 MULTIMEDIA2_PCM_DEVICE},
155 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
156 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800157 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
158 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700159
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700160 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
161 AUDIO_RECORD_PCM_DEVICE},
162 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
163 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700164
Eric Laurent0e46adf2016-12-16 12:49:24 -0800165 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
166 MMAP_RECORD_PCM_DEVICE},
167
Haynes Mathew George569b7482017-05-08 14:44:27 -0700168 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
169 MULTIMEDIA2_PCM_DEVICE},
170
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700171 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
172 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700173 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
174 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
175 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
176 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800177 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
178 VOICEMMODE1_CALL_PCM_DEVICE},
179 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
180 VOICEMMODE2_CALL_PCM_DEVICE},
181
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700182 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
183 AUDIO_RECORD_PCM_DEVICE},
184 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
185 AUDIO_RECORD_PCM_DEVICE},
186 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
187 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800188 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700189
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700190 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
191 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
192
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700193 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
194 AFE_PROXY_RECORD_PCM_DEVICE},
195 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
196 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800197 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700198
Eric Laurentb23d5282013-05-14 15:27:20 -0700199};
200
201/* Array to store sound devices */
202static const char * const device_table[SND_DEVICE_MAX] = {
203 [SND_DEVICE_NONE] = "none",
204 /* Playback sound devices */
205 [SND_DEVICE_OUT_HANDSET] = "handset",
206 [SND_DEVICE_OUT_SPEAKER] = "speaker",
207 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700208 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700209 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500210 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700211 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700212 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500213 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700214 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700215 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500216 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
218 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500219 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700220 [SND_DEVICE_OUT_HDMI] = "hdmi",
221 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
222 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700223 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700224 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
225 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
226 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
227 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800228 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
229 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700230 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700231 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700232 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700233 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700234 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700235 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700236 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
237 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700238 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800239 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
240 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700241
242 /* Capture sound devices */
243 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700244 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700245 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
246 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
247 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
248 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
249 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
250 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
251 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
252
253 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
254 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
255 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
256 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
257 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
258 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
259 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
260 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
261 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
262
263 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500264 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700265
Eric Laurentb23d5282013-05-14 15:27:20 -0700266 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
267 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700268 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700269 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700270 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700271 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700272
273 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
274 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
275 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
276 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700277 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700278 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700279 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
280 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
281 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800282 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
283 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700284
Eric Laurentb23d5282013-05-14 15:27:20 -0700285 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700286 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700287 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700288 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700289 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
290 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700291 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700292 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
293 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
294 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
295 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700296 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700297
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700298 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700299 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
300 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
301 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
302 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800303
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700304 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700305
Prashant Malanic92c5962015-08-11 15:10:18 -0700306 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
307 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700308 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700309 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
310 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700311 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
312 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700313};
314
315/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700316static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700317 [SND_DEVICE_NONE] = -1,
318 [SND_DEVICE_OUT_HANDSET] = 7,
319 [SND_DEVICE_OUT_SPEAKER] = 15,
320 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700321 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700322 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500323 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700324 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700325 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500326 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700327 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700328 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
329 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500330 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700331 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500332 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700333 [SND_DEVICE_OUT_HDMI] = 18,
334 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
335 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700336 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700337 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700338 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
339 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
340 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800341 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
342 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700343 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700344 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700345 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700346 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700347 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700348 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700349 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
350 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700351 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700352
353 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700354 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
355 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
356 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
357 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
358 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
359 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
360 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
361 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
362
363 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
364 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
365 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
366 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
367 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
368 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
369 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
370 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
371 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
372
rago90fb9612015-12-02 11:37:53 -0800373 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500374 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700375
Eric Laurentb23d5282013-05-14 15:27:20 -0700376 [SND_DEVICE_IN_HDMI_MIC] = 4,
377 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700378 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700379 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700380 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700381 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700382
383 [SND_DEVICE_IN_VOICE_DMIC] = 41,
384 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
385 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700386 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700387 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800388 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700389 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
390 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
391 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800392 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
393 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700394
rago90fb9612015-12-02 11:37:53 -0800395 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700396 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700397 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700398 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700399 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
400 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800401 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
402
403 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
404 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700405 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
406 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
407 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700408
409 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700410 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700411 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
412 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
413 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
414 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700415 [SND_DEVICE_IN_THREE_MIC] = 46,
416 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700417 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700418 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
419 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700420 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
421 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700422};
423
David Linee3fe402017-03-13 10:00:42 -0700424// Platform specific backend bit width table
425static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
426
Haynes Mathew George98c95622014-06-20 19:14:25 -0700427struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700428 char name[100];
429 unsigned int index;
430};
431
432#define TO_NAME_INDEX(X) #X, X
433
Haynes Mathew George98c95622014-06-20 19:14:25 -0700434/* Used to get index from parsed string */
435static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
436 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700437 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
438 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
439 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700440 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700441 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500442 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700443 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700444 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500445 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700446 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700447 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
448 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700449 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700450 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500451 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700452 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
453 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
454 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
455 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700456 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500457 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
459 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
460 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800461 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
462 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800463 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
464 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700465 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700466 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700467 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700468 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700469 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700470 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
471 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800472
473 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700474 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700475 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700476 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
477 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
478 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
479 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
480 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
481 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
482 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
483
484 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700485 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700486 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
488 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
490 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
491 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
492 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
493
494 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700495 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700496
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700497 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
498 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700499 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700500 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700501 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700502 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700503
504 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
505 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
506 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700508 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
509 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700510 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
511 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
512 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800513 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
514 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
515
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700516
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700518 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700523 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700524 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700525 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
528 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700529
rago90fb9612015-12-02 11:37:53 -0800530 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
531 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800535
Prashant Malanic92c5962015-08-11 15:10:18 -0700536 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700538 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700539 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700541 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700543};
544
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700545static char * backend_tag_table[SND_DEVICE_MAX] = {0};
546static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700547
548static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
549 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
550 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800551 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700552 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700553 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
554 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800555 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700556 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
557 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800558 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700559 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700560 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
561 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
562 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
563 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
564 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800565 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
566 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700567 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
568 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
569 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
570 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800571 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
572 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
573 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
574 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
575 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700576};
577
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800578static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
579 {TO_NAME_INDEX(PCM_PLAYBACK)},
580 {TO_NAME_INDEX(PCM_CAPTURE)},
581 {TO_NAME_INDEX(VOICE_CALL)},
582 {TO_NAME_INDEX(PCM_HFP_CALL)},
583};
584
585struct app_type_entry {
586 int uc_type;
587 int bit_width;
588 int app_type;
589 int max_rate;
590 struct listnode node; // membership in app_type_entry_list;
591};
592
593static struct listnode app_type_entry_list;
594
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700595#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
596#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800597#define ULL_PLATFORM_DELAY (3*1000LL)
598#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700599
Eric Laurentb23d5282013-05-14 15:27:20 -0700600static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
601static bool is_tmus = false;
602
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800603static int init_be_dai_name_table(struct audio_device *adev);
604
Eric Laurentb23d5282013-05-14 15:27:20 -0700605static void check_operator()
606{
607 char value[PROPERTY_VALUE_MAX];
608 int mccmnc;
609 property_get("gsm.sim.operator.numeric",value,"0");
610 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700611 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700612 switch(mccmnc) {
613 /* TMUS MCC(310), MNC(490, 260, 026) */
614 case 310490:
615 case 310260:
616 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900617 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
618 case 310800:
619 case 310660:
620 case 310580:
621 case 310310:
622 case 310270:
623 case 310250:
624 case 310240:
625 case 310230:
626 case 310220:
627 case 310210:
628 case 310200:
629 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700630 is_tmus = true;
631 break;
632 }
633}
634
635bool is_operator_tmus()
636{
637 pthread_once(&check_op_once_ctl, check_operator);
638 return is_tmus;
639}
640
keunhui.park2f7306a2015-07-16 16:48:06 +0900641static char *get_current_operator()
642{
643 struct listnode *node;
644 struct operator_info *info_item;
645 char mccmnc[PROPERTY_VALUE_MAX];
646 char *ret = NULL;
647
Tom Cherry7fea2042016-11-10 18:05:59 -0800648 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900649
650 list_for_each(node, &operator_info_list) {
651 info_item = node_to_item(node, struct operator_info, list);
652 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
653 ret = info_item->name;
654 }
655 }
656
657 return ret;
658}
659
660static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
661{
662 struct listnode *node;
663 struct operator_specific_device *ret = NULL;
664 struct operator_specific_device *device_item;
665 char *operator_name;
666
667 operator_name = get_current_operator();
668 if (operator_name == NULL)
669 return ret;
670
671 list_for_each(node, operator_specific_device_table[snd_device]) {
672 device_item = node_to_item(node, struct operator_specific_device, list);
673 if (strcmp(operator_name, device_item->operator) == 0) {
674 ret = device_item;
675 }
676 }
677
678 return ret;
679}
680
681
682static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
683{
684 struct operator_specific_device *device;
685 int ret = acdb_device_table[snd_device];
686
687 device = get_operator_specific_device(snd_device);
688 if (device != NULL)
689 ret = device->acdb_id;
690
691 return ret;
692}
693
694static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
695{
696 struct operator_specific_device *device;
697 const char *ret = device_table[snd_device];
698
699 device = get_operator_specific_device(snd_device);
700 if (device != NULL)
701 ret = device->mixer_path;
702
703 return ret;
704}
705
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800706inline bool platform_supports_app_type_cfg()
707{
708#ifdef PLATFORM_MSM8998
709 return true;
710#else
711 return false;
712#endif
713}
714
vivek mehta1a9b7c02015-06-25 11:49:38 -0700715bool platform_send_gain_dep_cal(void *platform, int level)
716{
717 bool ret_val = false;
718 struct platform_data *my_data = (struct platform_data *)platform;
719 struct audio_device *adev = my_data->adev;
720 int acdb_dev_id, app_type;
721 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
722 int mode = CAL_MODE_RTAC;
723 struct listnode *node;
724 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700725
726 if (my_data->acdb_send_gain_dep_cal == NULL) {
727 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
728 return ret_val;
729 }
730
731 if (!voice_is_in_call(adev)) {
732 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
733 __func__, level);
734 app_type = DEFAULT_APP_TYPE_RX_PATH;
735
736 // find the current active sound device
737 list_for_each(node, &adev->usecase_list) {
738 usecase = node_to_item(node, struct audio_usecase, list);
739
740 if (usecase != NULL &&
741 usecase->type == PCM_PLAYBACK &&
742 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
743
744 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700745 if (audio_extn_spkr_prot_is_enabled()) {
746 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
747 } else {
748 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
749 }
750
vivek mehta1a9b7c02015-06-25 11:49:38 -0700751 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
752 acdb_dev_type, mode, level)) {
753 // set ret_val true if at least one calibration is set successfully
754 ret_val = true;
755 } else {
756 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
757 }
758 } else {
759 ALOGW("%s: Usecase list is empty", __func__);
760 }
761 }
762 } else {
763 ALOGW("%s: Voice call in progress .. ignore setting new cal",
764 __func__);
765 }
766 return ret_val;
767}
768
Eric Laurentcefbbac2014-09-04 13:54:10 -0500769void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700770{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800771 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500772 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700773
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800774 if (strcmp(my_data->ec_ref_mixer_path, "")) {
775 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
776 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500777 }
778
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800779 if (enable) {
780 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
781 if (out_device != AUDIO_DEVICE_NONE) {
782 snd_device = platform_get_output_snd_device(adev->platform, out_device);
783 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
784 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500785
Joe Onorato188b6222016-03-01 11:02:27 -0800786 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800787 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
788 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700789}
790
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700791static struct csd_data *open_csd_client(bool i2s_ext_modem)
792{
793 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
794
795 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
796 if (csd->csd_client == NULL) {
797 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
798 goto error;
799 } else {
800 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
801
802 csd->deinit = (deinit_t)dlsym(csd->csd_client,
803 "csd_client_deinit");
804 if (csd->deinit == NULL) {
805 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
806 dlerror());
807 goto error;
808 }
809 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
810 "csd_client_disable_device");
811 if (csd->disable_device == NULL) {
812 ALOGE("%s: dlsym error %s for csd_client_disable_device",
813 __func__, dlerror());
814 goto error;
815 }
816 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
817 "csd_client_enable_device_config");
818 if (csd->enable_device_config == NULL) {
819 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
820 __func__, dlerror());
821 goto error;
822 }
823 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
824 "csd_client_enable_device");
825 if (csd->enable_device == NULL) {
826 ALOGE("%s: dlsym error %s for csd_client_enable_device",
827 __func__, dlerror());
828 goto error;
829 }
830 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
831 "csd_client_start_voice");
832 if (csd->start_voice == NULL) {
833 ALOGE("%s: dlsym error %s for csd_client_start_voice",
834 __func__, dlerror());
835 goto error;
836 }
837 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
838 "csd_client_stop_voice");
839 if (csd->stop_voice == NULL) {
840 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
841 __func__, dlerror());
842 goto error;
843 }
844 csd->volume = (volume_t)dlsym(csd->csd_client,
845 "csd_client_volume");
846 if (csd->volume == NULL) {
847 ALOGE("%s: dlsym error %s for csd_client_volume",
848 __func__, dlerror());
849 goto error;
850 }
851 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
852 "csd_client_mic_mute");
853 if (csd->mic_mute == NULL) {
854 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
855 __func__, dlerror());
856 goto error;
857 }
858 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
859 "csd_client_slow_talk");
860 if (csd->slow_talk == NULL) {
861 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
862 __func__, dlerror());
863 goto error;
864 }
865 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
866 "csd_client_start_playback");
867 if (csd->start_playback == NULL) {
868 ALOGE("%s: dlsym error %s for csd_client_start_playback",
869 __func__, dlerror());
870 goto error;
871 }
872 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
873 "csd_client_stop_playback");
874 if (csd->stop_playback == NULL) {
875 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
876 __func__, dlerror());
877 goto error;
878 }
879 csd->start_record = (start_record_t)dlsym(csd->csd_client,
880 "csd_client_start_record");
881 if (csd->start_record == NULL) {
882 ALOGE("%s: dlsym error %s for csd_client_start_record",
883 __func__, dlerror());
884 goto error;
885 }
886 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
887 "csd_client_stop_record");
888 if (csd->stop_record == NULL) {
889 ALOGE("%s: dlsym error %s for csd_client_stop_record",
890 __func__, dlerror());
891 goto error;
892 }
893
894 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
895 "csd_client_get_sample_rate");
896 if (csd->get_sample_rate == NULL) {
897 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
898 __func__, dlerror());
899
900 goto error;
901 }
902
903 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
904
905 if (csd->init == NULL) {
906 ALOGE("%s: dlsym error %s for csd_client_init",
907 __func__, dlerror());
908 goto error;
909 } else {
910 csd->init(i2s_ext_modem);
911 }
912 }
913 return csd;
914
915error:
916 free(csd);
917 csd = NULL;
918 return csd;
919}
920
921void close_csd_client(struct csd_data *csd)
922{
923 if (csd != NULL) {
924 csd->deinit();
925 dlclose(csd->csd_client);
926 free(csd);
927 csd = NULL;
928 }
929}
930
931static void platform_csd_init(struct platform_data *my_data)
932{
933#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700934 int32_t modems, (*count_modems)(void);
935 const char *name = "libdetectmodem.so";
936 const char *func = "count_modems";
937 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700938
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700939 my_data->csd = NULL;
940
941 void *lib = dlopen(name, RTLD_NOW);
942 error = dlerror();
943 if (!lib) {
944 ALOGE("%s: could not find %s: %s", __func__, name, error);
945 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700946 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700947
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700948 count_modems = NULL;
949 *(void **)(&count_modems) = dlsym(lib, func);
950 error = dlerror();
951 if (!count_modems) {
952 ALOGE("%s: could not find symbol %s in %s: %s",
953 __func__, func, name, error);
954 goto done;
955 }
956
957 modems = count_modems();
958 if (modems < 0) {
959 ALOGE("%s: count_modems failed\n", __func__);
960 goto done;
961 }
962
Eric Laurent2bafff12016-03-17 12:17:23 -0700963 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700964 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700965 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700966
967done:
968 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700969#else
970 my_data->csd = NULL;
971#endif
972}
973
Eric Laurentc6333382015-09-14 12:43:44 -0700974static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700975{
976 int32_t dev;
977 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700978 backend_tag_table[dev] = NULL;
979 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900980 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700981 }
982
David Linee3fe402017-03-13 10:00:42 -0700983 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
984 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
985 }
986
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700987 // To overwrite these go to the audio_platform_info.xml file.
988 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700989 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700990 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
991 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
992 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
993 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
994 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700995 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700996 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
997 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700998
David Linee3fe402017-03-13 10:00:42 -0700999 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001000 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001001 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001002 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001003 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1004 strdup("speaker-and-usb-headphones");
1005 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001006 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1007 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1008 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1009 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001010 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1011 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1012 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1013 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1014 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1015 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1016 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001017 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001018 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001019 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001020 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1021 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1022 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1023 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1024 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1025 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1026 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1027 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1028 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1029 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1030 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1031 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1032 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001033 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001034 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001035 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001036 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001037 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 -07001038 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1039 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1040 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -07001041
1042 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001043}
1044
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001045void get_cvd_version(char *cvd_version, struct audio_device *adev)
1046{
1047 struct mixer_ctl *ctl;
1048 int count;
1049 int ret = 0;
1050
1051 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1052 if (!ctl) {
1053 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1054 goto done;
1055 }
1056 mixer_ctl_update(ctl);
1057
1058 count = mixer_ctl_get_num_values(ctl);
1059 if (count > MAX_CVD_VERSION_STRING_SIZE)
1060 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1061
1062 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1063 if (ret != 0) {
1064 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1065 goto done;
1066 }
1067
1068done:
1069 return;
1070}
1071
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001072static int platform_acdb_init(void *platform)
1073{
1074 struct platform_data *my_data = (struct platform_data *)platform;
1075 struct audio_device *adev = my_data->adev;
1076
1077 if (!my_data->acdb_init) {
1078 ALOGE("%s: no acdb_init fn provided", __func__);
1079 return -1;
1080 }
1081
1082 if (my_data->acdb_initialized) {
1083 ALOGW("acdb is already initialized");
1084 return 0;
1085 }
1086
Thierry Strudel92232b42017-01-26 10:51:48 -08001087#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001088 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1089 if (!cvd_version)
1090 ALOGE("failed to allocate cvd_version");
1091 else {
1092 get_cvd_version(cvd_version, adev);
1093 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1094 free(cvd_version);
1095 }
1096#elif defined (PLATFORM_MSM8084)
1097 my_data->acdb_init((char *)my_data->snd_card_name);
1098#else
1099 my_data->acdb_init();
1100#endif
1101 my_data->acdb_initialized = true;
1102 return 0;
1103}
1104
David Linee3fe402017-03-13 10:00:42 -07001105static void
1106platform_backend_config_init(struct platform_data *pdata)
1107{
1108 int i;
1109
1110 /* initialize backend config */
1111 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1112 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1113 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1114 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1115
1116 if (i > MAX_RX_CODEC_BACKENDS)
1117 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1118
1119 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1120 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1121 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1122 }
1123
1124 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1125 strdup("SLIM_0_RX Format");
1126 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1127 strdup("SLIM_0_RX SampleRate");
1128
1129 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1130 strdup("SLIM_0_TX Format");
1131 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1132 strdup("SLIM_0_TX SampleRate");
1133
1134 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1135 strdup("USB_AUDIO_TX Format");
1136 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1137 strdup("USB_AUDIO_TX SampleRate");
1138 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1139 strdup("USB_AUDIO_TX Channels");
1140
1141 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1142 strdup("SLIM_6_RX Format");
1143 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1144 strdup("SLIM_6_RX SampleRate");
1145
1146 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1147 strdup("USB_AUDIO_RX Format");
1148 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1149 strdup("USB_AUDIO_RX SampleRate");
1150
1151 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1152 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1153 strdup("USB_AUDIO_RX Channels");
1154}
1155
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001156static int
1157platform_backend_app_type_cfg_init(struct platform_data *pdata,
1158 struct mixer *mixer)
1159{
1160 size_t app_type_cfg[128] = {0};
1161 int length, num_app_types = 0;
1162 struct mixer_ctl *ctl = NULL;
1163
1164 const char *mixer_ctl_name = "App Type Config";
1165 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1166 if (!ctl) {
1167 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1168 return -1;
1169 }
1170
1171 length = 1; // reserve index 0 for number of app types
1172
1173 struct listnode *node;
1174 struct app_type_entry *entry;
1175 list_for_each(node, &app_type_entry_list) {
1176 entry = node_to_item(node, struct app_type_entry, node);
1177 app_type_cfg[length++] = entry->app_type;
1178 app_type_cfg[length++] = entry->max_rate;
1179 app_type_cfg[length++] = entry->bit_width;
1180 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1181 num_app_types += 1;
1182 }
1183
1184 // default for capture
1185 int t;
1186 platform_get_default_app_type_v2(pdata,
1187 PCM_CAPTURE,
1188 &t);
1189 app_type_cfg[length++] = t;
1190 app_type_cfg[length++] = 48000;
1191 app_type_cfg[length++] = 16;
1192 num_app_types += 1;
1193
1194 if (num_app_types) {
1195 app_type_cfg[0] = num_app_types;
1196 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1197 ALOGE("Failed to set app type cfg");
1198 }
1199 }
1200 return 0;
1201}
1202
Eric Laurentb23d5282013-05-14 15:27:20 -07001203void *platform_init(struct audio_device *adev)
1204{
1205 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001206 struct platform_data *my_data = NULL;
1207 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1208 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001209 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001210 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001211 char *snd_internal_name = NULL;
1212 char *tmp = NULL;
1213 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001214 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1215 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001216 my_data = calloc(1, sizeof(struct platform_data));
1217
1218 my_data->adev = adev;
1219
keunhui.park2f7306a2015-07-16 16:48:06 +09001220 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001221 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001222
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001223 set_platform_defaults(my_data);
1224
vivek mehta0fb11312017-05-15 19:35:32 -07001225 // audio_extn_utils_get_snd_card_num does
1226 // - open mixer and get snd card name
1227 // - parse platform info xml file and check for valid snd card name
1228 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001229
vivek mehta0fb11312017-05-15 19:35:32 -07001230 snd_card_num = audio_extn_utils_get_snd_card_num();
1231 if (-1 == snd_card_num) {
1232 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1233 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001234 }
1235
vivek mehta0fb11312017-05-15 19:35:32 -07001236 adev->mixer = mixer_open(snd_card_num);
1237 snd_card_name = mixer_get_name(adev->mixer);
1238 my_data->hw_info = hw_info_init(snd_card_name);
1239
1240 audio_extn_set_snd_card_split(snd_card_name);
1241 snd_split_handle = audio_extn_get_snd_card_split();
1242
1243 /* Get the codec internal name from the sound card and/or form factor
1244 * name and form the mixer paths and platfor info file name dynamically.
1245 * This is generic way of picking any codec and forma factor name based
1246 * mixer and platform info files in future with no code change.
1247
1248 * current code extends and looks for any of the exteneded mixer path and
1249 * platform info file present based on codec and form factor.
1250
1251 * order of picking appropriate file is
1252 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1253 * <ii> mixer_paths_<codec_name>.xml, if file not present
1254 * <iii> mixer_paths.xml
1255
1256 * same order is followed for audio_platform_info.xml as well
1257 */
1258
1259 // need to carryforward old file name
1260 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1261 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1262 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1263 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1264 } else {
1265
1266 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1267 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1268 snd_split_handle->form_factor);
1269 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1270 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1271 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1272 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1273
1274 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1275 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1276 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1277 audio_extn_utils_resolve_config_file(mixer_xml_file);
1278 }
1279 }
1280 }
1281
1282 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1283
1284 /* Initialize platform specific ids and/or backends*/
1285 platform_info_init(platform_info_file, my_data);
1286
1287 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1288 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1289
1290 if (!adev->audio_route) {
1291 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1292 mixer_close(adev->mixer);
1293 adev->mixer = NULL;
1294 hw_info_deinit(my_data->hw_info);
1295 my_data->hw_info = NULL;
1296 goto init_failed;
1297 }
1298 adev->snd_card = snd_card_num;
1299 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1300
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001301 //set max volume step for voice call
1302 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1303 my_data->max_vol_index = atoi(value);
1304
vivek mehta65ad12d2015-08-13 18:32:48 -07001305 property_get("persist.audio.dualmic.config",value,"");
1306 if (!strcmp("endfire", value)) {
1307 dual_mic_config = true;
1308 }
1309
Prashant Malanic92c5962015-08-11 15:10:18 -07001310 my_data->source_mic_type = SOURCE_DUAL_MIC;
1311
Eric Laurentb23d5282013-05-14 15:27:20 -07001312 my_data->fluence_in_spkr_mode = false;
1313 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001314 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001315 my_data->fluence_in_voice_rec = false;
1316
vivek mehta65ad12d2015-08-13 18:32:48 -07001317 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001318 if (!strcmp("fluencepro", value)) {
1319 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001320 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001321 my_data->fluence_type = FLUENCE_ENABLE;
1322 } else if (!strcmp("none", value)) {
1323 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001324 }
1325
Prashant Malanic92c5962015-08-11 15:10:18 -07001326 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001327 property_get("persist.audio.fluence.voicecall",value,"");
1328 if (!strcmp("true", value)) {
1329 my_data->fluence_in_voice_call = true;
1330 }
1331
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001332 property_get("persist.audio.fluence.voicecomm",value,"");
1333 if (!strcmp("true", value)) {
1334 my_data->fluence_in_voice_comm = true;
1335 }
1336
Eric Laurentb23d5282013-05-14 15:27:20 -07001337 property_get("persist.audio.fluence.voicerec",value,"");
1338 if (!strcmp("true", value)) {
1339 my_data->fluence_in_voice_rec = true;
1340 }
1341
1342 property_get("persist.audio.fluence.speaker",value,"");
1343 if (!strcmp("true", value)) {
1344 my_data->fluence_in_spkr_mode = true;
1345 }
1346 }
1347
Prashant Malanic92c5962015-08-11 15:10:18 -07001348 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1349 switch (my_data->max_mic_count) {
1350 case 4:
1351 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1352 case 3:
1353 my_data->source_mic_type |= SOURCE_THREE_MIC;
1354 case 2:
1355 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1356 case 1:
1357 my_data->source_mic_type |= SOURCE_MONO_MIC;
1358 break;
1359 default:
1360 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1361 __func__, my_data->max_mic_count);
1362 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1363 break;
1364 }
1365
1366 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1367 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1368 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1369 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1370 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1371
Eric Laurentb23d5282013-05-14 15:27:20 -07001372 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1373 if (my_data->acdb_handle == NULL) {
1374 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1375 } else {
1376 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1377 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1378 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001379 if (!my_data->acdb_deallocate)
1380 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1381 __func__, LIB_ACDB_LOADER);
1382
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001383 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1384 "acdb_loader_send_audio_cal_v3");
1385 if (!my_data->acdb_send_audio_cal_v3)
1386 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1387 __func__, LIB_ACDB_LOADER);
1388
Eric Laurentb23d5282013-05-14 15:27:20 -07001389 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1390 "acdb_loader_send_audio_cal");
1391 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001392 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001393 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001394
Eric Laurentb23d5282013-05-14 15:27:20 -07001395 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1396 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001397 if (!my_data->acdb_send_voice_cal)
1398 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1399 __func__, LIB_ACDB_LOADER);
1400
1401 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1402 "acdb_loader_reload_vocvoltable");
1403 if (!my_data->acdb_reload_vocvoltable)
1404 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1405 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001406
1407 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1408 "acdb_loader_send_gain_dep_cal");
1409 if (!my_data->acdb_send_gain_dep_cal)
1410 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1411 __func__, LIB_ACDB_LOADER);
1412
Thierry Strudel92232b42017-01-26 10:51:48 -08001413#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
vivek mehta0fb11312017-05-15 19:35:32 -07001414 acdb_init_v2_cvd_t acdb_init_local;
1415 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001416 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001417 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001418 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1419 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001420
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001421#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001422 acdb_init_v2_t acdb_init_local;
1423 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001424 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001425 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001426 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1427 dlerror());
1428
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001429#else
vivek mehta0fb11312017-05-15 19:35:32 -07001430 acdb_init_t acdb_init_local;
1431 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001432 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001433 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001434 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1435 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001436#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001437 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001438
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001439 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1440 dlsym(my_data->acdb_handle,
1441 "acdb_loader_send_common_custom_topology");
1442
1443 if (!my_data->acdb_send_custom_top)
1444 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1445 __func__, LIB_ACDB_LOADER);
1446
vivek mehta0fb11312017-05-15 19:35:32 -07001447 int result = acdb_init(adev->snd_card);
1448 if (!result) {
1449 my_data->acdb_initialized = true;
1450 ALOGD("ACDB initialized");
1451 } else {
1452 my_data->acdb_initialized = false;
1453 ALOGD("ACDB initialization failed");
1454 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001455 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001456
David Linee3fe402017-03-13 10:00:42 -07001457 /* init usb */
1458 audio_extn_usb_init(adev);
1459
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001460 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001461
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001462 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1463
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001464 /* load csd client */
1465 platform_csd_init(my_data);
1466
David Linee3fe402017-03-13 10:00:42 -07001467 platform_backend_config_init(my_data);
1468
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001469 init_be_dai_name_table(adev);
1470
1471 if (platform_supports_app_type_cfg())
1472 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1473
Eric Laurentb23d5282013-05-14 15:27:20 -07001474 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001475
1476init_failed:
1477 if (my_data)
1478 free(my_data);
1479 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001480}
1481
1482void platform_deinit(void *platform)
1483{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001484 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001485 struct operator_info *info_item;
1486 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001487 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001488 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001489
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001490 struct platform_data *my_data = (struct platform_data *)platform;
1491 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001492
vivek mehtade4849c2016-03-03 17:23:38 -08001493 hw_info_deinit(my_data->hw_info);
1494
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001495 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1496 if (backend_tag_table[dev])
1497 free(backend_tag_table[dev]);
1498 if (hw_interface_table[dev])
1499 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001500 if (operator_specific_device_table[dev]) {
1501 while (!list_empty(operator_specific_device_table[dev])) {
1502 node = list_head(operator_specific_device_table[dev]);
1503 list_remove(node);
1504 device_item = node_to_item(node, struct operator_specific_device, list);
1505 free(device_item->operator);
1506 free(device_item->mixer_path);
1507 free(device_item);
1508 }
1509 free(operator_specific_device_table[dev]);
1510 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001511 }
1512
1513 if (my_data->snd_card_name)
1514 free(my_data->snd_card_name);
1515
keunhui.park2f7306a2015-07-16 16:48:06 +09001516 while (!list_empty(&operator_info_list)) {
1517 node = list_head(&operator_info_list);
1518 list_remove(node);
1519 info_item = node_to_item(node, struct operator_info, list);
1520 free(info_item->name);
1521 free(info_item->mccmnc);
1522 free(info_item);
1523 }
1524
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001525 while (!list_empty(&app_type_entry_list)) {
1526 node = list_head(&app_type_entry_list);
1527 list_remove(node);
1528 ap = node_to_item(node, struct app_type_entry, node);
1529 free(ap);
1530 }
1531
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001532 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001533 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001534
1535 /* deinit usb */
1536 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001537}
1538
1539const char *platform_get_snd_device_name(snd_device_t snd_device)
1540{
keunhui.park2f7306a2015-07-16 16:48:06 +09001541 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1542 if (operator_specific_device_table[snd_device] != NULL) {
1543 return get_operator_specific_device_mixer_path(snd_device);
1544 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001545 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001546 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001547 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001548}
1549
vivek mehtade4849c2016-03-03 17:23:38 -08001550int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1551 char *device_name)
1552{
1553 struct platform_data *my_data = (struct platform_data *)platform;
1554
David Benjamin1565f992016-09-21 12:10:34 -04001555 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001556 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001557 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1558 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001559 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1560 if (operator_specific_device_table[snd_device] != NULL) {
1561 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1562 DEVICE_NAME_MAX_SIZE);
1563 } else {
1564 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1565 }
1566 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1567 } else {
1568 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1569 }
1570
1571 return 0;
1572}
1573
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001574void platform_add_backend_name(void *platform, char *mixer_path,
1575 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001576{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001577 struct platform_data *my_data = (struct platform_data *)platform;
1578
Haynes Mathew George98c95622014-06-20 19:14:25 -07001579 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1580 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1581 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001582 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001583
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001584 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001585
1586 if (suffix != NULL) {
1587 strcat(mixer_path, " ");
1588 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001589 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001590}
1591
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001592bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1593{
1594 bool result = true;
1595
1596 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1597 platform_get_snd_device_name(snd_device1),
1598 platform_get_snd_device_name(snd_device2));
1599
1600 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1601 ALOGE("%s: Invalid snd_device = %s", __func__,
1602 platform_get_snd_device_name(snd_device1));
1603 return false;
1604 }
1605 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1606 ALOGE("%s: Invalid snd_device = %s", __func__,
1607 platform_get_snd_device_name(snd_device2));
1608 return false;
1609 }
1610 const char * be_itf1 = hw_interface_table[snd_device1];
1611 const char * be_itf2 = hw_interface_table[snd_device2];
1612
1613 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001614 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001615 result = false;
1616 }
1617
1618 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1619 return result;
1620}
1621
Eric Laurentb23d5282013-05-14 15:27:20 -07001622int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1623{
1624 int device_id;
1625 if (device_type == PCM_PLAYBACK)
1626 device_id = pcm_device_table[usecase][0];
1627 else
1628 device_id = pcm_device_table[usecase][1];
1629 return device_id;
1630}
1631
Haynes Mathew George98c95622014-06-20 19:14:25 -07001632static int find_index(const struct name_to_index * table, int32_t len,
1633 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001634{
1635 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001636 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001637
Haynes Mathew George98c95622014-06-20 19:14:25 -07001638 if (table == NULL) {
1639 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001640 ret = -ENODEV;
1641 goto done;
1642 }
1643
Haynes Mathew George98c95622014-06-20 19:14:25 -07001644 if (name == NULL) {
1645 ALOGE("null key");
1646 ret = -ENODEV;
1647 goto done;
1648 }
1649
1650 for (i=0; i < len; i++) {
1651 if (!strcmp(table[i].name, name)) {
1652 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001653 goto done;
1654 }
1655 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001656 ALOGE("%s: Could not find index for name = %s",
1657 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001658 ret = -ENODEV;
1659done:
1660 return ret;
1661}
1662
Haynes Mathew George98c95622014-06-20 19:14:25 -07001663int platform_get_snd_device_index(char *device_name)
1664{
1665 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1666}
1667
1668int platform_get_usecase_index(const char *usecase_name)
1669{
1670 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1671}
1672
keunhui.park2f7306a2015-07-16 16:48:06 +09001673void platform_add_operator_specific_device(snd_device_t snd_device,
1674 const char *operator,
1675 const char *mixer_path,
1676 unsigned int acdb_id)
1677{
1678 struct operator_specific_device *device;
1679
1680 if (operator_specific_device_table[snd_device] == NULL) {
1681 operator_specific_device_table[snd_device] =
1682 (struct listnode *)calloc(1, sizeof(struct listnode));
1683 list_init(operator_specific_device_table[snd_device]);
1684 }
1685
1686 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1687
1688 device->operator = strdup(operator);
1689 device->mixer_path = strdup(mixer_path);
1690 device->acdb_id = acdb_id;
1691
1692 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1693
Eric Laurent2bafff12016-03-17 12:17:23 -07001694 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001695 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1696
1697}
1698
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001699int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1700{
1701 int ret = 0;
1702
1703 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1704 ALOGE("%s: Invalid snd_device = %d",
1705 __func__, snd_device);
1706 ret = -EINVAL;
1707 goto done;
1708 }
1709
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001710 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1711 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001712 acdb_device_table[snd_device] = acdb_id;
1713done:
1714 return ret;
1715}
1716
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001717int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1718{
1719 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1720 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1721 return -EINVAL;
1722 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001723
1724 if (operator_specific_device_table[snd_device] != NULL)
1725 return get_operator_specific_device_acdb_id(snd_device);
1726 else
1727 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001728}
1729
David Linee3fe402017-03-13 10:00:42 -07001730static int platform_get_backend_index(snd_device_t snd_device)
1731{
1732 int32_t port = DEFAULT_CODEC_BACKEND;
1733
1734 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1735 if (backend_tag_table[snd_device] != NULL) {
1736 if (strncmp(backend_tag_table[snd_device], "headphones",
1737 sizeof("headphones")) == 0)
1738 port = HEADPHONE_BACKEND;
1739 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1740 port = HDMI_RX_BACKEND;
1741 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1742 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1743 port = USB_AUDIO_RX_BACKEND;
1744 }
1745 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1746 port = DEFAULT_CODEC_TX_BACKEND;
1747 if (backend_tag_table[snd_device] != NULL) {
1748 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1749 port = USB_AUDIO_TX_BACKEND;
1750 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1751 port = BT_SCO_TX_BACKEND;
1752 }
1753 } else {
1754 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1755 }
1756
1757 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1758
1759 return port;
1760}
1761
Eric Laurentb23d5282013-05-14 15:27:20 -07001762int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1763{
1764 struct platform_data *my_data = (struct platform_data *)platform;
1765 int acdb_dev_id, acdb_dev_type;
1766
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001767 if (platform_supports_app_type_cfg()) // use v2 instead
1768 return -ENOSYS;
1769
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001770 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001771 if (acdb_dev_id < 0) {
1772 ALOGE("%s: Could not find acdb id for device(%d)",
1773 __func__, snd_device);
1774 return -EINVAL;
1775 }
1776 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001777 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001778 __func__, snd_device, acdb_dev_id);
1779 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1780 snd_device < SND_DEVICE_OUT_END)
1781 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1782 else
1783 acdb_dev_type = ACDB_DEV_TYPE_IN;
1784 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1785 }
1786 return 0;
1787}
1788
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001789int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1790 int app_type, int sample_rate)
1791{
1792 struct platform_data *my_data = (struct platform_data *)platform;
1793 int acdb_dev_id, acdb_dev_type;
1794 int snd_device = SND_DEVICE_OUT_SPEAKER;
1795 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1796 int i, num_devices = 1;
1797
1798 if (!platform_supports_app_type_cfg()) // use v1 instead
1799 return -ENOSYS;
1800
1801 if (usecase->type == PCM_PLAYBACK)
1802 snd_device = usecase->out_snd_device;
1803 else if (usecase->type == PCM_CAPTURE)
1804 snd_device = usecase->in_snd_device;
1805
1806 // skipped over get_spkr_prot_device
1807 acdb_dev_id = acdb_device_table[snd_device];
1808 if (acdb_dev_id < 0) {
1809 ALOGE("%s: Could not find acdb id for device(%d)",
1810 __func__, snd_device);
1811 return -EINVAL;
1812 }
1813
1814 if (platform_can_split_snd_device(snd_device,
1815 &num_devices, new_snd_device) < 0) {
1816 new_snd_device[0] = snd_device;
1817 }
1818
1819 for (i = 0; i < num_devices; i++) {
1820 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1821 if (acdb_dev_id < 0) {
1822 ALOGE("%s: Could not find acdb id for device(%d)",
1823 __func__, new_snd_device[i]);
1824 return -EINVAL;
1825 }
1826 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1827 __func__, new_snd_device[i], acdb_dev_id);
1828 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1829 new_snd_device[i] < SND_DEVICE_OUT_END)
1830 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1831 else
1832 acdb_dev_type = ACDB_DEV_TYPE_IN;
1833
1834 if (my_data->acdb_send_audio_cal_v3) {
1835 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1836 app_type, sample_rate, i);
1837 } else if (my_data->acdb_send_audio_cal) {
1838 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1839 }
1840 }
1841
1842 return 0;
1843}
1844
1845
Eric Laurentb23d5282013-05-14 15:27:20 -07001846int platform_switch_voice_call_device_pre(void *platform)
1847{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001848 struct platform_data *my_data = (struct platform_data *)platform;
1849 int ret = 0;
1850
1851 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001852 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001853 /* This must be called before disabling mixer controls on APQ side */
1854 ret = my_data->csd->disable_device();
1855 if (ret < 0) {
1856 ALOGE("%s: csd_client_disable_device, failed, error %d",
1857 __func__, ret);
1858 }
1859 }
1860 return ret;
1861}
1862
1863int platform_switch_voice_call_enable_device_config(void *platform,
1864 snd_device_t out_snd_device,
1865 snd_device_t in_snd_device)
1866{
1867 struct platform_data *my_data = (struct platform_data *)platform;
1868 int acdb_rx_id, acdb_tx_id;
1869 int ret = 0;
1870
1871 if (my_data->csd == NULL)
1872 return ret;
1873
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001874 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1875 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001876 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001877 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001878 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001879
keunhui.park2f7306a2015-07-16 16:48:06 +09001880 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001881
1882 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1883 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1884 if (ret < 0) {
1885 ALOGE("%s: csd_enable_device_config, failed, error %d",
1886 __func__, ret);
1887 }
1888 } else {
1889 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1890 acdb_rx_id, acdb_tx_id);
1891 }
1892
1893 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001894}
1895
1896int platform_switch_voice_call_device_post(void *platform,
1897 snd_device_t out_snd_device,
1898 snd_device_t in_snd_device)
1899{
1900 struct platform_data *my_data = (struct platform_data *)platform;
1901 int acdb_rx_id, acdb_tx_id;
1902
1903 if (my_data->acdb_send_voice_cal == NULL) {
1904 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1905 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001906 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1907 audio_extn_spkr_prot_is_enabled())
1908 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1909
keunhui.park2f7306a2015-07-16 16:48:06 +09001910 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1911 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001912
1913 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1914 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1915 else
1916 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1917 acdb_rx_id, acdb_tx_id);
1918 }
1919
1920 return 0;
1921}
1922
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001923int platform_switch_voice_call_usecase_route_post(void *platform,
1924 snd_device_t out_snd_device,
1925 snd_device_t in_snd_device)
1926{
1927 struct platform_data *my_data = (struct platform_data *)platform;
1928 int acdb_rx_id, acdb_tx_id;
1929 int ret = 0;
1930
1931 if (my_data->csd == NULL)
1932 return ret;
1933
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001934 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1935 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001936 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001937 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001938 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001939
keunhui.park2f7306a2015-07-16 16:48:06 +09001940 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001941
1942 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1943 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1944 my_data->adev->acdb_settings);
1945 if (ret < 0) {
1946 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1947 }
1948 } else {
1949 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1950 acdb_rx_id, acdb_tx_id);
1951 }
1952
1953 return ret;
1954}
1955
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001956int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001957{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001958 struct platform_data *my_data = (struct platform_data *)platform;
1959 int ret = 0;
1960
1961 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001962 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001963 if (ret < 0) {
1964 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1965 }
1966 }
1967 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001968}
1969
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001970int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001971{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001972 struct platform_data *my_data = (struct platform_data *)platform;
1973 int ret = 0;
1974
1975 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001976 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001977 if (ret < 0) {
1978 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1979 }
1980 }
1981 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001982}
1983
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001984int platform_get_sample_rate(void *platform, uint32_t *rate)
1985{
1986 struct platform_data *my_data = (struct platform_data *)platform;
1987 int ret = 0;
1988
1989 if (my_data->csd != NULL) {
1990 ret = my_data->csd->get_sample_rate(rate);
1991 if (ret < 0) {
1992 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1993 }
1994 }
1995 return ret;
1996}
1997
vivek mehtab6506412015-08-07 16:55:17 -07001998void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1999 snd_device_t snd_device,
2000 bool enable)
2001{
2002 const char* name;
2003 switch (snd_device) {
2004 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2005 if (enable)
2006 name = "spkr-gain-in-headphone-combo";
2007 else
2008 name = "speaker-gain-default";
2009 break;
2010 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2011 if (enable)
2012 name = "spkr-gain-in-line-combo";
2013 else
2014 name = "speaker-gain-default";
2015 break;
2016 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2017 if (enable)
2018 name = "spkr-safe-gain-in-headphone-combo";
2019 else
2020 name = "speaker-safe-gain-default";
2021 break;
2022 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2023 if (enable)
2024 name = "spkr-safe-gain-in-line-combo";
2025 else
2026 name = "speaker-safe-gain-default";
2027 break;
2028 default:
2029 return;
2030 }
2031
2032 audio_route_apply_and_update_path(adev->audio_route, name);
2033}
2034
Eric Laurentb23d5282013-05-14 15:27:20 -07002035int platform_set_voice_volume(void *platform, int volume)
2036{
2037 struct platform_data *my_data = (struct platform_data *)platform;
2038 struct audio_device *adev = my_data->adev;
2039 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002040 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002041 int vol_index = 0, ret = 0;
2042 uint32_t set_values[ ] = {0,
2043 ALL_SESSION_VSID,
2044 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002045
2046 // Voice volume levels are mapped to adsp volume levels as follows.
2047 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2048 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002049 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002050 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002051
2052 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2053 if (!ctl) {
2054 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2055 __func__, mixer_ctl_name);
2056 return -EINVAL;
2057 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002058 ALOGV("Setting voice volume index: %d", set_values[0]);
2059 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2060
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002061 if (my_data->csd != NULL) {
2062 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2063 DEFAULT_VOLUME_RAMP_DURATION_MS);
2064 if (ret < 0) {
2065 ALOGE("%s: csd_volume error %d", __func__, ret);
2066 }
2067 }
2068 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002069}
2070
2071int platform_set_mic_mute(void *platform, bool state)
2072{
2073 struct platform_data *my_data = (struct platform_data *)platform;
2074 struct audio_device *adev = my_data->adev;
2075 struct mixer_ctl *ctl;
2076 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002077 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002078 uint32_t set_values[ ] = {0,
2079 ALL_SESSION_VSID,
2080 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002081
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002082 if (adev->mode != AUDIO_MODE_IN_CALL &&
2083 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002084 return 0;
2085
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002086 if (adev->enable_hfp)
2087 mixer_ctl_name = "HFP Tx Mute";
2088
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002089 set_values[0] = state;
2090 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2091 if (!ctl) {
2092 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2093 __func__, mixer_ctl_name);
2094 return -EINVAL;
2095 }
2096 ALOGV("Setting voice mute state: %d", state);
2097 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2098
2099 if (my_data->csd != NULL) {
2100 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2101 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002102 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002103 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002104 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002105 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002106 return ret;
2107}
Eric Laurentb23d5282013-05-14 15:27:20 -07002108
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002109int platform_set_device_mute(void *platform, bool state, char *dir)
2110{
2111 struct platform_data *my_data = (struct platform_data *)platform;
2112 struct audio_device *adev = my_data->adev;
2113 struct mixer_ctl *ctl;
2114 char *mixer_ctl_name = NULL;
2115 int ret = 0;
2116 uint32_t set_values[ ] = {0,
2117 ALL_SESSION_VSID,
2118 0};
2119 if(dir == NULL) {
2120 ALOGE("%s: Invalid direction:%s", __func__, dir);
2121 return -EINVAL;
2122 }
2123
2124 if (!strncmp("rx", dir, sizeof("rx"))) {
2125 mixer_ctl_name = "Voice Rx Device Mute";
2126 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2127 mixer_ctl_name = "Voice Tx Device Mute";
2128 } else {
2129 return -EINVAL;
2130 }
2131
2132 set_values[0] = state;
2133 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2134 if (!ctl) {
2135 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2136 __func__, mixer_ctl_name);
2137 return -EINVAL;
2138 }
2139
2140 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2141 __func__,state, mixer_ctl_name);
2142 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2143
2144 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002145}
2146
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002147int platform_can_split_snd_device(snd_device_t snd_device,
2148 int *num_devices,
2149 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002150{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002151 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002152 if (NULL == num_devices || NULL == new_snd_devices) {
2153 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002154 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002155 }
2156
2157 /*
2158 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002159 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002160 */
2161 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2162 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2163 *num_devices = 2;
2164 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2165 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002166 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002167 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2168 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2169 *num_devices = 2;
2170 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2171 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002172 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002173 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2174 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2175 *num_devices = 2;
2176 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2177 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002178 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002179 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2180 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2181 *num_devices = 2;
2182 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2183 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002184 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002185 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2186 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2187 SND_DEVICE_OUT_BT_SCO)) {
2188 *num_devices = 2;
2189 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2190 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2191 ret = 0;
2192 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2193 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2194 SND_DEVICE_OUT_BT_SCO_WB)) {
2195 *num_devices = 2;
2196 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2197 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2198 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002199 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2200 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2201 *num_devices = 2;
2202 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2203 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2204 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002205 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002206 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002207}
2208
Eric Laurentb23d5282013-05-14 15:27:20 -07002209snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2210{
2211 struct platform_data *my_data = (struct platform_data *)platform;
2212 struct audio_device *adev = my_data->adev;
2213 audio_mode_t mode = adev->mode;
2214 snd_device_t snd_device = SND_DEVICE_NONE;
2215
2216 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2217 if (devices == AUDIO_DEVICE_NONE ||
2218 devices & AUDIO_DEVICE_BIT_IN) {
2219 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2220 goto exit;
2221 }
2222
Eric Laurent1b491552015-09-15 17:52:41 -07002223 if (popcount(devices) == 2) {
2224 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2225 AUDIO_DEVICE_OUT_SPEAKER) ||
2226 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2227 AUDIO_DEVICE_OUT_SPEAKER)) {
2228 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2229 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2230 AUDIO_DEVICE_OUT_SPEAKER)) {
2231 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2232 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2233 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2234 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2235 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2236 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2237 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2238 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2239 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2240 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2241 AUDIO_DEVICE_OUT_SPEAKER)) {
2242 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002243 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2244 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2245 snd_device = adev->bt_wb_speech_enabled ?
2246 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2247 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
David Linee3fe402017-03-13 10:00:42 -07002248 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2249 AUDIO_DEVICE_OUT_SPEAKER)) {
2250 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002251 } else {
2252 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2253 goto exit;
2254 }
2255 if (snd_device != SND_DEVICE_NONE) {
2256 goto exit;
2257 }
2258 }
2259
2260 if (popcount(devices) != 1) {
2261 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2262 goto exit;
2263 }
2264
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302265 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002266 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002267 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2268 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002269 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002270 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002271 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002272 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002273 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002274 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002275 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002276 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002277 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002278 else {
2279 if (devices & AUDIO_DEVICE_OUT_LINE)
2280 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2281 else
2282 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2283 }
vivek mehtaa6b79742017-03-09 15:40:43 -08002284 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2285 if (voice_is_in_call(adev)) {
2286 switch (adev->voice.tty_mode) {
2287 case TTY_MODE_FULL:
2288 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2289 break;
2290 case TTY_MODE_VCO:
2291 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2292 break;
2293 case TTY_MODE_HCO:
2294 // since Hearing will be on handset\speaker, use existing device
2295 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2296 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002297 case TTY_MODE_OFF:
2298 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002299 default:
2300 ALOGE("%s: Invalid TTY mode (%#x)",
2301 __func__, adev->voice.tty_mode);
2302 }
2303 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002304 if (snd_device == SND_DEVICE_NONE) {
2305 snd_device = audio_extn_usb_is_capture_supported() ?
2306 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2307 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2308 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002309 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002310 if (adev->bt_wb_speech_enabled) {
2311 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2312 } else {
2313 snd_device = SND_DEVICE_OUT_BT_SCO;
2314 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002315 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002316 if (!adev->enable_hfp) {
2317 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2318 } else {
2319 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2320 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002321 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002322 if(adev->voice.hac)
2323 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2324 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002325 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2326 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002327 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002328 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2329 snd_device = SND_DEVICE_OUT_VOICE_TX;
2330
Eric Laurentb23d5282013-05-14 15:27:20 -07002331 if (snd_device != SND_DEVICE_NONE) {
2332 goto exit;
2333 }
2334 }
2335
Eric Laurentb23d5282013-05-14 15:27:20 -07002336 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2337 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2338 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002339 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2340 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002341 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2342 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002343 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002344 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002345 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2346 else
2347 snd_device = SND_DEVICE_OUT_SPEAKER;
2348 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002349 if (adev->bt_wb_speech_enabled) {
2350 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2351 } else {
2352 snd_device = SND_DEVICE_OUT_BT_SCO;
2353 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002354 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2355 snd_device = SND_DEVICE_OUT_HDMI ;
David Linee3fe402017-03-13 10:00:42 -07002356 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2357 if (audio_extn_usb_is_capture_supported())
2358 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2359 else
2360 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2361 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002362 /*HAC support for voice-ish audio (eg visual voicemail)*/
2363 if(adev->voice.hac)
2364 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2365 else
2366 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002367 } else {
2368 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2369 }
2370exit:
2371 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2372 return snd_device;
2373}
2374
2375snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2376{
2377 struct platform_data *my_data = (struct platform_data *)platform;
2378 struct audio_device *adev = my_data->adev;
2379 audio_source_t source = (adev->active_input == NULL) ?
2380 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2381
2382 audio_mode_t mode = adev->mode;
2383 audio_devices_t in_device = ((adev->active_input == NULL) ?
2384 AUDIO_DEVICE_NONE : adev->active_input->device)
2385 & ~AUDIO_DEVICE_BIT_IN;
2386 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2387 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2388 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002389 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002390
Prashant Malanic92c5962015-08-11 15:10:18 -07002391 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2392 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002393 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2394 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002395 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002396 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002397 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2398 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002399 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002400 case TTY_MODE_FULL:
2401 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2402 break;
2403 case TTY_MODE_VCO:
2404 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2405 break;
2406 case TTY_MODE_HCO:
2407 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2408 break;
2409 default:
2410 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2411 }
2412 goto exit;
2413 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2414 switch (adev->voice.tty_mode) {
2415 case TTY_MODE_FULL:
2416 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2417 break;
2418 case TTY_MODE_VCO:
2419 // since voice will be captured from handset mic, use existing device
2420 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2421 break;
2422 case TTY_MODE_HCO:
2423 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2424 break;
2425 default:
2426 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002427 }
2428 goto exit;
2429 }
2430 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002431 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002432 if (my_data->fluence_in_voice_call == false) {
2433 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2434 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002435 if (is_operator_tmus())
2436 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002437 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002438 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002439 }
2440 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2441 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2442 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002443 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002444 if (adev->bluetooth_nrec)
2445 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2446 else
2447 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002448 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002449 if (adev->bluetooth_nrec)
2450 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2451 else
2452 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002453 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002454 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002455 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2456 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2457 out_device & AUDIO_DEVICE_OUT_LINE) {
2458 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2459 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2460 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2461 } else {
2462 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2463 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002464 }
vivek mehtafe121d52015-08-10 23:39:23 -07002465
2466 //select default
2467 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002468 if (!adev->enable_hfp) {
2469 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2470 } else {
2471 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2472 platform_set_echo_reference(adev, true, out_device);
2473 }
vivek mehtafe121d52015-08-10 23:39:23 -07002474 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002475 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002476 snd_device = SND_DEVICE_IN_VOICE_RX;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002477 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2478 if (audio_extn_usb_is_capture_supported()) {
2479 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2480 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002481 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002482 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2483 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2484 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2485 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2486 }
2487 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2488 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002489 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2490 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2491 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002492 if (adev->active_input->enable_aec)
2493 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2494 else
2495 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002496 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2497 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002498 if (adev->active_input->enable_aec)
2499 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2500 else
2501 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002502 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2503 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2504 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002505 if (adev->active_input->enable_aec)
2506 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2507 else
2508 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002509 }
2510 platform_set_echo_reference(adev, true, out_device);
2511 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2512 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2513 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002514 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002515 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2516 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002517 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002518 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2519 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002520 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002521 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002522 if (adev->active_input->enable_aec) {
2523 if (adev->active_input->enable_ns) {
2524 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2525 } else {
2526 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2527 }
vivek mehta733c1df2016-04-04 15:09:24 -07002528 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002529 } else if (adev->active_input->enable_ns) {
2530 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2531 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002532 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002533 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002534 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002535 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2536 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002537 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2538 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002539 }
rago90fb9612015-12-02 11:37:53 -08002540 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2541 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002542 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2543 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2544 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2545 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002546 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002547 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2548 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002549 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002550 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2551 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2552 } else {
2553 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2554 }
rago90fb9612015-12-02 11:37:53 -08002555 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2556 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002557 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2558 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002559 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002560 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002561 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002562 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002563 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2564 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002565 if (adev->active_input->enable_aec &&
2566 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002567 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002568 if (my_data->fluence_in_spkr_mode &&
2569 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002570 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002571 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002572 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002573 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002574 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002575 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002576 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002577 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002578 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002579 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002580 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002581 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002582 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2583 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002584 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2585 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002586 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002587 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002588 } else if (adev->active_input->enable_aec) {
2589 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2590 if (my_data->fluence_in_spkr_mode &&
2591 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002592 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002593 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002594 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002595 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002596 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002597 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2598 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002599 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002600 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002601 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002602 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002603 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002604 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2605 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002606 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
2607 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002608 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002609 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002610 } else if (adev->active_input->enable_ns) {
2611 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2612 if (my_data->fluence_in_spkr_mode &&
2613 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002614 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002615 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002616 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002617 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002618 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002619 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2620 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002621 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002622 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002623 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002624 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002625 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002626 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002627 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002628 }
2629 } else if (source == AUDIO_SOURCE_DEFAULT) {
2630 goto exit;
2631 }
2632
2633
2634 if (snd_device != SND_DEVICE_NONE) {
2635 goto exit;
2636 }
2637
2638 if (in_device != AUDIO_DEVICE_NONE &&
2639 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2640 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2641 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002642 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002643 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002644 snd_device = SND_DEVICE_IN_QUAD_MIC;
2645 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002646 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002647 snd_device = SND_DEVICE_IN_THREE_MIC;
2648 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2649 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002650 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002651 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2652 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002653 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002654 } else {
2655 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2656 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2657 my_data->source_mic_type, channel_count, channel_mask);
2658 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2659 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002660 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002661 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2662 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002663 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002664 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2665 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002666 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002667 } else {
2668 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2669 " no combination found .. setting to mono", __func__,
2670 my_data->source_mic_type, channel_count);
2671 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2672 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002673 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2674 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2675 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002676 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002677 if (adev->bluetooth_nrec)
2678 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2679 else
2680 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002681 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002682 if (adev->bluetooth_nrec)
2683 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2684 else
2685 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002686 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002687 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2688 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002689 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2690 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002691 } else {
2692 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2693 ALOGW("%s: Using default handset-mic", __func__);
2694 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2695 }
2696 } else {
2697 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2698 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2699 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2700 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002701 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002702 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002703 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002704 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002705 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2706 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002707 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002708 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2709 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002710 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002711 } else {
2712 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2713 " no combination found .. setting to mono", __func__,
2714 my_data->source_mic_type, channel_count);
2715 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2716 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002717 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002718 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002719 if (adev->bluetooth_nrec)
2720 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2721 else
2722 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002723 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002724 if (adev->bluetooth_nrec)
2725 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2726 else
2727 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002728 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002729 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2730 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002731 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2732 if (audio_extn_usb_is_capture_supported())
2733 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2734 else
2735 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002736 } else {
2737 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2738 ALOGW("%s: Using default handset-mic", __func__);
2739 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2740 }
2741 }
2742exit:
2743 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2744 return snd_device;
2745}
2746
2747int platform_set_hdmi_channels(void *platform, int channel_count)
2748{
2749 struct platform_data *my_data = (struct platform_data *)platform;
2750 struct audio_device *adev = my_data->adev;
2751 struct mixer_ctl *ctl;
2752 const char *channel_cnt_str = NULL;
2753 const char *mixer_ctl_name = "HDMI_RX Channels";
2754 switch (channel_count) {
2755 case 8:
2756 channel_cnt_str = "Eight"; break;
2757 case 7:
2758 channel_cnt_str = "Seven"; break;
2759 case 6:
2760 channel_cnt_str = "Six"; break;
2761 case 5:
2762 channel_cnt_str = "Five"; break;
2763 case 4:
2764 channel_cnt_str = "Four"; break;
2765 case 3:
2766 channel_cnt_str = "Three"; break;
2767 default:
2768 channel_cnt_str = "Two"; break;
2769 }
2770 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2771 if (!ctl) {
2772 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2773 __func__, mixer_ctl_name);
2774 return -EINVAL;
2775 }
2776 ALOGV("HDMI channel count: %s", channel_cnt_str);
2777 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2778 return 0;
2779}
2780
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002781int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002782{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002783 struct platform_data *my_data = (struct platform_data *)platform;
2784 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002785 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2786 char *sad = block;
2787 int num_audio_blocks;
2788 int channel_count;
2789 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002790 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002791
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002792 struct mixer_ctl *ctl;
2793
2794 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2795 if (!ctl) {
2796 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2797 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002798 return 0;
2799 }
2800
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002801 mixer_ctl_update(ctl);
2802
2803 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002804
2805 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002806 if (count > (int)sizeof(block))
2807 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002808
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002809 ret = mixer_ctl_get_array(ctl, block, count);
2810 if (ret != 0) {
2811 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2812 return 0;
2813 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002814
2815 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002816 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002817
2818 for (i = 0; i < num_audio_blocks; i++) {
2819 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002820 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2821 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002822 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002823 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002824
2825 channel_count = (sad[0] & 0x7) + 1;
2826 if (channel_count > max_channels)
2827 max_channels = channel_count;
2828
2829 /* Advance to next block */
2830 sad += 3;
2831 }
2832
2833 return max_channels;
2834}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002835
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002836int platform_set_incall_recording_session_id(void *platform,
2837 uint32_t session_id, int rec_mode)
2838{
2839 int ret = 0;
2840 struct platform_data *my_data = (struct platform_data *)platform;
2841 struct audio_device *adev = my_data->adev;
2842 struct mixer_ctl *ctl;
2843 const char *mixer_ctl_name = "Voc VSID";
2844 int num_ctl_values;
2845 int i;
2846
2847 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2848 if (!ctl) {
2849 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2850 __func__, mixer_ctl_name);
2851 ret = -EINVAL;
2852 } else {
2853 num_ctl_values = mixer_ctl_get_num_values(ctl);
2854 for (i = 0; i < num_ctl_values; i++) {
2855 if (mixer_ctl_set_value(ctl, i, session_id)) {
2856 ALOGV("Error: invalid session_id: %x", session_id);
2857 ret = -EINVAL;
2858 break;
2859 }
2860 }
2861 }
2862
2863 if (my_data->csd != NULL) {
2864 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2865 if (ret < 0) {
2866 ALOGE("%s: csd_client_start_record failed, error %d",
2867 __func__, ret);
2868 }
2869 }
2870
2871 return ret;
2872}
2873
2874int platform_stop_incall_recording_usecase(void *platform)
2875{
2876 int ret = 0;
2877 struct platform_data *my_data = (struct platform_data *)platform;
2878
2879 if (my_data->csd != NULL) {
2880 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2881 if (ret < 0) {
2882 ALOGE("%s: csd_client_stop_record failed, error %d",
2883 __func__, ret);
2884 }
2885 }
2886
2887 return ret;
2888}
2889
2890int platform_start_incall_music_usecase(void *platform)
2891{
2892 int ret = 0;
2893 struct platform_data *my_data = (struct platform_data *)platform;
2894
2895 if (my_data->csd != NULL) {
2896 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2897 if (ret < 0) {
2898 ALOGE("%s: csd_client_start_playback failed, error %d",
2899 __func__, ret);
2900 }
2901 }
2902
2903 return ret;
2904}
2905
2906int platform_stop_incall_music_usecase(void *platform)
2907{
2908 int ret = 0;
2909 struct platform_data *my_data = (struct platform_data *)platform;
2910
2911 if (my_data->csd != NULL) {
2912 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2913 if (ret < 0) {
2914 ALOGE("%s: csd_client_stop_playback failed, error %d",
2915 __func__, ret);
2916 }
2917 }
2918
2919 return ret;
2920}
2921
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002922int platform_set_parameters(void *platform, struct str_parms *parms)
2923{
2924 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002925 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002926 char *kv_pairs = str_parms_to_str(parms);
2927 int ret = 0, err;
2928
2929 if (kv_pairs == NULL) {
2930 ret = -EINVAL;
2931 ALOGE("%s: key-value pair is NULL",__func__);
2932 goto done;
2933 }
2934
2935 ALOGV("%s: enter: %s", __func__, kv_pairs);
2936
2937 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2938 value, sizeof(value));
2939 if (err >= 0) {
2940 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2941 my_data->snd_card_name = strdup(value);
2942 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2943 }
2944
keunhui.park2f7306a2015-07-16 16:48:06 +09002945 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2946 value, sizeof(value));
2947 if (err >= 0) {
2948 struct operator_info *info;
2949 char *str = value;
2950 char *name;
2951
2952 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2953 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2954 name = strtok(str, ";");
2955 info->name = strdup(name);
2956 info->mccmnc = strdup(str + strlen(name) + 1);
2957
2958 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002959 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002960 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002961
2962 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002963 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002964 value, sizeof(value));
2965 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002966 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002967 my_data->max_mic_count = atoi(value);
2968 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002969 }
2970
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002971done:
2972 ALOGV("%s: exit with code(%d)", __func__, ret);
2973 if (kv_pairs != NULL)
2974 free(kv_pairs);
2975
2976 return ret;
2977}
2978
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002979/* Delay in Us */
2980int64_t platform_render_latency(audio_usecase_t usecase)
2981{
2982 switch (usecase) {
2983 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2984 return DEEP_BUFFER_PLATFORM_DELAY;
2985 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2986 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002987 case USECASE_AUDIO_PLAYBACK_ULL:
2988 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002989 case USECASE_AUDIO_PLAYBACK_MMAP:
2990 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002991 default:
2992 return 0;
2993 }
2994}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002995
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002996int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2997 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002998{
2999 int ret = 0;
3000
3001 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3002 ALOGE("%s: Invalid snd_device = %d",
3003 __func__, device);
3004 ret = -EINVAL;
3005 goto done;
3006 }
3007
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003008 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3009 platform_get_snd_device_name(device),
3010 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3011 if (backend_tag_table[device]) {
3012 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003013 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003014 backend_tag_table[device] = strdup(backend_tag);
3015
3016 if (hw_interface != NULL) {
3017 if (hw_interface_table[device])
3018 free(hw_interface_table[device]);
3019 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3020 hw_interface_table[device] = strdup(hw_interface);
3021 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003022done:
3023 return ret;
3024}
3025
3026int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3027{
3028 int ret = 0;
3029 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3030 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3031 ret = -EINVAL;
3032 goto done;
3033 }
3034
3035 if ((type != 0) && (type != 1)) {
3036 ALOGE("%s: invalid usecase type", __func__);
3037 ret = -EINVAL;
3038 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003039 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003040 pcm_device_table[usecase][type] = pcm_id;
3041done:
3042 return ret;
3043}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003044
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003045#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3046int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3047 // backup_gain: gain to try to set in case of an error during ramp
3048 int start_gain, end_gain, step, backup_gain, i;
3049 bool error = false;
3050 const struct mixer_ctl *ctl;
3051 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3052 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3053 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3054 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3055 if (!ctl_left || !ctl_right) {
3056 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3057 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3058 return -EINVAL;
3059 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3060 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3061 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3062 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3063 return -EINVAL;
3064 }
3065 if (ramp_up) {
3066 start_gain = 0;
3067 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3068 step = +1;
3069 backup_gain = end_gain;
3070 } else {
3071 // using same gain on left and right
3072 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3073 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3074 end_gain = 0;
3075 step = -1;
3076 backup_gain = start_gain;
3077 }
3078 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3079 //ALOGV("setting speaker gain to %d", i);
3080 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3081 ALOGE("%s: error setting %s to %d during gain ramp",
3082 __func__, mixer_ctl_name_gain_left, i);
3083 error = true;
3084 break;
3085 }
3086 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3087 ALOGE("%s: error setting %s to %d during gain ramp",
3088 __func__, mixer_ctl_name_gain_right, i);
3089 error = true;
3090 break;
3091 }
3092 usleep(1000);
3093 }
3094 if (error) {
3095 // an error occured during the ramp, let's still try to go back to a safe volume
3096 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3097 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3098 }
3099 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3100 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3101 }
3102 }
3103 return start_gain;
3104}
3105
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003106int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
3107{
3108 // only update if there is active pcm playback on speaker
3109 struct audio_usecase *usecase;
3110 struct listnode *node;
3111 struct platform_data *my_data = (struct platform_data *)adev->platform;
3112
3113 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003114
3115 // do not swap channels in audio modes with concurrent capture and playback
3116 // as this may break the echo reference
3117 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3118 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3119 return 0;
3120 }
3121
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003122 my_data->speaker_lr_swap = swap_channels;
3123
3124 list_for_each(node, &adev->usecase_list) {
3125 usecase = node_to_item(node, struct audio_usecase, list);
3126 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003127 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3128 /*
3129 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3130 * to perform device switch to disable the current backend to
3131 * enable it with new acdb data.
3132 */
3133 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3134 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003135 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003136 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003137 if (initial_skpr_gain != -EINVAL) {
3138 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3139 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003140 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07003141 const char *mixer_path;
3142 if (swap_channels) {
3143 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3144 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3145 } else {
3146 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3147 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3148 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003149 }
3150 break;
3151 }
3152 }
3153 }
3154 return 0;
3155}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003156
3157static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3158static int num_gain_tbl_entry = 0;
3159
3160bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3161
3162 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3163 if (num_gain_tbl_entry == -1) {
3164 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3165 __func__);
3166 return false;
3167 }
3168
3169 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3170 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3171 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3172 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3173 return false;
3174 }
3175
3176 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3177 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3178 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3179 return false;
3180 }
3181
3182 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3183 ++num_gain_tbl_entry;
3184
3185 return true;
3186}
3187
3188int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3189 int table_size) {
3190 int itt = 0;
3191 ALOGV("platform_get_gain_level_mapping called ");
3192
3193 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3194 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3195 return 0;
3196 }
3197
3198 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3199 mapping_tbl[itt] = tbl_mapping[itt];
3200 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3201 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3202 }
3203
3204 return num_gain_tbl_entry;
3205}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003206
3207int platform_snd_card_update(void *platform, card_status_t status)
3208{
3209 struct platform_data *my_data = (struct platform_data *)platform;
3210 struct audio_device *adev = my_data->adev;
3211
3212 if (status == CARD_STATUS_ONLINE) {
3213 if (my_data->acdb_send_custom_top)
3214 my_data->acdb_send_custom_top();
3215 }
3216 return 0;
3217}
David Linee3fe402017-03-13 10:00:42 -07003218
3219/*
3220 * configures afe with bit width and Sample Rate
3221 */
3222static int platform_set_backend_cfg(const struct audio_device* adev,
3223 snd_device_t snd_device,
3224 const struct audio_backend_cfg *backend_cfg)
3225{
3226
3227 int ret = 0;
3228 const int backend_idx = platform_get_backend_index(snd_device);
3229 struct platform_data *my_data = (struct platform_data *)adev->platform;
3230 const unsigned int bit_width = backend_cfg->bit_width;
3231 const unsigned int sample_rate = backend_cfg->sample_rate;
3232 const unsigned int channels = backend_cfg->channels;
3233 const audio_format_t format = backend_cfg->format;
3234 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3235
3236
3237 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3238 ", backend_idx %d device (%s)", __func__, bit_width,
3239 sample_rate, channels, backend_idx,
3240 platform_get_snd_device_name(snd_device));
3241
3242 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3243 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3244
3245 struct mixer_ctl *ctl = NULL;
3246 ctl = mixer_get_ctl_by_name(adev->mixer,
3247 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3248 if (!ctl) {
3249 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3250 __func__,
3251 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3252 return -EINVAL;
3253 }
3254
3255 if (bit_width == 24) {
3256 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3257 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3258 else
3259 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3260 } else if (bit_width == 32) {
3261 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3262 } else {
3263 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3264 }
3265 if ( ret < 0) {
3266 ALOGE("%s:becf: afe: fail for %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 } else {
3269 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3270 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3271 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3272 }
3273 /* set the ret as 0 and not pass back to upper layer */
3274 ret = 0;
3275 }
3276
3277 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3278 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3279 char *rate_str = NULL;
3280 struct mixer_ctl *ctl = NULL;
3281
3282 switch (sample_rate) {
3283 case 32000:
3284 if (passthrough_enabled) {
3285 rate_str = "KHZ_32";
3286 break;
3287 }
3288 case 8000:
3289 case 11025:
3290 case 16000:
3291 case 22050:
3292 case 48000:
3293 rate_str = "KHZ_48";
3294 break;
3295 case 44100:
3296 rate_str = "KHZ_44P1";
3297 break;
3298 case 64000:
3299 case 96000:
3300 rate_str = "KHZ_96";
3301 break;
3302 case 88200:
3303 rate_str = "KHZ_88P2";
3304 break;
3305 case 176400:
3306 rate_str = "KHZ_176P4";
3307 break;
3308 case 192000:
3309 rate_str = "KHZ_192";
3310 break;
3311 case 352800:
3312 rate_str = "KHZ_352P8";
3313 break;
3314 case 384000:
3315 rate_str = "KHZ_384";
3316 break;
3317 case 144000:
3318 if (passthrough_enabled) {
3319 rate_str = "KHZ_144";
3320 break;
3321 }
3322 default:
3323 rate_str = "KHZ_48";
3324 break;
3325 }
3326
3327 ctl = mixer_get_ctl_by_name(adev->mixer,
3328 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3329 if(!ctl) {
3330 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3331 __func__,
3332 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3333 return -EINVAL;
3334 }
3335
3336 ALOGD("%s:becf: afe: %s set to %s", __func__,
3337 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3338 mixer_ctl_set_enum_by_string(ctl, rate_str);
3339 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3340 }
3341 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3342 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3343 struct mixer_ctl *ctl = NULL;
3344 char *channel_cnt_str = NULL;
3345
3346 switch (channels) {
3347 case 8:
3348 channel_cnt_str = "Eight"; break;
3349 case 7:
3350 channel_cnt_str = "Seven"; break;
3351 case 6:
3352 channel_cnt_str = "Six"; break;
3353 case 5:
3354 channel_cnt_str = "Five"; break;
3355 case 4:
3356 channel_cnt_str = "Four"; break;
3357 case 3:
3358 channel_cnt_str = "Three"; break;
3359 case 1:
3360 channel_cnt_str = "One"; break;
3361 case 2:
3362 default:
3363 channel_cnt_str = "Two"; break;
3364 }
3365
3366 ctl = mixer_get_ctl_by_name(adev->mixer,
3367 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3368 if (!ctl) {
3369 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3370 __func__,
3371 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3372 return -EINVAL;
3373 }
3374 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3375 my_data->current_backend_cfg[backend_idx].channels = channels;
3376
3377 // skip EDID configuration for HDMI backend
3378
3379 ALOGD("%s:becf: afe: %s set to %s", __func__,
3380 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3381 channel_cnt_str);
3382 }
3383
3384 // skip set ext_display format mixer control
3385 return ret;
3386}
3387
3388static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3389{
3390 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3391 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3392 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3393 }
3394
3395 return backend_bit_width_table[snd_device];
3396}
3397
3398/*
3399 * return backend_idx on which voice call is active
3400 */
3401static int platform_get_voice_call_backend(struct audio_device* adev)
3402{
3403 struct audio_usecase *uc = NULL;
3404 struct listnode *node;
3405 snd_device_t out_snd_device = SND_DEVICE_NONE;
3406
3407 int backend_idx = -1;
3408
3409 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3410 list_for_each(node, &adev->usecase_list) {
3411 uc = node_to_item(node, struct audio_usecase, list);
3412 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3413 out_snd_device = platform_get_output_snd_device(adev->platform,
3414 uc->stream.out->devices);
3415 backend_idx = platform_get_backend_index(out_snd_device);
3416 break;
3417 }
3418 }
3419 }
3420 return backend_idx;
3421}
3422
3423/*
3424 * goes through all the current usecases and picks the highest
3425 * bitwidth & samplerate
3426 */
3427static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3428 int backend_idx,
3429 struct audio_backend_cfg *backend_cfg)
3430{
3431 bool backend_change = false;
3432 unsigned int bit_width;
3433 unsigned int sample_rate;
3434 unsigned int channels;
3435 struct platform_data *my_data = (struct platform_data *)adev->platform;
3436
3437 bit_width = backend_cfg->bit_width;
3438 sample_rate = backend_cfg->sample_rate;
3439 channels = backend_cfg->channels;
3440
3441 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3442 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3443 sample_rate, channels);
3444
3445 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3446 // default backend
3447 // force routing is not required here, caller will do it anyway
3448 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3449 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3450 "for unprocessed/camera source", __func__);
3451 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3452 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3453 }
3454
3455 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3456 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3457 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3458 __func__, bit_width, sample_rate, channels);
3459 }
3460
3461 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3462 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3463
3464 // Force routing if the expected bitwdith or samplerate
3465 // is not same as current backend comfiguration
3466 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3467 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3468 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3469 backend_cfg->bit_width = bit_width;
3470 backend_cfg->sample_rate= sample_rate;
3471 backend_cfg->channels = channels;
3472 backend_change = true;
3473 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3474 "new sample rate: %d new channel: %d",
3475 __func__, backend_cfg->bit_width,
3476 backend_cfg->sample_rate, backend_cfg->channels);
3477 }
3478
3479 return backend_change;
3480}
3481
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003482static void pick_playback_cfg_for_uc(struct audio_device *adev,
3483 struct audio_usecase *usecase,
3484 snd_device_t snd_device,
3485 unsigned int *bit_width,
3486 unsigned int *sample_rate,
3487 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003488{
3489 int i =0;
3490 struct listnode *node;
3491 list_for_each(node, &adev->usecase_list) {
3492 struct audio_usecase *uc;
3493 uc = node_to_item(node, struct audio_usecase, list);
3494 struct stream_out *out = (struct stream_out*) uc->stream.out;
3495 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3496 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3497 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3498 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3499 uc->id, out->sample_rate,
3500 pcm_format_to_bits(out->config.format), out_channels,
3501 platform_get_snd_device_name(uc->out_snd_device));
3502
3503 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3504 if (*bit_width < pcm_format_to_bits(out->config.format))
3505 *bit_width = pcm_format_to_bits(out->config.format);
3506 if (*sample_rate < out->sample_rate)
3507 *sample_rate = out->sample_rate;
3508 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3509 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3510 if (*channels < out_channels)
3511 *channels = out_channels;
3512 }
3513 }
3514 }
3515 return;
3516}
3517
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003518static void headset_is_config_supported(unsigned int *bit_width,
3519 unsigned int *sample_rate,
3520 unsigned int *channels) {
3521 switch (*bit_width) {
3522 case 16:
3523 case 24:
3524 break;
3525 default:
3526 *bit_width = 16;
3527 break;
3528 }
3529
3530 if (*sample_rate > 192000) {
3531 *sample_rate = 192000;
3532 }
3533
3534 if (*channels > 2) {
3535 *channels = 2;
3536 }
3537}
3538
David Linee3fe402017-03-13 10:00:42 -07003539static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3540 struct audio_usecase* usecase,
3541 snd_device_t snd_device,
3542 struct audio_backend_cfg *backend_cfg)
3543{
3544 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003545 unsigned int bit_width;
3546 unsigned int sample_rate;
3547 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003548 int backend_idx = DEFAULT_CODEC_BACKEND;
3549 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003550
3551 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3552 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3553 backend_change = false;
3554 return backend_change;
3555 }
3556
3557 backend_idx = platform_get_backend_index(snd_device);
3558 bit_width = backend_cfg->bit_width;
3559 sample_rate = backend_cfg->sample_rate;
3560 channels = backend_cfg->channels;
3561
3562 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3563 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3564 sample_rate, channels, backend_idx, usecase->id,
3565 platform_get_snd_device_name(snd_device));
3566
3567 if (backend_idx == platform_get_voice_call_backend(adev)) {
3568 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3569 __func__);
3570 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3571 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3572 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3573 } else {
3574 /*
3575 * The backend should be configured at highest bit width and/or
3576 * sample rate amongst all playback usecases.
3577 * If the selected sample rate and/or bit width differ with
3578 * current backend sample rate and/or bit width, then, we set the
3579 * backend re-configuration flag.
3580 *
3581 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3582 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003583 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3584 &bit_width,
3585 &sample_rate,
3586 &channels);
David Linee3fe402017-03-13 10:00:42 -07003587 }
3588
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003589 switch (backend_idx) {
3590 case USB_AUDIO_RX_BACKEND:
3591 audio_extn_usb_is_config_supported(&bit_width,
3592 &sample_rate, &channels, true);
3593 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3594 __func__, bit_width, sample_rate, channels);
3595 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003596 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003597 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3598 break;
3599 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003600 default:
3601 bit_width = platform_get_snd_device_bit_width(snd_device);
3602 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3603 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3604 break;
David Linee3fe402017-03-13 10:00:42 -07003605 }
3606
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003607 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3608 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003609 __func__, backend_idx , bit_width, sample_rate);
3610
3611 // Force routing if the expected bitwdith or samplerate
3612 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003613 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3614 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3615 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003616 backend_cfg->bit_width = bit_width;
3617 backend_cfg->sample_rate = sample_rate;
3618 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003619 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003620 backend_change = true;
3621 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3622 "new sample rate: %d new channels: %d",
3623 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3624 }
3625
3626 return backend_change;
3627}
3628
3629bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3630 struct audio_usecase *usecase, snd_device_t snd_device)
3631{
3632 int backend_idx = DEFAULT_CODEC_BACKEND;
3633 int new_snd_devices[SND_DEVICE_OUT_END];
3634 int i, num_devices = 1;
3635 bool ret = false;
3636 struct platform_data *my_data = (struct platform_data *)adev->platform;
3637 struct audio_backend_cfg backend_cfg;
3638
3639 backend_idx = platform_get_backend_index(snd_device);
3640
3641 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3642 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3643 backend_cfg.format = usecase->stream.out->format;
3644 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3645 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3646 backend_cfg.passthrough_enabled = false;
3647
3648 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3649 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3650 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3651 platform_get_snd_device_name(snd_device));
3652
3653 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3654 new_snd_devices[0] = snd_device;
3655
3656 for (i = 0; i < num_devices; i++) {
3657 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3658 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3659 &backend_cfg))) {
3660 platform_set_backend_cfg(adev, new_snd_devices[i],
3661 &backend_cfg);
3662 ret = true;
3663 }
3664 }
3665 return ret;
3666}
3667
3668bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3669 struct audio_usecase *usecase, snd_device_t snd_device)
3670{
3671 int backend_idx = platform_get_backend_index(snd_device);
3672 int ret = 0;
3673 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003674 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003675
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003676 if (usecase->type == PCM_CAPTURE) {
3677 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003678 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3679 } else {
3680 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3681 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3682 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3683 backend_cfg.channels = 1;
3684 }
3685
3686 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3687 ", backend_idx %d usecase = %d device (%s)", __func__,
3688 backend_cfg.bit_width,
3689 backend_cfg.sample_rate,
3690 backend_cfg.channels,
3691 backend_idx, usecase->id,
3692 platform_get_snd_device_name(snd_device));
3693
3694 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3695 ret = platform_set_backend_cfg(adev, snd_device,
3696 &backend_cfg);
3697 if(!ret)
3698 return true;
3699 }
3700
3701 return false;
3702}
3703
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003704static int max_be_dai_names = 0;
3705static const struct be_dai_name_struct *be_dai_name_table;
3706
3707/*
3708 * Retrieves the be_dai_name_table from kernel to enable a mapping
3709 * between sound device hw interfaces and backend IDs. This allows HAL to
3710 * specify the backend a specific calibration is needed for.
3711 */
3712static int init_be_dai_name_table(struct audio_device *adev)
3713{
3714 const char *mixer_ctl_name = "Backend DAI Name Table";
3715 struct mixer_ctl *ctl;
3716 int i, j, ret, size;
3717 bool valid_hw_interface;
3718
3719 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3720 if (!ctl) {
3721 ALOGE("%s: Could not get ctl for mixer name %s\n",
3722 __func__, mixer_ctl_name);
3723 ret = -EINVAL;
3724 goto done;
3725 }
3726
3727 mixer_ctl_update(ctl);
3728
3729 size = mixer_ctl_get_num_values(ctl);
3730 if (size <= 0){
3731 ALOGE("%s: Failed to get %s size %d\n",
3732 __func__, mixer_ctl_name, size);
3733 ret = -EFAULT;
3734 goto done;
3735 }
3736
3737 posix_memalign((void **)&be_dai_name_table, 32, size);
3738 if (be_dai_name_table == NULL) {
3739 ALOGE("%s: Failed to allocate memory for %s\n",
3740 __func__, mixer_ctl_name);
3741 ret = -ENOMEM;
3742 goto freeMem;
3743 }
3744
3745 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3746 if (ret) {
3747 ALOGE("%s: Failed to get %s, ret %d\n",
3748 __func__, mixer_ctl_name, ret);
3749 ret = -EFAULT;
3750 goto freeMem;
3751 }
3752
3753 if (be_dai_name_table != NULL) {
3754 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3755 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3756 __func__, mixer_ctl_name, max_be_dai_names);
3757 ret = 0;
3758 } else {
3759 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3760 ret = -EFAULT;
3761 goto freeMem;
3762 }
3763
3764 /*
3765 * Validate all sound devices have a valid backend set to catch
3766 * errors for uncommon sound devices
3767 */
3768 for (i = 0; i < SND_DEVICE_MAX; i++) {
3769 valid_hw_interface = false;
3770
3771 if (hw_interface_table[i] == NULL) {
3772 ALOGW("%s: sound device %s has no hw interface set\n",
3773 __func__, platform_get_snd_device_name(i));
3774 continue;
3775 }
3776
3777 for (j = 0; j < max_be_dai_names; j++) {
3778 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3779 == 0) {
3780 valid_hw_interface = true;
3781 break;
3782 }
3783 }
3784 if (!valid_hw_interface)
3785 ALOGD("%s: sound device %s does not have a valid hw interface set "
3786 "(disregard for combo devices) %s\n",
3787 __func__, platform_get_snd_device_name(i),
3788 hw_interface_table[i]);
3789 }
3790
3791 goto done;
3792
3793freeMem:
3794 if (be_dai_name_table) {
3795 free((void *)be_dai_name_table);
3796 be_dai_name_table = NULL;
3797 }
3798
3799done:
3800 return ret;
3801}
3802
3803int platform_get_snd_device_backend_index(snd_device_t device)
3804{
3805 int i, be_dai_id;
3806 const char * hw_interface_name = NULL;
3807
3808 ALOGV("%s: enter with device %d\n", __func__, device);
3809
3810 if ((device <= SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3811 ALOGE("%s: Invalid snd_device = %d",
3812 __func__, device);
3813 be_dai_id = -EINVAL;
3814 goto done;
3815 }
3816
3817 /* Get string value of necessary backend for device */
3818 hw_interface_name = hw_interface_table[device];
3819 if (hw_interface_name == NULL) {
3820 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3821 be_dai_id = -EINVAL;
3822 goto done;
3823 }
3824
3825 /* Check if be dai name table was retrieved successfully */
3826 if (be_dai_name_table == NULL) {
3827 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3828 be_dai_id = -EFAULT;
3829 goto done;
3830 }
3831
3832 /* Get backend ID for device specified */
3833 for (i = 0; i < max_be_dai_names; i++) {
3834 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3835 be_dai_id = be_dai_name_table[i].be_id;
3836 goto done;
3837 }
3838 }
3839 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3840 be_dai_id = -EINVAL;
3841 goto done;
3842
3843done:
3844 return be_dai_id;
3845}
3846
3847void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
3848 unsigned int stream_sr, int* sample_rate)
3849{
3850 struct platform_data* my_data = (struct platform_data *)platform;
3851 int backend_idx = platform_get_backend_index(snd_device);
3852 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
3853 /*
3854 *Check if device SR is multiple of 8K or 11.025 Khz
3855 *check if the stream SR is multiple of same base, if yes
3856 *then have copp SR equal to stream SR, this ensures that
3857 *post processing happens at stream SR, else have
3858 *copp SR equal to device SR.
3859 */
3860 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
3861 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
3862 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
3863 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
3864 *sample_rate = device_sr;
3865 } else
3866 *sample_rate = stream_sr;
3867
3868 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
3869 , *sample_rate);
3870
3871}
3872
3873// called from info parser
3874void platform_add_app_type(int bw, const char *uc_type,
3875 int app_type, int max_rate) {
3876 struct app_type_entry *ap =
3877 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
3878
3879 if (!ap) {
3880 ALOGE("%s failed to allocate mem for app type", __func__);
3881 return;
3882 }
3883
3884 ap->uc_type = -1;
3885 for (int i=0; i<USECASE_TYPE_MAX; i++) {
3886 if (!strcmp(uc_type, usecase_type_index[i].name)) {
3887 ap->uc_type = usecase_type_index[i].index;
3888 break;
3889 }
3890 }
3891
3892 if (ap->uc_type == -1) {
3893 free(ap);
3894 return;
3895 }
3896
3897 ALOGI("%s bw %d uc %s app_type %d max_rate %d",
3898 __func__, bw, uc_type, app_type, max_rate);
3899 ap->bit_width = bw;
3900 ap->app_type = app_type;
3901 ap->max_rate = max_rate;
3902 list_add_tail(&app_type_entry_list, &ap->node);
3903}
3904
3905
3906int platform_get_default_app_type_v2(void *platform __unused,
3907 usecase_type_t type,
3908 int *app_type )
3909{
3910 if (type == PCM_PLAYBACK)
3911 *app_type = DEFAULT_APP_TYPE_RX_PATH;
3912 else
3913 *app_type = DEFAULT_APP_TYPE_TX_PATH;
3914 return 0;
3915}
3916
3917int platform_get_app_type_v2(void *platform, usecase_type_t uc_type,
3918 int bw, int sr __unused,
3919 int *app_type)
3920{
3921 struct listnode *node;
3922 struct app_type_entry *entry;
3923 *app_type = -1;
3924 list_for_each(node, &app_type_entry_list) {
3925 entry = node_to_item(node, struct app_type_entry, node);
3926 if (entry->bit_width == bw &&
3927 entry->uc_type == uc_type) {
3928 *app_type = entry->app_type;
3929 break;
3930 }
3931 }
3932
3933 if (*app_type == -1) {
3934 return platform_get_default_app_type_v2(platform, uc_type, app_type);
3935 }
3936 return 0;
3937}