blob: 1ce9e53e03fb81063d2749e2074db15c6664562b [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 Linee3fe402017-03-13 10:00:42 -0700141 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 Linee3fe402017-03-13 10:00:42 -0700231 [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",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800237 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
238 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700239
240 /* Capture sound devices */
241 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700242 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700243 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
244 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
245 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
246 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
247 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
248 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
249 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
250
251 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
252 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
253 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
254 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
255 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
256 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
257 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
258 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
259 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
260
261 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500262 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700263
Eric Laurentb23d5282013-05-14 15:27:20 -0700264 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
265 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700266 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700267 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700268 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700269 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700270
271 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
272 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
273 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
274 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700275 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700276 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700277 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
278 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
279 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700280
Eric Laurentb23d5282013-05-14 15:27:20 -0700281 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700282 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700283 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700284 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700285 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
286 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700287 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700288 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700289
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700290 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700291 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
292 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
293 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
294 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800295
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700296 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700297
Prashant Malanic92c5962015-08-11 15:10:18 -0700298 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
299 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700300 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700301 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
302 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700303 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
304 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700305};
306
307/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700308static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700309 [SND_DEVICE_NONE] = -1,
310 [SND_DEVICE_OUT_HANDSET] = 7,
311 [SND_DEVICE_OUT_SPEAKER] = 15,
312 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700313 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700314 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500315 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700316 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700317 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500318 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700319 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700320 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
321 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500322 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700323 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500324 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700325 [SND_DEVICE_OUT_HDMI] = 18,
326 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
327 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700328 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700329 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700330 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
331 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
332 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700333 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700334 [SND_DEVICE_OUT_USB_HEADSET] = 45,
335 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
336 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700337 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
338 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700339 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700340
341 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700342 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
343 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
344 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
345 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
346 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
347 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
348 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
349 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
350
351 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
352 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
353 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
354 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
355 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
356 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
357 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
358 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
359 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
360
rago90fb9612015-12-02 11:37:53 -0800361 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500362 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700363
Eric Laurentb23d5282013-05-14 15:27:20 -0700364 [SND_DEVICE_IN_HDMI_MIC] = 4,
365 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700366 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700367 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700368 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700370
371 [SND_DEVICE_IN_VOICE_DMIC] = 41,
372 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
373 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700374 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700375 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800376 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700377 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
378 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
379 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700380
rago90fb9612015-12-02 11:37:53 -0800381 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700382 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700383 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700384 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700385 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
386 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800387 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
388
389 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
390 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700391 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
392 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
393 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700394
395 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700396 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700397 [SND_DEVICE_IN_THREE_MIC] = 46,
398 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700399 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700400 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
401 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700402 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
403 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700404};
405
David Linee3fe402017-03-13 10:00:42 -0700406// Platform specific backend bit width table
407static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
408
Haynes Mathew George98c95622014-06-20 19:14:25 -0700409struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700410 char name[100];
411 unsigned int index;
412};
413
414#define TO_NAME_INDEX(X) #X, X
415
Haynes Mathew George98c95622014-06-20 19:14:25 -0700416/* Used to get index from parsed string */
417static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
418 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700419 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
420 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
421 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700422 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700423 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500424 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700425 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700426 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500427 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700428 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700429 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
430 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700431 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700432 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500433 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700434 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
435 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
436 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
437 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700438 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500439 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700440 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
441 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
442 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800443 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
444 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
David Linee3fe402017-03-13 10:00:42 -0700445 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
446 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
447 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700448
449 /* in */
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700450 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
451 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700452 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700453 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700454 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
455 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
456 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
457 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
458 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
459 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
460 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
461
462 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700463 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700464 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
465 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
466 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
467 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
468 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
469 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
470 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
471
472 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700473 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700474
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700475 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
476 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700477 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700478 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700479 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700480 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700481
482 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
483 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
484 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700485 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700486 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
487 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700488 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
489 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
490 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700491
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700492 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700493 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700494 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700495 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700496 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
497 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700498 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700499 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700500
rago90fb9612015-12-02 11:37:53 -0800501 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700503 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
504 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
505 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800506
Prashant Malanic92c5962015-08-11 15:10:18 -0700507 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
508 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700509 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700510 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
511 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700512 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
513 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700514};
515
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700516static char * backend_tag_table[SND_DEVICE_MAX] = {0};
517static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700518
519static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
520 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
521 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
522 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
523 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700524 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
525 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800526 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700527 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
528 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800529 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700530 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
531 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
532 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
533 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
534 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800535 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
536 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700537 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
538 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
539 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
540 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800541 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
542 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
543 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
544 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
545 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700546};
547
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700548#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
549#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800550#define ULL_PLATFORM_DELAY (3*1000LL)
551#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700552
Eric Laurentb23d5282013-05-14 15:27:20 -0700553static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
554static bool is_tmus = false;
555
556static void check_operator()
557{
558 char value[PROPERTY_VALUE_MAX];
559 int mccmnc;
560 property_get("gsm.sim.operator.numeric",value,"0");
561 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700562 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700563 switch(mccmnc) {
564 /* TMUS MCC(310), MNC(490, 260, 026) */
565 case 310490:
566 case 310260:
567 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900568 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
569 case 310800:
570 case 310660:
571 case 310580:
572 case 310310:
573 case 310270:
574 case 310250:
575 case 310240:
576 case 310230:
577 case 310220:
578 case 310210:
579 case 310200:
580 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700581 is_tmus = true;
582 break;
583 }
584}
585
586bool is_operator_tmus()
587{
588 pthread_once(&check_op_once_ctl, check_operator);
589 return is_tmus;
590}
591
keunhui.park2f7306a2015-07-16 16:48:06 +0900592static char *get_current_operator()
593{
594 struct listnode *node;
595 struct operator_info *info_item;
596 char mccmnc[PROPERTY_VALUE_MAX];
597 char *ret = NULL;
598
Tom Cherry7fea2042016-11-10 18:05:59 -0800599 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900600
601 list_for_each(node, &operator_info_list) {
602 info_item = node_to_item(node, struct operator_info, list);
603 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
604 ret = info_item->name;
605 }
606 }
607
608 return ret;
609}
610
611static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
612{
613 struct listnode *node;
614 struct operator_specific_device *ret = NULL;
615 struct operator_specific_device *device_item;
616 char *operator_name;
617
618 operator_name = get_current_operator();
619 if (operator_name == NULL)
620 return ret;
621
622 list_for_each(node, operator_specific_device_table[snd_device]) {
623 device_item = node_to_item(node, struct operator_specific_device, list);
624 if (strcmp(operator_name, device_item->operator) == 0) {
625 ret = device_item;
626 }
627 }
628
629 return ret;
630}
631
632
633static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
634{
635 struct operator_specific_device *device;
636 int ret = acdb_device_table[snd_device];
637
638 device = get_operator_specific_device(snd_device);
639 if (device != NULL)
640 ret = device->acdb_id;
641
642 return ret;
643}
644
645static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
646{
647 struct operator_specific_device *device;
648 const char *ret = device_table[snd_device];
649
650 device = get_operator_specific_device(snd_device);
651 if (device != NULL)
652 ret = device->mixer_path;
653
654 return ret;
655}
656
vivek mehta1a9b7c02015-06-25 11:49:38 -0700657bool platform_send_gain_dep_cal(void *platform, int level)
658{
659 bool ret_val = false;
660 struct platform_data *my_data = (struct platform_data *)platform;
661 struct audio_device *adev = my_data->adev;
662 int acdb_dev_id, app_type;
663 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
664 int mode = CAL_MODE_RTAC;
665 struct listnode *node;
666 struct audio_usecase *usecase;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700667
668 if (my_data->acdb_send_gain_dep_cal == NULL) {
669 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
670 return ret_val;
671 }
672
673 if (!voice_is_in_call(adev)) {
674 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
675 __func__, level);
676 app_type = DEFAULT_APP_TYPE_RX_PATH;
677
678 // find the current active sound device
679 list_for_each(node, &adev->usecase_list) {
680 usecase = node_to_item(node, struct audio_usecase, list);
681
682 if (usecase != NULL &&
683 usecase->type == PCM_PLAYBACK &&
684 (usecase->stream.out->devices == AUDIO_DEVICE_OUT_SPEAKER)) {
685
686 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
vivek mehta4cb82982015-07-13 12:05:49 -0700687 if (audio_extn_spkr_prot_is_enabled()) {
688 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
689 } else {
690 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
691 }
692
vivek mehta1a9b7c02015-06-25 11:49:38 -0700693 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
694 acdb_dev_type, mode, level)) {
695 // set ret_val true if at least one calibration is set successfully
696 ret_val = true;
697 } else {
698 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
699 }
700 } else {
701 ALOGW("%s: Usecase list is empty", __func__);
702 }
703 }
704 } else {
705 ALOGW("%s: Voice call in progress .. ignore setting new cal",
706 __func__);
707 }
708 return ret_val;
709}
710
Eric Laurentcefbbac2014-09-04 13:54:10 -0500711void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700712{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800713 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500714 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700715
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800716 if (strcmp(my_data->ec_ref_mixer_path, "")) {
717 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
718 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500719 }
720
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800721 if (enable) {
722 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
723 if (out_device != AUDIO_DEVICE_NONE) {
724 snd_device = platform_get_output_snd_device(adev->platform, out_device);
725 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
726 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500727
Joe Onorato188b6222016-03-01 11:02:27 -0800728 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800729 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
730 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700731}
732
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700733static struct csd_data *open_csd_client(bool i2s_ext_modem)
734{
735 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
736
737 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
738 if (csd->csd_client == NULL) {
739 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
740 goto error;
741 } else {
742 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
743
744 csd->deinit = (deinit_t)dlsym(csd->csd_client,
745 "csd_client_deinit");
746 if (csd->deinit == NULL) {
747 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
748 dlerror());
749 goto error;
750 }
751 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
752 "csd_client_disable_device");
753 if (csd->disable_device == NULL) {
754 ALOGE("%s: dlsym error %s for csd_client_disable_device",
755 __func__, dlerror());
756 goto error;
757 }
758 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
759 "csd_client_enable_device_config");
760 if (csd->enable_device_config == NULL) {
761 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
762 __func__, dlerror());
763 goto error;
764 }
765 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
766 "csd_client_enable_device");
767 if (csd->enable_device == NULL) {
768 ALOGE("%s: dlsym error %s for csd_client_enable_device",
769 __func__, dlerror());
770 goto error;
771 }
772 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
773 "csd_client_start_voice");
774 if (csd->start_voice == NULL) {
775 ALOGE("%s: dlsym error %s for csd_client_start_voice",
776 __func__, dlerror());
777 goto error;
778 }
779 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
780 "csd_client_stop_voice");
781 if (csd->stop_voice == NULL) {
782 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
783 __func__, dlerror());
784 goto error;
785 }
786 csd->volume = (volume_t)dlsym(csd->csd_client,
787 "csd_client_volume");
788 if (csd->volume == NULL) {
789 ALOGE("%s: dlsym error %s for csd_client_volume",
790 __func__, dlerror());
791 goto error;
792 }
793 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
794 "csd_client_mic_mute");
795 if (csd->mic_mute == NULL) {
796 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
797 __func__, dlerror());
798 goto error;
799 }
800 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
801 "csd_client_slow_talk");
802 if (csd->slow_talk == NULL) {
803 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
804 __func__, dlerror());
805 goto error;
806 }
807 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
808 "csd_client_start_playback");
809 if (csd->start_playback == NULL) {
810 ALOGE("%s: dlsym error %s for csd_client_start_playback",
811 __func__, dlerror());
812 goto error;
813 }
814 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
815 "csd_client_stop_playback");
816 if (csd->stop_playback == NULL) {
817 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
818 __func__, dlerror());
819 goto error;
820 }
821 csd->start_record = (start_record_t)dlsym(csd->csd_client,
822 "csd_client_start_record");
823 if (csd->start_record == NULL) {
824 ALOGE("%s: dlsym error %s for csd_client_start_record",
825 __func__, dlerror());
826 goto error;
827 }
828 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
829 "csd_client_stop_record");
830 if (csd->stop_record == NULL) {
831 ALOGE("%s: dlsym error %s for csd_client_stop_record",
832 __func__, dlerror());
833 goto error;
834 }
835
836 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
837 "csd_client_get_sample_rate");
838 if (csd->get_sample_rate == NULL) {
839 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
840 __func__, dlerror());
841
842 goto error;
843 }
844
845 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
846
847 if (csd->init == NULL) {
848 ALOGE("%s: dlsym error %s for csd_client_init",
849 __func__, dlerror());
850 goto error;
851 } else {
852 csd->init(i2s_ext_modem);
853 }
854 }
855 return csd;
856
857error:
858 free(csd);
859 csd = NULL;
860 return csd;
861}
862
863void close_csd_client(struct csd_data *csd)
864{
865 if (csd != NULL) {
866 csd->deinit();
867 dlclose(csd->csd_client);
868 free(csd);
869 csd = NULL;
870 }
871}
872
873static void platform_csd_init(struct platform_data *my_data)
874{
875#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700876 int32_t modems, (*count_modems)(void);
877 const char *name = "libdetectmodem.so";
878 const char *func = "count_modems";
879 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700880
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700881 my_data->csd = NULL;
882
883 void *lib = dlopen(name, RTLD_NOW);
884 error = dlerror();
885 if (!lib) {
886 ALOGE("%s: could not find %s: %s", __func__, name, error);
887 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700888 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700889
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700890 count_modems = NULL;
891 *(void **)(&count_modems) = dlsym(lib, func);
892 error = dlerror();
893 if (!count_modems) {
894 ALOGE("%s: could not find symbol %s in %s: %s",
895 __func__, func, name, error);
896 goto done;
897 }
898
899 modems = count_modems();
900 if (modems < 0) {
901 ALOGE("%s: count_modems failed\n", __func__);
902 goto done;
903 }
904
Eric Laurent2bafff12016-03-17 12:17:23 -0700905 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700906 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700907 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700908
909done:
910 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700911#else
912 my_data->csd = NULL;
913#endif
914}
915
Eric Laurentc6333382015-09-14 12:43:44 -0700916static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -0700917{
918 int32_t dev;
919 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700920 backend_tag_table[dev] = NULL;
921 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +0900922 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700923 }
924
David Linee3fe402017-03-13 10:00:42 -0700925 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
926 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
927 }
928
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700929 // To overwrite these go to the audio_platform_info.xml file.
930 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700931 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700932 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
933 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
934 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
935 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
936 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700937 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700938 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
939 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -0700940
David Linee3fe402017-03-13 10:00:42 -0700941 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
942 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
943 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
944 strdup("speaker-and-usb-headphones");
945 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700946 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
947 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
948 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
949 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
950 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
951 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
952 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700953 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700954 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700955 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700956 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
957 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
958 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
959 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
960 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
961 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
962 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
963 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
964 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
965 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
966 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
967 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
968 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -0700969 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
970 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
971 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 -0700972 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
973 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
974 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Eric Laurentc6333382015-09-14 12:43:44 -0700975
976 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -0700977}
978
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +0900979void get_cvd_version(char *cvd_version, struct audio_device *adev)
980{
981 struct mixer_ctl *ctl;
982 int count;
983 int ret = 0;
984
985 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
986 if (!ctl) {
987 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
988 goto done;
989 }
990 mixer_ctl_update(ctl);
991
992 count = mixer_ctl_get_num_values(ctl);
993 if (count > MAX_CVD_VERSION_STRING_SIZE)
994 count = MAX_CVD_VERSION_STRING_SIZE - 1;
995
996 ret = mixer_ctl_get_array(ctl, cvd_version, count);
997 if (ret != 0) {
998 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
999 goto done;
1000 }
1001
1002done:
1003 return;
1004}
1005
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001006static int platform_acdb_init(void *platform)
1007{
1008 struct platform_data *my_data = (struct platform_data *)platform;
1009 struct audio_device *adev = my_data->adev;
1010
1011 if (!my_data->acdb_init) {
1012 ALOGE("%s: no acdb_init fn provided", __func__);
1013 return -1;
1014 }
1015
1016 if (my_data->acdb_initialized) {
1017 ALOGW("acdb is already initialized");
1018 return 0;
1019 }
1020
Thierry Strudel92232b42017-01-26 10:51:48 -08001021#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001022 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1023 if (!cvd_version)
1024 ALOGE("failed to allocate cvd_version");
1025 else {
1026 get_cvd_version(cvd_version, adev);
1027 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1028 free(cvd_version);
1029 }
1030#elif defined (PLATFORM_MSM8084)
1031 my_data->acdb_init((char *)my_data->snd_card_name);
1032#else
1033 my_data->acdb_init();
1034#endif
1035 my_data->acdb_initialized = true;
1036 return 0;
1037}
1038
David Linee3fe402017-03-13 10:00:42 -07001039static void
1040platform_backend_config_init(struct platform_data *pdata)
1041{
1042 int i;
1043
1044 /* initialize backend config */
1045 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1046 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1047 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1048 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1049
1050 if (i > MAX_RX_CODEC_BACKENDS)
1051 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1052
1053 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1054 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1055 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1056 }
1057
1058 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1059 strdup("SLIM_0_RX Format");
1060 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1061 strdup("SLIM_0_RX SampleRate");
1062
1063 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1064 strdup("SLIM_0_TX Format");
1065 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1066 strdup("SLIM_0_TX SampleRate");
1067
1068 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1069 strdup("USB_AUDIO_TX Format");
1070 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1071 strdup("USB_AUDIO_TX SampleRate");
1072 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1073 strdup("USB_AUDIO_TX Channels");
1074
1075 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1076 strdup("SLIM_6_RX Format");
1077 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1078 strdup("SLIM_6_RX SampleRate");
1079
1080 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1081 strdup("USB_AUDIO_RX Format");
1082 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1083 strdup("USB_AUDIO_RX SampleRate");
1084
1085 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1086 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1087 strdup("USB_AUDIO_RX Channels");
1088}
1089
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001090// Treblized config files will be located in /odm/etc or /vendor/etc.
1091static const char *kConfigLocationList[] =
1092 {"/odm/etc", "/vendor/etc", "/system/etc"};
1093static const int kConfigLocationListSize =
1094 (sizeof(kConfigLocationList) / sizeof(kConfigLocationList[0]));
1095
1096bool resolveConfigFile(char file_name[MIXER_PATH_MAX_LENGTH]) {
1097 char full_config_path[MIXER_PATH_MAX_LENGTH];
1098 for (int i = 0; i < kConfigLocationListSize; i++) {
1099 snprintf(full_config_path,
1100 MIXER_PATH_MAX_LENGTH,
1101 "%s/%s",
1102 kConfigLocationList[i],
1103 file_name);
1104 if (F_OK == access(full_config_path, 0)) {
1105 strcpy(file_name, full_config_path);
1106 return true;
1107 }
1108 }
1109 return false;
1110}
1111
Eric Laurentb23d5282013-05-14 15:27:20 -07001112void *platform_init(struct audio_device *adev)
1113{
1114 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001115 struct platform_data *my_data = NULL;
1116 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1117 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001118 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001119 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001120 char *snd_internal_name = NULL;
1121 char *tmp = NULL;
1122 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001123 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1124 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001125 my_data = calloc(1, sizeof(struct platform_data));
1126
1127 my_data->adev = adev;
1128
keunhui.park2f7306a2015-07-16 16:48:06 +09001129 list_init(&operator_info_list);
1130
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001131 set_platform_defaults(my_data);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001132 bool card_verifed[MAX_SND_CARD] = {0};
1133 const int retry_limit = property_get_int32("audio.snd_card.open.retries", RETRY_NUMBER);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001134
vivek mehta2b0e5a62016-09-02 17:31:58 -07001135 for (;;) {
1136 if (snd_card_num >= MAX_SND_CARD) {
1137 if (retry_num++ >= retry_limit) {
1138 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1139 goto init_failed;
1140 }
sangwoo1b9f4b32013-06-21 18:22:55 -07001141
vivek mehta2b0e5a62016-09-02 17:31:58 -07001142 snd_card_num = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001143 usleep(RETRY_US);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001144 continue;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001145 }
1146
vivek mehta2b0e5a62016-09-02 17:31:58 -07001147 if (card_verifed[snd_card_num]) {
1148 ++snd_card_num;
1149 continue;
1150 }
1151
1152 adev->mixer = mixer_open(snd_card_num);
1153
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001154 if (!adev->mixer) {
1155 ALOGE("%s: Unable to open the mixer card: %d", __func__,
vivek mehta2b0e5a62016-09-02 17:31:58 -07001156 snd_card_num);
1157 ++snd_card_num;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001158 continue;
1159 }
1160
vivek mehta2b0e5a62016-09-02 17:31:58 -07001161 card_verifed[snd_card_num] = true;
1162
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001163 snd_card_name = mixer_get_name(adev->mixer);
vivek mehtade4849c2016-03-03 17:23:38 -08001164 my_data->hw_info = hw_info_init(snd_card_name);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001165
vivek mehtade4849c2016-03-03 17:23:38 -08001166 audio_extn_set_snd_card_split(snd_card_name);
1167 snd_split_handle = audio_extn_get_snd_card_split();
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001168
vivek mehtade4849c2016-03-03 17:23:38 -08001169 /* Get the codec internal name from the sound card and/or form factor
1170 * name and form the mixer paths and platfor info file name dynamically.
1171 * This is generic way of picking any codec and forma factor name based
1172 * mixer and platform info files in future with no code change.
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001173
vivek mehtade4849c2016-03-03 17:23:38 -08001174 * current code extends and looks for any of the exteneded mixer path and
1175 * platform info file present based on codec and form factor.
vivek mehta60ea4152016-02-18 17:10:26 -08001176
vivek mehtade4849c2016-03-03 17:23:38 -08001177 * order of picking appropriate file is
1178 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1179 * <ii> mixer_paths_<codec_name>.xml, if file not present
1180 * <iii> mixer_paths.xml
1181
1182 * same order is followed for audio_platform_info.xml as well
1183 */
1184
1185 // need to carryforward old file name
1186 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
Eric Laurentf9583c32016-03-28 13:50:50 -07001187 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
vivek mehtade4849c2016-03-03 17:23:38 -08001188 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
vivek mehta60ea4152016-02-18 17:10:26 -08001189 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
vivek mehtade4849c2016-03-03 17:23:38 -08001190 } else {
Ed Tamb0b0d572016-03-21 10:45:37 -07001191
vivek mehtade4849c2016-03-03 17:23:38 -08001192 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1193 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1194 snd_split_handle->form_factor);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001195 if (!resolveConfigFile(mixer_xml_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001196 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1197 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1198 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1199
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001200 if (!resolveConfigFile(mixer_xml_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001201 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1202 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001203 resolveConfigFile(mixer_xml_file);
vivek mehtade4849c2016-03-03 17:23:38 -08001204 }
1205 }
1206
1207 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s_%s.xml",
1208 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card,
1209 snd_split_handle->form_factor);
1210
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001211 if (!resolveConfigFile(platform_info_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001212 memset(platform_info_file, 0, sizeof(platform_info_file));
1213 snprintf(platform_info_file, sizeof(platform_info_file), "%s_%s.xml",
1214 PLATFORM_INFO_XML_BASE_STRING, snd_split_handle->snd_card);
1215
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001216 if (!resolveConfigFile(platform_info_file)) {
vivek mehtade4849c2016-03-03 17:23:38 -08001217 memset(platform_info_file, 0, sizeof(platform_info_file));
1218 strlcpy(platform_info_file, PLATFORM_INFO_XML_PATH, MIXER_PATH_MAX_LENGTH);
Jaekyun Seokf62e17d2017-03-08 17:15:28 +09001219 resolveConfigFile(platform_info_file);
vivek mehta60ea4152016-02-18 17:10:26 -08001220 }
1221 }
Uday Kishore Pasupuleti11dd2232015-06-24 14:18:01 -07001222 }
1223
vivek mehtade4849c2016-03-03 17:23:38 -08001224 /* Initialize platform specific ids and/or backends*/
1225 platform_info_init(platform_info_file, my_data);
1226
1227 /* validate the sound card name
1228 * my_data->snd_card_name can contain
1229 * <a> complete sound card name, i.e. <device>-<codec>-<form_factor>-snd-card
1230 * example: msm8994-tomtom-mtp-snd-card
1231 * <b> or sub string of the card name, i.e. <device>-<codec>
1232 * example: msm8994-tomtom
Eric Laurentf9583c32016-03-28 13:50:50 -07001233 * snd_card_name is truncated to 32 charaters as per mixer_get_name() implementation
1234 * so use min of my_data->snd_card_name and snd_card_name length for comparison
vivek mehtade4849c2016-03-03 17:23:38 -08001235 */
1236
1237 if (my_data->snd_card_name != NULL &&
Eric Laurentf9583c32016-03-28 13:50:50 -07001238 strncmp(snd_card_name, my_data->snd_card_name,
1239 min(strlen(snd_card_name), strlen(my_data->snd_card_name))) != 0) {
vivek mehtade4849c2016-03-03 17:23:38 -08001240 ALOGI("%s: found valid sound card %s, but not primary sound card %s",
1241 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001242 ++snd_card_num;
1243 mixer_close(adev->mixer);
1244 adev->mixer = NULL;
vivek mehtade4849c2016-03-03 17:23:38 -08001245 hw_info_deinit(my_data->hw_info);
1246 my_data->hw_info = NULL;
1247 continue;
Ed Tam70b5c142016-03-21 19:14:29 -07001248 }
vivek mehtade4849c2016-03-03 17:23:38 -08001249 ALOGI("%s: found sound card %s, primary sound card expeted is %s",
1250 __func__, snd_card_name, my_data->snd_card_name);
vivek mehta60ea4152016-02-18 17:10:26 -08001251
1252 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1253 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1254
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001255 if (!adev->audio_route) {
1256 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
vivek mehta2b0e5a62016-09-02 17:31:58 -07001257 mixer_close(adev->mixer);
1258 adev->mixer = NULL;
1259 hw_info_deinit(my_data->hw_info);
1260 my_data->hw_info = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001261 goto init_failed;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001262 }
1263 adev->snd_card = snd_card_num;
Eric Laurent2bafff12016-03-17 12:17:23 -07001264 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001265 break;
sangwoo1b9f4b32013-06-21 18:22:55 -07001266 }
1267
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001268 //set max volume step for voice call
1269 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1270 my_data->max_vol_index = atoi(value);
1271
vivek mehta65ad12d2015-08-13 18:32:48 -07001272 property_get("persist.audio.dualmic.config",value,"");
1273 if (!strcmp("endfire", value)) {
1274 dual_mic_config = true;
1275 }
1276
Prashant Malanic92c5962015-08-11 15:10:18 -07001277 my_data->source_mic_type = SOURCE_DUAL_MIC;
1278
Eric Laurentb23d5282013-05-14 15:27:20 -07001279 my_data->fluence_in_spkr_mode = false;
1280 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001281 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001282 my_data->fluence_in_voice_rec = false;
1283
vivek mehta65ad12d2015-08-13 18:32:48 -07001284 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001285 if (!strcmp("fluencepro", value)) {
1286 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001287 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001288 my_data->fluence_type = FLUENCE_ENABLE;
1289 } else if (!strcmp("none", value)) {
1290 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001291 }
1292
Prashant Malanic92c5962015-08-11 15:10:18 -07001293 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001294 property_get("persist.audio.fluence.voicecall",value,"");
1295 if (!strcmp("true", value)) {
1296 my_data->fluence_in_voice_call = true;
1297 }
1298
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001299 property_get("persist.audio.fluence.voicecomm",value,"");
1300 if (!strcmp("true", value)) {
1301 my_data->fluence_in_voice_comm = true;
1302 }
1303
Eric Laurentb23d5282013-05-14 15:27:20 -07001304 property_get("persist.audio.fluence.voicerec",value,"");
1305 if (!strcmp("true", value)) {
1306 my_data->fluence_in_voice_rec = true;
1307 }
1308
1309 property_get("persist.audio.fluence.speaker",value,"");
1310 if (!strcmp("true", value)) {
1311 my_data->fluence_in_spkr_mode = true;
1312 }
1313 }
1314
Prashant Malanic92c5962015-08-11 15:10:18 -07001315 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1316 switch (my_data->max_mic_count) {
1317 case 4:
1318 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1319 case 3:
1320 my_data->source_mic_type |= SOURCE_THREE_MIC;
1321 case 2:
1322 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1323 case 1:
1324 my_data->source_mic_type |= SOURCE_MONO_MIC;
1325 break;
1326 default:
1327 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1328 __func__, my_data->max_mic_count);
1329 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1330 break;
1331 }
1332
1333 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1334 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1335 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1336 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1337 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1338
Eric Laurentb23d5282013-05-14 15:27:20 -07001339 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1340 if (my_data->acdb_handle == NULL) {
1341 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1342 } else {
1343 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1344 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1345 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001346 if (!my_data->acdb_deallocate)
1347 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1348 __func__, LIB_ACDB_LOADER);
1349
Eric Laurentb23d5282013-05-14 15:27:20 -07001350 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1351 "acdb_loader_send_audio_cal");
1352 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001353 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001354 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001355
Eric Laurentb23d5282013-05-14 15:27:20 -07001356 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1357 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001358 if (!my_data->acdb_send_voice_cal)
1359 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1360 __func__, LIB_ACDB_LOADER);
1361
1362 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1363 "acdb_loader_reload_vocvoltable");
1364 if (!my_data->acdb_reload_vocvoltable)
1365 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1366 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001367
1368 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1369 "acdb_loader_send_gain_dep_cal");
1370 if (!my_data->acdb_send_gain_dep_cal)
1371 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1372 __func__, LIB_ACDB_LOADER);
1373
Thierry Strudel92232b42017-01-26 10:51:48 -08001374#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998)
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001375 acdb_init_v2_cvd_t acdb_init;
1376 acdb_init = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
1377 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001378 if (acdb_init == NULL)
1379 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1380 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001381
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001382#elif defined (PLATFORM_MSM8084)
1383 acdb_init_v2_t acdb_init;
1384 acdb_init = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
1385 "acdb_loader_init_v2");
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001386 if (acdb_init == NULL)
1387 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1388 dlerror());
1389
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001390#else
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001391 acdb_init_t acdb_init;
1392 acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001393 "acdb_loader_init_ACDB");
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001394 if (acdb_init == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001395 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1396 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001397#endif
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001398 my_data->acdb_init = acdb_init;
Eric Laurentb23d5282013-05-14 15:27:20 -07001399
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001400 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1401 dlsym(my_data->acdb_handle,
1402 "acdb_loader_send_common_custom_topology");
1403
1404 if (!my_data->acdb_send_custom_top)
1405 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1406 __func__, LIB_ACDB_LOADER);
1407
1408 platform_acdb_init(my_data);
1409 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001410
David Linee3fe402017-03-13 10:00:42 -07001411 /* init usb */
1412 audio_extn_usb_init(adev);
1413
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001414 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001415
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001416 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1417
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001418 /* load csd client */
1419 platform_csd_init(my_data);
1420
David Linee3fe402017-03-13 10:00:42 -07001421 platform_backend_config_init(my_data);
1422
Eric Laurentb23d5282013-05-14 15:27:20 -07001423 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001424
1425init_failed:
1426 if (my_data)
1427 free(my_data);
1428 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001429}
1430
1431void platform_deinit(void *platform)
1432{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001433 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001434 struct operator_info *info_item;
1435 struct operator_specific_device *device_item;
1436 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001437
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001438 struct platform_data *my_data = (struct platform_data *)platform;
1439 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001440
vivek mehtade4849c2016-03-03 17:23:38 -08001441 hw_info_deinit(my_data->hw_info);
1442
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001443 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1444 if (backend_tag_table[dev])
1445 free(backend_tag_table[dev]);
1446 if (hw_interface_table[dev])
1447 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001448 if (operator_specific_device_table[dev]) {
1449 while (!list_empty(operator_specific_device_table[dev])) {
1450 node = list_head(operator_specific_device_table[dev]);
1451 list_remove(node);
1452 device_item = node_to_item(node, struct operator_specific_device, list);
1453 free(device_item->operator);
1454 free(device_item->mixer_path);
1455 free(device_item);
1456 }
1457 free(operator_specific_device_table[dev]);
1458 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001459 }
1460
1461 if (my_data->snd_card_name)
1462 free(my_data->snd_card_name);
1463
keunhui.park2f7306a2015-07-16 16:48:06 +09001464 while (!list_empty(&operator_info_list)) {
1465 node = list_head(&operator_info_list);
1466 list_remove(node);
1467 info_item = node_to_item(node, struct operator_info, list);
1468 free(info_item->name);
1469 free(info_item->mccmnc);
1470 free(info_item);
1471 }
1472
Eric Laurentb23d5282013-05-14 15:27:20 -07001473 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001474
1475 /* deinit usb */
1476 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001477}
1478
1479const char *platform_get_snd_device_name(snd_device_t snd_device)
1480{
keunhui.park2f7306a2015-07-16 16:48:06 +09001481 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1482 if (operator_specific_device_table[snd_device] != NULL) {
1483 return get_operator_specific_device_mixer_path(snd_device);
1484 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001485 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001486 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001487 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001488}
1489
vivek mehtade4849c2016-03-03 17:23:38 -08001490int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1491 char *device_name)
1492{
1493 struct platform_data *my_data = (struct platform_data *)platform;
1494
David Benjamin1565f992016-09-21 12:10:34 -04001495 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001496 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001497 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1498 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001499 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1500 if (operator_specific_device_table[snd_device] != NULL) {
1501 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1502 DEVICE_NAME_MAX_SIZE);
1503 } else {
1504 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1505 }
1506 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1507 } else {
1508 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1509 }
1510
1511 return 0;
1512}
1513
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001514void platform_add_backend_name(void *platform, char *mixer_path,
1515 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001516{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001517 struct platform_data *my_data = (struct platform_data *)platform;
1518
Haynes Mathew George98c95622014-06-20 19:14:25 -07001519 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1520 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1521 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001522 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001523
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001524 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001525
1526 if (suffix != NULL) {
1527 strcat(mixer_path, " ");
1528 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001529 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001530}
1531
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001532bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1533{
1534 bool result = true;
1535
1536 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1537 platform_get_snd_device_name(snd_device1),
1538 platform_get_snd_device_name(snd_device2));
1539
1540 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1541 ALOGE("%s: Invalid snd_device = %s", __func__,
1542 platform_get_snd_device_name(snd_device1));
1543 return false;
1544 }
1545 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1546 ALOGE("%s: Invalid snd_device = %s", __func__,
1547 platform_get_snd_device_name(snd_device2));
1548 return false;
1549 }
1550 const char * be_itf1 = hw_interface_table[snd_device1];
1551 const char * be_itf2 = hw_interface_table[snd_device2];
1552
1553 if (NULL != be_itf1 && NULL != be_itf2) {
Eric Laurente63e61d2015-09-10 12:19:33 -07001554 if ((NULL == strstr(be_itf2, be_itf1)) && (NULL == strstr(be_itf1, be_itf2)))
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001555 result = false;
1556 }
1557
1558 ALOGV("%s: be_itf1 = %s, be_itf2 = %s, match %d", __func__, be_itf1, be_itf2, result);
1559 return result;
1560}
1561
Eric Laurentb23d5282013-05-14 15:27:20 -07001562int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1563{
1564 int device_id;
1565 if (device_type == PCM_PLAYBACK)
1566 device_id = pcm_device_table[usecase][0];
1567 else
1568 device_id = pcm_device_table[usecase][1];
1569 return device_id;
1570}
1571
Haynes Mathew George98c95622014-06-20 19:14:25 -07001572static int find_index(const struct name_to_index * table, int32_t len,
1573 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001574{
1575 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001576 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001577
Haynes Mathew George98c95622014-06-20 19:14:25 -07001578 if (table == NULL) {
1579 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001580 ret = -ENODEV;
1581 goto done;
1582 }
1583
Haynes Mathew George98c95622014-06-20 19:14:25 -07001584 if (name == NULL) {
1585 ALOGE("null key");
1586 ret = -ENODEV;
1587 goto done;
1588 }
1589
1590 for (i=0; i < len; i++) {
1591 if (!strcmp(table[i].name, name)) {
1592 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001593 goto done;
1594 }
1595 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001596 ALOGE("%s: Could not find index for name = %s",
1597 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001598 ret = -ENODEV;
1599done:
1600 return ret;
1601}
1602
Haynes Mathew George98c95622014-06-20 19:14:25 -07001603int platform_get_snd_device_index(char *device_name)
1604{
1605 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1606}
1607
1608int platform_get_usecase_index(const char *usecase_name)
1609{
1610 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1611}
1612
keunhui.park2f7306a2015-07-16 16:48:06 +09001613void platform_add_operator_specific_device(snd_device_t snd_device,
1614 const char *operator,
1615 const char *mixer_path,
1616 unsigned int acdb_id)
1617{
1618 struct operator_specific_device *device;
1619
1620 if (operator_specific_device_table[snd_device] == NULL) {
1621 operator_specific_device_table[snd_device] =
1622 (struct listnode *)calloc(1, sizeof(struct listnode));
1623 list_init(operator_specific_device_table[snd_device]);
1624 }
1625
1626 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1627
1628 device->operator = strdup(operator);
1629 device->mixer_path = strdup(mixer_path);
1630 device->acdb_id = acdb_id;
1631
1632 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1633
Eric Laurent2bafff12016-03-17 12:17:23 -07001634 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001635 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1636
1637}
1638
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001639int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1640{
1641 int ret = 0;
1642
1643 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1644 ALOGE("%s: Invalid snd_device = %d",
1645 __func__, snd_device);
1646 ret = -EINVAL;
1647 goto done;
1648 }
1649
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001650 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1651 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001652 acdb_device_table[snd_device] = acdb_id;
1653done:
1654 return ret;
1655}
1656
Glenn Kastencbe06ca2016-11-09 10:49:26 -08001657int platform_get_default_app_type_v2(void *platform __unused, usecase_type_t type __unused,
1658 int *app_type __unused)
Yamit Mehtae3b99562016-09-16 22:44:00 +05301659{
1660 ALOGE("%s: Not implemented", __func__);
1661 return -ENOSYS;
1662}
1663
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001664int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1665{
1666 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1667 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1668 return -EINVAL;
1669 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001670
1671 if (operator_specific_device_table[snd_device] != NULL)
1672 return get_operator_specific_device_acdb_id(snd_device);
1673 else
1674 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001675}
1676
David Linee3fe402017-03-13 10:00:42 -07001677static int platform_get_backend_index(snd_device_t snd_device)
1678{
1679 int32_t port = DEFAULT_CODEC_BACKEND;
1680
1681 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1682 if (backend_tag_table[snd_device] != NULL) {
1683 if (strncmp(backend_tag_table[snd_device], "headphones",
1684 sizeof("headphones")) == 0)
1685 port = HEADPHONE_BACKEND;
1686 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1687 port = HDMI_RX_BACKEND;
1688 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1689 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1690 port = USB_AUDIO_RX_BACKEND;
1691 }
1692 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1693 port = DEFAULT_CODEC_TX_BACKEND;
1694 if (backend_tag_table[snd_device] != NULL) {
1695 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1696 port = USB_AUDIO_TX_BACKEND;
1697 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1698 port = BT_SCO_TX_BACKEND;
1699 }
1700 } else {
1701 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1702 }
1703
1704 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1705
1706 return port;
1707}
1708
Eric Laurentb23d5282013-05-14 15:27:20 -07001709int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1710{
1711 struct platform_data *my_data = (struct platform_data *)platform;
1712 int acdb_dev_id, acdb_dev_type;
1713
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001714 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001715 if (acdb_dev_id < 0) {
1716 ALOGE("%s: Could not find acdb id for device(%d)",
1717 __func__, snd_device);
1718 return -EINVAL;
1719 }
1720 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001721 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001722 __func__, snd_device, acdb_dev_id);
1723 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1724 snd_device < SND_DEVICE_OUT_END)
1725 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1726 else
1727 acdb_dev_type = ACDB_DEV_TYPE_IN;
1728 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1729 }
1730 return 0;
1731}
1732
1733int platform_switch_voice_call_device_pre(void *platform)
1734{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001735 struct platform_data *my_data = (struct platform_data *)platform;
1736 int ret = 0;
1737
1738 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001739 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001740 /* This must be called before disabling mixer controls on APQ side */
1741 ret = my_data->csd->disable_device();
1742 if (ret < 0) {
1743 ALOGE("%s: csd_client_disable_device, failed, error %d",
1744 __func__, ret);
1745 }
1746 }
1747 return ret;
1748}
1749
1750int platform_switch_voice_call_enable_device_config(void *platform,
1751 snd_device_t out_snd_device,
1752 snd_device_t in_snd_device)
1753{
1754 struct platform_data *my_data = (struct platform_data *)platform;
1755 int acdb_rx_id, acdb_tx_id;
1756 int ret = 0;
1757
1758 if (my_data->csd == NULL)
1759 return ret;
1760
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001761 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1762 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001763 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001764 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001765 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001766
keunhui.park2f7306a2015-07-16 16:48:06 +09001767 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001768
1769 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1770 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1771 if (ret < 0) {
1772 ALOGE("%s: csd_enable_device_config, failed, error %d",
1773 __func__, ret);
1774 }
1775 } else {
1776 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1777 acdb_rx_id, acdb_tx_id);
1778 }
1779
1780 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001781}
1782
1783int platform_switch_voice_call_device_post(void *platform,
1784 snd_device_t out_snd_device,
1785 snd_device_t in_snd_device)
1786{
1787 struct platform_data *my_data = (struct platform_data *)platform;
1788 int acdb_rx_id, acdb_tx_id;
1789
1790 if (my_data->acdb_send_voice_cal == NULL) {
1791 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1792 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001793 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1794 audio_extn_spkr_prot_is_enabled())
1795 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1796
keunhui.park2f7306a2015-07-16 16:48:06 +09001797 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1798 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001799
1800 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1801 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1802 else
1803 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1804 acdb_rx_id, acdb_tx_id);
1805 }
1806
1807 return 0;
1808}
1809
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001810int platform_switch_voice_call_usecase_route_post(void *platform,
1811 snd_device_t out_snd_device,
1812 snd_device_t in_snd_device)
1813{
1814 struct platform_data *my_data = (struct platform_data *)platform;
1815 int acdb_rx_id, acdb_tx_id;
1816 int ret = 0;
1817
1818 if (my_data->csd == NULL)
1819 return ret;
1820
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001821 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1822 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001823 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001824 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001825 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001826
keunhui.park2f7306a2015-07-16 16:48:06 +09001827 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001828
1829 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1830 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1831 my_data->adev->acdb_settings);
1832 if (ret < 0) {
1833 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
1834 }
1835 } else {
1836 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1837 acdb_rx_id, acdb_tx_id);
1838 }
1839
1840 return ret;
1841}
1842
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001843int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001844{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001845 struct platform_data *my_data = (struct platform_data *)platform;
1846 int ret = 0;
1847
1848 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001849 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001850 if (ret < 0) {
1851 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1852 }
1853 }
1854 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001855}
1856
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001857int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001858{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001859 struct platform_data *my_data = (struct platform_data *)platform;
1860 int ret = 0;
1861
1862 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001863 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001864 if (ret < 0) {
1865 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1866 }
1867 }
1868 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001869}
1870
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001871int platform_get_sample_rate(void *platform, uint32_t *rate)
1872{
1873 struct platform_data *my_data = (struct platform_data *)platform;
1874 int ret = 0;
1875
1876 if (my_data->csd != NULL) {
1877 ret = my_data->csd->get_sample_rate(rate);
1878 if (ret < 0) {
1879 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1880 }
1881 }
1882 return ret;
1883}
1884
vivek mehtab6506412015-08-07 16:55:17 -07001885void platform_set_speaker_gain_in_combo(struct audio_device *adev,
1886 snd_device_t snd_device,
1887 bool enable)
1888{
1889 const char* name;
1890 switch (snd_device) {
1891 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
1892 if (enable)
1893 name = "spkr-gain-in-headphone-combo";
1894 else
1895 name = "speaker-gain-default";
1896 break;
1897 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
1898 if (enable)
1899 name = "spkr-gain-in-line-combo";
1900 else
1901 name = "speaker-gain-default";
1902 break;
1903 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
1904 if (enable)
1905 name = "spkr-safe-gain-in-headphone-combo";
1906 else
1907 name = "speaker-safe-gain-default";
1908 break;
1909 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
1910 if (enable)
1911 name = "spkr-safe-gain-in-line-combo";
1912 else
1913 name = "speaker-safe-gain-default";
1914 break;
1915 default:
1916 return;
1917 }
1918
1919 audio_route_apply_and_update_path(adev->audio_route, name);
1920}
1921
Eric Laurentb23d5282013-05-14 15:27:20 -07001922int platform_set_voice_volume(void *platform, int volume)
1923{
1924 struct platform_data *my_data = (struct platform_data *)platform;
1925 struct audio_device *adev = my_data->adev;
1926 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001927 const char *mixer_ctl_name = "Voice Rx Gain";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001928 int vol_index = 0, ret = 0;
1929 uint32_t set_values[ ] = {0,
1930 ALL_SESSION_VSID,
1931 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001932
1933 // Voice volume levels are mapped to adsp volume levels as follows.
1934 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1935 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001936 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001937 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001938
1939 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1940 if (!ctl) {
1941 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1942 __func__, mixer_ctl_name);
1943 return -EINVAL;
1944 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001945 ALOGV("Setting voice volume index: %d", set_values[0]);
1946 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1947
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001948 if (my_data->csd != NULL) {
1949 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1950 DEFAULT_VOLUME_RAMP_DURATION_MS);
1951 if (ret < 0) {
1952 ALOGE("%s: csd_volume error %d", __func__, ret);
1953 }
1954 }
1955 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001956}
1957
1958int platform_set_mic_mute(void *platform, bool state)
1959{
1960 struct platform_data *my_data = (struct platform_data *)platform;
1961 struct audio_device *adev = my_data->adev;
1962 struct mixer_ctl *ctl;
1963 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07001964 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001965 uint32_t set_values[ ] = {0,
1966 ALL_SESSION_VSID,
1967 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001968
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001969 if (adev->mode != AUDIO_MODE_IN_CALL &&
1970 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001971 return 0;
1972
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09001973 if (adev->enable_hfp)
1974 mixer_ctl_name = "HFP Tx Mute";
1975
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001976 set_values[0] = state;
1977 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1978 if (!ctl) {
1979 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1980 __func__, mixer_ctl_name);
1981 return -EINVAL;
1982 }
1983 ALOGV("Setting voice mute state: %d", state);
1984 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1985
1986 if (my_data->csd != NULL) {
1987 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1988 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07001989 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001990 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07001991 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001992 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001993 return ret;
1994}
Eric Laurentb23d5282013-05-14 15:27:20 -07001995
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001996int platform_set_device_mute(void *platform, bool state, char *dir)
1997{
1998 struct platform_data *my_data = (struct platform_data *)platform;
1999 struct audio_device *adev = my_data->adev;
2000 struct mixer_ctl *ctl;
2001 char *mixer_ctl_name = NULL;
2002 int ret = 0;
2003 uint32_t set_values[ ] = {0,
2004 ALL_SESSION_VSID,
2005 0};
2006 if(dir == NULL) {
2007 ALOGE("%s: Invalid direction:%s", __func__, dir);
2008 return -EINVAL;
2009 }
2010
2011 if (!strncmp("rx", dir, sizeof("rx"))) {
2012 mixer_ctl_name = "Voice Rx Device Mute";
2013 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2014 mixer_ctl_name = "Voice Tx Device Mute";
2015 } else {
2016 return -EINVAL;
2017 }
2018
2019 set_values[0] = state;
2020 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2021 if (!ctl) {
2022 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2023 __func__, mixer_ctl_name);
2024 return -EINVAL;
2025 }
2026
2027 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2028 __func__,state, mixer_ctl_name);
2029 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2030
2031 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002032}
2033
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002034int platform_can_split_snd_device(snd_device_t snd_device,
2035 int *num_devices,
2036 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002037{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002038 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002039 if (NULL == num_devices || NULL == new_snd_devices) {
2040 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002041 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002042 }
2043
2044 /*
2045 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002046 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002047 */
2048 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2049 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2050 *num_devices = 2;
2051 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2052 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002053 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002054 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2055 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2056 *num_devices = 2;
2057 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2058 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002059 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002060 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2061 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2062 *num_devices = 2;
2063 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2064 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002065 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002066 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2067 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2068 *num_devices = 2;
2069 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2070 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002071 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002072 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2073 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2074 SND_DEVICE_OUT_BT_SCO)) {
2075 *num_devices = 2;
2076 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2077 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2078 ret = 0;
2079 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2080 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2081 SND_DEVICE_OUT_BT_SCO_WB)) {
2082 *num_devices = 2;
2083 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2084 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2085 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002086 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2087 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2088 *num_devices = 2;
2089 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2090 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2091 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002092 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002093 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002094}
2095
Eric Laurentb23d5282013-05-14 15:27:20 -07002096snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2097{
2098 struct platform_data *my_data = (struct platform_data *)platform;
2099 struct audio_device *adev = my_data->adev;
2100 audio_mode_t mode = adev->mode;
2101 snd_device_t snd_device = SND_DEVICE_NONE;
2102
2103 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2104 if (devices == AUDIO_DEVICE_NONE ||
2105 devices & AUDIO_DEVICE_BIT_IN) {
2106 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2107 goto exit;
2108 }
2109
Eric Laurent1b491552015-09-15 17:52:41 -07002110 if (popcount(devices) == 2) {
2111 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2112 AUDIO_DEVICE_OUT_SPEAKER) ||
2113 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2114 AUDIO_DEVICE_OUT_SPEAKER)) {
2115 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2116 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2117 AUDIO_DEVICE_OUT_SPEAKER)) {
2118 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2119 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2120 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2121 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2122 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2123 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2124 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2125 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2126 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2127 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2128 AUDIO_DEVICE_OUT_SPEAKER)) {
2129 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002130 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2131 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2132 snd_device = adev->bt_wb_speech_enabled ?
2133 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2134 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
David Linee3fe402017-03-13 10:00:42 -07002135 } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2136 AUDIO_DEVICE_OUT_SPEAKER)) {
2137 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002138 } else {
2139 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2140 goto exit;
2141 }
2142 if (snd_device != SND_DEVICE_NONE) {
2143 goto exit;
2144 }
2145 }
2146
2147 if (popcount(devices) != 1) {
2148 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2149 goto exit;
2150 }
2151
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302152 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002153 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002154 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2155 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002156 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002157 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002158 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002159 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002160 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002161 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002162 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002163 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002164 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002165 else {
2166 if (devices & AUDIO_DEVICE_OUT_LINE)
2167 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2168 else
2169 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2170 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002171 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002172 if (adev->bt_wb_speech_enabled) {
2173 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2174 } else {
2175 snd_device = SND_DEVICE_OUT_BT_SCO;
2176 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002177 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002178 if (!adev->enable_hfp) {
2179 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2180 } else {
2181 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2182 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002183 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002184 if(adev->voice.hac)
2185 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2186 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002187 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2188 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002189 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002190 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2191 snd_device = SND_DEVICE_OUT_VOICE_TX;
2192
Eric Laurentb23d5282013-05-14 15:27:20 -07002193 if (snd_device != SND_DEVICE_NONE) {
2194 goto exit;
2195 }
2196 }
2197
Eric Laurentb23d5282013-05-14 15:27:20 -07002198 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2199 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2200 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002201 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2202 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002203 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2204 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002205 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002206 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002207 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2208 else
2209 snd_device = SND_DEVICE_OUT_SPEAKER;
2210 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002211 if (adev->bt_wb_speech_enabled) {
2212 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2213 } else {
2214 snd_device = SND_DEVICE_OUT_BT_SCO;
2215 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002216 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2217 snd_device = SND_DEVICE_OUT_HDMI ;
David Linee3fe402017-03-13 10:00:42 -07002218 } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
2219 if (audio_extn_usb_is_capture_supported())
2220 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2221 else
2222 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2223 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002224 /*HAC support for voice-ish audio (eg visual voicemail)*/
2225 if(adev->voice.hac)
2226 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2227 else
2228 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002229 } else {
2230 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2231 }
2232exit:
2233 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2234 return snd_device;
2235}
2236
2237snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2238{
2239 struct platform_data *my_data = (struct platform_data *)platform;
2240 struct audio_device *adev = my_data->adev;
2241 audio_source_t source = (adev->active_input == NULL) ?
2242 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2243
2244 audio_mode_t mode = adev->mode;
2245 audio_devices_t in_device = ((adev->active_input == NULL) ?
2246 AUDIO_DEVICE_NONE : adev->active_input->device)
2247 & ~AUDIO_DEVICE_BIT_IN;
2248 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2249 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2250 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002251 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002252
Prashant Malanic92c5962015-08-11 15:10:18 -07002253 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2254 __func__, out_device, in_device, channel_count, channel_mask);
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002255 if ((out_device != AUDIO_DEVICE_NONE) && voice_is_in_call(adev)) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002256 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002257 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002258 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2259 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002260 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002261 case TTY_MODE_FULL:
2262 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2263 break;
2264 case TTY_MODE_VCO:
2265 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2266 break;
2267 case TTY_MODE_HCO:
2268 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2269 break;
2270 default:
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002271 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002272 }
2273 goto exit;
2274 }
2275 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002276 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002277 if (my_data->fluence_in_voice_call == false) {
2278 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2279 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002280 if (is_operator_tmus())
2281 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002282 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002283 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002284 }
2285 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2286 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2287 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002288 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002289 if (adev->bluetooth_nrec)
2290 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2291 else
2292 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002293 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002294 if (adev->bluetooth_nrec)
2295 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2296 else
2297 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002298 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002299 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002300 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2301 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2302 out_device & AUDIO_DEVICE_OUT_LINE) {
2303 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2304 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2305 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2306 } else {
2307 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2308 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002309 }
vivek mehtafe121d52015-08-10 23:39:23 -07002310
2311 //select default
2312 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002313 if (!adev->enable_hfp) {
2314 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2315 } else {
2316 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2317 platform_set_echo_reference(adev, true, out_device);
2318 }
vivek mehtafe121d52015-08-10 23:39:23 -07002319 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002320 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002321 snd_device = SND_DEVICE_IN_VOICE_RX;
Prashant Malanic92c5962015-08-11 15:10:18 -07002322 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002323 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2324 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2325 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2326 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2327 }
2328 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2329 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002330 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2331 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2332 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002333 if (adev->active_input->enable_aec)
2334 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2335 else
2336 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002337 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2338 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002339 if (adev->active_input->enable_aec)
2340 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2341 else
2342 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002343 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2344 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2345 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002346 if (adev->active_input->enable_aec)
2347 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2348 else
2349 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002350 }
2351 platform_set_echo_reference(adev, true, out_device);
2352 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2353 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2354 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002355 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002356 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2357 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002358 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002359 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2360 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002361 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002362 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002363 if (adev->active_input->enable_aec) {
2364 if (adev->active_input->enable_ns) {
2365 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2366 } else {
2367 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2368 }
vivek mehta733c1df2016-04-04 15:09:24 -07002369 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002370 } else if (adev->active_input->enable_ns) {
2371 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2372 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002373 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002374 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002375 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002376 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2377 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002378 }
rago90fb9612015-12-02 11:37:53 -08002379 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2380 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002381 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2382 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2383 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2384 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002385 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002386 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2387 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002388 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002389 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2390 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2391 } else {
2392 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2393 }
rago90fb9612015-12-02 11:37:53 -08002394 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2395 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
2396 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002397 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002398 mode == AUDIO_MODE_IN_COMMUNICATION) {
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002399 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE))
Eric Laurentb23d5282013-05-14 15:27:20 -07002400 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2401 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002402 if (adev->active_input->enable_aec &&
2403 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002404 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002405 if (my_data->fluence_in_spkr_mode &&
2406 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002407 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002408 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002409 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002410 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002411 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002412 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002413 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002414 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002415 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002416 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002417 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002418 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002419 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2420 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002421 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002422 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002423 } else if (adev->active_input->enable_aec) {
2424 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2425 if (my_data->fluence_in_spkr_mode &&
2426 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002427 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002428 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002429 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002430 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002431 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002432 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2433 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002434 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002435 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002436 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002437 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002438 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002439 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2440 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
2441 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002442 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002443 } else if (adev->active_input->enable_ns) {
2444 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2445 if (my_data->fluence_in_spkr_mode &&
2446 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002447 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002448 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002449 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002450 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002451 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002452 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2453 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002454 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002455 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002456 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002457 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002458 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002459 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002460 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002461 }
2462 } else if (source == AUDIO_SOURCE_DEFAULT) {
2463 goto exit;
2464 }
2465
2466
2467 if (snd_device != SND_DEVICE_NONE) {
2468 goto exit;
2469 }
2470
2471 if (in_device != AUDIO_DEVICE_NONE &&
2472 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2473 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2474 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002475 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002476 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002477 snd_device = SND_DEVICE_IN_QUAD_MIC;
2478 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002479 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002480 snd_device = SND_DEVICE_IN_THREE_MIC;
2481 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2482 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002483 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002484 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2485 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002486 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002487 } else {
2488 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2489 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2490 my_data->source_mic_type, channel_count, channel_mask);
2491 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2492 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002493 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002494 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2495 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002496 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002497 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2498 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002499 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002500 } else {
2501 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2502 " no combination found .. setting to mono", __func__,
2503 my_data->source_mic_type, channel_count);
2504 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2505 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002506 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2507 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2508 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002509 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002510 if (adev->bluetooth_nrec)
2511 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2512 else
2513 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002514 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002515 if (adev->bluetooth_nrec)
2516 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2517 else
2518 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002519 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002520 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2521 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002522 } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
2523 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002524 } else {
2525 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2526 ALOGW("%s: Using default handset-mic", __func__);
2527 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2528 }
2529 } else {
2530 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2531 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2532 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2533 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002534 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002535 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002536 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002537 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002538 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2539 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002540 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002541 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2542 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002543 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002544 } else {
2545 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2546 " no combination found .. setting to mono", __func__,
2547 my_data->source_mic_type, channel_count);
2548 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2549 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002550 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002551 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002552 if (adev->bluetooth_nrec)
2553 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2554 else
2555 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002556 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002557 if (adev->bluetooth_nrec)
2558 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2559 else
2560 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002561 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002562 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2563 snd_device = SND_DEVICE_IN_HDMI_MIC;
David Linee3fe402017-03-13 10:00:42 -07002564 } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
2565 if (audio_extn_usb_is_capture_supported())
2566 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2567 else
2568 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002569 } else {
2570 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2571 ALOGW("%s: Using default handset-mic", __func__);
2572 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2573 }
2574 }
2575exit:
2576 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2577 return snd_device;
2578}
2579
2580int platform_set_hdmi_channels(void *platform, int channel_count)
2581{
2582 struct platform_data *my_data = (struct platform_data *)platform;
2583 struct audio_device *adev = my_data->adev;
2584 struct mixer_ctl *ctl;
2585 const char *channel_cnt_str = NULL;
2586 const char *mixer_ctl_name = "HDMI_RX Channels";
2587 switch (channel_count) {
2588 case 8:
2589 channel_cnt_str = "Eight"; break;
2590 case 7:
2591 channel_cnt_str = "Seven"; break;
2592 case 6:
2593 channel_cnt_str = "Six"; break;
2594 case 5:
2595 channel_cnt_str = "Five"; break;
2596 case 4:
2597 channel_cnt_str = "Four"; break;
2598 case 3:
2599 channel_cnt_str = "Three"; break;
2600 default:
2601 channel_cnt_str = "Two"; break;
2602 }
2603 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2604 if (!ctl) {
2605 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2606 __func__, mixer_ctl_name);
2607 return -EINVAL;
2608 }
2609 ALOGV("HDMI channel count: %s", channel_cnt_str);
2610 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2611 return 0;
2612}
2613
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002614int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002615{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002616 struct platform_data *my_data = (struct platform_data *)platform;
2617 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002618 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2619 char *sad = block;
2620 int num_audio_blocks;
2621 int channel_count;
2622 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002623 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002624
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002625 struct mixer_ctl *ctl;
2626
2627 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2628 if (!ctl) {
2629 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2630 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002631 return 0;
2632 }
2633
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002634 mixer_ctl_update(ctl);
2635
2636 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002637
2638 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002639 if (count > (int)sizeof(block))
2640 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002641
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002642 ret = mixer_ctl_get_array(ctl, block, count);
2643 if (ret != 0) {
2644 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2645 return 0;
2646 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002647
2648 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002649 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002650
2651 for (i = 0; i < num_audio_blocks; i++) {
2652 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002653 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2654 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002655 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002656 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002657
2658 channel_count = (sad[0] & 0x7) + 1;
2659 if (channel_count > max_channels)
2660 max_channels = channel_count;
2661
2662 /* Advance to next block */
2663 sad += 3;
2664 }
2665
2666 return max_channels;
2667}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002668
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002669int platform_set_incall_recording_session_id(void *platform,
2670 uint32_t session_id, int rec_mode)
2671{
2672 int ret = 0;
2673 struct platform_data *my_data = (struct platform_data *)platform;
2674 struct audio_device *adev = my_data->adev;
2675 struct mixer_ctl *ctl;
2676 const char *mixer_ctl_name = "Voc VSID";
2677 int num_ctl_values;
2678 int i;
2679
2680 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2681 if (!ctl) {
2682 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2683 __func__, mixer_ctl_name);
2684 ret = -EINVAL;
2685 } else {
2686 num_ctl_values = mixer_ctl_get_num_values(ctl);
2687 for (i = 0; i < num_ctl_values; i++) {
2688 if (mixer_ctl_set_value(ctl, i, session_id)) {
2689 ALOGV("Error: invalid session_id: %x", session_id);
2690 ret = -EINVAL;
2691 break;
2692 }
2693 }
2694 }
2695
2696 if (my_data->csd != NULL) {
2697 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2698 if (ret < 0) {
2699 ALOGE("%s: csd_client_start_record failed, error %d",
2700 __func__, ret);
2701 }
2702 }
2703
2704 return ret;
2705}
2706
2707int platform_stop_incall_recording_usecase(void *platform)
2708{
2709 int ret = 0;
2710 struct platform_data *my_data = (struct platform_data *)platform;
2711
2712 if (my_data->csd != NULL) {
2713 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2714 if (ret < 0) {
2715 ALOGE("%s: csd_client_stop_record failed, error %d",
2716 __func__, ret);
2717 }
2718 }
2719
2720 return ret;
2721}
2722
2723int platform_start_incall_music_usecase(void *platform)
2724{
2725 int ret = 0;
2726 struct platform_data *my_data = (struct platform_data *)platform;
2727
2728 if (my_data->csd != NULL) {
2729 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2730 if (ret < 0) {
2731 ALOGE("%s: csd_client_start_playback failed, error %d",
2732 __func__, ret);
2733 }
2734 }
2735
2736 return ret;
2737}
2738
2739int platform_stop_incall_music_usecase(void *platform)
2740{
2741 int ret = 0;
2742 struct platform_data *my_data = (struct platform_data *)platform;
2743
2744 if (my_data->csd != NULL) {
2745 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2746 if (ret < 0) {
2747 ALOGE("%s: csd_client_stop_playback failed, error %d",
2748 __func__, ret);
2749 }
2750 }
2751
2752 return ret;
2753}
2754
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002755int platform_set_parameters(void *platform, struct str_parms *parms)
2756{
2757 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09002758 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002759 char *kv_pairs = str_parms_to_str(parms);
2760 int ret = 0, err;
2761
2762 if (kv_pairs == NULL) {
2763 ret = -EINVAL;
2764 ALOGE("%s: key-value pair is NULL",__func__);
2765 goto done;
2766 }
2767
2768 ALOGV("%s: enter: %s", __func__, kv_pairs);
2769
2770 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
2771 value, sizeof(value));
2772 if (err >= 0) {
2773 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
2774 my_data->snd_card_name = strdup(value);
2775 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
2776 }
2777
keunhui.park2f7306a2015-07-16 16:48:06 +09002778 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
2779 value, sizeof(value));
2780 if (err >= 0) {
2781 struct operator_info *info;
2782 char *str = value;
2783 char *name;
2784
2785 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
2786 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
2787 name = strtok(str, ";");
2788 info->name = strdup(name);
2789 info->mccmnc = strdup(str + strlen(name) + 1);
2790
2791 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08002792 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09002793 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002794
2795 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07002796 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07002797 value, sizeof(value));
2798 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07002799 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07002800 my_data->max_mic_count = atoi(value);
2801 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07002802 }
2803
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07002804done:
2805 ALOGV("%s: exit with code(%d)", __func__, ret);
2806 if (kv_pairs != NULL)
2807 free(kv_pairs);
2808
2809 return ret;
2810}
2811
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002812/* Delay in Us */
2813int64_t platform_render_latency(audio_usecase_t usecase)
2814{
2815 switch (usecase) {
2816 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
2817 return DEEP_BUFFER_PLATFORM_DELAY;
2818 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
2819 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08002820 case USECASE_AUDIO_PLAYBACK_ULL:
2821 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08002822 case USECASE_AUDIO_PLAYBACK_MMAP:
2823 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002824 default:
2825 return 0;
2826 }
2827}
Haynes Mathew George98c95622014-06-20 19:14:25 -07002828
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002829int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
2830 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07002831{
2832 int ret = 0;
2833
2834 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
2835 ALOGE("%s: Invalid snd_device = %d",
2836 __func__, device);
2837 ret = -EINVAL;
2838 goto done;
2839 }
2840
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002841 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
2842 platform_get_snd_device_name(device),
2843 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
2844 if (backend_tag_table[device]) {
2845 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002846 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002847 backend_tag_table[device] = strdup(backend_tag);
2848
2849 if (hw_interface != NULL) {
2850 if (hw_interface_table[device])
2851 free(hw_interface_table[device]);
2852 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
2853 hw_interface_table[device] = strdup(hw_interface);
2854 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07002855done:
2856 return ret;
2857}
2858
2859int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
2860{
2861 int ret = 0;
2862 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
2863 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
2864 ret = -EINVAL;
2865 goto done;
2866 }
2867
2868 if ((type != 0) && (type != 1)) {
2869 ALOGE("%s: invalid usecase type", __func__);
2870 ret = -EINVAL;
2871 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002872 ALOGV("%s: pcm_device_table[%d][%d] = %d", __func__, usecase, type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07002873 pcm_device_table[usecase][type] = pcm_id;
2874done:
2875 return ret;
2876}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002877
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002878#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
2879int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
2880 // backup_gain: gain to try to set in case of an error during ramp
2881 int start_gain, end_gain, step, backup_gain, i;
2882 bool error = false;
2883 const struct mixer_ctl *ctl;
2884 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
2885 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
2886 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
2887 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
2888 if (!ctl_left || !ctl_right) {
2889 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
2890 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2891 return -EINVAL;
2892 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
2893 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
2894 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
2895 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
2896 return -EINVAL;
2897 }
2898 if (ramp_up) {
2899 start_gain = 0;
2900 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2901 step = +1;
2902 backup_gain = end_gain;
2903 } else {
2904 // using same gain on left and right
2905 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
2906 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
2907 end_gain = 0;
2908 step = -1;
2909 backup_gain = start_gain;
2910 }
2911 for (i = start_gain ; i != (end_gain + step) ; i += step) {
2912 //ALOGV("setting speaker gain to %d", i);
2913 if (mixer_ctl_set_value(ctl_left, 0, i)) {
2914 ALOGE("%s: error setting %s to %d during gain ramp",
2915 __func__, mixer_ctl_name_gain_left, i);
2916 error = true;
2917 break;
2918 }
2919 if (mixer_ctl_set_value(ctl_right, 0, i)) {
2920 ALOGE("%s: error setting %s to %d during gain ramp",
2921 __func__, mixer_ctl_name_gain_right, i);
2922 error = true;
2923 break;
2924 }
2925 usleep(1000);
2926 }
2927 if (error) {
2928 // an error occured during the ramp, let's still try to go back to a safe volume
2929 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
2930 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
2931 }
2932 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
2933 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
2934 }
2935 }
2936 return start_gain;
2937}
2938
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002939int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
2940{
2941 // only update if there is active pcm playback on speaker
2942 struct audio_usecase *usecase;
2943 struct listnode *node;
2944 struct platform_data *my_data = (struct platform_data *)adev->platform;
2945
2946 if (my_data->speaker_lr_swap != swap_channels) {
Jean-Michel Trivif7148702016-09-16 18:23:05 -07002947
2948 // do not swap channels in audio modes with concurrent capture and playback
2949 // as this may break the echo reference
2950 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
2951 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
2952 return 0;
2953 }
2954
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002955 my_data->speaker_lr_swap = swap_channels;
2956
2957 list_for_each(node, &adev->usecase_list) {
2958 usecase = node_to_item(node, struct audio_usecase, list);
2959 if (usecase->type == PCM_PLAYBACK &&
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002960 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
2961 /*
2962 * If acdb tuning is different for SPEAKER_REVERSE, it is must
2963 * to perform device switch to disable the current backend to
2964 * enable it with new acdb data.
2965 */
2966 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
2967 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002968 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002969 select_devices(adev, usecase->id);
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07002970 if (initial_skpr_gain != -EINVAL) {
2971 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
2972 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002973 } else {
Ravi Kumar Alamanda425e1542015-09-22 09:11:18 -07002974 const char *mixer_path;
2975 if (swap_channels) {
2976 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
2977 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2978 } else {
2979 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
2980 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
2981 }
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002982 }
2983 break;
2984 }
2985 }
2986 }
2987 return 0;
2988}
vivek mehtaa8d7c922016-05-25 14:40:44 -07002989
2990static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
2991static int num_gain_tbl_entry = 0;
2992
2993bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
2994
2995 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
2996 if (num_gain_tbl_entry == -1) {
2997 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
2998 __func__);
2999 return false;
3000 }
3001
3002 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3003 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3004 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3005 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3006 return false;
3007 }
3008
3009 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3010 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3011 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3012 return false;
3013 }
3014
3015 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3016 ++num_gain_tbl_entry;
3017
3018 return true;
3019}
3020
3021int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3022 int table_size) {
3023 int itt = 0;
3024 ALOGV("platform_get_gain_level_mapping called ");
3025
3026 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3027 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3028 return 0;
3029 }
3030
3031 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3032 mapping_tbl[itt] = tbl_mapping[itt];
3033 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3034 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3035 }
3036
3037 return num_gain_tbl_entry;
3038}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003039
3040int platform_snd_card_update(void *platform, card_status_t status)
3041{
3042 struct platform_data *my_data = (struct platform_data *)platform;
3043 struct audio_device *adev = my_data->adev;
3044
3045 if (status == CARD_STATUS_ONLINE) {
3046 if (my_data->acdb_send_custom_top)
3047 my_data->acdb_send_custom_top();
3048 }
3049 return 0;
3050}
David Linee3fe402017-03-13 10:00:42 -07003051
3052/*
3053 * configures afe with bit width and Sample Rate
3054 */
3055static int platform_set_backend_cfg(const struct audio_device* adev,
3056 snd_device_t snd_device,
3057 const struct audio_backend_cfg *backend_cfg)
3058{
3059
3060 int ret = 0;
3061 const int backend_idx = platform_get_backend_index(snd_device);
3062 struct platform_data *my_data = (struct platform_data *)adev->platform;
3063 const unsigned int bit_width = backend_cfg->bit_width;
3064 const unsigned int sample_rate = backend_cfg->sample_rate;
3065 const unsigned int channels = backend_cfg->channels;
3066 const audio_format_t format = backend_cfg->format;
3067 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3068
3069
3070 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3071 ", backend_idx %d device (%s)", __func__, bit_width,
3072 sample_rate, channels, backend_idx,
3073 platform_get_snd_device_name(snd_device));
3074
3075 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3076 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3077
3078 struct mixer_ctl *ctl = NULL;
3079 ctl = mixer_get_ctl_by_name(adev->mixer,
3080 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3081 if (!ctl) {
3082 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3083 __func__,
3084 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3085 return -EINVAL;
3086 }
3087
3088 if (bit_width == 24) {
3089 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3090 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3091 else
3092 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3093 } else if (bit_width == 32) {
3094 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3095 } else {
3096 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3097 }
3098 if ( ret < 0) {
3099 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3100 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3101 } else {
3102 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3103 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3104 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3105 }
3106 /* set the ret as 0 and not pass back to upper layer */
3107 ret = 0;
3108 }
3109
3110 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3111 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3112 char *rate_str = NULL;
3113 struct mixer_ctl *ctl = NULL;
3114
3115 switch (sample_rate) {
3116 case 32000:
3117 if (passthrough_enabled) {
3118 rate_str = "KHZ_32";
3119 break;
3120 }
3121 case 8000:
3122 case 11025:
3123 case 16000:
3124 case 22050:
3125 case 48000:
3126 rate_str = "KHZ_48";
3127 break;
3128 case 44100:
3129 rate_str = "KHZ_44P1";
3130 break;
3131 case 64000:
3132 case 96000:
3133 rate_str = "KHZ_96";
3134 break;
3135 case 88200:
3136 rate_str = "KHZ_88P2";
3137 break;
3138 case 176400:
3139 rate_str = "KHZ_176P4";
3140 break;
3141 case 192000:
3142 rate_str = "KHZ_192";
3143 break;
3144 case 352800:
3145 rate_str = "KHZ_352P8";
3146 break;
3147 case 384000:
3148 rate_str = "KHZ_384";
3149 break;
3150 case 144000:
3151 if (passthrough_enabled) {
3152 rate_str = "KHZ_144";
3153 break;
3154 }
3155 default:
3156 rate_str = "KHZ_48";
3157 break;
3158 }
3159
3160 ctl = mixer_get_ctl_by_name(adev->mixer,
3161 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3162 if(!ctl) {
3163 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3164 __func__,
3165 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3166 return -EINVAL;
3167 }
3168
3169 ALOGD("%s:becf: afe: %s set to %s", __func__,
3170 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3171 mixer_ctl_set_enum_by_string(ctl, rate_str);
3172 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3173 }
3174 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3175 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3176 struct mixer_ctl *ctl = NULL;
3177 char *channel_cnt_str = NULL;
3178
3179 switch (channels) {
3180 case 8:
3181 channel_cnt_str = "Eight"; break;
3182 case 7:
3183 channel_cnt_str = "Seven"; break;
3184 case 6:
3185 channel_cnt_str = "Six"; break;
3186 case 5:
3187 channel_cnt_str = "Five"; break;
3188 case 4:
3189 channel_cnt_str = "Four"; break;
3190 case 3:
3191 channel_cnt_str = "Three"; break;
3192 case 1:
3193 channel_cnt_str = "One"; break;
3194 case 2:
3195 default:
3196 channel_cnt_str = "Two"; break;
3197 }
3198
3199 ctl = mixer_get_ctl_by_name(adev->mixer,
3200 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3201 if (!ctl) {
3202 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3203 __func__,
3204 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3205 return -EINVAL;
3206 }
3207 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3208 my_data->current_backend_cfg[backend_idx].channels = channels;
3209
3210 // skip EDID configuration for HDMI backend
3211
3212 ALOGD("%s:becf: afe: %s set to %s", __func__,
3213 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3214 channel_cnt_str);
3215 }
3216
3217 // skip set ext_display format mixer control
3218 return ret;
3219}
3220
3221static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3222{
3223 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3224 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3225 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3226 }
3227
3228 return backend_bit_width_table[snd_device];
3229}
3230
3231/*
3232 * return backend_idx on which voice call is active
3233 */
3234static int platform_get_voice_call_backend(struct audio_device* adev)
3235{
3236 struct audio_usecase *uc = NULL;
3237 struct listnode *node;
3238 snd_device_t out_snd_device = SND_DEVICE_NONE;
3239
3240 int backend_idx = -1;
3241
3242 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3243 list_for_each(node, &adev->usecase_list) {
3244 uc = node_to_item(node, struct audio_usecase, list);
3245 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3246 out_snd_device = platform_get_output_snd_device(adev->platform,
3247 uc->stream.out->devices);
3248 backend_idx = platform_get_backend_index(out_snd_device);
3249 break;
3250 }
3251 }
3252 }
3253 return backend_idx;
3254}
3255
3256/*
3257 * goes through all the current usecases and picks the highest
3258 * bitwidth & samplerate
3259 */
3260static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3261 int backend_idx,
3262 struct audio_backend_cfg *backend_cfg)
3263{
3264 bool backend_change = false;
3265 unsigned int bit_width;
3266 unsigned int sample_rate;
3267 unsigned int channels;
3268 struct platform_data *my_data = (struct platform_data *)adev->platform;
3269
3270 bit_width = backend_cfg->bit_width;
3271 sample_rate = backend_cfg->sample_rate;
3272 channels = backend_cfg->channels;
3273
3274 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3275 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3276 sample_rate, channels);
3277
3278 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3279 // default backend
3280 // force routing is not required here, caller will do it anyway
3281 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3282 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3283 "for unprocessed/camera source", __func__);
3284 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3285 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3286 }
3287
3288 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3289 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3290 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3291 __func__, bit_width, sample_rate, channels);
3292 }
3293
3294 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3295 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3296
3297 // Force routing if the expected bitwdith or samplerate
3298 // is not same as current backend comfiguration
3299 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3300 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3301 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3302 backend_cfg->bit_width = bit_width;
3303 backend_cfg->sample_rate= sample_rate;
3304 backend_cfg->channels = channels;
3305 backend_change = true;
3306 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3307 "new sample rate: %d new channel: %d",
3308 __func__, backend_cfg->bit_width,
3309 backend_cfg->sample_rate, backend_cfg->channels);
3310 }
3311
3312 return backend_change;
3313}
3314
3315static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3316 struct audio_usecase* usecase,
3317 snd_device_t snd_device,
3318 struct audio_backend_cfg *backend_cfg)
3319{
3320 bool backend_change = false;
3321 struct listnode *node;
3322 unsigned int bit_width;
3323 unsigned int sample_rate;
3324 unsigned int channels;
3325 bool passthrough_enabled = false;
3326 int backend_idx = DEFAULT_CODEC_BACKEND;
3327 struct platform_data *my_data = (struct platform_data *)adev->platform;
3328 bool channels_updated = false;
3329
3330 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3331 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3332 backend_change = false;
3333 return backend_change;
3334 }
3335
3336 backend_idx = platform_get_backend_index(snd_device);
3337 bit_width = backend_cfg->bit_width;
3338 sample_rate = backend_cfg->sample_rate;
3339 channels = backend_cfg->channels;
3340
3341 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3342 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3343 sample_rate, channels, backend_idx, usecase->id,
3344 platform_get_snd_device_name(snd_device));
3345
3346 if (backend_idx == platform_get_voice_call_backend(adev)) {
3347 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3348 __func__);
3349 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3350 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3351 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3352 } else {
3353 /*
3354 * The backend should be configured at highest bit width and/or
3355 * sample rate amongst all playback usecases.
3356 * If the selected sample rate and/or bit width differ with
3357 * current backend sample rate and/or bit width, then, we set the
3358 * backend re-configuration flag.
3359 *
3360 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3361 */
3362
3363 int i =0;
3364 list_for_each(node, &adev->usecase_list) {
3365 struct audio_usecase *uc;
3366 uc = node_to_item(node, struct audio_usecase, list);
3367 struct stream_out *out = (struct stream_out*) uc->stream.out;
3368 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3369 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3370
3371 ALOGD("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3372 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3373 uc->id, out->sample_rate,
3374 pcm_format_to_bits(out->config.format), out_channels,
3375 platform_get_snd_device_name(uc->out_snd_device));
3376
3377 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3378 if (bit_width < pcm_format_to_bits(out->config.format))
3379 bit_width = pcm_format_to_bits(out->config.format);
3380 if (sample_rate < out->sample_rate)
3381 sample_rate = out->sample_rate;
3382 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3383 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3384 if (channels < out_channels)
3385 channels = out_channels;
3386 }
3387 }
3388 }
3389 }
3390
3391 /*
3392 * Check if the device is speaker or handset,assumption handset shares
3393 * backend with speaker, and these devices are restricited to 48kHz.
3394 */
3395 if (platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, snd_device)) {
3396
3397 if (bit_width >= 24) {
3398 bit_width = platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
3399 ALOGD("%s:becf: afe: reset bitwidth to %d (based on supported"
3400 " value for this platform)", __func__, bit_width);
3401 }
3402 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3403 ALOGD("%s:becf: afe: playback on codec device not supporting native playback set "
3404 "default Sample Rate(48k)", __func__);
3405 }
3406
3407 if (backend_idx == USB_AUDIO_RX_BACKEND) {
3408 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, true);
3409 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3410 __func__, bit_width, sample_rate, channels);
3411 if (channels != my_data->current_backend_cfg[backend_idx].channels)
3412 channels_updated = true;
3413 }
3414
3415 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and sample rate: %d",
3416 __func__, backend_idx , bit_width, sample_rate);
3417
3418 // Force routing if the expected bitwdith or samplerate
3419 // is not same as current backend comfiguration
3420 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3421 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3422 passthrough_enabled || channels_updated) {
3423 backend_cfg->bit_width = bit_width;
3424 backend_cfg->sample_rate = sample_rate;
3425 backend_cfg->channels = channels;
3426 backend_cfg->passthrough_enabled = passthrough_enabled;
3427 backend_change = true;
3428 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3429 "new sample rate: %d new channels: %d",
3430 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3431 }
3432
3433 return backend_change;
3434}
3435
3436bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3437 struct audio_usecase *usecase, snd_device_t snd_device)
3438{
3439 int backend_idx = DEFAULT_CODEC_BACKEND;
3440 int new_snd_devices[SND_DEVICE_OUT_END];
3441 int i, num_devices = 1;
3442 bool ret = false;
3443 struct platform_data *my_data = (struct platform_data *)adev->platform;
3444 struct audio_backend_cfg backend_cfg;
3445
3446 backend_idx = platform_get_backend_index(snd_device);
3447
3448 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3449 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3450 backend_cfg.format = usecase->stream.out->format;
3451 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3452 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3453 backend_cfg.passthrough_enabled = false;
3454
3455 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3456 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3457 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3458 platform_get_snd_device_name(snd_device));
3459
3460 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3461 new_snd_devices[0] = snd_device;
3462
3463 for (i = 0; i < num_devices; i++) {
3464 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3465 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3466 &backend_cfg))) {
3467 platform_set_backend_cfg(adev, new_snd_devices[i],
3468 &backend_cfg);
3469 ret = true;
3470 }
3471 }
3472 return ret;
3473}
3474
3475bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3476 struct audio_usecase *usecase, snd_device_t snd_device)
3477{
3478 int backend_idx = platform_get_backend_index(snd_device);
3479 int ret = 0;
3480 struct audio_backend_cfg backend_cfg;
3481
3482 backend_cfg.passthrough_enabled = false;
3483
3484 if(usecase->type == PCM_CAPTURE) {
3485 backend_cfg.format= usecase->stream.in->format;
3486 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3487 } else {
3488 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3489 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3490 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3491 backend_cfg.channels = 1;
3492 }
3493
3494 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3495 ", backend_idx %d usecase = %d device (%s)", __func__,
3496 backend_cfg.bit_width,
3497 backend_cfg.sample_rate,
3498 backend_cfg.channels,
3499 backend_idx, usecase->id,
3500 platform_get_snd_device_name(snd_device));
3501
3502 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3503 ret = platform_set_backend_cfg(adev, snd_device,
3504 &backend_cfg);
3505 if(!ret)
3506 return true;
3507 }
3508
3509 return false;
3510}
3511