blob: a77be166cafa31fa30f021233a1b6ef0016e3168 [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
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090031#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
32#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080033#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
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001086// Treblized config files will be located in /odm/etc or /vendor/etc.
1087static const char *kConfigLocationList[] =
1088 {"/odm/etc", "/vendor/etc", "/system/etc"};
1089static const int kConfigLocationListSize =
1090 (sizeof(kConfigLocationList) / sizeof(kConfigLocationList[0]));
1091
1092bool resolveConfigFile(char file_name[MIXER_PATH_MAX_LENGTH]) {
1093 char full_config_path[MIXER_PATH_MAX_LENGTH];
1094 for (int i = 0; i < kConfigLocationListSize; i++) {
1095 snprintf(full_config_path,
1096 MIXER_PATH_MAX_LENGTH,
1097 "%s/%s",
1098 kConfigLocationList[i],
1099 file_name);
1100 if (F_OK == access(full_config_path, 0)) {
1101 strcpy(file_name, full_config_path);
1102 return true;
1103 }
1104 }
1105 return false;
1106}
1107
Eric Laurentb23d5282013-05-14 15:27:20 -07001108void *platform_init(struct audio_device *adev)
1109{
1110 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001111 struct platform_data *my_data = NULL;
1112 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1113 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001114 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001115 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001116 char *snd_internal_name = NULL;
1117 char *tmp = NULL;
1118 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001119 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1120 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001121 my_data = calloc(1, sizeof(struct platform_data));
1122
1123 my_data->adev = adev;
1124
keunhui.park2f7306a2015-07-16 16:48:06 +09001125 list_init(&operator_info_list);
1126
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001127 set_platform_defaults(my_data);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001128 bool card_verifed[MAX_SND_CARD] = {0};
1129 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001130
vivek mehta2b0e5a62016-09-02 17:31:58 -07001131 for (;;) {
1132 if (snd_card_num >= MAX_SND_CARD) {
1133 if (retry_num++ >= retry_limit) {
1134 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1135 goto init_failed;
1136 }
sangwoo1b9f4b32013-06-21 18:22:55 -07001137
vivek mehta2b0e5a62016-09-02 17:31:58 -07001138 snd_card_num = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001139 usleep(RETRY_US);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001140 continue;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001141 }
1142
vivek mehta2b0e5a62016-09-02 17:31:58 -07001143 if (card_verifed[snd_card_num]) {
1144 ++snd_card_num;
1145 continue;
1146 }
1147
1148 adev->mixer = mixer_open(snd_card_num);
1149
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001150 if (!adev->mixer) {
1151 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehta2b0e5a62016-09-02 17:31:58 -07001152 snd_card_num);
1153 ++snd_card_num;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001154 continue;
1155 }
1156
vivek mehta2b0e5a62016-09-02 17:31:58 -07001157 card_verifed[snd_card_num] = true;
1158
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001159 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -08001160 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001161
vivek mehtade4849c2016-03-03 17:23:38 -08001162 audio_extn_set_snd_card_split(snd_card_name);
1163 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001164
vivek mehtade4849c2016-03-03 17:23:38 -08001165 /* Get the codec internal name from the sound card and/or form factor
1166 * name and form the mixer paths and platfor info file name dynamically.
1167 * This is generic way of picking any codec and forma factor name based
1168 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001169
vivek mehtade4849c2016-03-03 17:23:38 -08001170 * current code extends and looks for any of the exteneded mixer path and
1171 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001172
vivek mehtade4849c2016-03-03 17:23:38 -08001173 * order of picking appropriate file is
1174 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1175 * <ii> mixer_paths_<codec_name>.xml, if file not present
1176 * <iii> mixer_paths.xml
1177
1178 * same order is followed for audio_platform_info.xml as well
1179 */
1180
1181 // need to carryforward old file name
1182 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001183 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001184 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001185 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001186 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001187
vivek mehtade4849c2016-03-03 17:23:38 -08001188 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1189 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1190 snd_split_handle->form_factor);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001191 if (!resolveConfigFile(mixer_xml_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001192 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1193 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1194 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1195
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001196 if (!resolveConfigFile(mixer_xml_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001197 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1198 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001199 resolveConfigFile(mixer_xml_file);
vivek mehtade4849c2016-03-03 17:23:38 -08001200 }
1201 }
1202
1203 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1204 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1205 snd_split_handle->form_factor);
1206
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001207 if (!resolveConfigFile(platform_info_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001208 memset(platform_info_file, 0, sizeof(platform_info_file));
1209 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1210 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1211
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001212 if (!resolveConfigFile(platform_info_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001213 memset(platform_info_file, 0, sizeof(platform_info_file));
1214 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001215 resolveConfigFile(platform_info_file);
vivek mehta60ea4152016-02-18 17:10:26 -08001216 }
1217 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001218 }
1219
vivek mehtade4849c2016-03-03 17:23:38 -08001220 /* Initialize platform specific ids and/or backends*/
1221 platform_info_init(platform_info_file, my_data);
1222
1223 /* validate the sound card name
1224 * my_data->snd_card_name can contain
1225 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1226 * example: msm8994-tomtom-mtp-snd-card
1227 * <b> or sub string of the card name, i.e. <device>-<codec>
1228 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001229 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1230 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001231 */
1232
1233 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001234 strncmp(snd_card_name, my_data->snd_card_name,
1235 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001236 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1237 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001238 ++snd_card_num;
1239 mixer_close(adev->mixer);
1240 adev->mixer = NULL;
vivek mehtade4849c2016-03-03 17:23:38 -08001241 hw_info_deinit(my_data->hw_info);
1242 my_data->hw_info = NULL;
1243 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001244 }
vivek mehtade4849c2016-03-03 17:23:38 -08001245 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1246 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001247
1248 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1249 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1250
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001251 if (!adev->audio_route) {
1252 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001253 mixer_close(adev->mixer);
1254 adev->mixer = NULL;
1255 hw_info_deinit(my_data->hw_info);
1256 my_data->hw_info = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001257 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001258 }
1259 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001260 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001261 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001262 }
1263
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001264 //set max volume step for voice call
1265 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1266 my_data->max_vol_index = atoi(value);
1267
vivek mehta65ad12d2015-08-13 18:32:48 -07001268 property_get("persist.audio.dualmic.config",value,"");
1269 if (!strcmp("endfire", value)) {
1270 dual_mic_config = true;
1271 }
1272
Prashant Malanic92c5962015-08-11 15:10:18 -07001273 my_data->source_mic_type = SOURCE_DUAL_MIC;
1274
Eric Laurentb23d5282013-05-14 15:27:20 -07001275 my_data->fluence_in_spkr_mode = false;
1276 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001277 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001278 my_data->fluence_in_voice_rec = false;
1279
vivek mehta65ad12d2015-08-13 18:32:48 -07001280 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001281 if (!strcmp("fluencepro", value)) {
1282 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001283 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001284 my_data->fluence_type = FLUENCE_ENABLE;
1285 } else if (!strcmp("none", value)) {
1286 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001287 }
1288
Prashant Malanic92c5962015-08-11 15:10:18 -07001289 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001290 property_get("persist.audio.fluence.voicecall",value,"");
1291 if (!strcmp("true", value)) {
1292 my_data->fluence_in_voice_call = true;
1293 }
1294
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001295 property_get("persist.audio.fluence.voicecomm",value,"");
1296 if (!strcmp("true", value)) {
1297 my_data->fluence_in_voice_comm = true;
1298 }
1299
Eric Laurentb23d5282013-05-14 15:27:20 -07001300 property_get("persist.audio.fluence.voicerec",value,"");
1301 if (!strcmp("true", value)) {
1302 my_data->fluence_in_voice_rec = true;
1303 }
1304
1305 property_get("persist.audio.fluence.speaker",value,"");
1306 if (!strcmp("true", value)) {
1307 my_data->fluence_in_spkr_mode = true;
1308 }
1309 }
1310
Prashant Malanic92c5962015-08-11 15:10:18 -07001311 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1312 switch (my_data->max_mic_count) {
1313 case 4:
1314 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1315 case 3:
1316 my_data->source_mic_type |= SOURCE_THREE_MIC;
1317 case 2:
1318 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1319 case 1:
1320 my_data->source_mic_type |= SOURCE_MONO_MIC;
1321 break;
1322 default:
1323 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1324 __func__, my_data->max_mic_count);
1325 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1326 break;
1327 }
1328
1329 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1330 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1331 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1332 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1333 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1334
Eric Laurentb23d5282013-05-14 15:27:20 -07001335 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1336 if (my_data->acdb_handle == NULL) {
1337 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1338 } else {
1339 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1340 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1341 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001342 if (!my_data->acdb_deallocate)
1343 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1344 __func__, LIB_ACDB_LOADER);
1345
Eric Laurentb23d5282013-05-14 15:27:20 -07001346 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1347 "acdb_loader_send_audio_cal");
1348 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001349 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001350 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001351
Eric Laurentb23d5282013-05-14 15:27:20 -07001352 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1353 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001354 if (!my_data->acdb_send_voice_cal)
1355 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1356 __func__, LIB_ACDB_LOADER);
1357
1358 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1359 "acdb_loader_reload_vocvoltable");
1360 if (!my_data->acdb_reload_vocvoltable)
1361 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1362 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001363
1364 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1365 "acdb_loader_send_gain_dep_cal");
1366 if (!my_data->acdb_send_gain_dep_cal)
1367 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1368 __func__, LIB_ACDB_LOADER);
1369
Thierry Strudel92232b42017-01-26 10:51:48 -08001370#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001371 acdb_init_v2_cvd_t acdb_init;
1372 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1373 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001374 if (acdb_init == NULL)
1375 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1376 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001377
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001378#elif defined (PLATFORM_MSM8084)
1379 acdb_init_v2_t acdb_init;
1380 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1381 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001382 if (acdb_init == NULL)
1383 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1384 dlerror());
1385
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001386#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001387 acdb_init_t acdb_init;
1388 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001389 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001390 if (acdb_init == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001391 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1392 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001393#endif
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001394 my_data->acdb_init = acdb_init;
Eric Laurentb23d5282013-05-14 15:27:20 -07001395
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001396 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1397 dlsym(my_data->acdb_handle,
1398 "acdb_loader_send_common_custom_topology");
1399
1400 if (!my_data->acdb_send_custom_top)
1401 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1402 __func__, LIB_ACDB_LOADER);
1403
1404 platform_acdb_init(my_data);
1405 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001406
David Lin8c03e672017-02-06 20:31:38 -08001407 /* init usb */
1408 audio_extn_usb_init(adev);
1409
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001410 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001411
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001412 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1413
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001414 /* load csd client */
1415 platform_csd_init(my_data);
1416
David Lin8c03e672017-02-06 20:31:38 -08001417 platform_backend_config_init(my_data);
1418
Eric Laurentb23d5282013-05-14 15:27:20 -07001419 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001420
1421init_failed:
1422 if (my_data)
1423 free(my_data);
1424 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001425}
1426
1427void platform_deinit(void *platform)
1428{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001429 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001430 struct operator_info *info_item;
1431 struct operator_specific_device *device_item;
1432 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001433
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001434 struct platform_data *my_data = (struct platform_data *)platform;
1435 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001436
vivek mehtade4849c2016-03-03 17:23:38 -08001437 hw_info_deinit(my_data->hw_info);
1438
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001439 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1440 if (backend_tag_table[dev])
1441 free(backend_tag_table[dev]);
1442 if (hw_interface_table[dev])
1443 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001444 if (operator_specific_device_table[dev]) {
1445 while (!list_empty(operator_specific_device_table[dev])) {
1446 node = list_head(operator_specific_device_table[dev]);
1447 list_remove(node);
1448 device_item = node_to_item(node, struct operator_specific_device, list);
1449 free(device_item->operator);
1450 free(device_item->mixer_path);
1451 free(device_item);
1452 }
1453 free(operator_specific_device_table[dev]);
1454 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001455 }
1456
1457 if (my_data->snd_card_name)
1458 free(my_data->snd_card_name);
1459
keunhui.park2f7306a2015-07-16 16:48:06 +09001460 while (!list_empty(&operator_info_list)) {
1461 node = list_head(&operator_info_list);
1462 list_remove(node);
1463 info_item = node_to_item(node, struct operator_info, list);
1464 free(info_item->name);
1465 free(info_item->mccmnc);
1466 free(info_item);
1467 }
1468
Eric Laurentb23d5282013-05-14 15:27:20 -07001469 free(platform);
David Lin8c03e672017-02-06 20:31:38 -08001470
1471 /* deinit usb */
1472 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001473}
1474
1475const char *platform_get_snd_device_name(snd_device_t snd_device)
1476{
keunhui.park2f7306a2015-07-16 16:48:06 +09001477 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1478 if (operator_specific_device_table[snd_device] != NULL) {
1479 return get_operator_specific_device_mixer_path(snd_device);
1480 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001481 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001482 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001483 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001484}
1485
vivek mehtade4849c2016-03-03 17:23:38 -08001486int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1487 char *device_name)
1488{
1489 struct platform_data *my_data = (struct platform_data *)platform;
1490
David Benjamin1565f992016-09-21 12:10:34 -04001491 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001492 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001493 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1494 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001495 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1496 if (operator_specific_device_table[snd_device] != NULL) {
1497 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1498 DEVICE_NAME_MAX_SIZE);
1499 } else {
1500 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1501 }
1502 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1503 } else {
1504 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1505 }
1506
1507 return 0;
1508}
1509
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001510void platform_add_backend_name(void *platform, char *mixer_path,
1511 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001512{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001513 struct platform_data *my_data = (struct platform_data *)platform;
1514
Haynes Mathew George98c95622014-06-20 19:14:25 -07001515 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1516 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1517 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001518 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001519
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001520 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001521
1522 if (suffix != NULL) {
1523 strcat(mixer_path, " ");
1524 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001525 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001526}
1527
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001528bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1529{
1530 bool result = true;
1531
1532 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1533 platform_get_snd_device_name(snd_device1),
1534 platform_get_snd_device_name(snd_device2));
1535
1536 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1537 ALOGE("%s: Invalid snd_device = %s", __func__,
1538 platform_get_snd_device_name(snd_device1));
1539 return false;
1540 }
1541 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1542 ALOGE("%s: Invalid snd_device = %s", __func__,
1543 platform_get_snd_device_name(snd_device2));
1544 return false;
1545 }
1546 const char * be_itf1 = hw_interface_table[snd_device1];
1547 const char * be_itf2 = hw_interface_table[snd_device2];
1548
1549 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001550 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001551 result = false;
1552 }
1553
1554 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1555 return result;
1556}
1557
Eric Laurentb23d5282013-05-14 15:27:20 -07001558int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1559{
1560 int device_id;
1561 if (device_type == PCM_PLAYBACK)
1562 device_id = pcm_device_table[usecase][0];
1563 else
1564 device_id = pcm_device_table[usecase][1];
1565 return device_id;
1566}
1567
Haynes Mathew George98c95622014-06-20 19:14:25 -07001568static int find_index(const struct name_to_index * table, int32_t len,
1569 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001570{
1571 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001572 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001573
Haynes Mathew George98c95622014-06-20 19:14:25 -07001574 if (table == NULL) {
1575 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001576 ret = -ENODEV;
1577 goto done;
1578 }
1579
Haynes Mathew George98c95622014-06-20 19:14:25 -07001580 if (name == NULL) {
1581 ALOGE("null key");
1582 ret = -ENODEV;
1583 goto done;
1584 }
1585
1586 for (i=0; i < len; i++) {
1587 if (!strcmp(table[i].name, name)) {
1588 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001589 goto done;
1590 }
1591 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001592 ALOGE("%s: Could not find index for name = %s",
1593 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001594 ret = -ENODEV;
1595done:
1596 return ret;
1597}
1598
Haynes Mathew George98c95622014-06-20 19:14:25 -07001599int platform_get_snd_device_index(char *device_name)
1600{
1601 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1602}
1603
1604int platform_get_usecase_index(const char *usecase_name)
1605{
1606 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1607}
1608
keunhui.park2f7306a2015-07-16 16:48:06 +09001609void platform_add_operator_specific_device(snd_device_t snd_device,
1610 const char *operator,
1611 const char *mixer_path,
1612 unsigned int acdb_id)
1613{
1614 struct operator_specific_device *device;
1615
1616 if (operator_specific_device_table[snd_device] == NULL) {
1617 operator_specific_device_table[snd_device] =
1618 (struct listnode *)calloc(1, sizeof(struct listnode));
1619 list_init(operator_specific_device_table[snd_device]);
1620 }
1621
1622 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1623
1624 device->operator = strdup(operator);
1625 device->mixer_path = strdup(mixer_path);
1626 device->acdb_id = acdb_id;
1627
1628 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1629
Eric Laurent2bafff12016-03-17 12:17:23 -07001630 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001631 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1632
1633}
1634
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001635int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1636{
1637 int ret = 0;
1638
1639 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1640 ALOGE("%s: Invalid snd_device = %d",
1641 __func__, snd_device);
1642 ret = -EINVAL;
1643 goto done;
1644 }
1645
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001646 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1647 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001648 acdb_device_table[snd_device] = acdb_id;
1649done:
1650 return ret;
1651}
1652
Glenn Kastencbe06ca2016-11-09 10:49:26 -08001653int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1654 int *app_type __unused)
Yamit Mehtae3b99562016-09-16 22:44:00 +05301655{
1656 ALOGE("%s: Not implemented", __func__);
1657 return -ENOSYS;
1658}
1659
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001660int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1661{
1662 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1663 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1664 return -EINVAL;
1665 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001666
1667 if (operator_specific_device_table[snd_device] != NULL)
1668 return get_operator_specific_device_acdb_id(snd_device);
1669 else
1670 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001671}
1672
David Lin8c03e672017-02-06 20:31:38 -08001673static int platform_get_backend_index(snd_device_t snd_device)
1674{
1675 int32_t port = DEFAULT_CODEC_BACKEND;
1676
1677 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1678 if (backend_tag_table[snd_device] != NULL) {
1679 if (strncmp(backend_tag_table[snd_device], "headphones",
1680 sizeof("headphones")) == 0)
1681 port = HEADPHONE_BACKEND;
1682 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1683 port = HDMI_RX_BACKEND;
1684 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1685 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1686 port = USB_AUDIO_RX_BACKEND;
1687 }
1688 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1689 port = DEFAULT_CODEC_TX_BACKEND;
1690 if (backend_tag_table[snd_device] != NULL) {
1691 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1692 port = USB_AUDIO_TX_BACKEND;
1693 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1694 port = BT_SCO_TX_BACKEND;
1695 }
1696 } else {
1697 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1698 }
1699
1700 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1701
1702 return port;
1703}
1704
Eric Laurentb23d5282013-05-14 15:27:20 -07001705int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1706{
1707 struct platform_data *my_data = (struct platform_data *)platform;
1708 int acdb_dev_id, acdb_dev_type;
1709
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001710 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001711 if (acdb_dev_id < 0) {
1712 ALOGE("%s: Could not find acdb id for device(%d)",
1713 __func__, snd_device);
1714 return -EINVAL;
1715 }
1716 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001717 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001718 __func__, snd_device, acdb_dev_id);
1719 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1720 snd_device < SND_DEVICE_OUT_END)
1721 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1722 else
1723 acdb_dev_type = ACDB_DEV_TYPE_IN;
1724 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1725 }
1726 return 0;
1727}
1728
1729int platform_switch_voice_call_device_pre(void *platform)
1730{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001731 struct platform_data *my_data = (struct platform_data *)platform;
1732 int ret = 0;
1733
1734 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001735 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001736 /* This must be called before disabling mixer controls on APQ side */
1737 ret = my_data->csd->disable_device();
1738 if (ret < 0) {
1739 ALOGE("%s: csd_client_disable_device, failed, error %d",
1740 __func__, ret);
1741 }
1742 }
1743 return ret;
1744}
1745
1746int platform_switch_voice_call_enable_device_config(void *platform,
1747 snd_device_t out_snd_device,
1748 snd_device_t in_snd_device)
1749{
1750 struct platform_data *my_data = (struct platform_data *)platform;
1751 int acdb_rx_id, acdb_tx_id;
1752 int ret = 0;
1753
1754 if (my_data->csd == NULL)
1755 return ret;
1756
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001757 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1758 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001759 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001760 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001761 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001762
keunhui.park2f7306a2015-07-16 16:48:06 +09001763 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001764
1765 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1766 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1767 if (ret < 0) {
1768 ALOGE("%s: csd_enable_device_config, failed, error %d",
1769 __func__, ret);
1770 }
1771 } else {
1772 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1773 acdb_rx_id, acdb_tx_id);
1774 }
1775
1776 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001777}
1778
1779int platform_switch_voice_call_device_post(void *platform,
1780 snd_device_t out_snd_device,
1781 snd_device_t in_snd_device)
1782{
1783 struct platform_data *my_data = (struct platform_data *)platform;
1784 int acdb_rx_id, acdb_tx_id;
1785
1786 if (my_data->acdb_send_voice_cal == NULL) {
1787 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1788 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001789 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1790 audio_extn_spkr_prot_is_enabled())
1791 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1792
keunhui.park2f7306a2015-07-16 16:48:06 +09001793 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1794 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001795
1796 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1797 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1798 else
1799 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1800 acdb_rx_id, acdb_tx_id);
1801 }
1802
1803 return 0;
1804}
1805
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001806int platform_switch_voice_call_usecase_route_post(void *platform,
1807 snd_device_t out_snd_device,
1808 snd_device_t in_snd_device)
1809{
1810 struct platform_data *my_data = (struct platform_data *)platform;
1811 int acdb_rx_id, acdb_tx_id;
1812 int ret = 0;
1813
1814 if (my_data->csd == NULL)
1815 return ret;
1816
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001817 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1818 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001819 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001820 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001821 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001822
keunhui.park2f7306a2015-07-16 16:48:06 +09001823 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001824
1825 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1826 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1827 my_data->adev->acdb_settings);
1828 if (ret < 0) {
1829 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1830 }
1831 } else {
1832 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1833 acdb_rx_id, acdb_tx_id);
1834 }
1835
1836 return ret;
1837}
1838
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001839int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001840{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001841 struct platform_data *my_data = (struct platform_data *)platform;
1842 int ret = 0;
1843
1844 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001845 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001846 if (ret < 0) {
1847 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1848 }
1849 }
1850 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001851}
1852
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001853int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001854{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001855 struct platform_data *my_data = (struct platform_data *)platform;
1856 int ret = 0;
1857
1858 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001859 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001860 if (ret < 0) {
1861 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1862 }
1863 }
1864 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001865}
1866
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001867int platform_get_sample_rate(void *platform, uint32_t *rate)
1868{
1869 struct platform_data *my_data = (struct platform_data *)platform;
1870 int ret = 0;
1871
1872 if (my_data->csd != NULL) {
1873 ret = my_data->csd->get_sample_rate(rate);
1874 if (ret < 0) {
1875 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1876 }
1877 }
1878 return ret;
1879}
1880
vivek mehtab6506412015-08-07 16:55:17 -07001881void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1882 snd_device_t snd_device,
1883 bool enable)
1884{
1885 const char* name;
1886 switch (snd_device) {
1887 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1888 if (enable)
1889 name = "spkr-gain-in-headphone-combo";
1890 else
1891 name = "speaker-gain-default";
1892 break;
1893 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1894 if (enable)
1895 name = "spkr-gain-in-line-combo";
1896 else
1897 name = "speaker-gain-default";
1898 break;
1899 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1900 if (enable)
1901 name = "spkr-safe-gain-in-headphone-combo";
1902 else
1903 name = "speaker-safe-gain-default";
1904 break;
1905 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1906 if (enable)
1907 name = "spkr-safe-gain-in-line-combo";
1908 else
1909 name = "speaker-safe-gain-default";
1910 break;
1911 default:
1912 return;
1913 }
1914
1915 audio_route_apply_and_update_path(adev->audio_route, name);
1916}
1917
Eric Laurentb23d5282013-05-14 15:27:20 -07001918int platform_set_voice_volume(void *platform, int volume)
1919{
1920 struct platform_data *my_data = (struct platform_data *)platform;
1921 struct audio_device *adev = my_data->adev;
1922 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001923 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001924 int vol_index = 0, ret = 0;
1925 uint32_t set_values[ ] = {0,
1926 ALL_SESSION_VSID,
1927 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001928
1929 // Voice volume levels are mapped to adsp volume levels as follows.
1930 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1931 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001932 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001933 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001934
1935 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1936 if (!ctl) {
1937 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1938 __func__, mixer_ctl_name);
1939 return -EINVAL;
1940 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001941 ALOGV("Setting voice volume index: %d", set_values[0]);
1942 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1943
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001944 if (my_data->csd != NULL) {
1945 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1946 DEFAULT_VOLUME_RAMP_DURATION_MS);
1947 if (ret < 0) {
1948 ALOGE("%s: csd_volume error %d", __func__, ret);
1949 }
1950 }
1951 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001952}
1953
1954int platform_set_mic_mute(void *platform, bool state)
1955{
1956 struct platform_data *my_data = (struct platform_data *)platform;
1957 struct audio_device *adev = my_data->adev;
1958 struct mixer_ctl *ctl;
1959 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001960 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001961 uint32_t set_values[ ] = {0,
1962 ALL_SESSION_VSID,
1963 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001964
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001965 if (adev->mode != AUDIO_MODE_IN_CALL &&
1966 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001967 return 0;
1968
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001969 if (adev->enable_hfp)
1970 mixer_ctl_name = "HFP Tx Mute";
1971
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001972 set_values[0] = state;
1973 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1974 if (!ctl) {
1975 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1976 __func__, mixer_ctl_name);
1977 return -EINVAL;
1978 }
1979 ALOGV("Setting voice mute state: %d", state);
1980 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1981
1982 if (my_data->csd != NULL) {
1983 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1984 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001985 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001986 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001987 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001988 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001989 return ret;
1990}
Eric Laurentb23d5282013-05-14 15:27:20 -07001991
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001992int platform_set_device_mute(void *platform, bool state, char *dir)
1993{
1994 struct platform_data *my_data = (struct platform_data *)platform;
1995 struct audio_device *adev = my_data->adev;
1996 struct mixer_ctl *ctl;
1997 char *mixer_ctl_name = NULL;
1998 int ret = 0;
1999 uint32_t set_values[ ] = {0,
2000 ALL_SESSION_VSID,
2001 0};
2002 if(dir == NULL) {
2003 ALOGE("%s: Invalid direction:%s", __func__, dir);
2004 return -EINVAL;
2005 }
2006
2007 if (!strncmp("rx", dir, sizeof("rx"))) {
2008 mixer_ctl_name = "Voice Rx Device Mute";
2009 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2010 mixer_ctl_name = "Voice Tx Device Mute";
2011 } else {
2012 return -EINVAL;
2013 }
2014
2015 set_values[0] = state;
2016 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2017 if (!ctl) {
2018 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2019 __func__, mixer_ctl_name);
2020 return -EINVAL;
2021 }
2022
2023 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2024 __func__,state, mixer_ctl_name);
2025 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2026
2027 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002028}
2029
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002030int platform_can_split_snd_device(snd_device_t snd_device,
2031 int *num_devices,
2032 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002033{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002034 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002035 if (NULL == num_devices || NULL == new_snd_devices) {
2036 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002037 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002038 }
2039
2040 /*
2041 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002042 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002043 */
2044 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2045 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2046 *num_devices = 2;
2047 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2048 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002049 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002050 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2051 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2052 *num_devices = 2;
2053 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2054 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002055 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002056 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2057 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2058 *num_devices = 2;
2059 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2060 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002061 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002062 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2063 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2064 *num_devices = 2;
2065 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2066 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002067 ret = 0;
David Lin8c03e672017-02-06 20:31:38 -08002068 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2069 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2070 *num_devices = 2;
2071 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2072 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2073 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002074 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002075 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002076}
2077
Eric Laurentb23d5282013-05-14 15:27:20 -07002078snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2079{
2080 struct platform_data *my_data = (struct platform_data *)platform;
2081 struct audio_device *adev = my_data->adev;
2082 audio_mode_t mode = adev->mode;
2083 snd_device_t snd_device = SND_DEVICE_NONE;
2084
2085 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2086 if (devices == AUDIO_DEVICE_NONE ||
2087 devices & AUDIO_DEVICE_BIT_IN) {
2088 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2089 goto exit;
2090 }
2091
Eric Laurent1b491552015-09-15 17:52:41 -07002092 if (popcount(devices) == 2) {
2093 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2094 AUDIO_DEVICE_OUT_SPEAKER) ||
2095 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2096 AUDIO_DEVICE_OUT_SPEAKER)) {
2097 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2098 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2099 AUDIO_DEVICE_OUT_SPEAKER)) {
2100 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2101 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2102 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2103 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2104 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2105 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2106 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2107 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2108 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2109 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2110 AUDIO_DEVICE_OUT_SPEAKER)) {
2111 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
David Lin8c03e672017-02-06 20:31:38 -08002112 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2113 AUDIO_DEVICE_OUT_SPEAKER)) {
2114 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002115 } else {
2116 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2117 goto exit;
2118 }
2119 if (snd_device != SND_DEVICE_NONE) {
2120 goto exit;
2121 }
2122 }
2123
2124 if (popcount(devices) != 1) {
2125 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2126 goto exit;
2127 }
2128
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302129 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002130 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002131 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2132 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002133 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002134 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002135 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002136 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002137 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002138 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002139 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002140 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002141 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002142 else {
2143 if (devices & AUDIO_DEVICE_OUT_LINE)
2144 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2145 else
2146 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2147 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002148 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002149 if (adev->bt_wb_speech_enabled) {
2150 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2151 } else {
2152 snd_device = SND_DEVICE_OUT_BT_SCO;
2153 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002154 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002155 if (!adev->enable_hfp) {
2156 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2157 } else {
2158 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2159 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002160 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002161 if(adev->voice.hac)
2162 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2163 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002164 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2165 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002166 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002167 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2168 snd_device = SND_DEVICE_OUT_VOICE_TX;
2169
Eric Laurentb23d5282013-05-14 15:27:20 -07002170 if (snd_device != SND_DEVICE_NONE) {
2171 goto exit;
2172 }
2173 }
2174
Eric Laurentb23d5282013-05-14 15:27:20 -07002175 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2176 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2177 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002178 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2179 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002180 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2181 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002182 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002183 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002184 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2185 else
2186 snd_device = SND_DEVICE_OUT_SPEAKER;
2187 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002188 if (adev->bt_wb_speech_enabled) {
2189 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2190 } else {
2191 snd_device = SND_DEVICE_OUT_BT_SCO;
2192 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002193 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2194 snd_device = SND_DEVICE_OUT_HDMI ;
David Lin8c03e672017-02-06 20:31:38 -08002195 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2196 if (audio_extn_usb_is_capture_supported())
2197 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2198 else
2199 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2200 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002201 /*HAC support for voice-ish audio (eg visual voicemail)*/
2202 if(adev->voice.hac)
2203 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2204 else
2205 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002206 } else {
2207 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2208 }
2209exit:
2210 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2211 return snd_device;
2212}
2213
2214snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2215{
2216 struct platform_data *my_data = (struct platform_data *)platform;
2217 struct audio_device *adev = my_data->adev;
2218 audio_source_t source = (adev->active_input == NULL) ?
2219 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2220
2221 audio_mode_t mode = adev->mode;
2222 audio_devices_t in_device = ((adev->active_input == NULL) ?
2223 AUDIO_DEVICE_NONE : adev->active_input->device)
2224 & ~AUDIO_DEVICE_BIT_IN;
2225 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2226 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2227 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002228 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002229
Prashant Malanic92c5962015-08-11 15:10:18 -07002230 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2231 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002232 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002233 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002234 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002235 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2236 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002237 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002238 case TTY_MODE_FULL:
2239 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2240 break;
2241 case TTY_MODE_VCO:
2242 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2243 break;
2244 case TTY_MODE_HCO:
2245 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2246 break;
2247 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002248 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002249 }
2250 goto exit;
2251 }
2252 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002253 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002254 if (my_data->fluence_in_voice_call == false) {
2255 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2256 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002257 if (is_operator_tmus())
2258 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002259 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002260 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002261 }
2262 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2263 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2264 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002265 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002266 if (adev->bluetooth_nrec)
2267 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2268 else
2269 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002270 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002271 if (adev->bluetooth_nrec)
2272 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2273 else
2274 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002275 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002276 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002277 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2278 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2279 out_device & AUDIO_DEVICE_OUT_LINE) {
2280 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2281 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2282 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2283 } else {
2284 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2285 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002286 }
vivek mehtafe121d52015-08-10 23:39:23 -07002287
2288 //select default
2289 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002290 if (!adev->enable_hfp) {
2291 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2292 } else {
2293 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2294 platform_set_echo_reference(adev, true, out_device);
2295 }
vivek mehtafe121d52015-08-10 23:39:23 -07002296 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002297 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002298 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002299 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002300 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2301 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2302 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2303 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2304 }
2305 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2306 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002307 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2308 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2309 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002310 if (adev->active_input->enable_aec)
2311 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2312 else
2313 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002314 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2315 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002316 if (adev->active_input->enable_aec)
2317 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2318 else
2319 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002320 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2321 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2322 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002323 if (adev->active_input->enable_aec)
2324 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2325 else
2326 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002327 }
2328 platform_set_echo_reference(adev, true, out_device);
2329 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2330 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2331 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002332 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002333 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2334 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002335 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002336 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2337 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002338 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002339 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002340 if (adev->active_input->enable_aec) {
2341 if (adev->active_input->enable_ns) {
2342 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2343 } else {
2344 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2345 }
vivek mehta733c1df2016-04-04 15:09:24 -07002346 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002347 } else if (adev->active_input->enable_ns) {
2348 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2349 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002350 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002351 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002352 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002353 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2354 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002355 }
rago90fb9612015-12-02 11:37:53 -08002356 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2357 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002358 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2359 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2360 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2361 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002362 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002363 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2364 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002365 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002366 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2367 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2368 } else {
2369 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2370 }
rago90fb9612015-12-02 11:37:53 -08002371 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2372 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2373 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002374 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002375 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002376 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002377 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2378 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002379 if (adev->active_input->enable_aec &&
2380 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002381 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002382 if (my_data->fluence_in_spkr_mode &&
2383 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002384 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002385 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002386 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002387 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002388 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002389 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002390 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002391 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002392 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002393 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002394 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002395 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002396 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2397 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002398 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002399 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002400 } else if (adev->active_input->enable_aec) {
2401 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2402 if (my_data->fluence_in_spkr_mode &&
2403 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002404 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002405 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002406 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002407 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002408 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002409 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2410 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002411 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002412 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002413 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002414 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002415 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002416 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2417 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2418 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002419 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002420 } else if (adev->active_input->enable_ns) {
2421 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2422 if (my_data->fluence_in_spkr_mode &&
2423 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002424 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002425 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002426 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002427 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002428 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002429 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2430 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002431 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002432 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002433 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002434 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002435 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002436 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002437 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002438 }
2439 } else if (source == AUDIO_SOURCE_DEFAULT) {
2440 goto exit;
2441 }
2442
2443
2444 if (snd_device != SND_DEVICE_NONE) {
2445 goto exit;
2446 }
2447
2448 if (in_device != AUDIO_DEVICE_NONE &&
2449 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2450 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2451 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002452 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002453 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002454 snd_device = SND_DEVICE_IN_QUAD_MIC;
2455 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002456 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002457 snd_device = SND_DEVICE_IN_THREE_MIC;
2458 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2459 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002460 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002461 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2462 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002463 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002464 } else {
2465 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2466 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2467 my_data->source_mic_type, channel_count, channel_mask);
2468 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2469 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002470 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002471 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2472 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002473 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002474 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2475 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002476 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002477 } else {
2478 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2479 " no combination found .. setting to mono", __func__,
2480 my_data->source_mic_type, channel_count);
2481 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2482 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002483 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2484 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2485 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002486 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002487 if (adev->bluetooth_nrec)
2488 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2489 else
2490 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002491 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002492 if (adev->bluetooth_nrec)
2493 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2494 else
2495 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002496 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002497 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2498 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Lin8c03e672017-02-06 20:31:38 -08002499 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2500 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002501 } else {
2502 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2503 ALOGW("%s: Using default handset-mic", __func__);
2504 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2505 }
2506 } else {
2507 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2508 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2509 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2510 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002511 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002512 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002513 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002514 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002515 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2516 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002517 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002518 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2519 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002520 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002521 } else {
2522 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2523 " no combination found .. setting to mono", __func__,
2524 my_data->source_mic_type, channel_count);
2525 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2526 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002527 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002528 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002529 if (adev->bluetooth_nrec)
2530 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2531 else
2532 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002533 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002534 if (adev->bluetooth_nrec)
2535 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2536 else
2537 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002538 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002539 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2540 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Lin8c03e672017-02-06 20:31:38 -08002541 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2542 if (audio_extn_usb_is_capture_supported())
2543 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2544 else
2545 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002546 } else {
2547 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2548 ALOGW("%s: Using default handset-mic", __func__);
2549 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2550 }
2551 }
2552exit:
2553 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2554 return snd_device;
2555}
2556
2557int platform_set_hdmi_channels(void *platform, int channel_count)
2558{
2559 struct platform_data *my_data = (struct platform_data *)platform;
2560 struct audio_device *adev = my_data->adev;
2561 struct mixer_ctl *ctl;
2562 const char *channel_cnt_str = NULL;
2563 const char *mixer_ctl_name = "HDMI_RX Channels";
2564 switch (channel_count) {
2565 case 8:
2566 channel_cnt_str = "Eight"; break;
2567 case 7:
2568 channel_cnt_str = "Seven"; break;
2569 case 6:
2570 channel_cnt_str = "Six"; break;
2571 case 5:
2572 channel_cnt_str = "Five"; break;
2573 case 4:
2574 channel_cnt_str = "Four"; break;
2575 case 3:
2576 channel_cnt_str = "Three"; break;
2577 default:
2578 channel_cnt_str = "Two"; break;
2579 }
2580 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2581 if (!ctl) {
2582 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2583 __func__, mixer_ctl_name);
2584 return -EINVAL;
2585 }
2586 ALOGV("HDMI channel count: %s", channel_cnt_str);
2587 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2588 return 0;
2589}
2590
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002591int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002592{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002593 struct platform_data *my_data = (struct platform_data *)platform;
2594 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002595 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2596 char *sad = block;
2597 int num_audio_blocks;
2598 int channel_count;
2599 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002600 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002601
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002602 struct mixer_ctl *ctl;
2603
2604 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2605 if (!ctl) {
2606 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2607 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002608 return 0;
2609 }
2610
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002611 mixer_ctl_update(ctl);
2612
2613 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002614
2615 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002616 if (count > (int)sizeof(block))
2617 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002618
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002619 ret = mixer_ctl_get_array(ctl, block, count);
2620 if (ret != 0) {
2621 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2622 return 0;
2623 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002624
2625 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002626 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002627
2628 for (i = 0; i < num_audio_blocks; i++) {
2629 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002630 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2631 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002632 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002633 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002634
2635 channel_count = (sad[0] & 0x7) + 1;
2636 if (channel_count > max_channels)
2637 max_channels = channel_count;
2638
2639 /* Advance to next block */
2640 sad += 3;
2641 }
2642
2643 return max_channels;
2644}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002645
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002646int platform_set_incall_recording_session_id(void *platform,
2647 uint32_t session_id, int rec_mode)
2648{
2649 int ret = 0;
2650 struct platform_data *my_data = (struct platform_data *)platform;
2651 struct audio_device *adev = my_data->adev;
2652 struct mixer_ctl *ctl;
2653 const char *mixer_ctl_name = "Voc VSID";
2654 int num_ctl_values;
2655 int i;
2656
2657 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2658 if (!ctl) {
2659 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2660 __func__, mixer_ctl_name);
2661 ret = -EINVAL;
2662 } else {
2663 num_ctl_values = mixer_ctl_get_num_values(ctl);
2664 for (i = 0; i < num_ctl_values; i++) {
2665 if (mixer_ctl_set_value(ctl, i, session_id)) {
2666 ALOGV("Error: invalid session_id: %x", session_id);
2667 ret = -EINVAL;
2668 break;
2669 }
2670 }
2671 }
2672
2673 if (my_data->csd != NULL) {
2674 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2675 if (ret < 0) {
2676 ALOGE("%s: csd_client_start_record failed, error %d",
2677 __func__, ret);
2678 }
2679 }
2680
2681 return ret;
2682}
2683
2684int platform_stop_incall_recording_usecase(void *platform)
2685{
2686 int ret = 0;
2687 struct platform_data *my_data = (struct platform_data *)platform;
2688
2689 if (my_data->csd != NULL) {
2690 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2691 if (ret < 0) {
2692 ALOGE("%s: csd_client_stop_record failed, error %d",
2693 __func__, ret);
2694 }
2695 }
2696
2697 return ret;
2698}
2699
2700int platform_start_incall_music_usecase(void *platform)
2701{
2702 int ret = 0;
2703 struct platform_data *my_data = (struct platform_data *)platform;
2704
2705 if (my_data->csd != NULL) {
2706 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2707 if (ret < 0) {
2708 ALOGE("%s: csd_client_start_playback failed, error %d",
2709 __func__, ret);
2710 }
2711 }
2712
2713 return ret;
2714}
2715
2716int platform_stop_incall_music_usecase(void *platform)
2717{
2718 int ret = 0;
2719 struct platform_data *my_data = (struct platform_data *)platform;
2720
2721 if (my_data->csd != NULL) {
2722 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2723 if (ret < 0) {
2724 ALOGE("%s: csd_client_stop_playback failed, error %d",
2725 __func__, ret);
2726 }
2727 }
2728
2729 return ret;
2730}
2731
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002732int platform_set_parameters(void *platform, struct str_parms *parms)
2733{
2734 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002735 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002736 char *kv_pairs = str_parms_to_str(parms);
2737 int ret = 0, err;
2738
2739 if (kv_pairs == NULL) {
2740 ret = -EINVAL;
2741 ALOGE("%s: key-value pair is NULL",__func__);
2742 goto done;
2743 }
2744
2745 ALOGV("%s: enter: %s", __func__, kv_pairs);
2746
2747 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2748 value, sizeof(value));
2749 if (err >= 0) {
2750 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2751 my_data->snd_card_name = strdup(value);
2752 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2753 }
2754
keunhui.park2f7306a2015-07-16 16:48:06 +09002755 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2756 value, sizeof(value));
2757 if (err >= 0) {
2758 struct operator_info *info;
2759 char *str = value;
2760 char *name;
2761
2762 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2763 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2764 name = strtok(str, ";");
2765 info->name = strdup(name);
2766 info->mccmnc = strdup(str + strlen(name) + 1);
2767
2768 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002769 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002770 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002771
2772 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002773 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002774 value, sizeof(value));
2775 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002776 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002777 my_data->max_mic_count = atoi(value);
2778 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002779 }
2780
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002781done:
2782 ALOGV("%s: exit with code(%d)", __func__, ret);
2783 if (kv_pairs != NULL)
2784 free(kv_pairs);
2785
2786 return ret;
2787}
2788
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002789/* Delay in Us */
2790int64_t platform_render_latency(audio_usecase_t usecase)
2791{
2792 switch (usecase) {
2793 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2794 return DEEP_BUFFER_PLATFORM_DELAY;
2795 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2796 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002797 case USECASE_AUDIO_PLAYBACK_ULL:
2798 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002799 case USECASE_AUDIO_PLAYBACK_MMAP:
2800 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002801 default:
2802 return 0;
2803 }
2804}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002805
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002806int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2807 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002808{
2809 int ret = 0;
2810
2811 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2812 ALOGE("%s: Invalid snd_device = %d",
2813 __func__, device);
2814 ret = -EINVAL;
2815 goto done;
2816 }
2817
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002818 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2819 platform_get_snd_device_name(device),
2820 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2821 if (backend_tag_table[device]) {
2822 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002823 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002824 backend_tag_table[device] = strdup(backend_tag);
2825
2826 if (hw_interface != NULL) {
2827 if (hw_interface_table[device])
2828 free(hw_interface_table[device]);
2829 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2830 hw_interface_table[device] = strdup(hw_interface);
2831 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002832done:
2833 return ret;
2834}
2835
2836int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2837{
2838 int ret = 0;
2839 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2840 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2841 ret = -EINVAL;
2842 goto done;
2843 }
2844
2845 if ((type != 0) && (type != 1)) {
2846 ALOGE("%s: invalid usecase type", __func__);
2847 ret = -EINVAL;
2848 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002849 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002850 pcm_device_table[usecase][type] = pcm_id;
2851done:
2852 return ret;
2853}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002854
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002855#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2856int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2857 // backup_gain: gain to try to set in case of an error during ramp
2858 int start_gain, end_gain, step, backup_gain, i;
2859 bool error = false;
2860 const struct mixer_ctl *ctl;
2861 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2862 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2863 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2864 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2865 if (!ctl_left || !ctl_right) {
2866 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2867 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2868 return -EINVAL;
2869 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2870 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2871 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2872 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2873 return -EINVAL;
2874 }
2875 if (ramp_up) {
2876 start_gain = 0;
2877 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2878 step = +1;
2879 backup_gain = end_gain;
2880 } else {
2881 // using same gain on left and right
2882 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2883 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2884 end_gain = 0;
2885 step = -1;
2886 backup_gain = start_gain;
2887 }
2888 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2889 //ALOGV("setting speaker gain to %d", i);
2890 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2891 ALOGE("%s: error setting %s to %d during gain ramp",
2892 __func__, mixer_ctl_name_gain_left, i);
2893 error = true;
2894 break;
2895 }
2896 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2897 ALOGE("%s: error setting %s to %d during gain ramp",
2898 __func__, mixer_ctl_name_gain_right, i);
2899 error = true;
2900 break;
2901 }
2902 usleep(1000);
2903 }
2904 if (error) {
2905 // an error occured during the ramp, let's still try to go back to a safe volume
2906 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2907 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2908 }
2909 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2910 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2911 }
2912 }
2913 return start_gain;
2914}
2915
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002916int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2917{
2918 // only update if there is active pcm playback on speaker
2919 struct audio_usecase *usecase;
2920 struct listnode *node;
2921 struct platform_data *my_data = (struct platform_data *)adev->platform;
2922
2923 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07002924
2925 // do not swap channels in audio modes with concurrent capture and playback
2926 // as this may break the echo reference
2927 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
2928 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
2929 return 0;
2930 }
2931
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002932 my_data->speaker_lr_swap = swap_channels;
2933
2934 list_for_each(node, &adev->usecase_list) {
2935 usecase = node_to_item(node, struct audio_usecase, list);
2936 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002937 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2938 /*
2939 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2940 * to perform device switch to disable the current backend to
2941 * enable it with new acdb data.
2942 */
2943 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2944 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002945 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002946 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002947 if (initial_skpr_gain != -EINVAL) {
2948 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2949 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002950 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002951 const char *mixer_path;
2952 if (swap_channels) {
2953 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2954 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2955 } else {
2956 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2957 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2958 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002959 }
2960 break;
2961 }
2962 }
2963 }
2964 return 0;
2965}
vivek mehtaa8d7c922016-05-25 14:40:44 -07002966
2967static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
2968static int num_gain_tbl_entry = 0;
2969
2970bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
2971
2972 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
2973 if (num_gain_tbl_entry == -1) {
2974 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
2975 __func__);
2976 return false;
2977 }
2978
2979 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
2980 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
2981 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
2982 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2983 return false;
2984 }
2985
2986 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
2987 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
2988 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
2989 return false;
2990 }
2991
2992 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
2993 ++num_gain_tbl_entry;
2994
2995 return true;
2996}
2997
2998int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
2999 int table_size) {
3000 int itt = 0;
3001 ALOGV("platform_get_gain_level_mapping called ");
3002
3003 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3004 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3005 return 0;
3006 }
3007
3008 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3009 mapping_tbl[itt] = tbl_mapping[itt];
3010 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3011 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3012 }
3013
3014 return num_gain_tbl_entry;
3015}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003016
3017int platform_snd_card_update(void *platform, card_status_t status)
3018{
3019 struct platform_data *my_data = (struct platform_data *)platform;
3020 struct audio_device *adev = my_data->adev;
3021
3022 if (status == CARD_STATUS_ONLINE) {
3023 if (my_data->acdb_send_custom_top)
3024 my_data->acdb_send_custom_top();
3025 }
3026 return 0;
3027}
David Lin8c03e672017-02-06 20:31:38 -08003028
3029/*
3030 * configures afe with bit width and Sample Rate
3031 */
3032static int platform_set_backend_cfg(const struct audio_device* adev,
3033 snd_device_t snd_device,
3034 const struct audio_backend_cfg *backend_cfg)
3035{
3036
3037 int ret = 0;
3038 const int backend_idx = platform_get_backend_index(snd_device);
3039 struct platform_data *my_data = (struct platform_data *)adev->platform;
3040 const unsigned int bit_width = backend_cfg->bit_width;
3041 const unsigned int sample_rate = backend_cfg->sample_rate;
3042 const unsigned int channels = backend_cfg->channels;
3043 const audio_format_t format = backend_cfg->format;
3044 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3045
3046
3047 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3048 ", backend_idx %d device (%s)", __func__, bit_width,
3049 sample_rate, channels, backend_idx,
3050 platform_get_snd_device_name(snd_device));
3051
3052 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3053 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3054
3055 struct mixer_ctl *ctl = NULL;
3056 ctl = mixer_get_ctl_by_name(adev->mixer,
3057 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3058 if (!ctl) {
3059 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3060 __func__,
3061 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3062 return -EINVAL;
3063 }
3064
3065 if (bit_width == 24) {
3066 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3067 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3068 else
3069 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3070 } else if (bit_width == 32) {
3071 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3072 } else {
3073 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3074 }
3075 if ( ret < 0) {
3076 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3077 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3078 } else {
3079 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3080 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3081 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3082 }
3083 /* set the ret as 0 and not pass back to upper layer */
3084 ret = 0;
3085 }
3086
3087 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3088 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3089 char *rate_str = NULL;
3090 struct mixer_ctl *ctl = NULL;
3091
3092 switch (sample_rate) {
3093 case 32000:
3094 if (passthrough_enabled) {
3095 rate_str = "KHZ_32";
3096 break;
3097 }
3098 case 8000:
3099 case 11025:
3100 case 16000:
3101 case 22050:
3102 case 48000:
3103 rate_str = "KHZ_48";
3104 break;
3105 case 44100:
3106 rate_str = "KHZ_44P1";
3107 break;
3108 case 64000:
3109 case 96000:
3110 rate_str = "KHZ_96";
3111 break;
3112 case 88200:
3113 rate_str = "KHZ_88P2";
3114 break;
3115 case 176400:
3116 rate_str = "KHZ_176P4";
3117 break;
3118 case 192000:
3119 rate_str = "KHZ_192";
3120 break;
3121 case 352800:
3122 rate_str = "KHZ_352P8";
3123 break;
3124 case 384000:
3125 rate_str = "KHZ_384";
3126 break;
3127 case 144000:
3128 if (passthrough_enabled) {
3129 rate_str = "KHZ_144";
3130 break;
3131 }
3132 default:
3133 rate_str = "KHZ_48";
3134 break;
3135 }
3136
3137 ctl = mixer_get_ctl_by_name(adev->mixer,
3138 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3139 if(!ctl) {
3140 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3141 __func__,
3142 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3143 return -EINVAL;
3144 }
3145
3146 ALOGD("%s:becf: afe: %s set to %s", __func__,
3147 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3148 mixer_ctl_set_enum_by_string(ctl, rate_str);
3149 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3150 }
3151 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3152 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3153 struct mixer_ctl *ctl = NULL;
3154 char *channel_cnt_str = NULL;
3155
3156 switch (channels) {
3157 case 8:
3158 channel_cnt_str = "Eight"; break;
3159 case 7:
3160 channel_cnt_str = "Seven"; break;
3161 case 6:
3162 channel_cnt_str = "Six"; break;
3163 case 5:
3164 channel_cnt_str = "Five"; break;
3165 case 4:
3166 channel_cnt_str = "Four"; break;
3167 case 3:
3168 channel_cnt_str = "Three"; break;
3169 case 1:
3170 channel_cnt_str = "One"; break;
3171 case 2:
3172 default:
3173 channel_cnt_str = "Two"; break;
3174 }
3175
3176 ctl = mixer_get_ctl_by_name(adev->mixer,
3177 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3178 if (!ctl) {
3179 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3180 __func__,
3181 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3182 return -EINVAL;
3183 }
3184 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3185 my_data->current_backend_cfg[backend_idx].channels = channels;
3186
3187 // skip EDID configuration for HDMI backend
3188
3189 ALOGD("%s:becf: afe: %s set to %s", __func__,
3190 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3191 channel_cnt_str);
3192 }
3193
3194 // skip set ext_display format mixer control
3195 return ret;
3196}
3197
3198static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3199{
3200 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3201 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3202 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3203 }
3204
3205 return backend_bit_width_table[snd_device];
3206}
3207
3208/*
3209 * return backend_idx on which voice call is active
3210 */
3211static int platform_get_voice_call_backend(struct audio_device* adev)
3212{
3213 struct audio_usecase *uc = NULL;
3214 struct listnode *node;
3215 snd_device_t out_snd_device = SND_DEVICE_NONE;
3216
3217 int backend_idx = -1;
3218
3219 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3220 list_for_each(node, &adev->usecase_list) {
3221 uc = node_to_item(node, struct audio_usecase, list);
3222 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3223 out_snd_device = platform_get_output_snd_device(adev->platform,
3224 uc->stream.out->devices);
3225 backend_idx = platform_get_backend_index(out_snd_device);
3226 break;
3227 }
3228 }
3229 }
3230 return backend_idx;
3231}
3232
3233/*
3234 * goes through all the current usecases and picks the highest
3235 * bitwidth & samplerate
3236 */
3237static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3238 int backend_idx,
3239 struct audio_backend_cfg *backend_cfg)
3240{
3241 bool backend_change = false;
3242 unsigned int bit_width;
3243 unsigned int sample_rate;
3244 unsigned int channels;
3245 struct platform_data *my_data = (struct platform_data *)adev->platform;
3246
3247 bit_width = backend_cfg->bit_width;
3248 sample_rate = backend_cfg->sample_rate;
3249 channels = backend_cfg->channels;
3250
3251 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3252 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3253 sample_rate, channels);
3254
3255 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3256 // default backend
3257 // force routing is not required here, caller will do it anyway
3258 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3259 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3260 "for unprocessed/camera source", __func__);
3261 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3262 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3263 }
3264
3265 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3266 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3267 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3268 __func__, bit_width, sample_rate, channels);
3269 }
3270
3271 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3272 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3273
3274 // Force routing if the expected bitwdith or samplerate
3275 // is not same as current backend comfiguration
3276 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3277 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3278 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3279 backend_cfg->bit_width = bit_width;
3280 backend_cfg->sample_rate= sample_rate;
3281 backend_cfg->channels = channels;
3282 backend_change = true;
3283 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3284 "new sample rate: %d new channel: %d",
3285 __func__, backend_cfg->bit_width,
3286 backend_cfg->sample_rate, backend_cfg->channels);
3287 }
3288
3289 return backend_change;
3290}
3291
3292static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3293 struct audio_usecase* usecase,
3294 snd_device_t snd_device,
3295 struct audio_backend_cfg *backend_cfg)
3296{
3297 bool backend_change = false;
3298 struct listnode *node;
3299 unsigned int bit_width;
3300 unsigned int sample_rate;
3301 unsigned int channels;
3302 bool passthrough_enabled = false;
3303 int backend_idx = DEFAULT_CODEC_BACKEND;
3304 struct platform_data *my_data = (struct platform_data *)adev->platform;
3305 bool channels_updated = false;
3306
3307 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3308 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3309 backend_change = false;
3310 return backend_change;
3311 }
3312
3313 backend_idx = platform_get_backend_index(snd_device);
3314 bit_width = backend_cfg->bit_width;
3315 sample_rate = backend_cfg->sample_rate;
3316 channels = backend_cfg->channels;
3317
3318 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3319 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3320 sample_rate, channels, backend_idx, usecase->id,
3321 platform_get_snd_device_name(snd_device));
3322
3323 if (backend_idx == platform_get_voice_call_backend(adev)) {
3324 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3325 __func__);
3326 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3327 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3328 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3329 } else {
3330 /*
3331 * The backend should be configured at highest bit width and/or
3332 * sample rate amongst all playback usecases.
3333 * If the selected sample rate and/or bit width differ with
3334 * current backend sample rate and/or bit width, then, we set the
3335 * backend re-configuration flag.
3336 *
3337 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3338 */
3339
3340 int i =0;
3341 list_for_each(node, &adev->usecase_list) {
3342 struct audio_usecase *uc;
3343 uc = node_to_item(node, struct audio_usecase, list);
3344 struct stream_out *out = (struct stream_out*) uc->stream.out;
3345 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3346 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3347
3348 ALOGD("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3349 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3350 uc->id, out->sample_rate,
3351 pcm_format_to_bits(out->config.format), out_channels,
3352 platform_get_snd_device_name(uc->out_snd_device));
3353
3354 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3355 if (bit_width < pcm_format_to_bits(out->config.format))
3356 bit_width = pcm_format_to_bits(out->config.format);
3357 if (sample_rate < out->sample_rate)
3358 sample_rate = out->sample_rate;
3359 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3360 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3361 if (channels < out_channels)
3362 channels = out_channels;
3363 }
3364 }
3365 }
3366 }
3367
3368 /*
3369 * Check if the device is speaker or handset,assumption handset shares
3370 * backend with speaker, and these devices are restricited to 48kHz.
3371 */
3372 if (platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, snd_device)) {
3373
3374 if (bit_width >= 24) {
3375 bit_width = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
3376 ALOGD("%s:becf: afe: reset bitwidth to %d (based on supported"
3377 " value for this platform)", __func__, bit_width);
3378 }
3379 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3380 ALOGD("%s:becf: afe: playback on codec device not supporting native playback set "
3381 "default Sample Rate(48k)", __func__);
3382 }
3383
3384 if (backend_idx == USB_AUDIO_RX_BACKEND) {
3385 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, true);
3386 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3387 __func__, bit_width, sample_rate, channels);
3388 if (channels != my_data->current_backend_cfg[backend_idx].channels)
3389 channels_updated = true;
3390 }
3391
3392 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and sample rate: %d",
3393 __func__, backend_idx , bit_width, sample_rate);
3394
3395 // Force routing if the expected bitwdith or samplerate
3396 // is not same as current backend comfiguration
3397 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3398 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3399 passthrough_enabled || channels_updated) {
3400 backend_cfg->bit_width = bit_width;
3401 backend_cfg->sample_rate = sample_rate;
3402 backend_cfg->channels = channels;
3403 backend_cfg->passthrough_enabled = passthrough_enabled;
3404 backend_change = true;
3405 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3406 "new sample rate: %d new channels: %d",
3407 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3408 }
3409
3410 return backend_change;
3411}
3412
3413bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3414 struct audio_usecase *usecase, snd_device_t snd_device)
3415{
3416 int backend_idx = DEFAULT_CODEC_BACKEND;
3417 int new_snd_devices[SND_DEVICE_OUT_END];
3418 int i, num_devices = 1;
3419 bool ret = false;
3420 struct platform_data *my_data = (struct platform_data *)adev->platform;
3421 struct audio_backend_cfg backend_cfg;
3422
3423 backend_idx = platform_get_backend_index(snd_device);
3424
3425 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3426 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3427 backend_cfg.format = usecase->stream.out->format;
3428 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3429 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3430 backend_cfg.passthrough_enabled = false;
3431
3432 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3433 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3434 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3435 platform_get_snd_device_name(snd_device));
3436
3437 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3438 new_snd_devices[0] = snd_device;
3439
3440 for (i = 0; i < num_devices; i++) {
3441 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3442 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3443 &backend_cfg))) {
3444 platform_set_backend_cfg(adev, new_snd_devices[i],
3445 &backend_cfg);
3446 ret = true;
3447 }
3448 }
3449 return ret;
3450}
3451
3452bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3453 struct audio_usecase *usecase, snd_device_t snd_device)
3454{
3455 int backend_idx = platform_get_backend_index(snd_device);
3456 int ret = 0;
3457 struct audio_backend_cfg backend_cfg;
3458
3459 backend_cfg.passthrough_enabled = false;
3460
3461 if(usecase->type == PCM_CAPTURE) {
3462 backend_cfg.format= usecase->stream.in->format;
3463 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3464 } else {
3465 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3466 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3467 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3468 backend_cfg.channels = 1;
3469 }
3470
3471 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3472 ", backend_idx %d usecase = %d device (%s)", __func__,
3473 backend_cfg.bit_width,
3474 backend_cfg.sample_rate,
3475 backend_cfg.channels,
3476 backend_idx, usecase->id,
3477 platform_get_snd_device_name(snd_device));
3478
3479 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3480 ret = platform_set_backend_cfg(adev, snd_device,
3481 &backend_cfg);
3482 if(!ret)
3483 return true;
3484 }
3485
3486 return false;
3487}
3488