blob: 330894086aad8f12bc9287c24b6a5a5e0c683759 [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa51fd402016-02-04 19:49:33 -08002 * Copyright (C) 2013-2016 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>
27#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070028#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070029#include <linux/msm_audio.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070030
vivek mehta60ea4152016-02-18 17:10:26 -080031#define MIXER_XML_DEFAULT_PATH "/system/etc/mixer_paths.xml"
32#define MIXER_XML_BASE_STRING "/system/etc/mixer_paths"
33#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
34#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
35
Eric Laurentb23d5282013-05-14 15:27:20 -070036#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070037#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090038#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070039
Eric Laurentf9583c32016-03-28 13:50:50 -070040#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070041
42/*
Eric Laurentb23d5282013-05-14 15:27:20 -070043 * This file will have a maximum of 38 bytes:
44 *
45 * 4 bytes: number of audio blocks
46 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
47 * Maximum 10 * 3 bytes: SAD blocks
48 */
49#define MAX_SAD_BLOCKS 10
50#define SAD_BLOCK_SIZE 3
51
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090052#define MAX_CVD_VERSION_STRING_SIZE 100
53
Eric Laurentb23d5282013-05-14 15:27:20 -070054/* EDID format ID for LPCM audio */
55#define EDID_FORMAT_LPCM 1
56
sangwoo1b9f4b32013-06-21 18:22:55 -070057/* Retry for delay in FW loading*/
58#define RETRY_NUMBER 10
59#define RETRY_US 500000
Vineeta Srivastava4b89e372014-06-19 14:21:42 -070060#define MAX_SND_CARD 8
sangwoo53b2cf02013-07-25 19:18:44 -070061
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070062#define MAX_SND_CARD_NAME_LEN 31
63
vivek mehta1a9b7c02015-06-25 11:49:38 -070064#define DEFAULT_APP_TYPE_RX_PATH 0x11130
65
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090066#define TOSTRING_(x) #x
67#define TOSTRING(x) TOSTRING_(x)
68
Eric Laurentb23d5282013-05-14 15:27:20 -070069struct audio_block_header
70{
71 int reserved;
72 int length;
73};
74
vivek mehta1a9b7c02015-06-25 11:49:38 -070075enum {
76 CAL_MODE_SEND = 0x1,
77 CAL_MODE_PERSIST = 0x2,
78 CAL_MODE_RTAC = 0x4
79};
80
keunhui.park2f7306a2015-07-16 16:48:06 +090081#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
82
83struct operator_info {
84 struct listnode list;
85 char *name;
86 char *mccmnc;
87};
88
89struct operator_specific_device {
90 struct listnode list;
91 char *operator;
92 char *mixer_path;
93 int acdb_id;
94};
95
96static struct listnode operator_info_list;
97static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
98
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -070099/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700100typedef void (*acdb_deallocate_t)();
vivek mehtac698f132016-02-25 18:50:35 -0800101typedef int (*acdb_init_v2_cvd_t)(char *, char *, int);
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900102typedef int (*acdb_init_v2_t)(char *);
Eric Laurentb23d5282013-05-14 15:27:20 -0700103typedef int (*acdb_init_t)();
104typedef void (*acdb_send_audio_cal_t)(int, int);
105typedef void (*acdb_send_voice_cal_t)(int, int);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700106typedef int (*acdb_reload_vocvoltable_t)(int);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700107typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int);
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700108typedef int (*acdb_send_custom_top_t) (void);
Eric Laurentb23d5282013-05-14 15:27:20 -0700109
110/* Audio calibration related functions */
111struct platform_data {
112 struct audio_device *adev;
113 bool fluence_in_spkr_mode;
114 bool fluence_in_voice_call;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700115 bool fluence_in_voice_comm;
Eric Laurentb23d5282013-05-14 15:27:20 -0700116 bool fluence_in_voice_rec;
Prashant Malanic92c5962015-08-11 15:10:18 -0700117 /* 0 = no fluence, 1 = fluence, 2 = fluence pro */
118 int fluence_type;
119 int source_mic_type;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -0700120 bool speaker_lr_swap;
121
Eric Laurentb23d5282013-05-14 15:27:20 -0700122 void *acdb_handle;
Thierry Strudel92232b42017-01-26 10:51:48 -0800123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700124 acdb_init_v2_cvd_t acdb_init;
125#elif defined (PLATFORM_MSM8084)
126 acdb_init_v2_t acdb_init;
127#else
128 acdb_init_t acdb_init;
129#endif
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700130 acdb_deallocate_t acdb_deallocate;
131 acdb_send_audio_cal_t acdb_send_audio_cal;
132 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700133 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700134 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700135 acdb_send_custom_top_t acdb_send_custom_top;
136 bool acdb_initialized;
137
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700138 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800139 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700140
David Lin8c03e672017-02-06 20:31:38 -0800141 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700142 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900143 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700144 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800145
146 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700147};
148
Haynes Mathew George98c95622014-06-20 19:14:25 -0700149static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700150 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
151 DEEP_BUFFER_PCM_DEVICE},
152 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
153 LOWLATENCY_PCM_DEVICE},
154 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
155 MULTIMEDIA2_PCM_DEVICE},
156 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
157 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700158 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
159 MULTIMEDIA2_PCM_DEVICE},
160 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
161 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800162 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
163 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700164
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700165 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
166 AUDIO_RECORD_PCM_DEVICE},
167 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
168 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700169
Eric Laurent0e46adf2016-12-16 12:49:24 -0800170 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
171 MMAP_RECORD_PCM_DEVICE},
172
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700173 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
174 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700175 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
176 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
177 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
178 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800179 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
180 VOICEMMODE1_CALL_PCM_DEVICE},
181 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
182 VOICEMMODE2_CALL_PCM_DEVICE},
183
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700184 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
185 AUDIO_RECORD_PCM_DEVICE},
186 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
187 AUDIO_RECORD_PCM_DEVICE},
188 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
189 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800190 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700191
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700192 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
193 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
194
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700195 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
196 AFE_PROXY_RECORD_PCM_DEVICE},
197 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
198 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800199 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700200
Eric Laurentb23d5282013-05-14 15:27:20 -0700201};
202
203/* Array to store sound devices */
204static const char * const device_table[SND_DEVICE_MAX] = {
205 [SND_DEVICE_NONE] = "none",
206 /* Playback sound devices */
207 [SND_DEVICE_OUT_HANDSET] = "handset",
208 [SND_DEVICE_OUT_SPEAKER] = "speaker",
209 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700210 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700211 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500212 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700213 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700214 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500215 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700216 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700217 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500218 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700219 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
220 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500221 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700222 [SND_DEVICE_OUT_HDMI] = "hdmi",
223 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
224 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700225 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700226 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
227 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
228 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
229 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700230 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Lin8c03e672017-02-06 20:31:38 -0800231 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
232 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
233 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700234 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
235 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700236 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Eric Laurentb23d5282013-05-14 15:27:20 -0700237
238 /* Capture sound devices */
239 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700240 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700241 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
242 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
243 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
244 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
245 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
246 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
247 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
248
249 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
250 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
251 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
252 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
253 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
254 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
255 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
256 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
257 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
258
259 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500260 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700261
Eric Laurentb23d5282013-05-14 15:27:20 -0700262 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
263 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700264 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700265 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700266 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700267 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700268
269 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
270 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
271 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
272 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700273 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700274 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700275 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
276 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
277 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700278
Eric Laurentb23d5282013-05-14 15:27:20 -0700279 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700280 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700281 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700282 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700283 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
284 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Lin8c03e672017-02-06 20:31:38 -0800285 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700286 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700287
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700288 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700289 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
290 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
291 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
292 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800293
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700294 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700295
Prashant Malanic92c5962015-08-11 15:10:18 -0700296 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
297 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700298 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700299 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
300 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700301 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
302 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700303};
304
305/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700306static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700307 [SND_DEVICE_NONE] = -1,
308 [SND_DEVICE_OUT_HANDSET] = 7,
309 [SND_DEVICE_OUT_SPEAKER] = 15,
310 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700311 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700312 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500313 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700314 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700315 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500316 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700317 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700318 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
319 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500320 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700321 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500322 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700323 [SND_DEVICE_OUT_HDMI] = 18,
324 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
325 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700326 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700327 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700328 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
329 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
330 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700331 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Lin8c03e672017-02-06 20:31:38 -0800332 [SND_DEVICE_OUT_USB_HEADSET] = 45,
333 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
334 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700335 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
336 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700337 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700338
339 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700340 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
341 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
342 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
343 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
344 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
345 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
346 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
347 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
348
349 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
350 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
351 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
352 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
353 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
354 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
355 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
356 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
357 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
358
rago90fb9612015-12-02 11:37:53 -0800359 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500360 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700361
Eric Laurentb23d5282013-05-14 15:27:20 -0700362 [SND_DEVICE_IN_HDMI_MIC] = 4,
363 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700364 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700365 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700366 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700367 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700368
369 [SND_DEVICE_IN_VOICE_DMIC] = 41,
370 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
371 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700372 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700373 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800374 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700375 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
376 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
377 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700378
rago90fb9612015-12-02 11:37:53 -0800379 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700380 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700381 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700382 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700383 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
384 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800385 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
386
387 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
388 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700389 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
390 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
391 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700392
393 [SND_DEVICE_IN_VOICE_RX] = 44,
David Lin8c03e672017-02-06 20:31:38 -0800394 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700395 [SND_DEVICE_IN_THREE_MIC] = 46,
396 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700397 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700398 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
399 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700400 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
401 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700402};
403
David Lin8c03e672017-02-06 20:31:38 -0800404// Platform specific backend bit width table
405static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
406
Haynes Mathew George98c95622014-06-20 19:14:25 -0700407struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700408 char name[100];
409 unsigned int index;
410};
411
412#define TO_NAME_INDEX(X) #X, X
413
Haynes Mathew George98c95622014-06-20 19:14:25 -0700414/* Used to get index from parsed string */
415static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
416 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700417 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
418 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
419 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700420 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700421 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500422 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700423 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700424 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500425 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700426 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700427 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
428 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700429 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700430 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500431 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700432 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
433 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
434 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
435 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700436 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500437 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700438 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
439 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
440 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
David Lin8c03e672017-02-06 20:31:38 -0800441 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
442 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
443 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700444
445 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700446 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
447 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700448 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700449 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700450 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
451 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
452 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
453 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
454 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
455 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
456 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
457
458 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700459 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700460 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
461 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
462 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
463 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
464 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
465 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
467
468 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700469 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700470
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700471 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
472 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700473 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700474 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700475 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700476 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700477
478 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
479 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
480 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700481 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700482 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
483 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700484 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
485 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
486 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700487
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700488 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700489 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700490 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700491 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700492 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
493 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700494 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Lin8c03e672017-02-06 20:31:38 -0800495 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700496
rago90fb9612015-12-02 11:37:53 -0800497 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
498 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700499 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
500 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
501 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800502
Prashant Malanic92c5962015-08-11 15:10:18 -0700503 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
504 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700505 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700506 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
507 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700508 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
509 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700510};
511
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700512static char * backend_tag_table[SND_DEVICE_MAX] = {0};
513static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700514
515static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
516 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
517 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
518 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
519 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700520 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
521 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800522 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700523 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
524 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800525 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700526 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
527 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
528 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
529 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
530 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800531 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
532 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700533 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
534 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
535 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
536 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800537 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
538 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
539 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
540 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
541 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700542};
543
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700544#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
545#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800546#define ULL_PLATFORM_DELAY (3*1000LL)
547#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700548
Eric Laurentb23d5282013-05-14 15:27:20 -0700549static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
550static bool is_tmus = false;
551
552static void check_operator()
553{
554 char value[PROPERTY_VALUE_MAX];
555 int mccmnc;
556 property_get("gsm.sim.operator.numeric",value,"0");
557 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700558 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700559 switch(mccmnc) {
560 /* TMUS MCC(310), MNC(490, 260, 026) */
561 case 310490:
562 case 310260:
563 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900564 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
565 case 310800:
566 case 310660:
567 case 310580:
568 case 310310:
569 case 310270:
570 case 310250:
571 case 310240:
572 case 310230:
573 case 310220:
574 case 310210:
575 case 310200:
576 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700577 is_tmus = true;
578 break;
579 }
580}
581
582bool is_operator_tmus()
583{
584 pthread_once(&check_op_once_ctl, check_operator);
585 return is_tmus;
586}
587
keunhui.park2f7306a2015-07-16 16:48:06 +0900588static char *get_current_operator()
589{
590 struct listnode *node;
591 struct operator_info *info_item;
592 char mccmnc[PROPERTY_VALUE_MAX];
593 char *ret = NULL;
594
Tom Cherry7fea2042016-11-10 18:05:59 -0800595 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900596
597 list_for_each(node, &operator_info_list) {
598 info_item = node_to_item(node, struct operator_info, list);
599 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
600 ret = info_item->name;
601 }
602 }
603
604 return ret;
605}
606
607static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
608{
609 struct listnode *node;
610 struct operator_specific_device *ret = NULL;
611 struct operator_specific_device *device_item;
612 char *operator_name;
613
614 operator_name = get_current_operator();
615 if (operator_name == NULL)
616 return ret;
617
618 list_for_each(node, operator_specific_device_table[snd_device]) {
619 device_item = node_to_item(node, struct operator_specific_device, list);
620 if (strcmp(operator_name, device_item->operator) == 0) {
621 ret = device_item;
622 }
623 }
624
625 return ret;
626}
627
628
629static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
630{
631 struct operator_specific_device *device;
632 int ret = acdb_device_table[snd_device];
633
634 device = get_operator_specific_device(snd_device);
635 if (device != NULL)
636 ret = device->acdb_id;
637
638 return ret;
639}
640
641static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
642{
643 struct operator_specific_device *device;
644 const char *ret = device_table[snd_device];
645
646 device = get_operator_specific_device(snd_device);
647 if (device != NULL)
648 ret = device->mixer_path;
649
650 return ret;
651}
652
vivek mehta1a9b7c02015-06-25 11:49:38 -0700653bool platform_send_gain_dep_cal(void *platform, int level)
654{
655 bool ret_val = false;
656 struct platform_data *my_data = (struct platform_data *)platform;
657 struct audio_device *adev = my_data->adev;
658 int acdb_dev_id, app_type;
659 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
660 int mode = CAL_MODE_RTAC;
661 struct listnode *node;
662 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700663
664 if (my_data->acdb_send_gain_dep_cal == NULL) {
665 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
666 return ret_val;
667 }
668
669 if (!voice_is_in_call(adev)) {
670 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
671 __func__, level);
672 app_type = DEFAULT_APP_TYPE_RX_PATH;
673
674 // find the current active sound device
675 list_for_each(node, &adev->usecase_list) {
676 usecase = node_to_item(node, struct audio_usecase, list);
677
678 if (usecase != NULL &&
679 usecase->type == PCM_PLAYBACK &&
680 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
681
682 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700683 if (audio_extn_spkr_prot_is_enabled()) {
684 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
685 } else {
686 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
687 }
688
vivek mehta1a9b7c02015-06-25 11:49:38 -0700689 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
690 acdb_dev_type, mode, level)) {
691 // set ret_val true if at least one calibration is set successfully
692 ret_val = true;
693 } else {
694 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
695 }
696 } else {
697 ALOGW("%s: Usecase list is empty", __func__);
698 }
699 }
700 } else {
701 ALOGW("%s: Voice call in progress .. ignore setting new cal",
702 __func__);
703 }
704 return ret_val;
705}
706
Eric Laurentcefbbac2014-09-04 13:54:10 -0500707void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700708{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800709 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500710 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700711
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800712 if (strcmp(my_data->ec_ref_mixer_path, "")) {
713 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
714 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500715 }
716
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800717 if (enable) {
718 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
719 if (out_device != AUDIO_DEVICE_NONE) {
720 snd_device = platform_get_output_snd_device(adev->platform, out_device);
721 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
722 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500723
Joe Onorato188b6222016-03-01 11:02:27 -0800724 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800725 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
726 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700727}
728
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700729static struct csd_data *open_csd_client(bool i2s_ext_modem)
730{
731 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
732
733 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
734 if (csd->csd_client == NULL) {
735 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
736 goto error;
737 } else {
738 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
739
740 csd->deinit = (deinit_t)dlsym(csd->csd_client,
741 "csd_client_deinit");
742 if (csd->deinit == NULL) {
743 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
744 dlerror());
745 goto error;
746 }
747 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
748 "csd_client_disable_device");
749 if (csd->disable_device == NULL) {
750 ALOGE("%s: dlsym error %s for csd_client_disable_device",
751 __func__, dlerror());
752 goto error;
753 }
754 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
755 "csd_client_enable_device_config");
756 if (csd->enable_device_config == NULL) {
757 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
758 __func__, dlerror());
759 goto error;
760 }
761 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
762 "csd_client_enable_device");
763 if (csd->enable_device == NULL) {
764 ALOGE("%s: dlsym error %s for csd_client_enable_device",
765 __func__, dlerror());
766 goto error;
767 }
768 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
769 "csd_client_start_voice");
770 if (csd->start_voice == NULL) {
771 ALOGE("%s: dlsym error %s for csd_client_start_voice",
772 __func__, dlerror());
773 goto error;
774 }
775 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
776 "csd_client_stop_voice");
777 if (csd->stop_voice == NULL) {
778 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
779 __func__, dlerror());
780 goto error;
781 }
782 csd->volume = (volume_t)dlsym(csd->csd_client,
783 "csd_client_volume");
784 if (csd->volume == NULL) {
785 ALOGE("%s: dlsym error %s for csd_client_volume",
786 __func__, dlerror());
787 goto error;
788 }
789 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
790 "csd_client_mic_mute");
791 if (csd->mic_mute == NULL) {
792 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
793 __func__, dlerror());
794 goto error;
795 }
796 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
797 "csd_client_slow_talk");
798 if (csd->slow_talk == NULL) {
799 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
800 __func__, dlerror());
801 goto error;
802 }
803 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
804 "csd_client_start_playback");
805 if (csd->start_playback == NULL) {
806 ALOGE("%s: dlsym error %s for csd_client_start_playback",
807 __func__, dlerror());
808 goto error;
809 }
810 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
811 "csd_client_stop_playback");
812 if (csd->stop_playback == NULL) {
813 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
814 __func__, dlerror());
815 goto error;
816 }
817 csd->start_record = (start_record_t)dlsym(csd->csd_client,
818 "csd_client_start_record");
819 if (csd->start_record == NULL) {
820 ALOGE("%s: dlsym error %s for csd_client_start_record",
821 __func__, dlerror());
822 goto error;
823 }
824 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
825 "csd_client_stop_record");
826 if (csd->stop_record == NULL) {
827 ALOGE("%s: dlsym error %s for csd_client_stop_record",
828 __func__, dlerror());
829 goto error;
830 }
831
832 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
833 "csd_client_get_sample_rate");
834 if (csd->get_sample_rate == NULL) {
835 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
836 __func__, dlerror());
837
838 goto error;
839 }
840
841 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
842
843 if (csd->init == NULL) {
844 ALOGE("%s: dlsym error %s for csd_client_init",
845 __func__, dlerror());
846 goto error;
847 } else {
848 csd->init(i2s_ext_modem);
849 }
850 }
851 return csd;
852
853error:
854 free(csd);
855 csd = NULL;
856 return csd;
857}
858
859void close_csd_client(struct csd_data *csd)
860{
861 if (csd != NULL) {
862 csd->deinit();
863 dlclose(csd->csd_client);
864 free(csd);
865 csd = NULL;
866 }
867}
868
869static void platform_csd_init(struct platform_data *my_data)
870{
871#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700872 int32_t modems, (*count_modems)(void);
873 const char *name = "libdetectmodem.so";
874 const char *func = "count_modems";
875 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700876
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700877 my_data->csd = NULL;
878
879 void *lib = dlopen(name, RTLD_NOW);
880 error = dlerror();
881 if (!lib) {
882 ALOGE("%s: could not find %s: %s", __func__, name, error);
883 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700884 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700885
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700886 count_modems = NULL;
887 *(void **)(&count_modems) = dlsym(lib, func);
888 error = dlerror();
889 if (!count_modems) {
890 ALOGE("%s: could not find symbol %s in %s: %s",
891 __func__, func, name, error);
892 goto done;
893 }
894
895 modems = count_modems();
896 if (modems < 0) {
897 ALOGE("%s: count_modems failed\n", __func__);
898 goto done;
899 }
900
Eric Laurent2bafff12016-03-17 12:17:23 -0700901 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700902 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700903 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700904
905done:
906 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700907#else
908 my_data->csd = NULL;
909#endif
910}
911
Eric Laurentc6333382015-09-14 12:43:44 -0700912static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700913{
914 int32_t dev;
915 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700916 backend_tag_table[dev] = NULL;
917 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900918 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700919 }
920
David Lin8c03e672017-02-06 20:31:38 -0800921 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
922 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
923 }
924
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700925 // To overwrite these go to the audio_platform_info.xml file.
926 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700927 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700928 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
929 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
930 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
931 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
932 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700933 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700934 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
935 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700936
David Lin8c03e672017-02-06 20:31:38 -0800937 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
938 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
939 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
940 strdup("speaker-and-usb-headphones");
941 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700942 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
943 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
944 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
945 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
946 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
947 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
948 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700949 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700950 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700951 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700952 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
953 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
954 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
955 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
956 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
957 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
958 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
959 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
960 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
961 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
962 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
963 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
964 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Lin8c03e672017-02-06 20:31:38 -0800965 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
966 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
967 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 -0700968 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
969 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
970 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700971
972 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700973}
974
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900975void get_cvd_version(char *cvd_version, struct audio_device *adev)
976{
977 struct mixer_ctl *ctl;
978 int count;
979 int ret = 0;
980
981 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
982 if (!ctl) {
983 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
984 goto done;
985 }
986 mixer_ctl_update(ctl);
987
988 count = mixer_ctl_get_num_values(ctl);
989 if (count > MAX_CVD_VERSION_STRING_SIZE)
990 count = MAX_CVD_VERSION_STRING_SIZE - 1;
991
992 ret = mixer_ctl_get_array(ctl, cvd_version, count);
993 if (ret != 0) {
994 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
995 goto done;
996 }
997
998done:
999 return;
1000}
1001
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001002static int platform_acdb_init(void *platform)
1003{
1004 struct platform_data *my_data = (struct platform_data *)platform;
1005 struct audio_device *adev = my_data->adev;
1006
1007 if (!my_data->acdb_init) {
1008 ALOGE("%s: no acdb_init fn provided", __func__);
1009 return -1;
1010 }
1011
1012 if (my_data->acdb_initialized) {
1013 ALOGW("acdb is already initialized");
1014 return 0;
1015 }
1016
Thierry Strudel92232b42017-01-26 10:51:48 -08001017#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001018 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1019 if (!cvd_version)
1020 ALOGE("failed to allocate cvd_version");
1021 else {
1022 get_cvd_version(cvd_version, adev);
1023 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1024 free(cvd_version);
1025 }
1026#elif defined (PLATFORM_MSM8084)
1027 my_data->acdb_init((char *)my_data->snd_card_name);
1028#else
1029 my_data->acdb_init();
1030#endif
1031 my_data->acdb_initialized = true;
1032 return 0;
1033}
1034
David Lin8c03e672017-02-06 20:31:38 -08001035static void
1036platform_backend_config_init(struct platform_data *pdata)
1037{
1038 int i;
1039
1040 /* initialize backend config */
1041 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1042 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1043 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1044 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1045
1046 if (i > MAX_RX_CODEC_BACKENDS)
1047 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1048
1049 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1050 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1051 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1052 }
1053
1054 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1055 strdup("SLIM_0_RX Format");
1056 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1057 strdup("SLIM_0_RX SampleRate");
1058
1059 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1060 strdup("SLIM_0_TX Format");
1061 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1062 strdup("SLIM_0_TX SampleRate");
1063
1064 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1065 strdup("USB_AUDIO_TX Format");
1066 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1067 strdup("USB_AUDIO_TX SampleRate");
1068 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1069 strdup("USB_AUDIO_TX Channels");
1070
1071 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1072 strdup("SLIM_6_RX Format");
1073 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1074 strdup("SLIM_6_RX SampleRate");
1075
1076 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1077 strdup("USB_AUDIO_RX Format");
1078 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1079 strdup("USB_AUDIO_RX SampleRate");
1080
1081 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1082 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1083 strdup("USB_AUDIO_RX Channels");
1084}
1085
Eric Laurentb23d5282013-05-14 15:27:20 -07001086void *platform_init(struct audio_device *adev)
1087{
1088 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001089 struct platform_data *my_data = NULL;
1090 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1091 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001092 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001093 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001094 char *snd_internal_name = NULL;
1095 char *tmp = NULL;
1096 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001097 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1098 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001099 my_data = calloc(1, sizeof(struct platform_data));
1100
1101 my_data->adev = adev;
1102
keunhui.park2f7306a2015-07-16 16:48:06 +09001103 list_init(&operator_info_list);
1104
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001105 set_platform_defaults(my_data);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001106 bool card_verifed[MAX_SND_CARD] = {0};
1107 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001108
vivek mehta2b0e5a62016-09-02 17:31:58 -07001109 for (;;) {
1110 if (snd_card_num >= MAX_SND_CARD) {
1111 if (retry_num++ >= retry_limit) {
1112 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1113 goto init_failed;
1114 }
sangwoo1b9f4b32013-06-21 18:22:55 -07001115
vivek mehta2b0e5a62016-09-02 17:31:58 -07001116 snd_card_num = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001117 usleep(RETRY_US);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001118 continue;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001119 }
1120
vivek mehta2b0e5a62016-09-02 17:31:58 -07001121 if (card_verifed[snd_card_num]) {
1122 ++snd_card_num;
1123 continue;
1124 }
1125
1126 adev->mixer = mixer_open(snd_card_num);
1127
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001128 if (!adev->mixer) {
1129 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehta2b0e5a62016-09-02 17:31:58 -07001130 snd_card_num);
1131 ++snd_card_num;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001132 continue;
1133 }
1134
vivek mehta2b0e5a62016-09-02 17:31:58 -07001135 card_verifed[snd_card_num] = true;
1136
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001137 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -08001138 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001139
vivek mehtade4849c2016-03-03 17:23:38 -08001140 audio_extn_set_snd_card_split(snd_card_name);
1141 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001142
vivek mehtade4849c2016-03-03 17:23:38 -08001143 /* Get the codec internal name from the sound card and/or form factor
1144 * name and form the mixer paths and platfor info file name dynamically.
1145 * This is generic way of picking any codec and forma factor name based
1146 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001147
vivek mehtade4849c2016-03-03 17:23:38 -08001148 * current code extends and looks for any of the exteneded mixer path and
1149 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001150
vivek mehtade4849c2016-03-03 17:23:38 -08001151 * order of picking appropriate file is
1152 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1153 * <ii> mixer_paths_<codec_name>.xml, if file not present
1154 * <iii> mixer_paths.xml
1155
1156 * same order is followed for audio_platform_info.xml as well
1157 */
1158
1159 // need to carryforward old file name
1160 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001161 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001162 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001163 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001164 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001165
vivek mehtade4849c2016-03-03 17:23:38 -08001166 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1167 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1168 snd_split_handle->form_factor);
1169
1170 if (F_OK != access(mixer_xml_file, 0)) {
1171 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1172 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1173 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1174
1175 if (F_OK != access(mixer_xml_file, 0)) {
1176 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1177 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1178 }
1179 }
1180
1181 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1182 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1183 snd_split_handle->form_factor);
1184
1185 if (F_OK != access(platform_info_file, 0)) {
1186 memset(platform_info_file, 0, sizeof(platform_info_file));
1187 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1188 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1189
1190 if (F_OK != access(platform_info_file, 0)) {
1191 memset(platform_info_file, 0, sizeof(platform_info_file));
1192 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
vivek mehta60ea4152016-02-18 17:10:26 -08001193 }
1194 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001195 }
1196
vivek mehtade4849c2016-03-03 17:23:38 -08001197 /* Initialize platform specific ids and/or backends*/
1198 platform_info_init(platform_info_file, my_data);
1199
1200 /* validate the sound card name
1201 * my_data->snd_card_name can contain
1202 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1203 * example: msm8994-tomtom-mtp-snd-card
1204 * <b> or sub string of the card name, i.e. <device>-<codec>
1205 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001206 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1207 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001208 */
1209
1210 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001211 strncmp(snd_card_name, my_data->snd_card_name,
1212 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001213 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1214 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001215 ++snd_card_num;
1216 mixer_close(adev->mixer);
1217 adev->mixer = NULL;
vivek mehtade4849c2016-03-03 17:23:38 -08001218 hw_info_deinit(my_data->hw_info);
1219 my_data->hw_info = NULL;
1220 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001221 }
vivek mehtade4849c2016-03-03 17:23:38 -08001222 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1223 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001224
1225 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1226 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1227
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001228 if (!adev->audio_route) {
1229 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001230 mixer_close(adev->mixer);
1231 adev->mixer = NULL;
1232 hw_info_deinit(my_data->hw_info);
1233 my_data->hw_info = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001234 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001235 }
1236 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001237 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001238 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001239 }
1240
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001241 //set max volume step for voice call
1242 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1243 my_data->max_vol_index = atoi(value);
1244
vivek mehta65ad12d2015-08-13 18:32:48 -07001245 property_get("persist.audio.dualmic.config",value,"");
1246 if (!strcmp("endfire", value)) {
1247 dual_mic_config = true;
1248 }
1249
Prashant Malanic92c5962015-08-11 15:10:18 -07001250 my_data->source_mic_type = SOURCE_DUAL_MIC;
1251
Eric Laurentb23d5282013-05-14 15:27:20 -07001252 my_data->fluence_in_spkr_mode = false;
1253 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001254 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001255 my_data->fluence_in_voice_rec = false;
1256
vivek mehta65ad12d2015-08-13 18:32:48 -07001257 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001258 if (!strcmp("fluencepro", value)) {
1259 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001260 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001261 my_data->fluence_type = FLUENCE_ENABLE;
1262 } else if (!strcmp("none", value)) {
1263 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001264 }
1265
Prashant Malanic92c5962015-08-11 15:10:18 -07001266 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001267 property_get("persist.audio.fluence.voicecall",value,"");
1268 if (!strcmp("true", value)) {
1269 my_data->fluence_in_voice_call = true;
1270 }
1271
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001272 property_get("persist.audio.fluence.voicecomm",value,"");
1273 if (!strcmp("true", value)) {
1274 my_data->fluence_in_voice_comm = true;
1275 }
1276
Eric Laurentb23d5282013-05-14 15:27:20 -07001277 property_get("persist.audio.fluence.voicerec",value,"");
1278 if (!strcmp("true", value)) {
1279 my_data->fluence_in_voice_rec = true;
1280 }
1281
1282 property_get("persist.audio.fluence.speaker",value,"");
1283 if (!strcmp("true", value)) {
1284 my_data->fluence_in_spkr_mode = true;
1285 }
1286 }
1287
Prashant Malanic92c5962015-08-11 15:10:18 -07001288 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1289 switch (my_data->max_mic_count) {
1290 case 4:
1291 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1292 case 3:
1293 my_data->source_mic_type |= SOURCE_THREE_MIC;
1294 case 2:
1295 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1296 case 1:
1297 my_data->source_mic_type |= SOURCE_MONO_MIC;
1298 break;
1299 default:
1300 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1301 __func__, my_data->max_mic_count);
1302 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1303 break;
1304 }
1305
1306 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1307 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1308 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1309 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1310 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1311
Eric Laurentb23d5282013-05-14 15:27:20 -07001312 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1313 if (my_data->acdb_handle == NULL) {
1314 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1315 } else {
1316 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1317 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1318 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001319 if (!my_data->acdb_deallocate)
1320 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1321 __func__, LIB_ACDB_LOADER);
1322
Eric Laurentb23d5282013-05-14 15:27:20 -07001323 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1324 "acdb_loader_send_audio_cal");
1325 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001326 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001327 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001328
Eric Laurentb23d5282013-05-14 15:27:20 -07001329 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1330 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001331 if (!my_data->acdb_send_voice_cal)
1332 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1333 __func__, LIB_ACDB_LOADER);
1334
1335 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1336 "acdb_loader_reload_vocvoltable");
1337 if (!my_data->acdb_reload_vocvoltable)
1338 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1339 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001340
1341 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1342 "acdb_loader_send_gain_dep_cal");
1343 if (!my_data->acdb_send_gain_dep_cal)
1344 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1345 __func__, LIB_ACDB_LOADER);
1346
Thierry Strudel92232b42017-01-26 10:51:48 -08001347#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001348 acdb_init_v2_cvd_t acdb_init;
1349 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1350 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001351 if (acdb_init == NULL)
1352 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1353 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001354
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001355#elif defined (PLATFORM_MSM8084)
1356 acdb_init_v2_t acdb_init;
1357 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1358 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001359 if (acdb_init == NULL)
1360 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1361 dlerror());
1362
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001363#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001364 acdb_init_t acdb_init;
1365 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001366 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001367 if (acdb_init == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001368 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1369 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001370#endif
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001371 my_data->acdb_init = acdb_init;
Eric Laurentb23d5282013-05-14 15:27:20 -07001372
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001373 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1374 dlsym(my_data->acdb_handle,
1375 "acdb_loader_send_common_custom_topology");
1376
1377 if (!my_data->acdb_send_custom_top)
1378 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1379 __func__, LIB_ACDB_LOADER);
1380
1381 platform_acdb_init(my_data);
1382 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001383
David Lin8c03e672017-02-06 20:31:38 -08001384 /* init usb */
1385 audio_extn_usb_init(adev);
1386
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001387 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001388
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001389 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1390
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001391 /* load csd client */
1392 platform_csd_init(my_data);
1393
David Lin8c03e672017-02-06 20:31:38 -08001394 platform_backend_config_init(my_data);
1395
Eric Laurentb23d5282013-05-14 15:27:20 -07001396 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001397
1398init_failed:
1399 if (my_data)
1400 free(my_data);
1401 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001402}
1403
1404void platform_deinit(void *platform)
1405{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001406 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001407 struct operator_info *info_item;
1408 struct operator_specific_device *device_item;
1409 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001410
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001411 struct platform_data *my_data = (struct platform_data *)platform;
1412 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001413
vivek mehtade4849c2016-03-03 17:23:38 -08001414 hw_info_deinit(my_data->hw_info);
1415
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001416 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1417 if (backend_tag_table[dev])
1418 free(backend_tag_table[dev]);
1419 if (hw_interface_table[dev])
1420 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001421 if (operator_specific_device_table[dev]) {
1422 while (!list_empty(operator_specific_device_table[dev])) {
1423 node = list_head(operator_specific_device_table[dev]);
1424 list_remove(node);
1425 device_item = node_to_item(node, struct operator_specific_device, list);
1426 free(device_item->operator);
1427 free(device_item->mixer_path);
1428 free(device_item);
1429 }
1430 free(operator_specific_device_table[dev]);
1431 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001432 }
1433
1434 if (my_data->snd_card_name)
1435 free(my_data->snd_card_name);
1436
keunhui.park2f7306a2015-07-16 16:48:06 +09001437 while (!list_empty(&operator_info_list)) {
1438 node = list_head(&operator_info_list);
1439 list_remove(node);
1440 info_item = node_to_item(node, struct operator_info, list);
1441 free(info_item->name);
1442 free(info_item->mccmnc);
1443 free(info_item);
1444 }
1445
Eric Laurentb23d5282013-05-14 15:27:20 -07001446 free(platform);
David Lin8c03e672017-02-06 20:31:38 -08001447
1448 /* deinit usb */
1449 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001450}
1451
1452const char *platform_get_snd_device_name(snd_device_t snd_device)
1453{
keunhui.park2f7306a2015-07-16 16:48:06 +09001454 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1455 if (operator_specific_device_table[snd_device] != NULL) {
1456 return get_operator_specific_device_mixer_path(snd_device);
1457 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001458 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001459 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001460 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001461}
1462
vivek mehtade4849c2016-03-03 17:23:38 -08001463int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1464 char *device_name)
1465{
1466 struct platform_data *my_data = (struct platform_data *)platform;
1467
David Benjamin1565f992016-09-21 12:10:34 -04001468 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001469 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001470 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1471 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001472 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1473 if (operator_specific_device_table[snd_device] != NULL) {
1474 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1475 DEVICE_NAME_MAX_SIZE);
1476 } else {
1477 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1478 }
1479 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1480 } else {
1481 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1482 }
1483
1484 return 0;
1485}
1486
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001487void platform_add_backend_name(void *platform, char *mixer_path,
1488 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001489{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001490 struct platform_data *my_data = (struct platform_data *)platform;
1491
Haynes Mathew George98c95622014-06-20 19:14:25 -07001492 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1493 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1494 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001495 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001496
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001497 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001498
1499 if (suffix != NULL) {
1500 strcat(mixer_path, " ");
1501 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001502 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001503}
1504
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001505bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1506{
1507 bool result = true;
1508
1509 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1510 platform_get_snd_device_name(snd_device1),
1511 platform_get_snd_device_name(snd_device2));
1512
1513 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1514 ALOGE("%s: Invalid snd_device = %s", __func__,
1515 platform_get_snd_device_name(snd_device1));
1516 return false;
1517 }
1518 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1519 ALOGE("%s: Invalid snd_device = %s", __func__,
1520 platform_get_snd_device_name(snd_device2));
1521 return false;
1522 }
1523 const char * be_itf1 = hw_interface_table[snd_device1];
1524 const char * be_itf2 = hw_interface_table[snd_device2];
1525
1526 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001527 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001528 result = false;
1529 }
1530
1531 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1532 return result;
1533}
1534
Eric Laurentb23d5282013-05-14 15:27:20 -07001535int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1536{
1537 int device_id;
1538 if (device_type == PCM_PLAYBACK)
1539 device_id = pcm_device_table[usecase][0];
1540 else
1541 device_id = pcm_device_table[usecase][1];
1542 return device_id;
1543}
1544
Haynes Mathew George98c95622014-06-20 19:14:25 -07001545static int find_index(const struct name_to_index * table, int32_t len,
1546 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001547{
1548 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001549 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001550
Haynes Mathew George98c95622014-06-20 19:14:25 -07001551 if (table == NULL) {
1552 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001553 ret = -ENODEV;
1554 goto done;
1555 }
1556
Haynes Mathew George98c95622014-06-20 19:14:25 -07001557 if (name == NULL) {
1558 ALOGE("null key");
1559 ret = -ENODEV;
1560 goto done;
1561 }
1562
1563 for (i=0; i < len; i++) {
1564 if (!strcmp(table[i].name, name)) {
1565 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001566 goto done;
1567 }
1568 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001569 ALOGE("%s: Could not find index for name = %s",
1570 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001571 ret = -ENODEV;
1572done:
1573 return ret;
1574}
1575
Haynes Mathew George98c95622014-06-20 19:14:25 -07001576int platform_get_snd_device_index(char *device_name)
1577{
1578 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1579}
1580
1581int platform_get_usecase_index(const char *usecase_name)
1582{
1583 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1584}
1585
keunhui.park2f7306a2015-07-16 16:48:06 +09001586void platform_add_operator_specific_device(snd_device_t snd_device,
1587 const char *operator,
1588 const char *mixer_path,
1589 unsigned int acdb_id)
1590{
1591 struct operator_specific_device *device;
1592
1593 if (operator_specific_device_table[snd_device] == NULL) {
1594 operator_specific_device_table[snd_device] =
1595 (struct listnode *)calloc(1, sizeof(struct listnode));
1596 list_init(operator_specific_device_table[snd_device]);
1597 }
1598
1599 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1600
1601 device->operator = strdup(operator);
1602 device->mixer_path = strdup(mixer_path);
1603 device->acdb_id = acdb_id;
1604
1605 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1606
Eric Laurent2bafff12016-03-17 12:17:23 -07001607 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001608 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1609
1610}
1611
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001612int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1613{
1614 int ret = 0;
1615
1616 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1617 ALOGE("%s: Invalid snd_device = %d",
1618 __func__, snd_device);
1619 ret = -EINVAL;
1620 goto done;
1621 }
1622
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001623 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1624 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001625 acdb_device_table[snd_device] = acdb_id;
1626done:
1627 return ret;
1628}
1629
Glenn Kastencbe06ca2016-11-09 10:49:26 -08001630int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1631 int *app_type __unused)
Yamit Mehtae3b99562016-09-16 22:44:00 +05301632{
1633 ALOGE("%s: Not implemented", __func__);
1634 return -ENOSYS;
1635}
1636
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001637int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1638{
1639 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1640 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1641 return -EINVAL;
1642 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001643
1644 if (operator_specific_device_table[snd_device] != NULL)
1645 return get_operator_specific_device_acdb_id(snd_device);
1646 else
1647 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001648}
1649
David Lin8c03e672017-02-06 20:31:38 -08001650static int platform_get_backend_index(snd_device_t snd_device)
1651{
1652 int32_t port = DEFAULT_CODEC_BACKEND;
1653
1654 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1655 if (backend_tag_table[snd_device] != NULL) {
1656 if (strncmp(backend_tag_table[snd_device], "headphones",
1657 sizeof("headphones")) == 0)
1658 port = HEADPHONE_BACKEND;
1659 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1660 port = HDMI_RX_BACKEND;
1661 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1662 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1663 port = USB_AUDIO_RX_BACKEND;
1664 }
1665 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1666 port = DEFAULT_CODEC_TX_BACKEND;
1667 if (backend_tag_table[snd_device] != NULL) {
1668 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1669 port = USB_AUDIO_TX_BACKEND;
1670 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1671 port = BT_SCO_TX_BACKEND;
1672 }
1673 } else {
1674 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1675 }
1676
1677 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1678
1679 return port;
1680}
1681
Eric Laurentb23d5282013-05-14 15:27:20 -07001682int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1683{
1684 struct platform_data *my_data = (struct platform_data *)platform;
1685 int acdb_dev_id, acdb_dev_type;
1686
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001687 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001688 if (acdb_dev_id < 0) {
1689 ALOGE("%s: Could not find acdb id for device(%d)",
1690 __func__, snd_device);
1691 return -EINVAL;
1692 }
1693 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001694 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001695 __func__, snd_device, acdb_dev_id);
1696 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1697 snd_device < SND_DEVICE_OUT_END)
1698 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1699 else
1700 acdb_dev_type = ACDB_DEV_TYPE_IN;
1701 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1702 }
1703 return 0;
1704}
1705
1706int platform_switch_voice_call_device_pre(void *platform)
1707{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001708 struct platform_data *my_data = (struct platform_data *)platform;
1709 int ret = 0;
1710
1711 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001712 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001713 /* This must be called before disabling mixer controls on APQ side */
1714 ret = my_data->csd->disable_device();
1715 if (ret < 0) {
1716 ALOGE("%s: csd_client_disable_device, failed, error %d",
1717 __func__, ret);
1718 }
1719 }
1720 return ret;
1721}
1722
1723int platform_switch_voice_call_enable_device_config(void *platform,
1724 snd_device_t out_snd_device,
1725 snd_device_t in_snd_device)
1726{
1727 struct platform_data *my_data = (struct platform_data *)platform;
1728 int acdb_rx_id, acdb_tx_id;
1729 int ret = 0;
1730
1731 if (my_data->csd == NULL)
1732 return ret;
1733
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001734 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1735 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001736 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001737 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001738 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001739
keunhui.park2f7306a2015-07-16 16:48:06 +09001740 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001741
1742 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1743 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1744 if (ret < 0) {
1745 ALOGE("%s: csd_enable_device_config, failed, error %d",
1746 __func__, ret);
1747 }
1748 } else {
1749 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1750 acdb_rx_id, acdb_tx_id);
1751 }
1752
1753 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001754}
1755
1756int platform_switch_voice_call_device_post(void *platform,
1757 snd_device_t out_snd_device,
1758 snd_device_t in_snd_device)
1759{
1760 struct platform_data *my_data = (struct platform_data *)platform;
1761 int acdb_rx_id, acdb_tx_id;
1762
1763 if (my_data->acdb_send_voice_cal == NULL) {
1764 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1765 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001766 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1767 audio_extn_spkr_prot_is_enabled())
1768 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1769
keunhui.park2f7306a2015-07-16 16:48:06 +09001770 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1771 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001772
1773 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1774 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1775 else
1776 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1777 acdb_rx_id, acdb_tx_id);
1778 }
1779
1780 return 0;
1781}
1782
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001783int platform_switch_voice_call_usecase_route_post(void *platform,
1784 snd_device_t out_snd_device,
1785 snd_device_t in_snd_device)
1786{
1787 struct platform_data *my_data = (struct platform_data *)platform;
1788 int acdb_rx_id, acdb_tx_id;
1789 int ret = 0;
1790
1791 if (my_data->csd == NULL)
1792 return ret;
1793
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001794 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1795 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001796 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001797 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001798 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001799
keunhui.park2f7306a2015-07-16 16:48:06 +09001800 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001801
1802 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1803 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1804 my_data->adev->acdb_settings);
1805 if (ret < 0) {
1806 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1807 }
1808 } else {
1809 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1810 acdb_rx_id, acdb_tx_id);
1811 }
1812
1813 return ret;
1814}
1815
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001816int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001817{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001818 struct platform_data *my_data = (struct platform_data *)platform;
1819 int ret = 0;
1820
1821 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001822 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001823 if (ret < 0) {
1824 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1825 }
1826 }
1827 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001828}
1829
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001830int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001831{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001832 struct platform_data *my_data = (struct platform_data *)platform;
1833 int ret = 0;
1834
1835 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001836 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001837 if (ret < 0) {
1838 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1839 }
1840 }
1841 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001842}
1843
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001844int platform_get_sample_rate(void *platform, uint32_t *rate)
1845{
1846 struct platform_data *my_data = (struct platform_data *)platform;
1847 int ret = 0;
1848
1849 if (my_data->csd != NULL) {
1850 ret = my_data->csd->get_sample_rate(rate);
1851 if (ret < 0) {
1852 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1853 }
1854 }
1855 return ret;
1856}
1857
vivek mehtab6506412015-08-07 16:55:17 -07001858void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1859 snd_device_t snd_device,
1860 bool enable)
1861{
1862 const char* name;
1863 switch (snd_device) {
1864 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1865 if (enable)
1866 name = "spkr-gain-in-headphone-combo";
1867 else
1868 name = "speaker-gain-default";
1869 break;
1870 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1871 if (enable)
1872 name = "spkr-gain-in-line-combo";
1873 else
1874 name = "speaker-gain-default";
1875 break;
1876 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1877 if (enable)
1878 name = "spkr-safe-gain-in-headphone-combo";
1879 else
1880 name = "speaker-safe-gain-default";
1881 break;
1882 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1883 if (enable)
1884 name = "spkr-safe-gain-in-line-combo";
1885 else
1886 name = "speaker-safe-gain-default";
1887 break;
1888 default:
1889 return;
1890 }
1891
1892 audio_route_apply_and_update_path(adev->audio_route, name);
1893}
1894
Eric Laurentb23d5282013-05-14 15:27:20 -07001895int platform_set_voice_volume(void *platform, int volume)
1896{
1897 struct platform_data *my_data = (struct platform_data *)platform;
1898 struct audio_device *adev = my_data->adev;
1899 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001900 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001901 int vol_index = 0, ret = 0;
1902 uint32_t set_values[ ] = {0,
1903 ALL_SESSION_VSID,
1904 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001905
1906 // Voice volume levels are mapped to adsp volume levels as follows.
1907 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1908 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001909 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001910 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001911
1912 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1913 if (!ctl) {
1914 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1915 __func__, mixer_ctl_name);
1916 return -EINVAL;
1917 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001918 ALOGV("Setting voice volume index: %d", set_values[0]);
1919 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1920
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001921 if (my_data->csd != NULL) {
1922 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1923 DEFAULT_VOLUME_RAMP_DURATION_MS);
1924 if (ret < 0) {
1925 ALOGE("%s: csd_volume error %d", __func__, ret);
1926 }
1927 }
1928 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001929}
1930
1931int platform_set_mic_mute(void *platform, bool state)
1932{
1933 struct platform_data *my_data = (struct platform_data *)platform;
1934 struct audio_device *adev = my_data->adev;
1935 struct mixer_ctl *ctl;
1936 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001937 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001938 uint32_t set_values[ ] = {0,
1939 ALL_SESSION_VSID,
1940 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001941
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001942 if (adev->mode != AUDIO_MODE_IN_CALL &&
1943 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001944 return 0;
1945
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001946 if (adev->enable_hfp)
1947 mixer_ctl_name = "HFP Tx Mute";
1948
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001949 set_values[0] = state;
1950 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1951 if (!ctl) {
1952 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1953 __func__, mixer_ctl_name);
1954 return -EINVAL;
1955 }
1956 ALOGV("Setting voice mute state: %d", state);
1957 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1958
1959 if (my_data->csd != NULL) {
1960 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1961 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001962 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001963 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001964 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001965 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001966 return ret;
1967}
Eric Laurentb23d5282013-05-14 15:27:20 -07001968
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001969int platform_set_device_mute(void *platform, bool state, char *dir)
1970{
1971 struct platform_data *my_data = (struct platform_data *)platform;
1972 struct audio_device *adev = my_data->adev;
1973 struct mixer_ctl *ctl;
1974 char *mixer_ctl_name = NULL;
1975 int ret = 0;
1976 uint32_t set_values[ ] = {0,
1977 ALL_SESSION_VSID,
1978 0};
1979 if(dir == NULL) {
1980 ALOGE("%s: Invalid direction:%s", __func__, dir);
1981 return -EINVAL;
1982 }
1983
1984 if (!strncmp("rx", dir, sizeof("rx"))) {
1985 mixer_ctl_name = "Voice Rx Device Mute";
1986 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1987 mixer_ctl_name = "Voice Tx Device Mute";
1988 } else {
1989 return -EINVAL;
1990 }
1991
1992 set_values[0] = state;
1993 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1994 if (!ctl) {
1995 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1996 __func__, mixer_ctl_name);
1997 return -EINVAL;
1998 }
1999
2000 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2001 __func__,state, mixer_ctl_name);
2002 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2003
2004 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002005}
2006
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002007int platform_can_split_snd_device(snd_device_t snd_device,
2008 int *num_devices,
2009 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002010{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002011 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002012 if (NULL == num_devices || NULL == new_snd_devices) {
2013 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002014 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002015 }
2016
2017 /*
2018 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002019 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002020 */
2021 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2022 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2023 *num_devices = 2;
2024 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2025 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002026 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002027 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2028 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2029 *num_devices = 2;
2030 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2031 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002032 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002033 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2034 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2035 *num_devices = 2;
2036 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2037 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002038 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002039 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2040 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2041 *num_devices = 2;
2042 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2043 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002044 ret = 0;
David Lin8c03e672017-02-06 20:31:38 -08002045 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2046 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2047 *num_devices = 2;
2048 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2049 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2050 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002051 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002052 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002053}
2054
Eric Laurentb23d5282013-05-14 15:27:20 -07002055snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2056{
2057 struct platform_data *my_data = (struct platform_data *)platform;
2058 struct audio_device *adev = my_data->adev;
2059 audio_mode_t mode = adev->mode;
2060 snd_device_t snd_device = SND_DEVICE_NONE;
2061
2062 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2063 if (devices == AUDIO_DEVICE_NONE ||
2064 devices & AUDIO_DEVICE_BIT_IN) {
2065 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2066 goto exit;
2067 }
2068
Eric Laurent1b491552015-09-15 17:52:41 -07002069 if (popcount(devices) == 2) {
2070 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2071 AUDIO_DEVICE_OUT_SPEAKER) ||
2072 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2073 AUDIO_DEVICE_OUT_SPEAKER)) {
2074 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2075 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2076 AUDIO_DEVICE_OUT_SPEAKER)) {
2077 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2078 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2079 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2080 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2081 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2082 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2083 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2084 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2085 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2086 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2087 AUDIO_DEVICE_OUT_SPEAKER)) {
2088 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
David Lin8c03e672017-02-06 20:31:38 -08002089 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2090 AUDIO_DEVICE_OUT_SPEAKER)) {
2091 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002092 } else {
2093 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2094 goto exit;
2095 }
2096 if (snd_device != SND_DEVICE_NONE) {
2097 goto exit;
2098 }
2099 }
2100
2101 if (popcount(devices) != 1) {
2102 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2103 goto exit;
2104 }
2105
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302106 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002107 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002108 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2109 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002110 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002111 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002112 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002113 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002114 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002115 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002116 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002117 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002118 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002119 else {
2120 if (devices & AUDIO_DEVICE_OUT_LINE)
2121 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2122 else
2123 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2124 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002125 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002126 if (adev->bt_wb_speech_enabled) {
2127 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2128 } else {
2129 snd_device = SND_DEVICE_OUT_BT_SCO;
2130 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002131 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002132 if (!adev->enable_hfp) {
2133 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2134 } else {
2135 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2136 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002137 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002138 if(adev->voice.hac)
2139 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2140 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002141 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2142 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002143 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002144 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2145 snd_device = SND_DEVICE_OUT_VOICE_TX;
2146
Eric Laurentb23d5282013-05-14 15:27:20 -07002147 if (snd_device != SND_DEVICE_NONE) {
2148 goto exit;
2149 }
2150 }
2151
Eric Laurentb23d5282013-05-14 15:27:20 -07002152 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2153 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2154 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002155 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2156 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002157 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2158 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002159 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002160 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002161 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2162 else
2163 snd_device = SND_DEVICE_OUT_SPEAKER;
2164 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002165 if (adev->bt_wb_speech_enabled) {
2166 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2167 } else {
2168 snd_device = SND_DEVICE_OUT_BT_SCO;
2169 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002170 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2171 snd_device = SND_DEVICE_OUT_HDMI ;
David Lin8c03e672017-02-06 20:31:38 -08002172 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2173 if (audio_extn_usb_is_capture_supported())
2174 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2175 else
2176 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2177 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002178 /*HAC support for voice-ish audio (eg visual voicemail)*/
2179 if(adev->voice.hac)
2180 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2181 else
2182 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002183 } else {
2184 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2185 }
2186exit:
2187 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2188 return snd_device;
2189}
2190
2191snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2192{
2193 struct platform_data *my_data = (struct platform_data *)platform;
2194 struct audio_device *adev = my_data->adev;
2195 audio_source_t source = (adev->active_input == NULL) ?
2196 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2197
2198 audio_mode_t mode = adev->mode;
2199 audio_devices_t in_device = ((adev->active_input == NULL) ?
2200 AUDIO_DEVICE_NONE : adev->active_input->device)
2201 & ~AUDIO_DEVICE_BIT_IN;
2202 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2203 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2204 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002205 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002206
Prashant Malanic92c5962015-08-11 15:10:18 -07002207 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2208 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002209 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002210 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002211 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002212 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2213 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002214 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002215 case TTY_MODE_FULL:
2216 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2217 break;
2218 case TTY_MODE_VCO:
2219 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2220 break;
2221 case TTY_MODE_HCO:
2222 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2223 break;
2224 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002225 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002226 }
2227 goto exit;
2228 }
2229 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002230 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002231 if (my_data->fluence_in_voice_call == false) {
2232 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2233 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002234 if (is_operator_tmus())
2235 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002236 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002237 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002238 }
2239 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2240 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2241 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002242 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002243 if (adev->bluetooth_nrec)
2244 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2245 else
2246 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002247 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002248 if (adev->bluetooth_nrec)
2249 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2250 else
2251 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002252 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002253 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002254 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2255 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2256 out_device & AUDIO_DEVICE_OUT_LINE) {
2257 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2258 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2259 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2260 } else {
2261 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2262 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002263 }
vivek mehtafe121d52015-08-10 23:39:23 -07002264
2265 //select default
2266 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002267 if (!adev->enable_hfp) {
2268 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2269 } else {
2270 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2271 platform_set_echo_reference(adev, true, out_device);
2272 }
vivek mehtafe121d52015-08-10 23:39:23 -07002273 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002274 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002275 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002276 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002277 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2278 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2279 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2280 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2281 }
2282 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2283 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002284 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2285 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2286 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002287 if (adev->active_input->enable_aec)
2288 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2289 else
2290 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002291 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2292 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002293 if (adev->active_input->enable_aec)
2294 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2295 else
2296 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002297 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2298 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2299 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002300 if (adev->active_input->enable_aec)
2301 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2302 else
2303 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002304 }
2305 platform_set_echo_reference(adev, true, out_device);
2306 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2307 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2308 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002309 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002310 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2311 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002312 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002313 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2314 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002315 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002316 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002317 if (adev->active_input->enable_aec) {
2318 if (adev->active_input->enable_ns) {
2319 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2320 } else {
2321 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2322 }
vivek mehta733c1df2016-04-04 15:09:24 -07002323 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002324 } else if (adev->active_input->enable_ns) {
2325 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2326 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002327 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002328 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002329 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002330 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2331 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002332 }
rago90fb9612015-12-02 11:37:53 -08002333 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2334 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002335 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2336 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2337 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2338 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002339 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002340 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2341 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002342 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002343 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2344 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2345 } else {
2346 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2347 }
rago90fb9612015-12-02 11:37:53 -08002348 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2349 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2350 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002351 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002352 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002353 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002354 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2355 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002356 if (adev->active_input->enable_aec &&
2357 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002358 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002359 if (my_data->fluence_in_spkr_mode &&
2360 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002361 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002362 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002363 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002364 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002365 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002366 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002367 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002368 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002369 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002370 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002371 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002372 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002373 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2374 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002375 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002376 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002377 } else if (adev->active_input->enable_aec) {
2378 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2379 if (my_data->fluence_in_spkr_mode &&
2380 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002381 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002382 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002383 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002384 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002385 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002386 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2387 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002388 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002389 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002390 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002391 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002392 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002393 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2394 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2395 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002396 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002397 } else if (adev->active_input->enable_ns) {
2398 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2399 if (my_data->fluence_in_spkr_mode &&
2400 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002401 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002402 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002403 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002404 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002405 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002406 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2407 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002408 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002409 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002410 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002411 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002412 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002413 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002414 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002415 }
2416 } else if (source == AUDIO_SOURCE_DEFAULT) {
2417 goto exit;
2418 }
2419
2420
2421 if (snd_device != SND_DEVICE_NONE) {
2422 goto exit;
2423 }
2424
2425 if (in_device != AUDIO_DEVICE_NONE &&
2426 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2427 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2428 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002429 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002430 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002431 snd_device = SND_DEVICE_IN_QUAD_MIC;
2432 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002433 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002434 snd_device = SND_DEVICE_IN_THREE_MIC;
2435 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2436 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002437 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002438 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2439 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002440 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002441 } else {
2442 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2443 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2444 my_data->source_mic_type, channel_count, channel_mask);
2445 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2446 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002447 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002448 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2449 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002450 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002451 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2452 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002453 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002454 } else {
2455 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2456 " no combination found .. setting to mono", __func__,
2457 my_data->source_mic_type, channel_count);
2458 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2459 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002460 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2461 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2462 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002463 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002464 if (adev->bluetooth_nrec)
2465 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2466 else
2467 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002468 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002469 if (adev->bluetooth_nrec)
2470 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2471 else
2472 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002473 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002474 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2475 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Lin8c03e672017-02-06 20:31:38 -08002476 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2477 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002478 } else {
2479 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2480 ALOGW("%s: Using default handset-mic", __func__);
2481 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2482 }
2483 } else {
2484 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2485 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2486 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2487 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002488 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002489 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002490 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002491 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002492 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2493 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002494 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002495 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2496 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002497 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002498 } else {
2499 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2500 " no combination found .. setting to mono", __func__,
2501 my_data->source_mic_type, channel_count);
2502 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2503 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002504 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002505 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002506 if (adev->bluetooth_nrec)
2507 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2508 else
2509 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002510 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002511 if (adev->bluetooth_nrec)
2512 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2513 else
2514 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002515 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002516 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2517 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Lin8c03e672017-02-06 20:31:38 -08002518 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2519 if (audio_extn_usb_is_capture_supported())
2520 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2521 else
2522 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002523 } else {
2524 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2525 ALOGW("%s: Using default handset-mic", __func__);
2526 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2527 }
2528 }
2529exit:
2530 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2531 return snd_device;
2532}
2533
2534int platform_set_hdmi_channels(void *platform, int channel_count)
2535{
2536 struct platform_data *my_data = (struct platform_data *)platform;
2537 struct audio_device *adev = my_data->adev;
2538 struct mixer_ctl *ctl;
2539 const char *channel_cnt_str = NULL;
2540 const char *mixer_ctl_name = "HDMI_RX Channels";
2541 switch (channel_count) {
2542 case 8:
2543 channel_cnt_str = "Eight"; break;
2544 case 7:
2545 channel_cnt_str = "Seven"; break;
2546 case 6:
2547 channel_cnt_str = "Six"; break;
2548 case 5:
2549 channel_cnt_str = "Five"; break;
2550 case 4:
2551 channel_cnt_str = "Four"; break;
2552 case 3:
2553 channel_cnt_str = "Three"; break;
2554 default:
2555 channel_cnt_str = "Two"; break;
2556 }
2557 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2558 if (!ctl) {
2559 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2560 __func__, mixer_ctl_name);
2561 return -EINVAL;
2562 }
2563 ALOGV("HDMI channel count: %s", channel_cnt_str);
2564 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2565 return 0;
2566}
2567
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002568int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002569{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002570 struct platform_data *my_data = (struct platform_data *)platform;
2571 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002572 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2573 char *sad = block;
2574 int num_audio_blocks;
2575 int channel_count;
2576 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002577 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002578
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002579 struct mixer_ctl *ctl;
2580
2581 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2582 if (!ctl) {
2583 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2584 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002585 return 0;
2586 }
2587
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002588 mixer_ctl_update(ctl);
2589
2590 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002591
2592 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002593 if (count > (int)sizeof(block))
2594 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002595
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002596 ret = mixer_ctl_get_array(ctl, block, count);
2597 if (ret != 0) {
2598 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2599 return 0;
2600 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002601
2602 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002603 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002604
2605 for (i = 0; i < num_audio_blocks; i++) {
2606 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002607 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2608 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002609 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002610 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002611
2612 channel_count = (sad[0] & 0x7) + 1;
2613 if (channel_count > max_channels)
2614 max_channels = channel_count;
2615
2616 /* Advance to next block */
2617 sad += 3;
2618 }
2619
2620 return max_channels;
2621}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002622
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002623int platform_set_incall_recording_session_id(void *platform,
2624 uint32_t session_id, int rec_mode)
2625{
2626 int ret = 0;
2627 struct platform_data *my_data = (struct platform_data *)platform;
2628 struct audio_device *adev = my_data->adev;
2629 struct mixer_ctl *ctl;
2630 const char *mixer_ctl_name = "Voc VSID";
2631 int num_ctl_values;
2632 int i;
2633
2634 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2635 if (!ctl) {
2636 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2637 __func__, mixer_ctl_name);
2638 ret = -EINVAL;
2639 } else {
2640 num_ctl_values = mixer_ctl_get_num_values(ctl);
2641 for (i = 0; i < num_ctl_values; i++) {
2642 if (mixer_ctl_set_value(ctl, i, session_id)) {
2643 ALOGV("Error: invalid session_id: %x", session_id);
2644 ret = -EINVAL;
2645 break;
2646 }
2647 }
2648 }
2649
2650 if (my_data->csd != NULL) {
2651 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2652 if (ret < 0) {
2653 ALOGE("%s: csd_client_start_record failed, error %d",
2654 __func__, ret);
2655 }
2656 }
2657
2658 return ret;
2659}
2660
2661int platform_stop_incall_recording_usecase(void *platform)
2662{
2663 int ret = 0;
2664 struct platform_data *my_data = (struct platform_data *)platform;
2665
2666 if (my_data->csd != NULL) {
2667 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2668 if (ret < 0) {
2669 ALOGE("%s: csd_client_stop_record failed, error %d",
2670 __func__, ret);
2671 }
2672 }
2673
2674 return ret;
2675}
2676
2677int platform_start_incall_music_usecase(void *platform)
2678{
2679 int ret = 0;
2680 struct platform_data *my_data = (struct platform_data *)platform;
2681
2682 if (my_data->csd != NULL) {
2683 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2684 if (ret < 0) {
2685 ALOGE("%s: csd_client_start_playback failed, error %d",
2686 __func__, ret);
2687 }
2688 }
2689
2690 return ret;
2691}
2692
2693int platform_stop_incall_music_usecase(void *platform)
2694{
2695 int ret = 0;
2696 struct platform_data *my_data = (struct platform_data *)platform;
2697
2698 if (my_data->csd != NULL) {
2699 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2700 if (ret < 0) {
2701 ALOGE("%s: csd_client_stop_playback failed, error %d",
2702 __func__, ret);
2703 }
2704 }
2705
2706 return ret;
2707}
2708
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002709int platform_set_parameters(void *platform, struct str_parms *parms)
2710{
2711 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002712 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002713 char *kv_pairs = str_parms_to_str(parms);
2714 int ret = 0, err;
2715
2716 if (kv_pairs == NULL) {
2717 ret = -EINVAL;
2718 ALOGE("%s: key-value pair is NULL",__func__);
2719 goto done;
2720 }
2721
2722 ALOGV("%s: enter: %s", __func__, kv_pairs);
2723
2724 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2725 value, sizeof(value));
2726 if (err >= 0) {
2727 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2728 my_data->snd_card_name = strdup(value);
2729 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2730 }
2731
keunhui.park2f7306a2015-07-16 16:48:06 +09002732 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2733 value, sizeof(value));
2734 if (err >= 0) {
2735 struct operator_info *info;
2736 char *str = value;
2737 char *name;
2738
2739 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2740 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2741 name = strtok(str, ";");
2742 info->name = strdup(name);
2743 info->mccmnc = strdup(str + strlen(name) + 1);
2744
2745 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002746 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002747 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002748
2749 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002750 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002751 value, sizeof(value));
2752 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002753 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002754 my_data->max_mic_count = atoi(value);
2755 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002756 }
2757
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002758done:
2759 ALOGV("%s: exit with code(%d)", __func__, ret);
2760 if (kv_pairs != NULL)
2761 free(kv_pairs);
2762
2763 return ret;
2764}
2765
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002766/* Delay in Us */
2767int64_t platform_render_latency(audio_usecase_t usecase)
2768{
2769 switch (usecase) {
2770 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2771 return DEEP_BUFFER_PLATFORM_DELAY;
2772 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2773 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002774 case USECASE_AUDIO_PLAYBACK_ULL:
2775 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002776 case USECASE_AUDIO_PLAYBACK_MMAP:
2777 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002778 default:
2779 return 0;
2780 }
2781}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002782
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002783int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2784 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002785{
2786 int ret = 0;
2787
2788 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2789 ALOGE("%s: Invalid snd_device = %d",
2790 __func__, device);
2791 ret = -EINVAL;
2792 goto done;
2793 }
2794
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002795 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2796 platform_get_snd_device_name(device),
2797 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2798 if (backend_tag_table[device]) {
2799 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002800 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002801 backend_tag_table[device] = strdup(backend_tag);
2802
2803 if (hw_interface != NULL) {
2804 if (hw_interface_table[device])
2805 free(hw_interface_table[device]);
2806 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2807 hw_interface_table[device] = strdup(hw_interface);
2808 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002809done:
2810 return ret;
2811}
2812
2813int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2814{
2815 int ret = 0;
2816 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2817 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2818 ret = -EINVAL;
2819 goto done;
2820 }
2821
2822 if ((type != 0) && (type != 1)) {
2823 ALOGE("%s: invalid usecase type", __func__);
2824 ret = -EINVAL;
2825 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002826 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002827 pcm_device_table[usecase][type] = pcm_id;
2828done:
2829 return ret;
2830}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002831
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002832#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2833int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2834 // backup_gain: gain to try to set in case of an error during ramp
2835 int start_gain, end_gain, step, backup_gain, i;
2836 bool error = false;
2837 const struct mixer_ctl *ctl;
2838 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2839 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2840 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2841 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2842 if (!ctl_left || !ctl_right) {
2843 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2844 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2845 return -EINVAL;
2846 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2847 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2848 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2849 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2850 return -EINVAL;
2851 }
2852 if (ramp_up) {
2853 start_gain = 0;
2854 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2855 step = +1;
2856 backup_gain = end_gain;
2857 } else {
2858 // using same gain on left and right
2859 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2860 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2861 end_gain = 0;
2862 step = -1;
2863 backup_gain = start_gain;
2864 }
2865 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2866 //ALOGV("setting speaker gain to %d", i);
2867 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2868 ALOGE("%s: error setting %s to %d during gain ramp",
2869 __func__, mixer_ctl_name_gain_left, i);
2870 error = true;
2871 break;
2872 }
2873 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2874 ALOGE("%s: error setting %s to %d during gain ramp",
2875 __func__, mixer_ctl_name_gain_right, i);
2876 error = true;
2877 break;
2878 }
2879 usleep(1000);
2880 }
2881 if (error) {
2882 // an error occured during the ramp, let's still try to go back to a safe volume
2883 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2884 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2885 }
2886 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2887 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2888 }
2889 }
2890 return start_gain;
2891}
2892
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002893int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2894{
2895 // only update if there is active pcm playback on speaker
2896 struct audio_usecase *usecase;
2897 struct listnode *node;
2898 struct platform_data *my_data = (struct platform_data *)adev->platform;
2899
2900 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07002901
2902 // do not swap channels in audio modes with concurrent capture and playback
2903 // as this may break the echo reference
2904 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
2905 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
2906 return 0;
2907 }
2908
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002909 my_data->speaker_lr_swap = swap_channels;
2910
2911 list_for_each(node, &adev->usecase_list) {
2912 usecase = node_to_item(node, struct audio_usecase, list);
2913 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002914 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2915 /*
2916 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2917 * to perform device switch to disable the current backend to
2918 * enable it with new acdb data.
2919 */
2920 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2921 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002922 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002923 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002924 if (initial_skpr_gain != -EINVAL) {
2925 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2926 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002927 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002928 const char *mixer_path;
2929 if (swap_channels) {
2930 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2931 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2932 } else {
2933 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2934 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2935 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002936 }
2937 break;
2938 }
2939 }
2940 }
2941 return 0;
2942}
vivek mehtaa8d7c922016-05-25 14:40:44 -07002943
2944static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
2945static int num_gain_tbl_entry = 0;
2946
2947bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
2948
2949 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
2950 if (num_gain_tbl_entry == -1) {
2951 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
2952 __func__);
2953 return false;
2954 }
2955
2956 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
2957 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
2958 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
2959 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2960 return false;
2961 }
2962
2963 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
2964 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
2965 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2966 return false;
2967 }
2968
2969 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
2970 ++num_gain_tbl_entry;
2971
2972 return true;
2973}
2974
2975int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
2976 int table_size) {
2977 int itt = 0;
2978 ALOGV("platform_get_gain_level_mapping called ");
2979
2980 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
2981 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
2982 return 0;
2983 }
2984
2985 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
2986 mapping_tbl[itt] = tbl_mapping[itt];
2987 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
2988 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
2989 }
2990
2991 return num_gain_tbl_entry;
2992}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07002993
2994int platform_snd_card_update(void *platform, card_status_t status)
2995{
2996 struct platform_data *my_data = (struct platform_data *)platform;
2997 struct audio_device *adev = my_data->adev;
2998
2999 if (status == CARD_STATUS_ONLINE) {
3000 if (my_data->acdb_send_custom_top)
3001 my_data->acdb_send_custom_top();
3002 }
3003 return 0;
3004}
David Lin8c03e672017-02-06 20:31:38 -08003005
3006/*
3007 * configures afe with bit width and Sample Rate
3008 */
3009static int platform_set_backend_cfg(const struct audio_device* adev,
3010 snd_device_t snd_device,
3011 const struct audio_backend_cfg *backend_cfg)
3012{
3013
3014 int ret = 0;
3015 const int backend_idx = platform_get_backend_index(snd_device);
3016 struct platform_data *my_data = (struct platform_data *)adev->platform;
3017 const unsigned int bit_width = backend_cfg->bit_width;
3018 const unsigned int sample_rate = backend_cfg->sample_rate;
3019 const unsigned int channels = backend_cfg->channels;
3020 const audio_format_t format = backend_cfg->format;
3021 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3022
3023
3024 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3025 ", backend_idx %d device (%s)", __func__, bit_width,
3026 sample_rate, channels, backend_idx,
3027 platform_get_snd_device_name(snd_device));
3028
3029 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3030 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3031
3032 struct mixer_ctl *ctl = NULL;
3033 ctl = mixer_get_ctl_by_name(adev->mixer,
3034 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3035 if (!ctl) {
3036 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3037 __func__,
3038 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3039 return -EINVAL;
3040 }
3041
3042 if (bit_width == 24) {
3043 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3044 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3045 else
3046 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3047 } else if (bit_width == 32) {
3048 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3049 } else {
3050 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3051 }
3052 if ( ret < 0) {
3053 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3054 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3055 } else {
3056 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3057 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3058 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3059 }
3060 /* set the ret as 0 and not pass back to upper layer */
3061 ret = 0;
3062 }
3063
3064 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3065 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3066 char *rate_str = NULL;
3067 struct mixer_ctl *ctl = NULL;
3068
3069 switch (sample_rate) {
3070 case 32000:
3071 if (passthrough_enabled) {
3072 rate_str = "KHZ_32";
3073 break;
3074 }
3075 case 8000:
3076 case 11025:
3077 case 16000:
3078 case 22050:
3079 case 48000:
3080 rate_str = "KHZ_48";
3081 break;
3082 case 44100:
3083 rate_str = "KHZ_44P1";
3084 break;
3085 case 64000:
3086 case 96000:
3087 rate_str = "KHZ_96";
3088 break;
3089 case 88200:
3090 rate_str = "KHZ_88P2";
3091 break;
3092 case 176400:
3093 rate_str = "KHZ_176P4";
3094 break;
3095 case 192000:
3096 rate_str = "KHZ_192";
3097 break;
3098 case 352800:
3099 rate_str = "KHZ_352P8";
3100 break;
3101 case 384000:
3102 rate_str = "KHZ_384";
3103 break;
3104 case 144000:
3105 if (passthrough_enabled) {
3106 rate_str = "KHZ_144";
3107 break;
3108 }
3109 default:
3110 rate_str = "KHZ_48";
3111 break;
3112 }
3113
3114 ctl = mixer_get_ctl_by_name(adev->mixer,
3115 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3116 if(!ctl) {
3117 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3118 __func__,
3119 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3120 return -EINVAL;
3121 }
3122
3123 ALOGD("%s:becf: afe: %s set to %s", __func__,
3124 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3125 mixer_ctl_set_enum_by_string(ctl, rate_str);
3126 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3127 }
3128 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3129 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3130 struct mixer_ctl *ctl = NULL;
3131 char *channel_cnt_str = NULL;
3132
3133 switch (channels) {
3134 case 8:
3135 channel_cnt_str = "Eight"; break;
3136 case 7:
3137 channel_cnt_str = "Seven"; break;
3138 case 6:
3139 channel_cnt_str = "Six"; break;
3140 case 5:
3141 channel_cnt_str = "Five"; break;
3142 case 4:
3143 channel_cnt_str = "Four"; break;
3144 case 3:
3145 channel_cnt_str = "Three"; break;
3146 case 1:
3147 channel_cnt_str = "One"; break;
3148 case 2:
3149 default:
3150 channel_cnt_str = "Two"; break;
3151 }
3152
3153 ctl = mixer_get_ctl_by_name(adev->mixer,
3154 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3155 if (!ctl) {
3156 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3157 __func__,
3158 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3159 return -EINVAL;
3160 }
3161 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3162 my_data->current_backend_cfg[backend_idx].channels = channels;
3163
3164 // skip EDID configuration for HDMI backend
3165
3166 ALOGD("%s:becf: afe: %s set to %s", __func__,
3167 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3168 channel_cnt_str);
3169 }
3170
3171 // skip set ext_display format mixer control
3172 return ret;
3173}
3174
3175static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3176{
3177 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3178 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3179 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3180 }
3181
3182 return backend_bit_width_table[snd_device];
3183}
3184
3185/*
3186 * return backend_idx on which voice call is active
3187 */
3188static int platform_get_voice_call_backend(struct audio_device* adev)
3189{
3190 struct audio_usecase *uc = NULL;
3191 struct listnode *node;
3192 snd_device_t out_snd_device = SND_DEVICE_NONE;
3193
3194 int backend_idx = -1;
3195
3196 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3197 list_for_each(node, &adev->usecase_list) {
3198 uc = node_to_item(node, struct audio_usecase, list);
3199 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3200 out_snd_device = platform_get_output_snd_device(adev->platform,
3201 uc->stream.out->devices);
3202 backend_idx = platform_get_backend_index(out_snd_device);
3203 break;
3204 }
3205 }
3206 }
3207 return backend_idx;
3208}
3209
3210/*
3211 * goes through all the current usecases and picks the highest
3212 * bitwidth & samplerate
3213 */
3214static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3215 int backend_idx,
3216 struct audio_backend_cfg *backend_cfg)
3217{
3218 bool backend_change = false;
3219 unsigned int bit_width;
3220 unsigned int sample_rate;
3221 unsigned int channels;
3222 struct platform_data *my_data = (struct platform_data *)adev->platform;
3223
3224 bit_width = backend_cfg->bit_width;
3225 sample_rate = backend_cfg->sample_rate;
3226 channels = backend_cfg->channels;
3227
3228 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3229 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3230 sample_rate, channels);
3231
3232 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3233 // default backend
3234 // force routing is not required here, caller will do it anyway
3235 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3236 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3237 "for unprocessed/camera source", __func__);
3238 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3239 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3240 }
3241
3242 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3243 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3244 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3245 __func__, bit_width, sample_rate, channels);
3246 }
3247
3248 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3249 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3250
3251 // Force routing if the expected bitwdith or samplerate
3252 // is not same as current backend comfiguration
3253 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3254 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3255 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3256 backend_cfg->bit_width = bit_width;
3257 backend_cfg->sample_rate= sample_rate;
3258 backend_cfg->channels = channels;
3259 backend_change = true;
3260 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3261 "new sample rate: %d new channel: %d",
3262 __func__, backend_cfg->bit_width,
3263 backend_cfg->sample_rate, backend_cfg->channels);
3264 }
3265
3266 return backend_change;
3267}
3268
3269static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3270 struct audio_usecase* usecase,
3271 snd_device_t snd_device,
3272 struct audio_backend_cfg *backend_cfg)
3273{
3274 bool backend_change = false;
3275 struct listnode *node;
3276 unsigned int bit_width;
3277 unsigned int sample_rate;
3278 unsigned int channels;
3279 bool passthrough_enabled = false;
3280 int backend_idx = DEFAULT_CODEC_BACKEND;
3281 struct platform_data *my_data = (struct platform_data *)adev->platform;
3282 bool channels_updated = false;
3283
3284 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3285 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3286 backend_change = false;
3287 return backend_change;
3288 }
3289
3290 backend_idx = platform_get_backend_index(snd_device);
3291 bit_width = backend_cfg->bit_width;
3292 sample_rate = backend_cfg->sample_rate;
3293 channels = backend_cfg->channels;
3294
3295 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3296 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3297 sample_rate, channels, backend_idx, usecase->id,
3298 platform_get_snd_device_name(snd_device));
3299
3300 if (backend_idx == platform_get_voice_call_backend(adev)) {
3301 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3302 __func__);
3303 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3304 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3305 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3306 } else {
3307 /*
3308 * The backend should be configured at highest bit width and/or
3309 * sample rate amongst all playback usecases.
3310 * If the selected sample rate and/or bit width differ with
3311 * current backend sample rate and/or bit width, then, we set the
3312 * backend re-configuration flag.
3313 *
3314 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3315 */
3316
3317 int i =0;
3318 list_for_each(node, &adev->usecase_list) {
3319 struct audio_usecase *uc;
3320 uc = node_to_item(node, struct audio_usecase, list);
3321 struct stream_out *out = (struct stream_out*) uc->stream.out;
3322 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3323 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3324
3325 ALOGD("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3326 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3327 uc->id, out->sample_rate,
3328 pcm_format_to_bits(out->config.format), out_channels,
3329 platform_get_snd_device_name(uc->out_snd_device));
3330
3331 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3332 if (bit_width < pcm_format_to_bits(out->config.format))
3333 bit_width = pcm_format_to_bits(out->config.format);
3334 if (sample_rate < out->sample_rate)
3335 sample_rate = out->sample_rate;
3336 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3337 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3338 if (channels < out_channels)
3339 channels = out_channels;
3340 }
3341 }
3342 }
3343 }
3344
3345 /*
3346 * Check if the device is speaker or handset,assumption handset shares
3347 * backend with speaker, and these devices are restricited to 48kHz.
3348 */
3349 if (platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, snd_device)) {
3350
3351 if (bit_width >= 24) {
3352 bit_width = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
3353 ALOGD("%s:becf: afe: reset bitwidth to %d (based on supported"
3354 " value for this platform)", __func__, bit_width);
3355 }
3356 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3357 ALOGD("%s:becf: afe: playback on codec device not supporting native playback set "
3358 "default Sample Rate(48k)", __func__);
3359 }
3360
3361 if (backend_idx == USB_AUDIO_RX_BACKEND) {
3362 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, true);
3363 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3364 __func__, bit_width, sample_rate, channels);
3365 if (channels != my_data->current_backend_cfg[backend_idx].channels)
3366 channels_updated = true;
3367 }
3368
3369 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and sample rate: %d",
3370 __func__, backend_idx , bit_width, sample_rate);
3371
3372 // Force routing if the expected bitwdith or samplerate
3373 // is not same as current backend comfiguration
3374 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3375 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3376 passthrough_enabled || channels_updated) {
3377 backend_cfg->bit_width = bit_width;
3378 backend_cfg->sample_rate = sample_rate;
3379 backend_cfg->channels = channels;
3380 backend_cfg->passthrough_enabled = passthrough_enabled;
3381 backend_change = true;
3382 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3383 "new sample rate: %d new channels: %d",
3384 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3385 }
3386
3387 return backend_change;
3388}
3389
3390bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3391 struct audio_usecase *usecase, snd_device_t snd_device)
3392{
3393 int backend_idx = DEFAULT_CODEC_BACKEND;
3394 int new_snd_devices[SND_DEVICE_OUT_END];
3395 int i, num_devices = 1;
3396 bool ret = false;
3397 struct platform_data *my_data = (struct platform_data *)adev->platform;
3398 struct audio_backend_cfg backend_cfg;
3399
3400 backend_idx = platform_get_backend_index(snd_device);
3401
3402 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3403 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3404 backend_cfg.format = usecase->stream.out->format;
3405 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3406 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3407 backend_cfg.passthrough_enabled = false;
3408
3409 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3410 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3411 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3412 platform_get_snd_device_name(snd_device));
3413
3414 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3415 new_snd_devices[0] = snd_device;
3416
3417 for (i = 0; i < num_devices; i++) {
3418 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3419 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3420 &backend_cfg))) {
3421 platform_set_backend_cfg(adev, new_snd_devices[i],
3422 &backend_cfg);
3423 ret = true;
3424 }
3425 }
3426 return ret;
3427}
3428
3429bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3430 struct audio_usecase *usecase, snd_device_t snd_device)
3431{
3432 int backend_idx = platform_get_backend_index(snd_device);
3433 int ret = 0;
3434 struct audio_backend_cfg backend_cfg;
3435
3436 backend_cfg.passthrough_enabled = false;
3437
3438 if(usecase->type == PCM_CAPTURE) {
3439 backend_cfg.format= usecase->stream.in->format;
3440 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3441 } else {
3442 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3443 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3444 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3445 backend_cfg.channels = 1;
3446 }
3447
3448 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3449 ", backend_idx %d usecase = %d device (%s)", __func__,
3450 backend_cfg.bit_width,
3451 backend_cfg.sample_rate,
3452 backend_cfg.channels,
3453 backend_idx, usecase->id,
3454 platform_get_snd_device_name(snd_device));
3455
3456 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3457 ret = platform_set_backend_cfg(adev, snd_device,
3458 &backend_cfg);
3459 if(!ret)
3460 return true;
3461 }
3462
3463 return false;
3464}
3465