blob: 4efd1d2424f4e193d89581027ab878e308da752b [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
vivek mehtaa6b79742017-03-09 15:40:43 -08002 * Copyright (C) 2013-2017 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Eric Laurentb23d5282013-05-14 15:27:20 -070016#define LOG_TAG "msm8974_platform"
17/*#define LOG_NDEBUG 0*/
18#define LOG_NDDEBUG 0
19
20#include <stdlib.h>
21#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090022#include <pthread.h>
23#include <unistd.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070024#include <cutils/log.h>
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -070025#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070026#include <cutils/properties.h>
27#include <audio_hw.h>
28#include <platform_api.h>
vivek mehta0fb11312017-05-15 19:35:32 -070029#include "acdb.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070030#include "platform.h"
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -070031#include "audio_extn.h"
vivek mehta1a9b7c02015-06-25 11:49:38 -070032#include <linux/msm_audio.h>
Alexey Polyudove920d4b2017-09-15 17:09:07 -070033#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -070034#include <sound/devdep_params.h>
35#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070036
Jaekyun Seokf62e17d2017-03-08 17:15:28 +090037#define MIXER_XML_DEFAULT_PATH "mixer_paths.xml"
38#define MIXER_XML_BASE_STRING "mixer_paths"
vivek mehta60ea4152016-02-18 17:10:26 -080039#define TOMTOM_8226_SND_CARD_NAME "msm8226-tomtom-snd-card"
40#define TOMTOM_MIXER_FILE_SUFFIX "wcd9330"
41
Eric Laurentb23d5282013-05-14 15:27:20 -070042#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070043#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090044#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070045
Eric Laurentf9583c32016-03-28 13:50:50 -070046#define min(a, b) ((a) < (b) ? (a) : (b))
Eric Laurentb23d5282013-05-14 15:27:20 -070047
48/*
Eric Laurentb23d5282013-05-14 15:27:20 -070049 * This file will have a maximum of 38 bytes:
50 *
51 * 4 bytes: number of audio blocks
52 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
53 * Maximum 10 * 3 bytes: SAD blocks
54 */
55#define MAX_SAD_BLOCKS 10
56#define SAD_BLOCK_SIZE 3
57
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +090058#define MAX_CVD_VERSION_STRING_SIZE 100
59
Eric Laurentb23d5282013-05-14 15:27:20 -070060/* EDID format ID for LPCM audio */
61#define EDID_FORMAT_LPCM 1
62
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -070063#define MAX_SND_CARD_NAME_LEN 31
64
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080065#define DEFAULT_APP_TYPE_RX_PATH 69936
66#define DEFAULT_APP_TYPE_TX_PATH 69938
Haynes Mathew George39c55dc2017-07-11 19:31:23 -070067#define DEFAULT_RX_BACKEND "SLIMBUS_0_RX"
vivek mehta1a9b7c02015-06-25 11:49:38 -070068
keunhui.parkc5aaa0e2015-07-13 10:57:37 +090069#define TOSTRING_(x) #x
70#define TOSTRING(x) TOSTRING_(x)
71
Eric Laurentb23d5282013-05-14 15:27:20 -070072struct audio_block_header
73{
74 int reserved;
75 int length;
76};
77
vivek mehta1a9b7c02015-06-25 11:49:38 -070078enum {
79 CAL_MODE_SEND = 0x1,
80 CAL_MODE_PERSIST = 0x2,
81 CAL_MODE_RTAC = 0x4
82};
83
keunhui.park2f7306a2015-07-16 16:48:06 +090084#define PLATFORM_CONFIG_KEY_OPERATOR_INFO "operator_info"
85
86struct operator_info {
87 struct listnode list;
88 char *name;
89 char *mccmnc;
90};
91
92struct operator_specific_device {
93 struct listnode list;
94 char *operator;
95 char *mixer_path;
96 int acdb_id;
97};
98
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -080099#define BE_DAI_NAME_MAX_LENGTH 24
100struct be_dai_name_struct {
101 unsigned int be_id;
102 char be_name[BE_DAI_NAME_MAX_LENGTH];
103};
104
keunhui.park2f7306a2015-07-16 16:48:06 +0900105static struct listnode operator_info_list;
106static struct listnode *operator_specific_device_table[SND_DEVICE_MAX];
107
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700108/* Audio calibration related functions */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800109typedef void (*acdb_send_audio_cal_v3_t)(int, int, int, int, int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700110
Eric Laurentb23d5282013-05-14 15:27:20 -0700111struct 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;
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700123#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
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;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800132 acdb_send_audio_cal_v3_t acdb_send_audio_cal_v3;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700133 acdb_send_voice_cal_t acdb_send_voice_cal;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700134 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700135 acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -0700136 acdb_send_custom_top_t acdb_send_custom_top;
137 bool acdb_initialized;
138
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700139 struct csd_data *csd;
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800140 char ec_ref_mixer_path[64];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700141
David Linee3fe402017-03-13 10:00:42 -0700142 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -0700143 char *snd_card_name;
keunhui.parkc5aaa0e2015-07-13 10:57:37 +0900144 int max_vol_index;
Prashant Malanic92c5962015-08-11 15:10:18 -0700145 int max_mic_count;
vivek mehtade4849c2016-03-03 17:23:38 -0800146
147 void *hw_info;
Eric Laurentb23d5282013-05-14 15:27:20 -0700148};
149
Haynes Mathew George98c95622014-06-20 19:14:25 -0700150static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700151 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
152 DEEP_BUFFER_PCM_DEVICE},
153 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
154 LOWLATENCY_PCM_DEVICE},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800155 [USECASE_AUDIO_PLAYBACK_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700156 MULTIMEDIA2_PCM_DEVICE},
157 [USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
158 PLAYBACK_OFFLOAD_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700159 [USECASE_AUDIO_PLAYBACK_TTS] = {MULTIMEDIA2_PCM_DEVICE,
160 MULTIMEDIA2_PCM_DEVICE},
161 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
162 MULTIMEDIA3_PCM_DEVICE},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800163 [USECASE_AUDIO_PLAYBACK_MMAP] = {MMAP_PLAYBACK_PCM_DEVICE,
164 MMAP_PLAYBACK_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700165
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700166 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
167 AUDIO_RECORD_PCM_DEVICE},
168 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
169 LOWLATENCY_PCM_DEVICE},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700170
Eric Laurent0e46adf2016-12-16 12:49:24 -0800171 [USECASE_AUDIO_RECORD_MMAP] = {MMAP_RECORD_PCM_DEVICE,
172 MMAP_RECORD_PCM_DEVICE},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700173 [USECASE_AUDIO_RECORD_HIFI] = {MULTIMEDIA2_PCM_DEVICE,
174 MULTIMEDIA2_PCM_DEVICE},
175
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700176 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
177 VOICE_CALL_PCM_DEVICE},
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700178 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
179 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
180 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
181 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
vivek mehtaa51fd402016-02-04 19:49:33 -0800182 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
183 VOICEMMODE1_CALL_PCM_DEVICE},
184 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
185 VOICEMMODE2_CALL_PCM_DEVICE},
186
Vineeta Srivastava4b89e372014-06-19 14:21:42 -0700187 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
188 AUDIO_RECORD_PCM_DEVICE},
189 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
190 AUDIO_RECORD_PCM_DEVICE},
191 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
192 AUDIO_RECORD_PCM_DEVICE},
Ravi Kumar Alamanda8e6e98f2013-11-05 15:57:39 -0800193 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700194
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700195 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
196 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
197
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700198 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
199 AFE_PROXY_RECORD_PCM_DEVICE},
200 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
201 AFE_PROXY_RECORD_PCM_DEVICE},
zhaoyang yin4211fad2015-06-04 21:13:25 +0800202 [USECASE_AUDIO_DSM_FEEDBACK] = {QUAT_MI2S_PCM_DEVICE, QUAT_MI2S_PCM_DEVICE},
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700203
vivek mehtaa68fea62017-06-08 19:04:02 -0700204 [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE,
205 AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
206 [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE,
207 AUDIO_RECORD_VOIP_PCM_DEVICE},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200208
209 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
210 INCALL_MUSIC_UPLINK_PCM_DEVICE},
Eric Laurentb23d5282013-05-14 15:27:20 -0700211};
212
213/* Array to store sound devices */
214static const char * const device_table[SND_DEVICE_MAX] = {
215 [SND_DEVICE_NONE] = "none",
216 /* Playback sound devices */
217 [SND_DEVICE_OUT_HANDSET] = "handset",
218 [SND_DEVICE_OUT_SPEAKER] = "speaker",
219 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700220 [SND_DEVICE_OUT_SPEAKER_SAFE] = "speaker-safe",
Eric Laurentb23d5282013-05-14 15:27:20 -0700221 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500222 [SND_DEVICE_OUT_LINE] = "line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700223 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700224 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = "speaker-safe-and-headphones",
Eric Laurent744996b2014-10-01 11:40:40 -0500225 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = "speaker-and-line",
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700226 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = "speaker-safe-and-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700227 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500228 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
Eric Laurentb23d5282013-05-14 15:27:20 -0700229 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
230 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500231 [SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
Eric Laurentb23d5282013-05-14 15:27:20 -0700232 [SND_DEVICE_OUT_HDMI] = "hdmi",
233 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
234 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700235 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700236 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
237 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
238 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
239 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
vivek mehtaa6b79742017-03-09 15:40:43 -0800240 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = "voice-tty-full-usb",
241 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = "voice-tty-vco-usb",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700242 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
David Linee3fe402017-03-13 10:00:42 -0700243 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headset",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700244 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = "usb-headset",
David Linee3fe402017-03-13 10:00:42 -0700245 [SND_DEVICE_OUT_USB_HEADPHONES] = "usb-headphones",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700246 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = "usb-headphones",
David Linee3fe402017-03-13 10:00:42 -0700247 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700248 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = "speaker-safe-and-usb-headphones",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700249 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
250 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700251 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = "voice-speaker-hfp",
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800252 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO] = "speaker-and-bt-sco",
253 [SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB] = "speaker-and-bt-sco-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700254
255 /* Capture sound devices */
256 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700257 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700258 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
259 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
260 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
261 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
262 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
263 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
264 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
265
266 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
267 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
268 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
269 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
270 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
271 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
272 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
273 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
274 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
275
276 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
Eric Laurentcefbbac2014-09-04 13:54:10 -0500277 [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700278
Eric Laurentb23d5282013-05-14 15:27:20 -0700279 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
280 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700281 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700282 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700283 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700284 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700285
286 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
287 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
288 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
289 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -0700290 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = "voice-speaker-mic-hfp",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700291 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700292 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
293 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
294 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
vivek mehtaa6b79742017-03-09 15:40:43 -0800295 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = "voice-tty-full-usb-mic",
296 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = "voice-tty-hco-usb-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700297
Eric Laurentb23d5282013-05-14 15:27:20 -0700298 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700299 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700300 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = "voice-rec-mic",
vivek mehtaf3440682016-05-11 14:24:37 -0700301 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = "voice-rec-mic",
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700302 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
303 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
David Linee3fe402017-03-13 10:00:42 -0700304 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700305 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] ="usb-headset-mic",
306 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = "usb-headset-mic",
307 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = "usb-headset-mic",
308 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = "usb-headset-mic",
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700309 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = "headset-mic",
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700310
Ricardo Garcia9034bc42016-04-04 07:11:46 -0700311 [SND_DEVICE_IN_UNPROCESSED_MIC] = "unprocessed-mic",
vivek mehta0125e782016-06-16 18:03:11 -0700312 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = "unprocessed-stereo-mic",
313 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = "unprocessed-three-mic",
314 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = "unprocessed-quad-mic",
315 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = "unprocessed-headset-mic",
rago90fb9612015-12-02 11:37:53 -0800316
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700317 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700318
Prashant Malanic92c5962015-08-11 15:10:18 -0700319 [SND_DEVICE_IN_THREE_MIC] = "three-mic",
320 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700321 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Prashant Malanic92c5962015-08-11 15:10:18 -0700322 [SND_DEVICE_IN_HANDSET_TMIC] = "three-mic",
323 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
vivek mehta733c1df2016-04-04 15:09:24 -0700324 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = "three-mic",
325 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700326};
327
328/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700329static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700330 [SND_DEVICE_NONE] = -1,
331 [SND_DEVICE_OUT_HANDSET] = 7,
332 [SND_DEVICE_OUT_SPEAKER] = 15,
333 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700334 [SND_DEVICE_OUT_SPEAKER_SAFE] = 15,
Eric Laurentb23d5282013-05-14 15:27:20 -0700335 [SND_DEVICE_OUT_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500336 [SND_DEVICE_OUT_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700337 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700338 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500339 [SND_DEVICE_OUT_SPEAKER_AND_LINE] = 77,
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700340 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = 77,
Ravi Kumar Alamanda235c3482014-08-21 17:32:44 -0700341 [SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
342 [SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500343 [SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
Eric Laurentb23d5282013-05-14 15:27:20 -0700344 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
Eric Laurent744996b2014-10-01 11:40:40 -0500345 [SND_DEVICE_OUT_VOICE_LINE] = 77,
Eric Laurentb23d5282013-05-14 15:27:20 -0700346 [SND_DEVICE_OUT_HDMI] = 18,
347 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
348 [SND_DEVICE_OUT_BT_SCO] = 22,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700349 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700350 [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
Eric Laurentb23d5282013-05-14 15:27:20 -0700351 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
352 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
353 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
vivek mehtaa6b79742017-03-09 15:40:43 -0800354 [SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = 17,
355 [SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = 17,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700356 [SND_DEVICE_OUT_VOICE_TX] = 45,
David Linee3fe402017-03-13 10:00:42 -0700357 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700358 [SND_DEVICE_OUT_VOICE_USB_HEADSET] = 45,
David Linee3fe402017-03-13 10:00:42 -0700359 [SND_DEVICE_OUT_USB_HEADPHONES] = 45,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700360 [SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = 45,
David Linee3fe402017-03-13 10:00:42 -0700361 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700362 [SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = 14,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700363 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
364 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700365 [SND_DEVICE_OUT_VOICE_SPEAKER_HFP] = ACDB_ID_VOICE_SPEAKER,
Eric Laurentb23d5282013-05-14 15:27:20 -0700366
367 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700368 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
369 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
370 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
371 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
372 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
373 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
374 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
375 [SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
376
377 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
378 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
379 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
380 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
381 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
382 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
383 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
384 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
385 [SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
386
rago90fb9612015-12-02 11:37:53 -0800387 [SND_DEVICE_IN_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentcefbbac2014-09-04 13:54:10 -0500388 [SND_DEVICE_IN_HEADSET_MIC_AEC] = ACDB_ID_HEADSET_MIC_AEC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700389
Eric Laurentb23d5282013-05-14 15:27:20 -0700390 [SND_DEVICE_IN_HDMI_MIC] = 4,
391 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700392 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 21,
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -0700393 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700394 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 38,
Eric Laurentb23d5282013-05-14 15:27:20 -0700395 [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700396
397 [SND_DEVICE_IN_VOICE_DMIC] = 41,
398 [SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
399 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700400 [SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP] = 11,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700401 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
rago90fb9612015-12-02 11:37:53 -0800402 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
Eric Laurentb23d5282013-05-14 15:27:20 -0700403 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
404 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
405 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
vivek mehtaa6b79742017-03-09 15:40:43 -0800406 [SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = 16,
407 [SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = 16,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700408
rago90fb9612015-12-02 11:37:53 -0800409 [SND_DEVICE_IN_VOICE_REC_MIC] = ACDB_ID_VOICE_REC_MIC,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700410 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
vivek mehta733c1df2016-04-04 15:09:24 -0700411 [SND_DEVICE_IN_VOICE_REC_MIC_AEC] = 112,
vivek mehtaf3440682016-05-11 14:24:37 -0700412 [SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS] = 114,
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700413 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
414 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
rago90fb9612015-12-02 11:37:53 -0800415 [SND_DEVICE_IN_VOICE_REC_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
416
417 [SND_DEVICE_IN_UNPROCESSED_MIC] = ACDB_ID_VOICE_REC_MIC,
418 [SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = ACDB_ID_HEADSET_MIC_AEC,
vivek mehta4ed66e62016-04-15 23:33:34 -0700419 [SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = 35,
420 [SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = 125,
421 [SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = 125,
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -0700422
423 [SND_DEVICE_IN_VOICE_RX] = 44,
David Linee3fe402017-03-13 10:00:42 -0700424 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700425 [SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = 44,
426 [SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = 44,
427 [SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = 44,
428 [SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = 44,
Prashant Malanic92c5962015-08-11 15:10:18 -0700429 [SND_DEVICE_IN_THREE_MIC] = 46,
430 [SND_DEVICE_IN_QUAD_MIC] = 46,
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700431 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Prashant Malanic92c5962015-08-11 15:10:18 -0700432 [SND_DEVICE_IN_HANDSET_TMIC] = 125,
433 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
vivek mehta733c1df2016-04-04 15:09:24 -0700434 [SND_DEVICE_IN_HANDSET_TMIC_AEC] = 125, /* override this for new target to 140 */
435 [SND_DEVICE_IN_HANDSET_QMIC_AEC] = 125, /* override this for new target to 140 */
Eric Laurentb23d5282013-05-14 15:27:20 -0700436};
437
David Linee3fe402017-03-13 10:00:42 -0700438// Platform specific backend bit width table
439static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
440
Haynes Mathew George98c95622014-06-20 19:14:25 -0700441struct name_to_index {
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700442 char name[100];
443 unsigned int index;
444};
445
446#define TO_NAME_INDEX(X) #X, X
447
Haynes Mathew George98c95622014-06-20 19:14:25 -0700448/* Used to get index from parsed string */
449static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
450 /* out */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700451 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
452 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
453 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
Eric Laurent1b0d8ce2014-09-11 09:59:28 -0700454 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700455 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500456 {TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700457 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700458 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES)},
Eric Laurent744996b2014-10-01 11:40:40 -0500459 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_LINE)},
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -0700460 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700461 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
462 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700463 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_HFP)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700464 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
Eric Laurent09f2e0e2014-07-29 16:02:32 -0500465 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700466 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
467 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
468 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
469 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700470 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
Eric Laurent9d0d3f12014-07-25 12:40:29 -0500471 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700472 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
473 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
474 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -0800475 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO)},
476 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800477 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_USB)},
478 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_USB)},
David Linee3fe402017-03-13 10:00:42 -0700479 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700480 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADSET)},
David Linee3fe402017-03-13 10:00:42 -0700481 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADPHONES)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700482 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_USB_HEADPHONES)},
David Linee3fe402017-03-13 10:00:42 -0700483 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
Haynes Mathew George9090bfb2017-05-31 11:44:50 -0700484 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700485 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
486 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800487
488 /* in */
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700489 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700490 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700491 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
492 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
493 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
494 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
495 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
496 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
497 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
498
499 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700500 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700501 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
502 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
503 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
504 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
505 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
506 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
507 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
508
509 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700510 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700511
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700512 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
513 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700514 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700515 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -0700516 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700517 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700518
519 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
520 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
521 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
Uday Kishore Pasupuletie9ef4782015-09-21 08:33:55 -0700522 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700523 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
524 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700525 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
526 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
527 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
vivek mehtaa6b79742017-03-09 15:40:43 -0800528 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC)},
529 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC)},
530
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700531
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700532 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700533 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
vivek mehta733c1df2016-04-04 15:09:24 -0700534 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC)},
vivek mehtaf3440682016-05-11 14:24:37 -0700535 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS)},
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -0700536 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -0700538 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_HEADSET_MIC)},
David Linee3fe402017-03-13 10:00:42 -0700539 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
Haynes Mathew George9a29f372017-04-11 19:19:07 -0700540 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_USB_HEADSET_MIC)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC_AEC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700544
rago90fb9612015-12-02 11:37:53 -0800545 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_MIC)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC)},
vivek mehta4ed66e62016-04-15 23:33:34 -0700547 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_STEREO_MIC)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_THREE_MIC)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_UNPROCESSED_QUAD_MIC)},
rago90fb9612015-12-02 11:37:53 -0800550
Prashant Malanic92c5962015-08-11 15:10:18 -0700551 {TO_NAME_INDEX(SND_DEVICE_IN_THREE_MIC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -0700553 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Prashant Malanic92c5962015-08-11 15:10:18 -0700554 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
vivek mehta733c1df2016-04-04 15:09:24 -0700556 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_TMIC_AEC)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC_AEC)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700558};
559
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -0700560static char * backend_tag_table[SND_DEVICE_MAX] = {0};
561static char * hw_interface_table[SND_DEVICE_MAX] = {0};
Haynes Mathew George98c95622014-06-20 19:14:25 -0700562
563static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
564 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
565 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800566 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700567 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Ravi Kumar Alamanda2bc7b022015-06-25 20:08:01 -0700568 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_TTS)},
569 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800570 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MMAP)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700571 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
572 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
Eric Laurent0e46adf2016-12-16 12:49:24 -0800573 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_MMAP)},
Haynes Mathew George569b7482017-05-08 14:44:27 -0700574 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_HIFI)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700575 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
576 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
577 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
578 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
579 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
John Muirf1346ce2016-12-06 00:03:41 -0800580 {TO_NAME_INDEX(USECASE_VOICEMMODE1_CALL)},
581 {TO_NAME_INDEX(USECASE_VOICEMMODE2_CALL)},
Haynes Mathew George98c95622014-06-20 19:14:25 -0700582 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
583 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
584 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
585 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
John Muirf1346ce2016-12-06 00:03:41 -0800586 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_RX)},
587 {TO_NAME_INDEX(USECASE_AUDIO_SPKR_CALIB_TX)},
588 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_AFE_PROXY)},
589 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_AFE_PROXY)},
590 {TO_NAME_INDEX(USECASE_AUDIO_DSM_FEEDBACK)},
vivek mehtaa68fea62017-06-08 19:04:02 -0700591 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_VOIP)},
592 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_VOIP)},
Nadav Bar3d72cfc2018-01-07 12:19:24 +0200593 {TO_NAME_INDEX(USECASE_INCALL_MUSIC_UPLINK)},
Haynes Mathew George5bc18842014-06-16 16:36:20 -0700594};
595
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800596static const struct name_to_index usecase_type_index[USECASE_TYPE_MAX] = {
597 {TO_NAME_INDEX(PCM_PLAYBACK)},
598 {TO_NAME_INDEX(PCM_CAPTURE)},
599 {TO_NAME_INDEX(VOICE_CALL)},
600 {TO_NAME_INDEX(PCM_HFP_CALL)},
601};
602
603struct app_type_entry {
604 int uc_type;
605 int bit_width;
606 int app_type;
607 int max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -0700608 char *mode;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800609 struct listnode node; // membership in app_type_entry_list;
610};
611
612static struct listnode app_type_entry_list;
613
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700614#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
615#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Eric Laurent0e46adf2016-12-16 12:49:24 -0800616#define ULL_PLATFORM_DELAY (3*1000LL)
617#define MMAP_PLATFORM_DELAY (3*1000LL)
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700618
Eric Laurentb23d5282013-05-14 15:27:20 -0700619static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
620static bool is_tmus = false;
621
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800622static int init_be_dai_name_table(struct audio_device *adev);
623
Eric Laurentb23d5282013-05-14 15:27:20 -0700624static void check_operator()
625{
626 char value[PROPERTY_VALUE_MAX];
627 int mccmnc;
628 property_get("gsm.sim.operator.numeric",value,"0");
629 mccmnc = atoi(value);
Eric Laurent2bafff12016-03-17 12:17:23 -0700630 ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
Eric Laurentb23d5282013-05-14 15:27:20 -0700631 switch(mccmnc) {
632 /* TMUS MCC(310), MNC(490, 260, 026) */
633 case 310490:
634 case 310260:
635 case 310026:
sangwon.jeonb891db52013-09-14 17:39:15 +0900636 /* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
637 case 310800:
638 case 310660:
639 case 310580:
640 case 310310:
641 case 310270:
642 case 310250:
643 case 310240:
644 case 310230:
645 case 310220:
646 case 310210:
647 case 310200:
648 case 310160:
Eric Laurentb23d5282013-05-14 15:27:20 -0700649 is_tmus = true;
650 break;
651 }
652}
653
654bool is_operator_tmus()
655{
656 pthread_once(&check_op_once_ctl, check_operator);
657 return is_tmus;
658}
659
keunhui.park2f7306a2015-07-16 16:48:06 +0900660static char *get_current_operator()
661{
662 struct listnode *node;
663 struct operator_info *info_item;
664 char mccmnc[PROPERTY_VALUE_MAX];
665 char *ret = NULL;
666
Tom Cherry7fea2042016-11-10 18:05:59 -0800667 property_get("gsm.sim.operator.numeric",mccmnc,"00000");
keunhui.park2f7306a2015-07-16 16:48:06 +0900668
669 list_for_each(node, &operator_info_list) {
670 info_item = node_to_item(node, struct operator_info, list);
671 if (strstr(info_item->mccmnc, mccmnc) != NULL) {
672 ret = info_item->name;
673 }
674 }
675
676 return ret;
677}
678
679static struct operator_specific_device *get_operator_specific_device(snd_device_t snd_device)
680{
681 struct listnode *node;
682 struct operator_specific_device *ret = NULL;
683 struct operator_specific_device *device_item;
684 char *operator_name;
685
686 operator_name = get_current_operator();
687 if (operator_name == NULL)
688 return ret;
689
690 list_for_each(node, operator_specific_device_table[snd_device]) {
691 device_item = node_to_item(node, struct operator_specific_device, list);
692 if (strcmp(operator_name, device_item->operator) == 0) {
693 ret = device_item;
694 }
695 }
696
697 return ret;
698}
699
700
701static int get_operator_specific_device_acdb_id(snd_device_t snd_device)
702{
703 struct operator_specific_device *device;
704 int ret = acdb_device_table[snd_device];
705
706 device = get_operator_specific_device(snd_device);
707 if (device != NULL)
708 ret = device->acdb_id;
709
710 return ret;
711}
712
713static const char *get_operator_specific_device_mixer_path(snd_device_t snd_device)
714{
715 struct operator_specific_device *device;
716 const char *ret = device_table[snd_device];
717
718 device = get_operator_specific_device(snd_device);
719 if (device != NULL)
720 ret = device->mixer_path;
721
722 return ret;
723}
724
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800725inline bool platform_supports_app_type_cfg()
726{
Alexey Polyudove920d4b2017-09-15 17:09:07 -0700727#if defined (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -0800728 return true;
729#else
730 return false;
731#endif
732}
733
vivek mehta1a9b7c02015-06-25 11:49:38 -0700734bool platform_send_gain_dep_cal(void *platform, int level)
735{
736 bool ret_val = false;
737 struct platform_data *my_data = (struct platform_data *)platform;
738 struct audio_device *adev = my_data->adev;
739 int acdb_dev_id, app_type;
740 int acdb_dev_type = MSM_SNDDEV_CAP_RX;
741 int mode = CAL_MODE_RTAC;
742 struct listnode *node;
743 struct audio_usecase *usecase;
Haynes Mathew George67486e22017-06-26 12:58:38 -0700744 bool valid_uc_type;
745 bool valid_dev;
vivek mehta1a9b7c02015-06-25 11:49:38 -0700746
747 if (my_data->acdb_send_gain_dep_cal == NULL) {
748 ALOGE("%s: dlsym error for acdb_send_gain_dep_cal", __func__);
749 return ret_val;
750 }
751
752 if (!voice_is_in_call(adev)) {
753 ALOGV("%s: Not Voice call usecase, apply new cal for level %d",
754 __func__, level);
vivek mehta1a9b7c02015-06-25 11:49:38 -0700755
756 // find the current active sound device
757 list_for_each(node, &adev->usecase_list) {
758 usecase = node_to_item(node, struct audio_usecase, list);
Haynes Mathew George67486e22017-06-26 12:58:38 -0700759 LOG_ALWAYS_FATAL_IF(usecase == NULL,
760 "unxpected NULL usecase in usecase_list");
761 valid_uc_type = usecase->type == PCM_PLAYBACK;
762 valid_dev = false;
763 if (valid_uc_type) {
764 audio_devices_t dev = usecase->stream.out->devices;
765 valid_dev = (dev == AUDIO_DEVICE_OUT_SPEAKER ||
vivek mehta40125092017-08-21 18:48:51 -0700766 dev == AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Haynes Mathew George67486e22017-06-26 12:58:38 -0700767 dev == AUDIO_DEVICE_OUT_WIRED_HEADSET ||
768 dev == AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
769 }
770 if (valid_dev) {
vivek mehta40125092017-08-21 18:48:51 -0700771 ALOGV("%s: out device is %d", __func__, usecase->out_snd_device);
772 if (platform_supports_app_type_cfg())
773 app_type = usecase->stream.out->app_type_cfg.app_type;
774 else
775 app_type = DEFAULT_APP_TYPE_RX_PATH;
vivek mehta4cb82982015-07-13 12:05:49 -0700776
vivek mehta40125092017-08-21 18:48:51 -0700777 if (audio_extn_spkr_prot_is_enabled())
778 acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
779 else
780 acdb_dev_id = acdb_device_table[usecase->out_snd_device];
781
782 if (!my_data->acdb_send_gain_dep_cal(acdb_dev_id, app_type,
vivek mehta1a9b7c02015-06-25 11:49:38 -0700783 acdb_dev_type, mode, level)) {
784 // set ret_val true if at least one calibration is set successfully
785 ret_val = true;
786 } else {
787 ALOGE("%s: my_data->acdb_send_gain_dep_cal failed ", __func__);
788 }
789 } else {
790 ALOGW("%s: Usecase list is empty", __func__);
791 }
792 }
793 } else {
794 ALOGW("%s: Voice call in progress .. ignore setting new cal",
795 __func__);
796 }
797 return ret_val;
798}
799
Eric Laurentcefbbac2014-09-04 13:54:10 -0500800void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700801{
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800802 struct platform_data *my_data = (struct platform_data *)adev->platform;
Eric Laurentcefbbac2014-09-04 13:54:10 -0500803 snd_device_t snd_device = SND_DEVICE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -0700804
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800805 if (strcmp(my_data->ec_ref_mixer_path, "")) {
806 ALOGV("%s: diabling %s", __func__, my_data->ec_ref_mixer_path);
807 audio_route_reset_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
Eric Laurentcefbbac2014-09-04 13:54:10 -0500808 }
809
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800810 if (enable) {
811 strcpy(my_data->ec_ref_mixer_path, "echo-reference");
812 if (out_device != AUDIO_DEVICE_NONE) {
813 snd_device = platform_get_output_snd_device(adev->platform, out_device);
814 platform_add_backend_name(adev->platform, my_data->ec_ref_mixer_path, snd_device);
815 }
Eric Laurentcefbbac2014-09-04 13:54:10 -0500816
Joe Onorato188b6222016-03-01 11:02:27 -0800817 ALOGV("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -0800818 audio_route_apply_and_update_path(adev->audio_route, my_data->ec_ref_mixer_path);
819 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700820}
821
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700822static struct csd_data *open_csd_client(bool i2s_ext_modem)
823{
824 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
825
826 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
827 if (csd->csd_client == NULL) {
828 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
829 goto error;
830 } else {
831 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
832
833 csd->deinit = (deinit_t)dlsym(csd->csd_client,
834 "csd_client_deinit");
835 if (csd->deinit == NULL) {
836 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
837 dlerror());
838 goto error;
839 }
840 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
841 "csd_client_disable_device");
842 if (csd->disable_device == NULL) {
843 ALOGE("%s: dlsym error %s for csd_client_disable_device",
844 __func__, dlerror());
845 goto error;
846 }
847 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
848 "csd_client_enable_device_config");
849 if (csd->enable_device_config == NULL) {
850 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
851 __func__, dlerror());
852 goto error;
853 }
854 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
855 "csd_client_enable_device");
856 if (csd->enable_device == NULL) {
857 ALOGE("%s: dlsym error %s for csd_client_enable_device",
858 __func__, dlerror());
859 goto error;
860 }
861 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
862 "csd_client_start_voice");
863 if (csd->start_voice == NULL) {
864 ALOGE("%s: dlsym error %s for csd_client_start_voice",
865 __func__, dlerror());
866 goto error;
867 }
868 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
869 "csd_client_stop_voice");
870 if (csd->stop_voice == NULL) {
871 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
872 __func__, dlerror());
873 goto error;
874 }
875 csd->volume = (volume_t)dlsym(csd->csd_client,
876 "csd_client_volume");
877 if (csd->volume == NULL) {
878 ALOGE("%s: dlsym error %s for csd_client_volume",
879 __func__, dlerror());
880 goto error;
881 }
882 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
883 "csd_client_mic_mute");
884 if (csd->mic_mute == NULL) {
885 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
886 __func__, dlerror());
887 goto error;
888 }
889 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
890 "csd_client_slow_talk");
891 if (csd->slow_talk == NULL) {
892 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
893 __func__, dlerror());
894 goto error;
895 }
896 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
897 "csd_client_start_playback");
898 if (csd->start_playback == NULL) {
899 ALOGE("%s: dlsym error %s for csd_client_start_playback",
900 __func__, dlerror());
901 goto error;
902 }
903 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
904 "csd_client_stop_playback");
905 if (csd->stop_playback == NULL) {
906 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
907 __func__, dlerror());
908 goto error;
909 }
910 csd->start_record = (start_record_t)dlsym(csd->csd_client,
911 "csd_client_start_record");
912 if (csd->start_record == NULL) {
913 ALOGE("%s: dlsym error %s for csd_client_start_record",
914 __func__, dlerror());
915 goto error;
916 }
917 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
918 "csd_client_stop_record");
919 if (csd->stop_record == NULL) {
920 ALOGE("%s: dlsym error %s for csd_client_stop_record",
921 __func__, dlerror());
922 goto error;
923 }
924
925 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
926 "csd_client_get_sample_rate");
927 if (csd->get_sample_rate == NULL) {
928 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
929 __func__, dlerror());
930
931 goto error;
932 }
933
934 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
935
936 if (csd->init == NULL) {
937 ALOGE("%s: dlsym error %s for csd_client_init",
938 __func__, dlerror());
939 goto error;
940 } else {
941 csd->init(i2s_ext_modem);
942 }
943 }
944 return csd;
945
946error:
947 free(csd);
948 csd = NULL;
949 return csd;
950}
951
952void close_csd_client(struct csd_data *csd)
953{
954 if (csd != NULL) {
955 csd->deinit();
956 dlclose(csd->csd_client);
957 free(csd);
958 csd = NULL;
959 }
960}
961
962static void platform_csd_init(struct platform_data *my_data)
963{
964#ifdef PLATFORM_MSM8084
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700965 int32_t modems, (*count_modems)(void);
966 const char *name = "libdetectmodem.so";
967 const char *func = "count_modems";
968 const char *error;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700969
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700970 my_data->csd = NULL;
971
972 void *lib = dlopen(name, RTLD_NOW);
973 error = dlerror();
974 if (!lib) {
975 ALOGE("%s: could not find %s: %s", __func__, name, error);
976 return;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700977 }
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700978
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700979 count_modems = NULL;
980 *(void **)(&count_modems) = dlsym(lib, func);
981 error = dlerror();
982 if (!count_modems) {
983 ALOGE("%s: could not find symbol %s in %s: %s",
984 __func__, func, name, error);
985 goto done;
986 }
987
988 modems = count_modems();
989 if (modems < 0) {
990 ALOGE("%s: count_modems failed\n", __func__);
991 goto done;
992 }
993
Eric Laurent2bafff12016-03-17 12:17:23 -0700994 ALOGD("%s: num_modems %d\n", __func__, modems);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700995 if (modems > 0)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -0700996 my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
Iliyan Malchevae9a10c2014-08-09 13:07:21 -0700997
998done:
999 dlclose(lib);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001000#else
1001 my_data->csd = NULL;
1002#endif
1003}
1004
Eric Laurentc6333382015-09-14 12:43:44 -07001005static void set_platform_defaults(struct platform_data * my_data)
Haynes Mathew George98c95622014-06-20 19:14:25 -07001006{
1007 int32_t dev;
1008 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001009 backend_tag_table[dev] = NULL;
1010 hw_interface_table[dev] = NULL;
keunhui.park2f7306a2015-07-16 16:48:06 +09001011 operator_specific_device_table[dev] = NULL;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001012 }
1013
David Linee3fe402017-03-13 10:00:42 -07001014 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1015 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1016 }
1017
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001018 // To overwrite these go to the audio_platform_info.xml file.
1019 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001020 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001021 backend_tag_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1022 backend_tag_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1023 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1024 backend_tag_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1025 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07001026 backend_tag_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001027 backend_tag_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1028 backend_tag_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
Haynes Mathew George98c95622014-06-20 19:14:25 -07001029
David Linee3fe402017-03-13 10:00:42 -07001030 backend_tag_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headset");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001031 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("usb-headset");
David Linee3fe402017-03-13 10:00:42 -07001032 backend_tag_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("usb-headphones");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001033 backend_tag_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001034 backend_tag_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1035 strdup("speaker-and-usb-headphones");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001036 backend_tag_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] =
1037 strdup("speaker-safe-and-usb-headphones");
David Linee3fe402017-03-13 10:00:42 -07001038 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001039 backend_tag_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1040 backend_tag_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1041 backend_tag_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1042 backend_tag_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("usb-headset-mic");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001043 hw_interface_table[SND_DEVICE_OUT_HANDSET] = strdup("SLIMBUS_0_RX");
1044 hw_interface_table[SND_DEVICE_OUT_SPEAKER] = strdup("SLIMBUS_0_RX");
1045 hw_interface_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("SLIMBUS_0_RX");
1046 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE] = strdup("SLIMBUS_0_RX");
1047 hw_interface_table[SND_DEVICE_OUT_HEADPHONES] = strdup("SLIMBUS_0_RX");
1048 hw_interface_table[SND_DEVICE_OUT_LINE] = strdup("SLIMBUS_0_RX");
1049 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001050 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001051 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07001052 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE] = strdup("SLIMBUS_0_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001053 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("SLIMBUS_0_RX");
1054 hw_interface_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("SLIMBUS_0_RX");
1055 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("SLIMBUS_0_RX");
1056 hw_interface_table[SND_DEVICE_OUT_VOICE_HEADPHONES] = strdup("SLIMBUS_0_RX");
1057 hw_interface_table[SND_DEVICE_OUT_VOICE_LINE] = strdup("SLIMBUS_0_RX");
1058 hw_interface_table[SND_DEVICE_OUT_HDMI] = strdup("HDMI_RX");
1059 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("SLIMBUS_0_RX-and-HDMI_RX");
1060 hw_interface_table[SND_DEVICE_OUT_BT_SCO] = strdup("SEC_AUX_PCM_RX");
1061 hw_interface_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("SEC_AUX_PCM_RX");
1062 hw_interface_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("SLIMBUS_0_RX");
1063 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = strdup("SLIMBUS_0_RX");
1064 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = strdup("SLIMBUS_0_RX");
1065 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("SLIMBUS_0_RX");
David Linee3fe402017-03-13 10:00:42 -07001066 hw_interface_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("USB_AUDIO_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001067 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_FULL_USB] = strdup("USB_AUDIO_RX");
1068 hw_interface_table[SND_DEVICE_OUT_VOICE_TTY_VCO_USB] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001069 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADSET] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001070 hw_interface_table[SND_DEVICE_OUT_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
Haynes Mathew George9a29f372017-04-11 19:19:07 -07001071 hw_interface_table[SND_DEVICE_OUT_VOICE_USB_HEADPHONES] = strdup("USB_AUDIO_RX");
David Linee3fe402017-03-13 10:00:42 -07001072 hw_interface_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07001073 hw_interface_table[SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET] = strdup("SLIMBUS_0_RX-and-USB_AUDIO_RX");
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001074 hw_interface_table[SND_DEVICE_OUT_VOICE_TX] = strdup("AFE_PCM_RX");
1075 hw_interface_table[SND_DEVICE_OUT_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
1076 hw_interface_table[SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = strdup("SLIMBUS_0_RX");
Haynes Mathew Georgee95340e2017-05-24 15:42:06 -07001077 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1078 hw_interface_table[SND_DEVICE_IN_VOICE_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1079 hw_interface_table[SND_DEVICE_IN_USB_HEADSET_MIC_AEC] = strdup("USB_AUDIO_TX");
1080 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1081 hw_interface_table[SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC] = strdup("USB_AUDIO_TX");
1082 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC] = strdup("USB_AUDIO_TX");
1083 hw_interface_table[SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC] = strdup("USB_AUDIO_TX");
1084 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1085 hw_interface_table[SND_DEVICE_IN_HANDSET_MIC] = strdup("SLIMBUS_0_TX");
1086 hw_interface_table[SND_DEVICE_IN_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1087 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1088 hw_interface_table[SND_DEVICE_IN_CAMCORDER_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001089 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC] = strdup("SLIMBUS_0_TX");
1090 hw_interface_table[SND_DEVICE_IN_VOICE_REC_MIC_NS] = strdup("SLIMBUS_0_TX");
1091 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = strdup("SLIMBUS_0_TX");
1092 hw_interface_table[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = strdup("SLIMBUS_0_TX");
David Lin93725722017-10-13 14:58:17 -07001093 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_MIC] = strdup("SLIMBUS_0_TX");
1094 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
1095 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_STEREO_MIC] = strdup("SLIMBUS_0_TX");
1096 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_THREE_MIC] = strdup("SLIMBUS_0_TX");
1097 hw_interface_table[SND_DEVICE_IN_UNPROCESSED_QUAD_MIC] = strdup("SLIMBUS_0_TX");
Haynes Mathew Georgec2f805c2017-06-27 11:28:35 -07001098 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1099 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC] = strdup("SLIMBUS_0_TX");
1100 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_NS] = strdup("SLIMBUS_0_TX");
1101 hw_interface_table[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1102 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC] = strdup("SLIMBUS_0_TX");
1103 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = strdup("SLIMBUS_0_TX");
1104 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_NS] = strdup("SLIMBUS_0_TX");
1105 hw_interface_table[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = strdup("SLIMBUS_0_TX");
1106 hw_interface_table[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = strdup("SLIMBUS_0_TX");
1107 hw_interface_table[SND_DEVICE_IN_VOICE_HEADSET_MIC] = strdup("SLIMBUS_0_TX");
Eric Laurentc6333382015-09-14 12:43:44 -07001108 my_data->max_mic_count = PLATFORM_DEFAULT_MIC_COUNT;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001109}
1110
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001111void get_cvd_version(char *cvd_version, struct audio_device *adev)
1112{
1113 struct mixer_ctl *ctl;
1114 int count;
1115 int ret = 0;
1116
1117 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1118 if (!ctl) {
1119 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1120 goto done;
1121 }
1122 mixer_ctl_update(ctl);
1123
1124 count = mixer_ctl_get_num_values(ctl);
1125 if (count > MAX_CVD_VERSION_STRING_SIZE)
1126 count = MAX_CVD_VERSION_STRING_SIZE - 1;
1127
1128 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1129 if (ret != 0) {
1130 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1131 goto done;
1132 }
1133
1134done:
1135 return;
1136}
1137
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001138static int platform_acdb_init(void *platform)
1139{
1140 struct platform_data *my_data = (struct platform_data *)platform;
1141 struct audio_device *adev = my_data->adev;
1142
1143 if (!my_data->acdb_init) {
1144 ALOGE("%s: no acdb_init fn provided", __func__);
1145 return -1;
1146 }
1147
1148 if (my_data->acdb_initialized) {
1149 ALOGW("acdb is already initialized");
1150 return 0;
1151 }
1152
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001153#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001154 char *cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1155 if (!cvd_version)
1156 ALOGE("failed to allocate cvd_version");
1157 else {
1158 get_cvd_version(cvd_version, adev);
1159 my_data->acdb_init((char *)my_data->snd_card_name, cvd_version, 0);
1160 free(cvd_version);
1161 }
1162#elif defined (PLATFORM_MSM8084)
1163 my_data->acdb_init((char *)my_data->snd_card_name);
1164#else
1165 my_data->acdb_init();
1166#endif
1167 my_data->acdb_initialized = true;
1168 return 0;
1169}
1170
David Linee3fe402017-03-13 10:00:42 -07001171static void
1172platform_backend_config_init(struct platform_data *pdata)
1173{
1174 int i;
1175
1176 /* initialize backend config */
1177 for (i = 0; i < MAX_CODEC_BACKENDS; i++) {
1178 pdata->current_backend_cfg[i].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1179 pdata->current_backend_cfg[i].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
1180 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_CHANNELS;
1181
1182 if (i > MAX_RX_CODEC_BACKENDS)
1183 pdata->current_backend_cfg[i].channels = CODEC_BACKEND_DEFAULT_TX_CHANNELS;
1184
1185 pdata->current_backend_cfg[i].bitwidth_mixer_ctl = NULL;
1186 pdata->current_backend_cfg[i].samplerate_mixer_ctl = NULL;
1187 pdata->current_backend_cfg[i].channels_mixer_ctl = NULL;
1188 }
1189
1190 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1191 strdup("SLIM_0_RX Format");
1192 pdata->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1193 strdup("SLIM_0_RX SampleRate");
1194
1195 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].bitwidth_mixer_ctl =
1196 strdup("SLIM_0_TX Format");
1197 pdata->current_backend_cfg[DEFAULT_CODEC_TX_BACKEND].samplerate_mixer_ctl =
1198 strdup("SLIM_0_TX SampleRate");
1199
1200 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].bitwidth_mixer_ctl =
1201 strdup("USB_AUDIO_TX Format");
1202 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].samplerate_mixer_ctl =
1203 strdup("USB_AUDIO_TX SampleRate");
1204 pdata->current_backend_cfg[USB_AUDIO_TX_BACKEND].channels_mixer_ctl =
1205 strdup("USB_AUDIO_TX Channels");
1206
1207 pdata->current_backend_cfg[HEADPHONE_BACKEND].bitwidth_mixer_ctl =
1208 strdup("SLIM_6_RX Format");
1209 pdata->current_backend_cfg[HEADPHONE_BACKEND].samplerate_mixer_ctl =
1210 strdup("SLIM_6_RX SampleRate");
1211
1212 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].bitwidth_mixer_ctl =
1213 strdup("USB_AUDIO_RX Format");
1214 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].samplerate_mixer_ctl =
1215 strdup("USB_AUDIO_RX SampleRate");
1216
1217 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels = 1;
1218 pdata->current_backend_cfg[USB_AUDIO_RX_BACKEND].channels_mixer_ctl =
1219 strdup("USB_AUDIO_RX Channels");
1220}
1221
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001222static int
1223platform_backend_app_type_cfg_init(struct platform_data *pdata,
1224 struct mixer *mixer)
1225{
1226 size_t app_type_cfg[128] = {0};
1227 int length, num_app_types = 0;
1228 struct mixer_ctl *ctl = NULL;
1229
1230 const char *mixer_ctl_name = "App Type Config";
1231 ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
1232 if (!ctl) {
1233 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
1234 return -1;
1235 }
1236
1237 length = 1; // reserve index 0 for number of app types
1238
1239 struct listnode *node;
1240 struct app_type_entry *entry;
1241 list_for_each(node, &app_type_entry_list) {
1242 entry = node_to_item(node, struct app_type_entry, node);
1243 app_type_cfg[length++] = entry->app_type;
1244 app_type_cfg[length++] = entry->max_rate;
1245 app_type_cfg[length++] = entry->bit_width;
1246 ALOGI("%s add entry %d %d", __func__, entry->app_type, entry->bit_width);
1247 num_app_types += 1;
1248 }
1249
1250 // default for capture
1251 int t;
1252 platform_get_default_app_type_v2(pdata,
1253 PCM_CAPTURE,
1254 &t);
1255 app_type_cfg[length++] = t;
1256 app_type_cfg[length++] = 48000;
1257 app_type_cfg[length++] = 16;
1258 num_app_types += 1;
1259
1260 if (num_app_types) {
1261 app_type_cfg[0] = num_app_types;
1262 if (mixer_ctl_set_array(ctl, app_type_cfg, length) < 0) {
1263 ALOGE("Failed to set app type cfg");
1264 }
1265 }
1266 return 0;
1267}
1268
Eric Laurentb23d5282013-05-14 15:27:20 -07001269void *platform_init(struct audio_device *adev)
1270{
1271 char value[PROPERTY_VALUE_MAX];
vivek mehta60ea4152016-02-18 17:10:26 -08001272 struct platform_data *my_data = NULL;
1273 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
1274 bool dual_mic_config = false, use_default_mixer_path = true;
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001275 const char *snd_card_name;
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001276 char *cvd_version = NULL;
vivek mehta60ea4152016-02-18 17:10:26 -08001277 char *snd_internal_name = NULL;
1278 char *tmp = NULL;
1279 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
vivek mehtade4849c2016-03-03 17:23:38 -08001280 char platform_info_file[MIXER_PATH_MAX_LENGTH]= {0};
1281 struct snd_card_split *snd_split_handle = NULL;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001282 my_data = calloc(1, sizeof(struct platform_data));
1283
1284 my_data->adev = adev;
1285
keunhui.park2f7306a2015-07-16 16:48:06 +09001286 list_init(&operator_info_list);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001287 list_init(&app_type_entry_list);
keunhui.park2f7306a2015-07-16 16:48:06 +09001288
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001289 set_platform_defaults(my_data);
1290
vivek mehta0fb11312017-05-15 19:35:32 -07001291 // audio_extn_utils_get_snd_card_num does
1292 // - open mixer and get snd card name
1293 // - parse platform info xml file and check for valid snd card name
1294 // - on failure loop through all the active snd card
sangwoo1b9f4b32013-06-21 18:22:55 -07001295
vivek mehta0fb11312017-05-15 19:35:32 -07001296 snd_card_num = audio_extn_utils_get_snd_card_num();
1297 if (-1 == snd_card_num) {
1298 ALOGE("%s: invalid sound card number (-1), bailing out ", __func__);
1299 goto init_failed;
sangwoo1b9f4b32013-06-21 18:22:55 -07001300 }
1301
vivek mehta0fb11312017-05-15 19:35:32 -07001302 adev->mixer = mixer_open(snd_card_num);
1303 snd_card_name = mixer_get_name(adev->mixer);
1304 my_data->hw_info = hw_info_init(snd_card_name);
1305
1306 audio_extn_set_snd_card_split(snd_card_name);
1307 snd_split_handle = audio_extn_get_snd_card_split();
1308
1309 /* Get the codec internal name from the sound card and/or form factor
1310 * name and form the mixer paths and platfor info file name dynamically.
1311 * This is generic way of picking any codec and forma factor name based
1312 * mixer and platform info files in future with no code change.
1313
1314 * current code extends and looks for any of the exteneded mixer path and
1315 * platform info file present based on codec and form factor.
1316
1317 * order of picking appropriate file is
1318 * <i> mixer_paths_<codec_name>_<form_factor>.xml, if file not present
1319 * <ii> mixer_paths_<codec_name>.xml, if file not present
1320 * <iii> mixer_paths.xml
1321
1322 * same order is followed for audio_platform_info.xml as well
1323 */
1324
1325 // need to carryforward old file name
1326 if (!strncmp(snd_card_name, TOMTOM_8226_SND_CARD_NAME,
1327 min(strlen(TOMTOM_8226_SND_CARD_NAME), strlen(snd_card_name)))) {
1328 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1329 MIXER_XML_BASE_STRING, TOMTOM_MIXER_FILE_SUFFIX );
1330 } else {
1331
1332 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s_%s.xml",
1333 MIXER_XML_BASE_STRING, snd_split_handle->snd_card,
1334 snd_split_handle->form_factor);
1335 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1336 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1337 snprintf(mixer_xml_file, sizeof(mixer_xml_file), "%s_%s.xml",
1338 MIXER_XML_BASE_STRING, snd_split_handle->snd_card);
1339
1340 if (!audio_extn_utils_resolve_config_file(mixer_xml_file)) {
1341 memset(mixer_xml_file, 0, sizeof(mixer_xml_file));
1342 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH, MIXER_PATH_MAX_LENGTH);
1343 audio_extn_utils_resolve_config_file(mixer_xml_file);
1344 }
1345 }
1346 }
1347
1348 audio_extn_utils_get_platform_info(snd_card_name, platform_info_file);
1349
1350 /* Initialize platform specific ids and/or backends*/
1351 platform_info_init(platform_info_file, my_data);
1352
1353 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1354 adev->audio_route = audio_route_init(snd_card_num, mixer_xml_file);
1355
1356 if (!adev->audio_route) {
1357 ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
1358 mixer_close(adev->mixer);
1359 adev->mixer = NULL;
1360 hw_info_deinit(my_data->hw_info);
1361 my_data->hw_info = NULL;
1362 goto init_failed;
1363 }
1364 adev->snd_card = snd_card_num;
1365 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1366
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09001367 //set max volume step for voice call
1368 property_get("ro.config.vc_call_vol_steps", value, TOSTRING(MAX_VOL_INDEX));
1369 my_data->max_vol_index = atoi(value);
1370
vivek mehta65ad12d2015-08-13 18:32:48 -07001371 property_get("persist.audio.dualmic.config",value,"");
1372 if (!strcmp("endfire", value)) {
1373 dual_mic_config = true;
1374 }
1375
John Muir9e59a962018-01-10 13:30:00 -08001376 my_data->source_mic_type = 0;
Prashant Malanic92c5962015-08-11 15:10:18 -07001377
Eric Laurentb23d5282013-05-14 15:27:20 -07001378 my_data->fluence_in_spkr_mode = false;
1379 my_data->fluence_in_voice_call = false;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001380 my_data->fluence_in_voice_comm = false;
Eric Laurentb23d5282013-05-14 15:27:20 -07001381 my_data->fluence_in_voice_rec = false;
1382
vivek mehta65ad12d2015-08-13 18:32:48 -07001383 property_get("ro.qc.sdk.audio.fluencetype", value, "none");
Prashant Malanic92c5962015-08-11 15:10:18 -07001384 if (!strcmp("fluencepro", value)) {
1385 my_data->fluence_type = FLUENCE_PRO_ENABLE;
vivek mehta65ad12d2015-08-13 18:32:48 -07001386 } else if (!strcmp("fluence", value) || (dual_mic_config)) {
Prashant Malanic92c5962015-08-11 15:10:18 -07001387 my_data->fluence_type = FLUENCE_ENABLE;
1388 } else if (!strcmp("none", value)) {
1389 my_data->fluence_type = FLUENCE_DISABLE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001390 }
1391
Prashant Malanic92c5962015-08-11 15:10:18 -07001392 if (my_data->fluence_type != FLUENCE_DISABLE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001393 property_get("persist.audio.fluence.voicecall",value,"");
1394 if (!strcmp("true", value)) {
1395 my_data->fluence_in_voice_call = true;
1396 }
1397
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07001398 property_get("persist.audio.fluence.voicecomm",value,"");
1399 if (!strcmp("true", value)) {
1400 my_data->fluence_in_voice_comm = true;
1401 }
1402
Eric Laurentb23d5282013-05-14 15:27:20 -07001403 property_get("persist.audio.fluence.voicerec",value,"");
1404 if (!strcmp("true", value)) {
1405 my_data->fluence_in_voice_rec = true;
1406 }
1407
1408 property_get("persist.audio.fluence.speaker",value,"");
1409 if (!strcmp("true", value)) {
1410 my_data->fluence_in_spkr_mode = true;
1411 }
1412 }
1413
Prashant Malanic92c5962015-08-11 15:10:18 -07001414 // support max to mono, example if max count is 3, usecase supports Three, dual and mono mic
1415 switch (my_data->max_mic_count) {
1416 case 4:
1417 my_data->source_mic_type |= SOURCE_QUAD_MIC;
1418 case 3:
1419 my_data->source_mic_type |= SOURCE_THREE_MIC;
1420 case 2:
1421 my_data->source_mic_type |= SOURCE_DUAL_MIC;
1422 case 1:
1423 my_data->source_mic_type |= SOURCE_MONO_MIC;
1424 break;
1425 default:
1426 ALOGE("%s: max_mic_count (%d), is not supported, setting to default",
1427 __func__, my_data->max_mic_count);
1428 my_data->source_mic_type = SOURCE_MONO_MIC|SOURCE_DUAL_MIC;
1429 break;
1430 }
1431
1432 ALOGV("%s: Fluence_Type(%d) max_mic_count(%d) mic_type(0x%x) fluence_in_voice_call(%d)"
1433 " fluence_in_voice_comm(%d) fluence_in_voice_rec(%d) fluence_in_spkr_mode(%d) ",
1434 __func__, my_data->fluence_type, my_data->max_mic_count, my_data->source_mic_type,
1435 my_data->fluence_in_voice_call, my_data->fluence_in_voice_comm,
1436 my_data->fluence_in_voice_rec, my_data->fluence_in_spkr_mode);
1437
Eric Laurentb23d5282013-05-14 15:27:20 -07001438 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1439 if (my_data->acdb_handle == NULL) {
1440 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1441 } else {
1442 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1443 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1444 "acdb_loader_deallocate_ACDB");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001445 if (!my_data->acdb_deallocate)
1446 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1447 __func__, LIB_ACDB_LOADER);
1448
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001449 my_data->acdb_send_audio_cal_v3 = (acdb_send_audio_cal_v3_t)dlsym(my_data->acdb_handle,
1450 "acdb_loader_send_audio_cal_v3");
1451 if (!my_data->acdb_send_audio_cal_v3)
1452 ALOGE("%s: Could not find the symbol acdb_send_audio_cal_v3 from %s",
1453 __func__, LIB_ACDB_LOADER);
1454
Eric Laurentb23d5282013-05-14 15:27:20 -07001455 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
1456 "acdb_loader_send_audio_cal");
1457 if (!my_data->acdb_send_audio_cal)
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001458 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001459 __func__, LIB_ACDB_LOADER);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001460
Eric Laurentb23d5282013-05-14 15:27:20 -07001461 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1462 "acdb_loader_send_voice_cal");
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001463 if (!my_data->acdb_send_voice_cal)
1464 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1465 __func__, LIB_ACDB_LOADER);
1466
1467 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1468 "acdb_loader_reload_vocvoltable");
1469 if (!my_data->acdb_reload_vocvoltable)
1470 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1471 __func__, LIB_ACDB_LOADER);
vivek mehta1a9b7c02015-06-25 11:49:38 -07001472
1473 my_data->acdb_send_gain_dep_cal = (acdb_send_gain_dep_cal_t)dlsym(my_data->acdb_handle,
1474 "acdb_loader_send_gain_dep_cal");
1475 if (!my_data->acdb_send_gain_dep_cal)
1476 ALOGV("%s: Could not find the symbol acdb_loader_send_gain_dep_cal from %s",
1477 __func__, LIB_ACDB_LOADER);
1478
Alexey Polyudove920d4b2017-09-15 17:09:07 -07001479#if defined (PLATFORM_MSM8994) || (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
vivek mehta0fb11312017-05-15 19:35:32 -07001480 acdb_init_v2_cvd_t acdb_init_local;
1481 acdb_init_local = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001482 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001483 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001484 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1485 dlerror());
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001486
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001487#elif defined (PLATFORM_MSM8084)
vivek mehta0fb11312017-05-15 19:35:32 -07001488 acdb_init_v2_t acdb_init_local;
1489 acdb_init_local = (acdb_init_v2_t)dlsym(my_data->acdb_handle,
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001490 "acdb_loader_init_v2");
vivek mehta0fb11312017-05-15 19:35:32 -07001491 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001492 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__,
1493 dlerror());
1494
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001495#else
vivek mehta0fb11312017-05-15 19:35:32 -07001496 acdb_init_t acdb_init_local;
1497 acdb_init_local = (acdb_init_t)dlsym(my_data->acdb_handle,
Eric Laurentb23d5282013-05-14 15:27:20 -07001498 "acdb_loader_init_ACDB");
vivek mehta0fb11312017-05-15 19:35:32 -07001499 if (acdb_init_local == NULL)
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001500 ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__,
1501 dlerror());
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001502#endif
vivek mehta0fb11312017-05-15 19:35:32 -07001503 my_data->acdb_init = acdb_init_local;
Eric Laurentb23d5282013-05-14 15:27:20 -07001504
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001505 my_data->acdb_send_custom_top = (acdb_send_custom_top_t)
1506 dlsym(my_data->acdb_handle,
1507 "acdb_loader_send_common_custom_topology");
1508
1509 if (!my_data->acdb_send_custom_top)
1510 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1511 __func__, LIB_ACDB_LOADER);
1512
vivek mehta0fb11312017-05-15 19:35:32 -07001513 int result = acdb_init(adev->snd_card);
1514 if (!result) {
1515 my_data->acdb_initialized = true;
1516 ALOGD("ACDB initialized");
1517 } else {
1518 my_data->acdb_initialized = false;
1519 ALOGD("ACDB initialization failed");
1520 }
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07001521 }
Ravi Kumar Alamanda5c049df2015-07-01 16:23:03 +09001522
David Linee3fe402017-03-13 10:00:42 -07001523 /* init usb */
1524 audio_extn_usb_init(adev);
1525
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001526 audio_extn_spkr_prot_init(adev);
Haynes Mathew George98c95622014-06-20 19:14:25 -07001527
Ravi Kumar Alamanda76315572015-04-23 13:13:56 -07001528 audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
1529
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001530 /* load csd client */
1531 platform_csd_init(my_data);
1532
David Linee3fe402017-03-13 10:00:42 -07001533 platform_backend_config_init(my_data);
1534
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001535 init_be_dai_name_table(adev);
1536
1537 if (platform_supports_app_type_cfg())
1538 platform_backend_app_type_cfg_init(my_data, adev->mixer);
1539
Eric Laurentb23d5282013-05-14 15:27:20 -07001540 return my_data;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001541
1542init_failed:
1543 if (my_data)
1544 free(my_data);
1545 return NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001546}
1547
1548void platform_deinit(void *platform)
1549{
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001550 int32_t dev;
keunhui.park2f7306a2015-07-16 16:48:06 +09001551 struct operator_info *info_item;
1552 struct operator_specific_device *device_item;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001553 struct app_type_entry *ap;
keunhui.park2f7306a2015-07-16 16:48:06 +09001554 struct listnode *node;
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001555
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07001556 struct platform_data *my_data = (struct platform_data *)platform;
1557 close_csd_client(my_data->csd);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001558
vivek mehtade4849c2016-03-03 17:23:38 -08001559 hw_info_deinit(my_data->hw_info);
1560
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001561 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1562 if (backend_tag_table[dev])
1563 free(backend_tag_table[dev]);
1564 if (hw_interface_table[dev])
1565 free(hw_interface_table[dev]);
keunhui.park2f7306a2015-07-16 16:48:06 +09001566 if (operator_specific_device_table[dev]) {
1567 while (!list_empty(operator_specific_device_table[dev])) {
1568 node = list_head(operator_specific_device_table[dev]);
1569 list_remove(node);
1570 device_item = node_to_item(node, struct operator_specific_device, list);
1571 free(device_item->operator);
1572 free(device_item->mixer_path);
1573 free(device_item);
1574 }
1575 free(operator_specific_device_table[dev]);
1576 }
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07001577 }
1578
1579 if (my_data->snd_card_name)
1580 free(my_data->snd_card_name);
1581
keunhui.park2f7306a2015-07-16 16:48:06 +09001582 while (!list_empty(&operator_info_list)) {
1583 node = list_head(&operator_info_list);
1584 list_remove(node);
1585 info_item = node_to_item(node, struct operator_info, list);
1586 free(info_item->name);
1587 free(info_item->mccmnc);
1588 free(info_item);
1589 }
1590
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001591 while (!list_empty(&app_type_entry_list)) {
1592 node = list_head(&app_type_entry_list);
1593 list_remove(node);
1594 ap = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07001595 if (ap->mode) free(ap->mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001596 free(ap);
1597 }
1598
Kevin Rocarde35d4af2017-05-02 16:55:28 -07001599 mixer_close(my_data->adev->mixer);
Eric Laurentb23d5282013-05-14 15:27:20 -07001600 free(platform);
David Linee3fe402017-03-13 10:00:42 -07001601
1602 /* deinit usb */
1603 audio_extn_usb_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001604}
1605
1606const char *platform_get_snd_device_name(snd_device_t snd_device)
1607{
keunhui.park2f7306a2015-07-16 16:48:06 +09001608 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1609 if (operator_specific_device_table[snd_device] != NULL) {
1610 return get_operator_specific_device_mixer_path(snd_device);
1611 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001612 return device_table[snd_device];
keunhui.park2f7306a2015-07-16 16:48:06 +09001613 } else
Ravi Kumar Alamanda64026462014-09-15 00:08:58 -07001614 return "none";
Eric Laurentb23d5282013-05-14 15:27:20 -07001615}
1616
vivek mehtade4849c2016-03-03 17:23:38 -08001617int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1618 char *device_name)
1619{
1620 struct platform_data *my_data = (struct platform_data *)platform;
1621
David Benjamin1565f992016-09-21 12:10:34 -04001622 if (platform == NULL) {
vivek mehtade4849c2016-03-03 17:23:38 -08001623 ALOGW("%s: something wrong, use legacy get_snd_device name", __func__);
David Benjamin1565f992016-09-21 12:10:34 -04001624 strlcpy(device_name, platform_get_snd_device_name(snd_device),
1625 DEVICE_NAME_MAX_SIZE);
vivek mehtade4849c2016-03-03 17:23:38 -08001626 } else if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1627 if (operator_specific_device_table[snd_device] != NULL) {
1628 strlcpy(device_name, get_operator_specific_device_mixer_path(snd_device),
1629 DEVICE_NAME_MAX_SIZE);
1630 } else {
1631 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1632 }
1633 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1634 } else {
1635 strlcpy(device_name, "none", DEVICE_NAME_MAX_SIZE);
1636 }
1637
1638 return 0;
1639}
1640
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001641void platform_add_backend_name(void *platform, char *mixer_path,
1642 snd_device_t snd_device)
Eric Laurentb23d5282013-05-14 15:27:20 -07001643{
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001644 struct platform_data *my_data = (struct platform_data *)platform;
1645
Haynes Mathew George98c95622014-06-20 19:14:25 -07001646 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1647 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1648 return;
Ravi Kumar Alamanda1de6e5a2014-06-19 21:55:39 -05001649 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001650
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001651 const char * suffix = backend_tag_table[snd_device];
Haynes Mathew George98c95622014-06-20 19:14:25 -07001652
1653 if (suffix != NULL) {
1654 strcat(mixer_path, " ");
1655 strcat(mixer_path, suffix);
Ravi Kumar Alamanda299760a2013-11-01 17:29:09 -05001656 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001657}
1658
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001659bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2)
1660{
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001661 ALOGV("%s: snd_device1 = %s, snd_device2 = %s", __func__,
1662 platform_get_snd_device_name(snd_device1),
1663 platform_get_snd_device_name(snd_device2));
1664
1665 if ((snd_device1 < SND_DEVICE_MIN) || (snd_device1 >= SND_DEVICE_MAX)) {
1666 ALOGE("%s: Invalid snd_device = %s", __func__,
1667 platform_get_snd_device_name(snd_device1));
1668 return false;
1669 }
1670 if ((snd_device2 < SND_DEVICE_MIN) || (snd_device2 >= SND_DEVICE_MAX)) {
1671 ALOGE("%s: Invalid snd_device = %s", __func__,
1672 platform_get_snd_device_name(snd_device2));
1673 return false;
1674 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001675
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001676 const char * be_itf1 = hw_interface_table[snd_device1];
1677 const char * be_itf2 = hw_interface_table[snd_device2];
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001678 /*
1679 hw_interface_table has overrides for a snd_device.
1680 if there is no entry for a device, assume DEFAULT_RX_BACKEND
1681 */
1682 if (be_itf1 == NULL) {
1683 be_itf1 = DEFAULT_RX_BACKEND;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001684 }
Haynes Mathew George39c55dc2017-07-11 19:31:23 -07001685 if (be_itf2 == NULL) {
1686 be_itf2 = DEFAULT_RX_BACKEND;
1687 }
1688 ALOGV("%s: be_itf1 = %s, be_itf2 = %s", __func__, be_itf1, be_itf2);
1689 /*
1690 this takes care of finding a device within a combo device pair as well
1691 */
1692 return strstr(be_itf1, be_itf2) != NULL || strstr(be_itf2, be_itf1) != NULL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001693}
1694
Eric Laurentb23d5282013-05-14 15:27:20 -07001695int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1696{
1697 int device_id;
1698 if (device_type == PCM_PLAYBACK)
1699 device_id = pcm_device_table[usecase][0];
1700 else
1701 device_id = pcm_device_table[usecase][1];
1702 return device_id;
1703}
1704
Haynes Mathew George98c95622014-06-20 19:14:25 -07001705static int find_index(const struct name_to_index * table, int32_t len,
1706 const char * name)
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001707{
1708 int ret = 0;
Haynes Mathew George98c95622014-06-20 19:14:25 -07001709 int32_t i;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001710
Haynes Mathew George98c95622014-06-20 19:14:25 -07001711 if (table == NULL) {
1712 ALOGE("%s: table is NULL", __func__);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001713 ret = -ENODEV;
1714 goto done;
1715 }
1716
Haynes Mathew George98c95622014-06-20 19:14:25 -07001717 if (name == NULL) {
1718 ALOGE("null key");
1719 ret = -ENODEV;
1720 goto done;
1721 }
1722
1723 for (i=0; i < len; i++) {
1724 if (!strcmp(table[i].name, name)) {
1725 ret = table[i].index;
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001726 goto done;
1727 }
1728 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07001729 ALOGE("%s: Could not find index for name = %s",
1730 __func__, name);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001731 ret = -ENODEV;
1732done:
1733 return ret;
1734}
1735
Haynes Mathew George98c95622014-06-20 19:14:25 -07001736int platform_get_snd_device_index(char *device_name)
1737{
1738 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1739}
1740
1741int platform_get_usecase_index(const char *usecase_name)
1742{
1743 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1744}
1745
keunhui.park2f7306a2015-07-16 16:48:06 +09001746void platform_add_operator_specific_device(snd_device_t snd_device,
1747 const char *operator,
1748 const char *mixer_path,
1749 unsigned int acdb_id)
1750{
1751 struct operator_specific_device *device;
1752
1753 if (operator_specific_device_table[snd_device] == NULL) {
1754 operator_specific_device_table[snd_device] =
1755 (struct listnode *)calloc(1, sizeof(struct listnode));
1756 list_init(operator_specific_device_table[snd_device]);
1757 }
1758
1759 device = (struct operator_specific_device *)calloc(1, sizeof(struct operator_specific_device));
1760
1761 device->operator = strdup(operator);
1762 device->mixer_path = strdup(mixer_path);
1763 device->acdb_id = acdb_id;
1764
1765 list_add_tail(operator_specific_device_table[snd_device], &device->list);
1766
Eric Laurent2bafff12016-03-17 12:17:23 -07001767 ALOGD("%s: device[%s] -> operator[%s] mixer_path[%s] acdb_id[%d]", __func__,
keunhui.park2f7306a2015-07-16 16:48:06 +09001768 platform_get_snd_device_name(snd_device), operator, mixer_path, acdb_id);
1769
1770}
1771
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001772int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1773{
1774 int ret = 0;
1775
1776 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1777 ALOGE("%s: Invalid snd_device = %d",
1778 __func__, snd_device);
1779 ret = -EINVAL;
1780 goto done;
1781 }
1782
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07001783 ALOGV("%s: acdb_device_table[%s]: old = %d new = %d", __func__,
1784 platform_get_snd_device_name(snd_device), acdb_device_table[snd_device], acdb_id);
Haynes Mathew George5bc18842014-06-16 16:36:20 -07001785 acdb_device_table[snd_device] = acdb_id;
1786done:
1787 return ret;
1788}
1789
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001790int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1791{
1792 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1793 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1794 return -EINVAL;
1795 }
keunhui.park2f7306a2015-07-16 16:48:06 +09001796
1797 if (operator_specific_device_table[snd_device] != NULL)
1798 return get_operator_specific_device_acdb_id(snd_device);
1799 else
1800 return acdb_device_table[snd_device];
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001801}
1802
David Linee3fe402017-03-13 10:00:42 -07001803static int platform_get_backend_index(snd_device_t snd_device)
1804{
1805 int32_t port = DEFAULT_CODEC_BACKEND;
1806
1807 if (snd_device >= SND_DEVICE_OUT_BEGIN && snd_device < SND_DEVICE_OUT_END) {
1808 if (backend_tag_table[snd_device] != NULL) {
1809 if (strncmp(backend_tag_table[snd_device], "headphones",
1810 sizeof("headphones")) == 0)
1811 port = HEADPHONE_BACKEND;
1812 else if (strcmp(backend_tag_table[snd_device], "hdmi") == 0)
1813 port = HDMI_RX_BACKEND;
1814 else if ((strcmp(backend_tag_table[snd_device], "usb-headphones") == 0) ||
1815 (strcmp(backend_tag_table[snd_device], "usb-headset") == 0))
1816 port = USB_AUDIO_RX_BACKEND;
1817 }
1818 } else if (snd_device >= SND_DEVICE_IN_BEGIN && snd_device < SND_DEVICE_IN_END) {
1819 port = DEFAULT_CODEC_TX_BACKEND;
1820 if (backend_tag_table[snd_device] != NULL) {
1821 if (strcmp(backend_tag_table[snd_device], "usb-headset-mic") == 0)
1822 port = USB_AUDIO_TX_BACKEND;
1823 else if (strstr(backend_tag_table[snd_device], "bt-sco") != NULL)
1824 port = BT_SCO_TX_BACKEND;
1825 }
1826 } else {
1827 ALOGW("%s:napb: Invalid device - %d ", __func__, snd_device);
1828 }
1829
1830 ALOGV("%s:napb: backend port - %d device - %d ", __func__, port, snd_device);
1831
1832 return port;
1833}
1834
Eric Laurentb23d5282013-05-14 15:27:20 -07001835int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
1836{
1837 struct platform_data *my_data = (struct platform_data *)platform;
1838 int acdb_dev_id, acdb_dev_type;
1839
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001840 if (platform_supports_app_type_cfg()) // use v2 instead
1841 return -ENOSYS;
1842
Ravi Kumar Alamandaadf0f3b2015-06-04 02:34:02 -07001843 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001844 if (acdb_dev_id < 0) {
1845 ALOGE("%s: Could not find acdb id for device(%d)",
1846 __func__, snd_device);
1847 return -EINVAL;
1848 }
1849 if (my_data->acdb_send_audio_cal) {
Joe Onorato188b6222016-03-01 11:02:27 -08001850 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001851 __func__, snd_device, acdb_dev_id);
1852 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1853 snd_device < SND_DEVICE_OUT_END)
1854 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1855 else
1856 acdb_dev_type = ACDB_DEV_TYPE_IN;
1857 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
1858 }
1859 return 0;
1860}
1861
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08001862int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase,
1863 int app_type, int sample_rate)
1864{
1865 struct platform_data *my_data = (struct platform_data *)platform;
1866 int acdb_dev_id, acdb_dev_type;
1867 int snd_device = SND_DEVICE_OUT_SPEAKER;
1868 int new_snd_device[SND_DEVICE_OUT_END] = {0};
1869 int i, num_devices = 1;
1870
1871 if (!platform_supports_app_type_cfg()) // use v1 instead
1872 return -ENOSYS;
1873
1874 if (usecase->type == PCM_PLAYBACK)
1875 snd_device = usecase->out_snd_device;
1876 else if (usecase->type == PCM_CAPTURE)
1877 snd_device = usecase->in_snd_device;
1878
1879 // skipped over get_spkr_prot_device
1880 acdb_dev_id = acdb_device_table[snd_device];
1881 if (acdb_dev_id < 0) {
1882 ALOGE("%s: Could not find acdb id for device(%d)",
1883 __func__, snd_device);
1884 return -EINVAL;
1885 }
1886
1887 if (platform_can_split_snd_device(snd_device,
1888 &num_devices, new_snd_device) < 0) {
1889 new_snd_device[0] = snd_device;
1890 }
1891
1892 for (i = 0; i < num_devices; i++) {
1893 acdb_dev_id = acdb_device_table[new_snd_device[i]];
1894 if (acdb_dev_id < 0) {
1895 ALOGE("%s: Could not find acdb id for device(%d)",
1896 __func__, new_snd_device[i]);
1897 return -EINVAL;
1898 }
1899 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
1900 __func__, new_snd_device[i], acdb_dev_id);
1901 if (new_snd_device[i] >= SND_DEVICE_OUT_BEGIN &&
1902 new_snd_device[i] < SND_DEVICE_OUT_END)
1903 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1904 else
1905 acdb_dev_type = ACDB_DEV_TYPE_IN;
1906
1907 if (my_data->acdb_send_audio_cal_v3) {
1908 my_data->acdb_send_audio_cal_v3(acdb_dev_id, acdb_dev_type,
1909 app_type, sample_rate, i);
1910 } else if (my_data->acdb_send_audio_cal) {
1911 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); // this version differs from internal
1912 }
1913 }
1914
1915 return 0;
1916}
1917
1918
Eric Laurentb23d5282013-05-14 15:27:20 -07001919int platform_switch_voice_call_device_pre(void *platform)
1920{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001921 struct platform_data *my_data = (struct platform_data *)platform;
1922 int ret = 0;
1923
1924 if (my_data->csd != NULL &&
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07001925 voice_is_in_call(my_data->adev)) {
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001926 /* This must be called before disabling mixer controls on APQ side */
1927 ret = my_data->csd->disable_device();
1928 if (ret < 0) {
1929 ALOGE("%s: csd_client_disable_device, failed, error %d",
1930 __func__, ret);
1931 }
1932 }
1933 return ret;
1934}
1935
1936int platform_switch_voice_call_enable_device_config(void *platform,
1937 snd_device_t out_snd_device,
1938 snd_device_t in_snd_device)
1939{
1940 struct platform_data *my_data = (struct platform_data *)platform;
1941 int acdb_rx_id, acdb_tx_id;
1942 int ret = 0;
1943
1944 if (my_data->csd == NULL)
1945 return ret;
1946
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001947 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1948 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09001949 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001950 else
keunhui.park2f7306a2015-07-16 16:48:06 +09001951 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001952
keunhui.park2f7306a2015-07-16 16:48:06 +09001953 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001954
1955 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1956 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1957 if (ret < 0) {
1958 ALOGE("%s: csd_enable_device_config, failed, error %d",
1959 __func__, ret);
1960 }
1961 } else {
1962 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1963 acdb_rx_id, acdb_tx_id);
1964 }
1965
1966 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001967}
1968
1969int platform_switch_voice_call_device_post(void *platform,
1970 snd_device_t out_snd_device,
1971 snd_device_t in_snd_device)
1972{
1973 struct platform_data *my_data = (struct platform_data *)platform;
1974 int acdb_rx_id, acdb_tx_id;
1975
1976 if (my_data->acdb_send_voice_cal == NULL) {
1977 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1978 } else {
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07001979 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1980 audio_extn_spkr_prot_is_enabled())
1981 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1982
keunhui.park2f7306a2015-07-16 16:48:06 +09001983 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
1984 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07001985
1986 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1987 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1988 else
1989 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1990 acdb_rx_id, acdb_tx_id);
1991 }
1992
1993 return 0;
1994}
1995
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07001996int platform_switch_voice_call_usecase_route_post(void *platform,
1997 snd_device_t out_snd_device,
1998 snd_device_t in_snd_device)
1999{
2000 struct platform_data *my_data = (struct platform_data *)platform;
2001 int acdb_rx_id, acdb_tx_id;
2002 int ret = 0;
2003
2004 if (my_data->csd == NULL)
2005 return ret;
2006
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002007 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
2008 audio_extn_spkr_prot_is_enabled())
keunhui.park2f7306a2015-07-16 16:48:06 +09002009 acdb_rx_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
Ravi Kumar Alamanda63863002015-04-22 11:15:25 -07002010 else
keunhui.park2f7306a2015-07-16 16:48:06 +09002011 acdb_rx_id = platform_get_snd_device_acdb_id(out_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002012
keunhui.park2f7306a2015-07-16 16:48:06 +09002013 acdb_tx_id = platform_get_snd_device_acdb_id(in_snd_device);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002014
2015 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
2016 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
2017 my_data->adev->acdb_settings);
2018 if (ret < 0) {
2019 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
2020 }
2021 } else {
2022 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
2023 acdb_rx_id, acdb_tx_id);
2024 }
2025
2026 return ret;
2027}
2028
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002029int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002030{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002031 struct platform_data *my_data = (struct platform_data *)platform;
2032 int ret = 0;
2033
2034 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002035 ret = my_data->csd->start_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002036 if (ret < 0) {
2037 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
2038 }
2039 }
2040 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002041}
2042
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002043int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07002044{
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002045 struct platform_data *my_data = (struct platform_data *)platform;
2046 int ret = 0;
2047
2048 if (my_data->csd != NULL) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002049 ret = my_data->csd->stop_voice(vsid);
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002050 if (ret < 0) {
2051 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
2052 }
2053 }
2054 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002055}
2056
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002057int platform_get_sample_rate(void *platform, uint32_t *rate)
2058{
2059 struct platform_data *my_data = (struct platform_data *)platform;
2060 int ret = 0;
2061
2062 if (my_data->csd != NULL) {
2063 ret = my_data->csd->get_sample_rate(rate);
2064 if (ret < 0) {
2065 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
2066 }
2067 }
2068 return ret;
2069}
2070
vivek mehtab6506412015-08-07 16:55:17 -07002071void platform_set_speaker_gain_in_combo(struct audio_device *adev,
2072 snd_device_t snd_device,
2073 bool enable)
2074{
2075 const char* name;
2076 switch (snd_device) {
2077 case SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES:
2078 if (enable)
2079 name = "spkr-gain-in-headphone-combo";
2080 else
2081 name = "speaker-gain-default";
2082 break;
2083 case SND_DEVICE_OUT_SPEAKER_AND_LINE:
2084 if (enable)
2085 name = "spkr-gain-in-line-combo";
2086 else
2087 name = "speaker-gain-default";
2088 break;
2089 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES:
2090 if (enable)
2091 name = "spkr-safe-gain-in-headphone-combo";
2092 else
2093 name = "speaker-safe-gain-default";
2094 break;
2095 case SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE:
2096 if (enable)
2097 name = "spkr-safe-gain-in-line-combo";
2098 else
2099 name = "speaker-safe-gain-default";
2100 break;
2101 default:
2102 return;
2103 }
2104
2105 audio_route_apply_and_update_path(adev->audio_route, name);
2106}
2107
Eric Laurentb23d5282013-05-14 15:27:20 -07002108int platform_set_voice_volume(void *platform, int volume)
2109{
2110 struct platform_data *my_data = (struct platform_data *)platform;
2111 struct audio_device *adev = my_data->adev;
2112 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07002113 const char *mixer_ctl_name = "Voice Rx Gain";
Nadav Barc46d0fa2017-12-24 14:50:37 +02002114 const char *mute_mixer_ctl_name = "Voice Rx Device Mute";
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002115 int vol_index = 0, ret = 0;
2116 uint32_t set_values[ ] = {0,
2117 ALL_SESSION_VSID,
2118 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002119
2120 // Voice volume levels are mapped to adsp volume levels as follows.
2121 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
2122 // But this values don't changed in kernel. So, below change is need.
keunhui.parkc5aaa0e2015-07-13 10:57:37 +09002123 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, my_data->max_vol_index);
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002124 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07002125
2126 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2127 if (!ctl) {
2128 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2129 __func__, mixer_ctl_name);
2130 return -EINVAL;
2131 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002132 ALOGV("Setting voice volume index: %d", set_values[0]);
2133 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2134
Nadav Barc46d0fa2017-12-24 14:50:37 +02002135 // Send mute command in case volume index is max since indexes are inverted
2136 // for mixer controls.
2137 if (vol_index == my_data->max_vol_index) {
2138 set_values[0] = 1;
2139 }
2140 else {
2141 set_values[0] = 0;
2142 }
2143
2144 ctl = mixer_get_ctl_by_name(adev->mixer, mute_mixer_ctl_name);
2145 if (!ctl) {
2146 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2147 __func__, mute_mixer_ctl_name);
2148 return -EINVAL;
2149 }
2150 ALOGV("%s: Setting RX Device Mute to: %d", __func__, set_values[0]);
2151 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2152
Ravi Kumar Alamanda83281a92014-05-19 18:14:57 -07002153 if (my_data->csd != NULL) {
2154 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
2155 DEFAULT_VOLUME_RAMP_DURATION_MS);
2156 if (ret < 0) {
2157 ALOGE("%s: csd_volume error %d", __func__, ret);
2158 }
2159 }
2160 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002161}
2162
2163int platform_set_mic_mute(void *platform, bool state)
2164{
2165 struct platform_data *my_data = (struct platform_data *)platform;
2166 struct audio_device *adev = my_data->adev;
2167 struct mixer_ctl *ctl;
2168 const char *mixer_ctl_name = "Voice Tx Mute";
sangwoo53b2cf02013-07-25 19:18:44 -07002169 int ret = 0;
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002170 uint32_t set_values[ ] = {0,
2171 ALL_SESSION_VSID,
2172 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002173
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002174 if (adev->mode != AUDIO_MODE_IN_CALL &&
2175 adev->mode != AUDIO_MODE_IN_COMMUNICATION)
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002176 return 0;
2177
Uday Kishore Pasupuletia1f48052015-09-08 22:49:18 +09002178 if (adev->enable_hfp)
2179 mixer_ctl_name = "HFP Tx Mute";
2180
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002181 set_values[0] = state;
2182 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2183 if (!ctl) {
2184 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2185 __func__, mixer_ctl_name);
2186 return -EINVAL;
2187 }
2188 ALOGV("Setting voice mute state: %d", state);
2189 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2190
2191 if (my_data->csd != NULL) {
2192 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2193 DEFAULT_MUTE_RAMP_DURATION_MS);
sangwoo53b2cf02013-07-25 19:18:44 -07002194 if (ret < 0) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002195 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
sangwoo53b2cf02013-07-25 19:18:44 -07002196 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002197 }
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002198 return ret;
2199}
Eric Laurentb23d5282013-05-14 15:27:20 -07002200
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002201int platform_set_device_mute(void *platform, bool state, char *dir)
2202{
2203 struct platform_data *my_data = (struct platform_data *)platform;
2204 struct audio_device *adev = my_data->adev;
2205 struct mixer_ctl *ctl;
2206 char *mixer_ctl_name = NULL;
2207 int ret = 0;
2208 uint32_t set_values[ ] = {0,
2209 ALL_SESSION_VSID,
2210 0};
2211 if(dir == NULL) {
2212 ALOGE("%s: Invalid direction:%s", __func__, dir);
2213 return -EINVAL;
2214 }
2215
2216 if (!strncmp("rx", dir, sizeof("rx"))) {
2217 mixer_ctl_name = "Voice Rx Device Mute";
2218 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2219 mixer_ctl_name = "Voice Tx Device Mute";
2220 } else {
2221 return -EINVAL;
2222 }
2223
2224 set_values[0] = state;
2225 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2226 if (!ctl) {
2227 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2228 __func__, mixer_ctl_name);
2229 return -EINVAL;
2230 }
2231
2232 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2233 __func__,state, mixer_ctl_name);
2234 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2235
2236 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002237}
2238
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002239int platform_can_split_snd_device(snd_device_t snd_device,
2240 int *num_devices,
2241 snd_device_t *new_snd_devices)
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002242{
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002243 int ret = -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002244 if (NULL == num_devices || NULL == new_snd_devices) {
2245 ALOGE("%s: NULL pointer ..", __func__);
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002246 return -EINVAL;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002247 }
2248
2249 /*
2250 * If wired headset/headphones/line devices share the same backend
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002251 * with speaker/earpiece this routine returns -EINVAL.
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002252 */
2253 if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES &&
2254 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_HEADPHONES)) {
2255 *num_devices = 2;
2256 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2257 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002258 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002259 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE &&
2260 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_LINE)) {
2261 *num_devices = 2;
2262 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2263 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002264 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002265 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES &&
2266 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_HEADPHONES)) {
2267 *num_devices = 2;
2268 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2269 new_snd_devices[1] = SND_DEVICE_OUT_HEADPHONES;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002270 ret = 0;
Ravi Kumar Alamanda3b86d472015-06-08 00:35:57 -07002271 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE &&
2272 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_LINE)) {
2273 *num_devices = 2;
2274 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2275 new_snd_devices[1] = SND_DEVICE_OUT_LINE;
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002276 ret = 0;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002277 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO &&
2278 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2279 SND_DEVICE_OUT_BT_SCO)) {
2280 *num_devices = 2;
2281 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2282 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO;
2283 ret = 0;
2284 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB &&
2285 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER,
2286 SND_DEVICE_OUT_BT_SCO_WB)) {
2287 *num_devices = 2;
2288 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2289 new_snd_devices[1] = SND_DEVICE_OUT_BT_SCO_WB;
2290 ret = 0;
David Linee3fe402017-03-13 10:00:42 -07002291 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET &&
2292 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER, SND_DEVICE_OUT_USB_HEADSET)) {
2293 *num_devices = 2;
2294 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
2295 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2296 ret = 0;
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002297 } else if (snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET &&
2298 !platform_check_backends_match(SND_DEVICE_OUT_SPEAKER_SAFE, SND_DEVICE_OUT_USB_HEADSET)) {
2299 *num_devices = 2;
2300 new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER_SAFE;
2301 new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
2302 ret = 0;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002303 }
Haynes Mathew George2d809e02016-09-22 17:38:16 -07002304 return ret;
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07002305}
2306
Eric Laurentb23d5282013-05-14 15:27:20 -07002307snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
2308{
2309 struct platform_data *my_data = (struct platform_data *)platform;
2310 struct audio_device *adev = my_data->adev;
2311 audio_mode_t mode = adev->mode;
2312 snd_device_t snd_device = SND_DEVICE_NONE;
2313
2314 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2315 if (devices == AUDIO_DEVICE_NONE ||
2316 devices & AUDIO_DEVICE_BIT_IN) {
2317 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2318 goto exit;
2319 }
2320
Eric Laurent1b491552015-09-15 17:52:41 -07002321 if (popcount(devices) == 2) {
2322 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2323 AUDIO_DEVICE_OUT_SPEAKER) ||
2324 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2325 AUDIO_DEVICE_OUT_SPEAKER)) {
2326 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2327 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2328 AUDIO_DEVICE_OUT_SPEAKER)) {
2329 snd_device = SND_DEVICE_OUT_SPEAKER_AND_LINE;
2330 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2331 AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2332 devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2333 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2334 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES;
2335 } else if (devices == (AUDIO_DEVICE_OUT_LINE |
2336 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
2337 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE;
2338 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2339 AUDIO_DEVICE_OUT_SPEAKER)) {
2340 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Haynes Mathew George6dcb1a82016-12-21 12:38:55 -08002341 } else if ((devices & AUDIO_DEVICE_OUT_ALL_SCO) &&
2342 ((devices & ~AUDIO_DEVICE_OUT_ALL_SCO) == AUDIO_DEVICE_OUT_SPEAKER)) {
2343 snd_device = adev->bt_wb_speech_enabled ?
2344 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
2345 SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
Eric Laurent99dab492017-06-17 15:19:08 -07002346 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2347 AUDIO_DEVICE_OUT_SPEAKER)) ||
2348 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2349 AUDIO_DEVICE_OUT_SPEAKER))) {
David Linee3fe402017-03-13 10:00:42 -07002350 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Eric Laurentd0f7c262017-07-05 09:09:12 -07002351 } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
2352 AUDIO_DEVICE_OUT_SPEAKER_SAFE)) ||
2353 (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
2354 AUDIO_DEVICE_OUT_SPEAKER_SAFE))) {
Haynes Mathew George9090bfb2017-05-31 11:44:50 -07002355 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET;
Eric Laurent1b491552015-09-15 17:52:41 -07002356 } else {
2357 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2358 goto exit;
2359 }
2360 if (snd_device != SND_DEVICE_NONE) {
2361 goto exit;
2362 }
2363 }
2364
2365 if (popcount(devices) != 1) {
2366 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2367 goto exit;
2368 }
2369
Madhuri Athota3f6051b2016-10-13 23:25:38 +05302370 if (voice_is_in_call(adev) || adev->enable_voicerx || audio_extn_hfp_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002371 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002372 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2373 devices & AUDIO_DEVICE_OUT_LINE) {
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002374 if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002375 (adev->voice.tty_mode == TTY_MODE_FULL))
Eric Laurentb23d5282013-05-14 15:27:20 -07002376 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002377 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002378 (adev->voice.tty_mode == TTY_MODE_VCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002379 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
Ravi Kumar Alamandab09e4a02014-10-20 17:07:43 -07002380 else if (voice_is_in_call(adev) &&
Eric Laurentcefbbac2014-09-04 13:54:10 -05002381 (adev->voice.tty_mode == TTY_MODE_HCO))
Eric Laurentb23d5282013-05-14 15:27:20 -07002382 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002383 else {
2384 if (devices & AUDIO_DEVICE_OUT_LINE)
2385 snd_device = SND_DEVICE_OUT_VOICE_LINE;
2386 else
2387 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2388 }
Eric Laurent99dab492017-06-17 15:19:08 -07002389 } else if (audio_is_usb_out_device(devices)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002390 if (voice_is_in_call(adev)) {
2391 switch (adev->voice.tty_mode) {
2392 case TTY_MODE_FULL:
2393 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_USB;
2394 break;
2395 case TTY_MODE_VCO:
2396 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_USB;
2397 break;
2398 case TTY_MODE_HCO:
2399 // since Hearing will be on handset\speaker, use existing device
2400 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2401 break;
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002402 case TTY_MODE_OFF:
2403 break;
vivek mehtaa6b79742017-03-09 15:40:43 -08002404 default:
2405 ALOGE("%s: Invalid TTY mode (%#x)",
2406 __func__, adev->voice.tty_mode);
2407 }
2408 }
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002409 if (snd_device == SND_DEVICE_NONE) {
2410 snd_device = audio_extn_usb_is_capture_supported() ?
2411 SND_DEVICE_OUT_VOICE_USB_HEADSET :
2412 SND_DEVICE_OUT_VOICE_USB_HEADPHONES;
2413 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002414 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002415 if (adev->bt_wb_speech_enabled) {
2416 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2417 } else {
2418 snd_device = SND_DEVICE_OUT_BT_SCO;
2419 }
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002420 } else if (devices & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002421 if (!adev->enable_hfp) {
2422 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
2423 } else {
2424 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_HFP;
2425 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002426 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002427 if(adev->voice.hac)
2428 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2429 else if (is_operator_tmus())
Eric Laurentb23d5282013-05-14 15:27:20 -07002430 snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
2431 else
Eric Laurentb4d368e2014-06-25 10:21:54 -05002432 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002433 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2434 snd_device = SND_DEVICE_OUT_VOICE_TX;
2435
Eric Laurentb23d5282013-05-14 15:27:20 -07002436 if (snd_device != SND_DEVICE_NONE) {
2437 goto exit;
2438 }
2439 }
2440
Eric Laurentb23d5282013-05-14 15:27:20 -07002441 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2442 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2443 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002444 } else if (devices & AUDIO_DEVICE_OUT_LINE) {
2445 snd_device = SND_DEVICE_OUT_LINE;
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002446 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
2447 snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002448 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07002449 if (my_data->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002450 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2451 else
2452 snd_device = SND_DEVICE_OUT_SPEAKER;
2453 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002454 if (adev->bt_wb_speech_enabled) {
2455 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2456 } else {
2457 snd_device = SND_DEVICE_OUT_BT_SCO;
2458 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002459 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2460 snd_device = SND_DEVICE_OUT_HDMI ;
Eric Laurent99dab492017-06-17 15:19:08 -07002461 } else if (audio_is_usb_out_device(devices)) {
David Linee3fe402017-03-13 10:00:42 -07002462 if (audio_extn_usb_is_capture_supported())
2463 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2464 else
2465 snd_device = SND_DEVICE_OUT_USB_HEADPHONES;
2466 }else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurent9d0d3f12014-07-25 12:40:29 -05002467 /*HAC support for voice-ish audio (eg visual voicemail)*/
2468 if(adev->voice.hac)
2469 snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
2470 else
2471 snd_device = SND_DEVICE_OUT_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002472 } else {
2473 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2474 }
2475exit:
2476 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2477 return snd_device;
2478}
2479
2480snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2481{
2482 struct platform_data *my_data = (struct platform_data *)platform;
2483 struct audio_device *adev = my_data->adev;
2484 audio_source_t source = (adev->active_input == NULL) ?
2485 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2486
2487 audio_mode_t mode = adev->mode;
2488 audio_devices_t in_device = ((adev->active_input == NULL) ?
2489 AUDIO_DEVICE_NONE : adev->active_input->device)
2490 & ~AUDIO_DEVICE_BIT_IN;
2491 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2492 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2493 snd_device_t snd_device = SND_DEVICE_NONE;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002494 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002495
Prashant Malanic92c5962015-08-11 15:10:18 -07002496 ALOGV("%s: enter: out_device(%#x) in_device(%#x) channel_count (%d) channel_mask (0x%x)",
2497 __func__, out_device, in_device, channel_count, channel_mask);
Devin Kimd789e432016-10-26 15:07:27 -07002498 if ((out_device != AUDIO_DEVICE_NONE) && (voice_is_in_call(adev) ||
2499 audio_extn_hfp_is_active(adev))) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002500 if (adev->voice.tty_mode != TTY_MODE_OFF) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002501 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002502 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
2503 out_device & AUDIO_DEVICE_OUT_LINE) {
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002504 switch (adev->voice.tty_mode) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002505 case TTY_MODE_FULL:
2506 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2507 break;
2508 case TTY_MODE_VCO:
2509 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2510 break;
2511 case TTY_MODE_HCO:
2512 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2513 break;
2514 default:
2515 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
2516 }
2517 goto exit;
Eric Laurent99dab492017-06-17 15:19:08 -07002518 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
vivek mehtaa6b79742017-03-09 15:40:43 -08002519 switch (adev->voice.tty_mode) {
2520 case TTY_MODE_FULL:
2521 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
2522 break;
2523 case TTY_MODE_VCO:
2524 // since voice will be captured from handset mic, use existing device
2525 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2526 break;
2527 case TTY_MODE_HCO:
2528 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC;
2529 break;
2530 default:
2531 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002532 }
2533 goto exit;
2534 }
2535 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002536 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002537 if (my_data->fluence_in_voice_call == false) {
2538 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2539 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002540 if (is_operator_tmus())
2541 snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002542 else
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002543 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002544 }
2545 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2546 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
2547 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002548 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002549 if (adev->bluetooth_nrec)
2550 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2551 else
2552 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002553 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002554 if (adev->bluetooth_nrec)
2555 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2556 else
2557 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002558 }
Eric Laurentb991fb02014-08-29 15:23:17 -05002559 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Prashant Malanic92c5962015-08-11 15:10:18 -07002560 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
2561 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2562 out_device & AUDIO_DEVICE_OUT_LINE) {
2563 if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2564 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2565 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2566 } else {
2567 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2568 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002569 }
vivek mehtafe121d52015-08-10 23:39:23 -07002570
2571 //select default
2572 if (snd_device == SND_DEVICE_NONE) {
Uday Kishore Pasupuleti76297192015-09-18 08:39:43 -07002573 if (!adev->enable_hfp) {
2574 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2575 } else {
2576 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP;
2577 platform_set_echo_reference(adev, true, out_device);
2578 }
vivek mehtafe121d52015-08-10 23:39:23 -07002579 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002580 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
Ravi Kumar Alamanda99c752d2014-08-20 17:55:26 -07002581 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurent99dab492017-06-17 15:19:08 -07002582 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Lin40b07892017-08-07 15:02:48 -07002583 if (audio_extn_usb_is_capture_supported()) {
2584 snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
2585 } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode) {
2586 if (my_data->source_mic_type & SOURCE_DUAL_MIC) {
2587 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
2588 } else {
2589 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
2590 }
2591 }
Prashant Malanic92c5962015-08-11 15:10:18 -07002592 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002593 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2594 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2595 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2596 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2597 }
2598 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2599 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002600 if (my_data->fluence_in_voice_rec && channel_count == 1) {
2601 if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2602 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002603 if (adev->active_input->enable_aec)
2604 snd_device = SND_DEVICE_IN_HANDSET_QMIC_AEC;
2605 else
2606 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002607 } else if ((my_data->fluence_type == FLUENCE_PRO_ENABLE) &&
2608 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002609 if (adev->active_input->enable_aec)
2610 snd_device = SND_DEVICE_IN_HANDSET_TMIC_AEC;
2611 else
2612 snd_device = SND_DEVICE_IN_HANDSET_TMIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002613 } else if (((my_data->fluence_type == FLUENCE_PRO_ENABLE) ||
2614 (my_data->fluence_type == FLUENCE_ENABLE)) &&
2615 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
vivek mehta733c1df2016-04-04 15:09:24 -07002616 if (adev->active_input->enable_aec)
2617 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2618 else
2619 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Prashant Malanic92c5962015-08-11 15:10:18 -07002620 }
2621 platform_set_echo_reference(adev, true, out_device);
2622 } else if ((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) &&
2623 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2624 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002625 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002626 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2627 snd_device = SND_DEVICE_IN_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002628 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002629 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2630 snd_device = SND_DEVICE_IN_QUAD_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002631 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002632 if (snd_device == SND_DEVICE_NONE) {
vivek mehtaf3440682016-05-11 14:24:37 -07002633 if (adev->active_input->enable_aec) {
2634 if (adev->active_input->enable_ns) {
2635 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS;
2636 } else {
2637 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_AEC;
2638 }
vivek mehta733c1df2016-04-04 15:09:24 -07002639 platform_set_echo_reference(adev, true, out_device);
vivek mehtaf3440682016-05-11 14:24:37 -07002640 } else if (adev->active_input->enable_ns) {
2641 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2642 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002643 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
vivek mehtaf3440682016-05-11 14:24:37 -07002644 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002645 }
Jean-Michel Trivi8c83fe82015-09-25 15:06:53 -07002646 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2647 snd_device = SND_DEVICE_IN_VOICE_REC_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002648 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002649 snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002650 }
rago90fb9612015-12-02 11:37:53 -08002651 } else if (source == AUDIO_SOURCE_UNPROCESSED) {
2652 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
vivek mehta4ed66e62016-04-15 23:33:34 -07002653 if (((channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) ||
2654 (channel_mask == AUDIO_CHANNEL_IN_STEREO)) &&
2655 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
2656 snd_device = SND_DEVICE_IN_UNPROCESSED_STEREO_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002657 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002658 (my_data->source_mic_type & SOURCE_THREE_MIC)) {
2659 snd_device = SND_DEVICE_IN_UNPROCESSED_THREE_MIC;
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002660 } else if ((channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) &&
vivek mehta4ed66e62016-04-15 23:33:34 -07002661 (my_data->source_mic_type & SOURCE_QUAD_MIC)) {
2662 snd_device = SND_DEVICE_IN_UNPROCESSED_QUAD_MIC;
2663 } else {
2664 snd_device = SND_DEVICE_IN_UNPROCESSED_MIC;
2665 }
rago90fb9612015-12-02 11:37:53 -08002666 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2667 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002668 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002669 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
rago90fb9612015-12-02 11:37:53 -08002670 }
Eric Laurent50a38ed2015-10-14 18:48:06 -07002671 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
rago90fb9612015-12-02 11:37:53 -08002672 mode == AUDIO_MODE_IN_COMMUNICATION) {
David Lin40b07892017-08-07 15:02:48 -07002673 if (out_device & (AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_OUT_SPEAKER_SAFE) ||
2674 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2675 (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE | AUDIO_DEVICE_OUT_USB_HEADSET) &&
2676 !audio_extn_usb_is_capture_supported())) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002677 in_device = AUDIO_DEVICE_IN_BACK_MIC;
David Lin40b07892017-08-07 15:02:48 -07002678 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002679 if (adev->active_input) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002680 if (adev->active_input->enable_aec &&
2681 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002682 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002683 if (my_data->fluence_in_spkr_mode &&
2684 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002685 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002686 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002687 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002688 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002689 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002690 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002691 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002692 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002693 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002694 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002695 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002696 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002697 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2698 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002699 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002700 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002701 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002702 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002703 } else if (adev->active_input->enable_aec) {
2704 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2705 if (my_data->fluence_in_spkr_mode &&
2706 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002707 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002708 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002709 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002710 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002711 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002712 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2713 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002714 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002715 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002716 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002717 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002718 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002719 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2720 snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
Eric Laurent99dab492017-06-17 15:19:08 -07002721 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
Haynes Mathew George9a29f372017-04-11 19:19:07 -07002722 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
Eric Laurentcefbbac2014-09-04 13:54:10 -05002723 }
Ravi Kumar Alamandaf2829012014-11-12 16:16:10 -08002724 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002725 } else if (adev->active_input->enable_ns) {
2726 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2727 if (my_data->fluence_in_spkr_mode &&
2728 my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002729 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002730 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002731 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002732 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002733 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002734 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2735 if (my_data->fluence_in_voice_comm &&
Prashant Malanic92c5962015-08-11 15:10:18 -07002736 (my_data->source_mic_type & SOURCE_DUAL_MIC)) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002737 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002738 } else {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002739 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
Prashant Malanic92c5962015-08-11 15:10:18 -07002740 }
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002741 }
Eric Laurentcefbbac2014-09-04 13:54:10 -05002742 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002743 }
2744 } else if (source == AUDIO_SOURCE_DEFAULT) {
2745 goto exit;
2746 }
2747
2748
2749 if (snd_device != SND_DEVICE_NONE) {
2750 goto exit;
2751 }
2752
2753 if (in_device != AUDIO_DEVICE_NONE &&
2754 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2755 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2756 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002757 if ((my_data->source_mic_type & SOURCE_QUAD_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002758 channel_mask == AUDIO_CHANNEL_INDEX_MASK_4) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002759 snd_device = SND_DEVICE_IN_QUAD_MIC;
2760 } else if ((my_data->source_mic_type & SOURCE_THREE_MIC) &&
Glenn Kastencbe06ca2016-11-09 10:49:26 -08002761 channel_mask == AUDIO_CHANNEL_INDEX_MASK_3) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002762 snd_device = SND_DEVICE_IN_THREE_MIC;
2763 } else if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2764 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002765 snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002766 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2767 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002768 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002769 } else {
2770 ALOGE("%s: something wrong (1): source type (%d) channel_count (%d) .."
2771 " channel mask (0x%x) no combination found .. setting to mono", __func__,
2772 my_data->source_mic_type, channel_count, channel_mask);
2773 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2774 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002775 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002776 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2777 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002778 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002779 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2780 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002781 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002782 } else {
2783 ALOGE("%s: something wrong (2): source type (%d) channel_count (%d) .."
2784 " no combination found .. setting to mono", __func__,
2785 my_data->source_mic_type, channel_count);
2786 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2787 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002788 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2789 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2790 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002791 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002792 if (adev->bluetooth_nrec)
2793 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2794 else
2795 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002796 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002797 if (adev->bluetooth_nrec)
2798 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2799 else
2800 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002801 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002802 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2803 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002804 } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
David Linee3fe402017-03-13 10:00:42 -07002805 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002806 } else {
2807 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2808 ALOGW("%s: Using default handset-mic", __func__);
2809 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2810 }
2811 } else {
2812 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2813 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2814 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2815 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002816 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
Eric Laurent1b0d8ce2014-09-11 09:59:28 -07002817 out_device & AUDIO_DEVICE_OUT_SPEAKER_SAFE ||
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002818 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
Eric Laurent09f2e0e2014-07-29 16:02:32 -05002819 out_device & AUDIO_DEVICE_OUT_LINE) {
Prashant Malanic92c5962015-08-11 15:10:18 -07002820 if ((my_data->source_mic_type & SOURCE_DUAL_MIC) &&
2821 channel_count == 2) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002822 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
Prashant Malanic92c5962015-08-11 15:10:18 -07002823 } else if ((my_data->source_mic_type & SOURCE_MONO_MIC) &&
2824 channel_count == 1) {
Ravi Kumar Alamanda3ad4e1b2014-06-03 00:08:15 -07002825 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Prashant Malanic92c5962015-08-11 15:10:18 -07002826 } else {
2827 ALOGE("%s: something wrong (3): source type (%d) channel_count (%d) .."
2828 " no combination found .. setting to mono", __func__,
2829 my_data->source_mic_type, channel_count);
2830 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2831 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002832 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002833 if (adev->bt_wb_speech_enabled) {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002834 if (adev->bluetooth_nrec)
2835 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2836 else
2837 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002838 } else {
Ravi Kumar Alamandae258e682015-06-25 13:32:42 -07002839 if (adev->bluetooth_nrec)
2840 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2841 else
2842 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
Ravi Kumar Alamanda9f306542014-04-02 15:11:49 -07002843 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002844 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2845 snd_device = SND_DEVICE_IN_HDMI_MIC;
Eric Laurent99dab492017-06-17 15:19:08 -07002846 } else if (out_device & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)) {
David Linee3fe402017-03-13 10:00:42 -07002847 if (audio_extn_usb_is_capture_supported())
2848 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2849 else
2850 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002851 } else {
2852 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2853 ALOGW("%s: Using default handset-mic", __func__);
2854 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2855 }
2856 }
2857exit:
2858 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2859 return snd_device;
2860}
2861
2862int platform_set_hdmi_channels(void *platform, int channel_count)
2863{
2864 struct platform_data *my_data = (struct platform_data *)platform;
2865 struct audio_device *adev = my_data->adev;
2866 struct mixer_ctl *ctl;
2867 const char *channel_cnt_str = NULL;
2868 const char *mixer_ctl_name = "HDMI_RX Channels";
2869 switch (channel_count) {
2870 case 8:
2871 channel_cnt_str = "Eight"; break;
2872 case 7:
2873 channel_cnt_str = "Seven"; break;
2874 case 6:
2875 channel_cnt_str = "Six"; break;
2876 case 5:
2877 channel_cnt_str = "Five"; break;
2878 case 4:
2879 channel_cnt_str = "Four"; break;
2880 case 3:
2881 channel_cnt_str = "Three"; break;
2882 default:
2883 channel_cnt_str = "Two"; break;
2884 }
2885 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2886 if (!ctl) {
2887 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2888 __func__, mixer_ctl_name);
2889 return -EINVAL;
2890 }
2891 ALOGV("HDMI channel count: %s", channel_cnt_str);
2892 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2893 return 0;
2894}
2895
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002896int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002897{
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002898 struct platform_data *my_data = (struct platform_data *)platform;
2899 struct audio_device *adev = my_data->adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07002900 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
2901 char *sad = block;
2902 int num_audio_blocks;
2903 int channel_count;
2904 int max_channels = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002905 int i, ret, count;
Eric Laurentb23d5282013-05-14 15:27:20 -07002906
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002907 struct mixer_ctl *ctl;
2908
2909 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
2910 if (!ctl) {
2911 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2912 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
Eric Laurentb23d5282013-05-14 15:27:20 -07002913 return 0;
2914 }
2915
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002916 mixer_ctl_update(ctl);
2917
2918 count = mixer_ctl_get_num_values(ctl);
Eric Laurentb23d5282013-05-14 15:27:20 -07002919
2920 /* Read SAD blocks, clamping the maximum size for safety */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002921 if (count > (int)sizeof(block))
2922 count = (int)sizeof(block);
Eric Laurentb23d5282013-05-14 15:27:20 -07002923
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002924 ret = mixer_ctl_get_array(ctl, block, count);
2925 if (ret != 0) {
2926 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
2927 return 0;
2928 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002929
2930 /* Calculate the number of SAD blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002931 num_audio_blocks = count / SAD_BLOCK_SIZE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002932
2933 for (i = 0; i < num_audio_blocks; i++) {
2934 /* Only consider LPCM blocks */
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002935 if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
2936 sad += 3;
Eric Laurentb23d5282013-05-14 15:27:20 -07002937 continue;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002938 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002939
2940 channel_count = (sad[0] & 0x7) + 1;
2941 if (channel_count > max_channels)
2942 max_channels = channel_count;
2943
2944 /* Advance to next block */
2945 sad += 3;
2946 }
2947
2948 return max_channels;
2949}
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07002950
Vineeta Srivastava4b89e372014-06-19 14:21:42 -07002951int platform_set_incall_recording_session_id(void *platform,
2952 uint32_t session_id, int rec_mode)
2953{
2954 int ret = 0;
2955 struct platform_data *my_data = (struct platform_data *)platform;
2956 struct audio_device *adev = my_data->adev;
2957 struct mixer_ctl *ctl;
2958 const char *mixer_ctl_name = "Voc VSID";
2959 int num_ctl_values;
2960 int i;
2961
2962 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2963 if (!ctl) {
2964 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2965 __func__, mixer_ctl_name);
2966 ret = -EINVAL;
2967 } else {
2968 num_ctl_values = mixer_ctl_get_num_values(ctl);
2969 for (i = 0; i < num_ctl_values; i++) {
2970 if (mixer_ctl_set_value(ctl, i, session_id)) {
2971 ALOGV("Error: invalid session_id: %x", session_id);
2972 ret = -EINVAL;
2973 break;
2974 }
2975 }
2976 }
2977
2978 if (my_data->csd != NULL) {
2979 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2980 if (ret < 0) {
2981 ALOGE("%s: csd_client_start_record failed, error %d",
2982 __func__, ret);
2983 }
2984 }
2985
2986 return ret;
2987}
2988
2989int platform_stop_incall_recording_usecase(void *platform)
2990{
2991 int ret = 0;
2992 struct platform_data *my_data = (struct platform_data *)platform;
2993
2994 if (my_data->csd != NULL) {
2995 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2996 if (ret < 0) {
2997 ALOGE("%s: csd_client_stop_record failed, error %d",
2998 __func__, ret);
2999 }
3000 }
3001
3002 return ret;
3003}
3004
3005int platform_start_incall_music_usecase(void *platform)
3006{
3007 int ret = 0;
3008 struct platform_data *my_data = (struct platform_data *)platform;
3009
3010 if (my_data->csd != NULL) {
3011 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
3012 if (ret < 0) {
3013 ALOGE("%s: csd_client_start_playback failed, error %d",
3014 __func__, ret);
3015 }
3016 }
3017
3018 return ret;
3019}
3020
3021int platform_stop_incall_music_usecase(void *platform)
3022{
3023 int ret = 0;
3024 struct platform_data *my_data = (struct platform_data *)platform;
3025
3026 if (my_data->csd != NULL) {
3027 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
3028 if (ret < 0) {
3029 ALOGE("%s: csd_client_stop_playback failed, error %d",
3030 __func__, ret);
3031 }
3032 }
3033
3034 return ret;
3035}
3036
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003037int platform_set_parameters(void *platform, struct str_parms *parms)
3038{
3039 struct platform_data *my_data = (struct platform_data *)platform;
keunhui.park2f7306a2015-07-16 16:48:06 +09003040 char value[128];
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003041 char *kv_pairs = str_parms_to_str(parms);
3042 int ret = 0, err;
3043
3044 if (kv_pairs == NULL) {
3045 ret = -EINVAL;
3046 ALOGE("%s: key-value pair is NULL",__func__);
3047 goto done;
3048 }
3049
3050 ALOGV("%s: enter: %s", __func__, kv_pairs);
3051
3052 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
3053 value, sizeof(value));
3054 if (err >= 0) {
3055 str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
3056 my_data->snd_card_name = strdup(value);
3057 ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
3058 }
3059
keunhui.park2f7306a2015-07-16 16:48:06 +09003060 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO,
3061 value, sizeof(value));
3062 if (err >= 0) {
3063 struct operator_info *info;
3064 char *str = value;
3065 char *name;
3066
3067 str_parms_del(parms, PLATFORM_CONFIG_KEY_OPERATOR_INFO);
3068 info = (struct operator_info *)calloc(1, sizeof(struct operator_info));
3069 name = strtok(str, ";");
3070 info->name = strdup(name);
3071 info->mccmnc = strdup(str + strlen(name) + 1);
3072
3073 list_add_tail(&operator_info_list, &info->list);
Joe Onorato188b6222016-03-01 11:02:27 -08003074 ALOGV("%s: add operator[%s] mccmnc[%s]", __func__, info->name, info->mccmnc);
keunhui.park2f7306a2015-07-16 16:48:06 +09003075 }
Prashant Malanic92c5962015-08-11 15:10:18 -07003076
3077 memset(value, 0, sizeof(value));
Eric Laurentc6333382015-09-14 12:43:44 -07003078 err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT,
Prashant Malanic92c5962015-08-11 15:10:18 -07003079 value, sizeof(value));
3080 if (err >= 0) {
Eric Laurentc6333382015-09-14 12:43:44 -07003081 str_parms_del(parms, PLATFORM_CONFIG_KEY_MAX_MIC_COUNT);
Prashant Malanic92c5962015-08-11 15:10:18 -07003082 my_data->max_mic_count = atoi(value);
3083 ALOGV("%s: max_mic_count %s/%d", __func__, value, my_data->max_mic_count);
Prashant Malanic92c5962015-08-11 15:10:18 -07003084 }
3085
vivek mehta90933872017-06-15 18:04:39 -07003086 // to-do: disable setting sidetone gain, will revist this later
3087 // audio_extn_usb_set_sidetone_gain(parms, value, len);
Ravi Kumar Alamandac4f57312015-06-26 17:41:02 -07003088done:
3089 ALOGV("%s: exit with code(%d)", __func__, ret);
3090 if (kv_pairs != NULL)
3091 free(kv_pairs);
3092
3093 return ret;
3094}
3095
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003096/* Delay in Us */
3097int64_t platform_render_latency(audio_usecase_t usecase)
3098{
3099 switch (usecase) {
3100 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3101 return DEEP_BUFFER_PLATFORM_DELAY;
3102 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3103 return LOW_LATENCY_PLATFORM_DELAY;
Haynes Mathew George03c40102016-01-29 17:57:48 -08003104 case USECASE_AUDIO_PLAYBACK_ULL:
3105 return ULL_PLATFORM_DELAY;
Eric Laurent0e46adf2016-12-16 12:49:24 -08003106 case USECASE_AUDIO_PLAYBACK_MMAP:
3107 return MMAP_PLATFORM_DELAY;
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003108 default:
3109 return 0;
3110 }
3111}
Haynes Mathew George98c95622014-06-20 19:14:25 -07003112
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003113int platform_set_snd_device_backend(snd_device_t device, const char *backend_tag,
3114 const char * hw_interface)
Haynes Mathew George98c95622014-06-20 19:14:25 -07003115{
3116 int ret = 0;
3117
3118 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3119 ALOGE("%s: Invalid snd_device = %d",
3120 __func__, device);
3121 ret = -EINVAL;
3122 goto done;
3123 }
3124
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003125 ALOGV("%s: backend_tag_table[%s]: old = %s new = %s", __func__,
3126 platform_get_snd_device_name(device),
3127 backend_tag_table[device] != NULL ? backend_tag_table[device]: "null", backend_tag);
3128 if (backend_tag_table[device]) {
3129 free(backend_tag_table[device]);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003130 }
Ravi Kumar Alamandab7ea4f52015-06-08 16:44:05 -07003131 backend_tag_table[device] = strdup(backend_tag);
3132
3133 if (hw_interface != NULL) {
3134 if (hw_interface_table[device])
3135 free(hw_interface_table[device]);
3136 ALOGV("%s: hw_interface_table[%d] = %s", __func__, device, hw_interface);
3137 hw_interface_table[device] = strdup(hw_interface);
3138 }
Haynes Mathew George98c95622014-06-20 19:14:25 -07003139done:
3140 return ret;
3141}
3142
3143int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3144{
3145 int ret = 0;
3146 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3147 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3148 ret = -EINVAL;
3149 goto done;
3150 }
3151
3152 if ((type != 0) && (type != 1)) {
3153 ALOGE("%s: invalid usecase type", __func__);
3154 ret = -EINVAL;
3155 }
vivek mehtaa68fea62017-06-08 19:04:02 -07003156 ALOGV("%s: pcm_device_table[%d %s][%d] = %d", __func__, usecase,
3157 use_case_table[usecase],
3158 type, pcm_id);
Haynes Mathew George98c95622014-06-20 19:14:25 -07003159 pcm_device_table[usecase][type] = pcm_id;
3160done:
3161 return ret;
3162}
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003163
Jean-Michel Trivi88cbad32015-09-23 14:51:02 -07003164#define DEFAULT_NOMINAL_SPEAKER_GAIN 20
3165int ramp_speaker_gain(struct audio_device *adev, bool ramp_up, int target_ramp_up_gain) {
3166 // backup_gain: gain to try to set in case of an error during ramp
3167 int start_gain, end_gain, step, backup_gain, i;
3168 bool error = false;
3169 const struct mixer_ctl *ctl;
3170 const char *mixer_ctl_name_gain_left = "Left Speaker Gain";
3171 const char *mixer_ctl_name_gain_right = "Right Speaker Gain";
3172 struct mixer_ctl *ctl_left = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_left);
3173 struct mixer_ctl *ctl_right = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name_gain_right);
3174 if (!ctl_left || !ctl_right) {
3175 ALOGE("%s: Could not get ctl for mixer cmd - %s or %s, not applying speaker gain ramp",
3176 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3177 return -EINVAL;
3178 } else if ((mixer_ctl_get_num_values(ctl_left) != 1)
3179 || (mixer_ctl_get_num_values(ctl_right) != 1)) {
3180 ALOGE("%s: Unexpected num values for mixer cmd - %s or %s, not applying speaker gain ramp",
3181 __func__, mixer_ctl_name_gain_left, mixer_ctl_name_gain_right);
3182 return -EINVAL;
3183 }
3184 if (ramp_up) {
3185 start_gain = 0;
3186 end_gain = target_ramp_up_gain > 0 ? target_ramp_up_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3187 step = +1;
3188 backup_gain = end_gain;
3189 } else {
3190 // using same gain on left and right
3191 const int left_gain = mixer_ctl_get_value(ctl_left, 0);
3192 start_gain = left_gain > 0 ? left_gain : DEFAULT_NOMINAL_SPEAKER_GAIN;
3193 end_gain = 0;
3194 step = -1;
3195 backup_gain = start_gain;
3196 }
3197 for (i = start_gain ; i != (end_gain + step) ; i += step) {
3198 //ALOGV("setting speaker gain to %d", i);
3199 if (mixer_ctl_set_value(ctl_left, 0, i)) {
3200 ALOGE("%s: error setting %s to %d during gain ramp",
3201 __func__, mixer_ctl_name_gain_left, i);
3202 error = true;
3203 break;
3204 }
3205 if (mixer_ctl_set_value(ctl_right, 0, i)) {
3206 ALOGE("%s: error setting %s to %d during gain ramp",
3207 __func__, mixer_ctl_name_gain_right, i);
3208 error = true;
3209 break;
3210 }
3211 usleep(1000);
3212 }
3213 if (error) {
3214 // an error occured during the ramp, let's still try to go back to a safe volume
3215 if (mixer_ctl_set_value(ctl_left, 0, backup_gain)) {
3216 ALOGE("%s: error restoring left gain to %d", __func__, backup_gain);
3217 }
3218 if (mixer_ctl_set_value(ctl_right, 0, backup_gain)) {
3219 ALOGE("%s: error restoring right gain to %d", __func__, backup_gain);
3220 }
3221 }
3222 return start_gain;
3223}
3224
vivek mehtae59cfb22017-06-16 15:57:11 -07003225int platform_set_swap_mixer(struct audio_device *adev, bool swap_channels)
3226{
3227 const char *mixer_ctl_name = "Swap channel";
3228 struct mixer_ctl *ctl;
3229 const char *mixer_path;
3230 struct platform_data *my_data = (struct platform_data *)adev->platform;
3231
3232 // forced to set to swap, but device not rotated ... ignore set
3233 if (swap_channels && !my_data->speaker_lr_swap)
3234 return 0;
3235
3236 ALOGV("%s:", __func__);
3237
3238 if (swap_channels) {
3239 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
3240 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3241 } else {
3242 mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
3243 audio_route_apply_and_update_path(adev->audio_route, mixer_path);
3244 }
3245
3246 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3247 if (!ctl) {
3248 ALOGE("%s: Could not get ctl for mixer cmd - %s",__func__, mixer_ctl_name);
3249 return -EINVAL;
3250 }
3251
3252 if (mixer_ctl_set_value(ctl, 0, swap_channels) < 0) {
3253 ALOGE("%s: Could not set reverse cotrol %d",__func__, swap_channels);
3254 return -EINVAL;
3255 }
3256
3257 ALOGV("platfor_force_swap_channel :: Channel orientation ( %s ) ",
3258 swap_channels?"R --> L":"L --> R");
3259
3260 return 0;
3261}
3262
3263int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels)
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003264{
3265 // only update if there is active pcm playback on speaker
3266 struct audio_usecase *usecase;
3267 struct listnode *node;
3268 struct platform_data *my_data = (struct platform_data *)adev->platform;
3269
vivek mehtae59cfb22017-06-16 15:57:11 -07003270 my_data->speaker_lr_swap = swap_channels;
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003271
vivek mehtae59cfb22017-06-16 15:57:11 -07003272 return platform_set_swap_channels(adev, swap_channels);
3273}
Jean-Michel Trivif7148702016-09-16 18:23:05 -07003274
vivek mehtae59cfb22017-06-16 15:57:11 -07003275int platform_set_swap_channels(struct audio_device *adev, bool swap_channels)
3276{
3277 // only update if there is active pcm playback on speaker
3278 struct audio_usecase *usecase;
3279 struct listnode *node;
3280 struct platform_data *my_data = (struct platform_data *)adev->platform;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003281
vivek mehtae59cfb22017-06-16 15:57:11 -07003282 // do not swap channels in audio modes with concurrent capture and playback
3283 // as this may break the echo reference
3284 if ((adev->mode == AUDIO_MODE_IN_COMMUNICATION) || (adev->mode == AUDIO_MODE_IN_CALL)) {
3285 ALOGV("%s: will not swap due to audio mode %d", __func__, adev->mode);
3286 return 0;
3287 }
3288
3289 list_for_each(node, &adev->usecase_list) {
3290 usecase = node_to_item(node, struct audio_usecase, list);
3291 if (usecase->type == PCM_PLAYBACK &&
3292 usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
3293 /*
3294 * If acdb tuning is different for SPEAKER_REVERSE, it is must
3295 * to perform device switch to disable the current backend to
3296 * enable it with new acdb data.
3297 */
3298 if (acdb_device_table[SND_DEVICE_OUT_SPEAKER] !=
3299 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE]) {
3300 const int initial_skpr_gain = ramp_speaker_gain(adev, false /*ramp_up*/, -1);
3301 select_devices(adev, usecase->id);
3302 if (initial_skpr_gain != -EINVAL)
3303 ramp_speaker_gain(adev, true /*ramp_up*/, initial_skpr_gain);
3304
3305 } else {
3306 platform_set_swap_mixer(adev, swap_channels);
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003307 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003308 break;
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003309 }
3310 }
vivek mehtae59cfb22017-06-16 15:57:11 -07003311
Ravi Kumar Alamanda1f60cf82015-04-23 19:45:17 -07003312 return 0;
3313}
vivek mehtaa8d7c922016-05-25 14:40:44 -07003314
3315static struct amp_db_and_gain_table tbl_mapping[MAX_VOLUME_CAL_STEPS];
3316static int num_gain_tbl_entry = 0;
3317
3318bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry) {
3319
3320 ALOGV("%s: enter .. add %f %f %d", __func__, tbl_entry->amp, tbl_entry->db, tbl_entry->level);
3321 if (num_gain_tbl_entry == -1) {
3322 ALOGE("%s: num entry beyond valid step levels or corrupted..rejecting custom mapping",
3323 __func__);
3324 return false;
3325 }
3326
3327 if (num_gain_tbl_entry >= MAX_VOLUME_CAL_STEPS) {
3328 ALOGE("%s: max entry reached max[%d] current index[%d] .. rejecting", __func__,
3329 MAX_VOLUME_CAL_STEPS, num_gain_tbl_entry);
3330 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3331 return false;
3332 }
3333
3334 if (num_gain_tbl_entry > 0 && tbl_mapping[num_gain_tbl_entry - 1].amp >= tbl_entry->amp) {
3335 ALOGE("%s: value not in ascending order .. rejecting custom mapping", __func__);
3336 num_gain_tbl_entry = -1; // indicates error and no more info will be cached
3337 return false;
3338 }
3339
3340 tbl_mapping[num_gain_tbl_entry] = *tbl_entry;
3341 ++num_gain_tbl_entry;
3342
3343 return true;
3344}
3345
3346int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl,
3347 int table_size) {
3348 int itt = 0;
3349 ALOGV("platform_get_gain_level_mapping called ");
3350
3351 if (num_gain_tbl_entry <= 0 || num_gain_tbl_entry > MAX_VOLUME_CAL_STEPS) {
3352 ALOGD("%s: empty or currupted gain_mapping_table", __func__);
3353 return 0;
3354 }
3355
3356 for (; itt < num_gain_tbl_entry && itt <= table_size; itt++) {
3357 mapping_tbl[itt] = tbl_mapping[itt];
3358 ALOGV("%s: added amp[%f] db[%f] level[%d]", __func__,
3359 mapping_tbl[itt].amp, mapping_tbl[itt].db, mapping_tbl[itt].level);
3360 }
3361
3362 return num_gain_tbl_entry;
3363}
Haynes Mathew Georgec735fb02016-06-30 18:00:28 -07003364
3365int platform_snd_card_update(void *platform, card_status_t status)
3366{
3367 struct platform_data *my_data = (struct platform_data *)platform;
3368 struct audio_device *adev = my_data->adev;
3369
3370 if (status == CARD_STATUS_ONLINE) {
3371 if (my_data->acdb_send_custom_top)
3372 my_data->acdb_send_custom_top();
3373 }
3374 return 0;
3375}
David Linee3fe402017-03-13 10:00:42 -07003376
3377/*
3378 * configures afe with bit width and Sample Rate
3379 */
3380static int platform_set_backend_cfg(const struct audio_device* adev,
3381 snd_device_t snd_device,
3382 const struct audio_backend_cfg *backend_cfg)
3383{
3384
3385 int ret = 0;
3386 const int backend_idx = platform_get_backend_index(snd_device);
3387 struct platform_data *my_data = (struct platform_data *)adev->platform;
3388 const unsigned int bit_width = backend_cfg->bit_width;
3389 const unsigned int sample_rate = backend_cfg->sample_rate;
3390 const unsigned int channels = backend_cfg->channels;
3391 const audio_format_t format = backend_cfg->format;
3392 const bool passthrough_enabled = backend_cfg->passthrough_enabled;
3393
3394
3395 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3396 ", backend_idx %d device (%s)", __func__, bit_width,
3397 sample_rate, channels, backend_idx,
3398 platform_get_snd_device_name(snd_device));
3399
3400 if ((my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl) &&
3401 (bit_width != my_data->current_backend_cfg[backend_idx].bit_width)) {
3402
3403 struct mixer_ctl *ctl = NULL;
3404 ctl = mixer_get_ctl_by_name(adev->mixer,
3405 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3406 if (!ctl) {
3407 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3408 __func__,
3409 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
3410 return -EINVAL;
3411 }
3412
3413 if (bit_width == 24) {
3414 if (format == AUDIO_FORMAT_PCM_24_BIT_PACKED)
3415 ret = mixer_ctl_set_enum_by_string(ctl, "S24_3LE");
3416 else
3417 ret = mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3418 } else if (bit_width == 32) {
3419 ret = mixer_ctl_set_enum_by_string(ctl, "S32_LE");
3420 } else {
3421 ret = mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3422 }
3423 if ( ret < 0) {
3424 ALOGE("%s:becf: afe: fail for %s mixer set to %d bit for %x format", __func__,
3425 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3426 } else {
3427 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3428 ALOGD("%s:becf: afe: %s mixer set to %d bit for %x format", __func__,
3429 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width, format);
3430 }
3431 /* set the ret as 0 and not pass back to upper layer */
3432 ret = 0;
3433 }
3434
3435 if (passthrough_enabled || ((my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl) &&
3436 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate))) {
3437 char *rate_str = NULL;
3438 struct mixer_ctl *ctl = NULL;
3439
3440 switch (sample_rate) {
3441 case 32000:
3442 if (passthrough_enabled) {
3443 rate_str = "KHZ_32";
3444 break;
3445 }
3446 case 8000:
3447 case 11025:
3448 case 16000:
3449 case 22050:
3450 case 48000:
3451 rate_str = "KHZ_48";
3452 break;
3453 case 44100:
3454 rate_str = "KHZ_44P1";
3455 break;
3456 case 64000:
3457 case 96000:
3458 rate_str = "KHZ_96";
3459 break;
3460 case 88200:
3461 rate_str = "KHZ_88P2";
3462 break;
3463 case 176400:
3464 rate_str = "KHZ_176P4";
3465 break;
3466 case 192000:
3467 rate_str = "KHZ_192";
3468 break;
3469 case 352800:
3470 rate_str = "KHZ_352P8";
3471 break;
3472 case 384000:
3473 rate_str = "KHZ_384";
3474 break;
3475 case 144000:
3476 if (passthrough_enabled) {
3477 rate_str = "KHZ_144";
3478 break;
3479 }
3480 default:
3481 rate_str = "KHZ_48";
3482 break;
3483 }
3484
3485 ctl = mixer_get_ctl_by_name(adev->mixer,
3486 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3487 if(!ctl) {
3488 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3489 __func__,
3490 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
3491 return -EINVAL;
3492 }
3493
3494 ALOGD("%s:becf: afe: %s set to %s", __func__,
3495 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
3496 mixer_ctl_set_enum_by_string(ctl, rate_str);
3497 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
3498 }
3499 if ((my_data->current_backend_cfg[backend_idx].channels_mixer_ctl) &&
3500 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3501 struct mixer_ctl *ctl = NULL;
3502 char *channel_cnt_str = NULL;
3503
3504 switch (channels) {
3505 case 8:
3506 channel_cnt_str = "Eight"; break;
3507 case 7:
3508 channel_cnt_str = "Seven"; break;
3509 case 6:
3510 channel_cnt_str = "Six"; break;
3511 case 5:
3512 channel_cnt_str = "Five"; break;
3513 case 4:
3514 channel_cnt_str = "Four"; break;
3515 case 3:
3516 channel_cnt_str = "Three"; break;
3517 case 1:
3518 channel_cnt_str = "One"; break;
3519 case 2:
3520 default:
3521 channel_cnt_str = "Two"; break;
3522 }
3523
3524 ctl = mixer_get_ctl_by_name(adev->mixer,
3525 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3526 if (!ctl) {
3527 ALOGE("%s:becf: afe: Could not get ctl for mixer command - %s",
3528 __func__,
3529 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl);
3530 return -EINVAL;
3531 }
3532 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
3533 my_data->current_backend_cfg[backend_idx].channels = channels;
3534
3535 // skip EDID configuration for HDMI backend
3536
3537 ALOGD("%s:becf: afe: %s set to %s", __func__,
3538 my_data->current_backend_cfg[backend_idx].channels_mixer_ctl,
3539 channel_cnt_str);
3540 }
3541
3542 // skip set ext_display format mixer control
3543 return ret;
3544}
3545
3546static int platform_get_snd_device_bit_width(snd_device_t snd_device)
3547{
3548 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
3549 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
3550 return CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3551 }
3552
3553 return backend_bit_width_table[snd_device];
3554}
3555
3556/*
3557 * return backend_idx on which voice call is active
3558 */
3559static int platform_get_voice_call_backend(struct audio_device* adev)
3560{
3561 struct audio_usecase *uc = NULL;
3562 struct listnode *node;
3563 snd_device_t out_snd_device = SND_DEVICE_NONE;
3564
3565 int backend_idx = -1;
3566
3567 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3568 list_for_each(node, &adev->usecase_list) {
3569 uc = node_to_item(node, struct audio_usecase, list);
3570 if (uc && uc->type == VOICE_CALL && uc->stream.out) {
3571 out_snd_device = platform_get_output_snd_device(adev->platform,
3572 uc->stream.out->devices);
3573 backend_idx = platform_get_backend_index(out_snd_device);
3574 break;
3575 }
3576 }
3577 }
3578 return backend_idx;
3579}
3580
3581/*
3582 * goes through all the current usecases and picks the highest
3583 * bitwidth & samplerate
3584 */
3585static bool platform_check_capture_backend_cfg(struct audio_device* adev,
3586 int backend_idx,
3587 struct audio_backend_cfg *backend_cfg)
3588{
3589 bool backend_change = false;
3590 unsigned int bit_width;
3591 unsigned int sample_rate;
3592 unsigned int channels;
3593 struct platform_data *my_data = (struct platform_data *)adev->platform;
3594
3595 bit_width = backend_cfg->bit_width;
3596 sample_rate = backend_cfg->sample_rate;
3597 channels = backend_cfg->channels;
3598
3599 ALOGV("%s:txbecf: afe: Codec selected backend: %d current bit width: %d and "
3600 "sample rate: %d, channels %d",__func__,backend_idx, bit_width,
3601 sample_rate, channels);
3602
3603 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3604 // default backend
3605 // force routing is not required here, caller will do it anyway
3606 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3607 ALOGW("%s:txbecf: afe: Use default bw and sr for voice/voip calls and "
3608 "for unprocessed/camera source", __func__);
3609 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3610 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3611 }
3612
3613 if (backend_idx == USB_AUDIO_TX_BACKEND) {
3614 audio_extn_usb_is_config_supported(&bit_width, &sample_rate, &channels, false);
3615 ALOGV("%s:txbecf: afe: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3616 __func__, bit_width, sample_rate, channels);
3617 }
3618
3619 ALOGV("%s:txbecf: afe: Codec selected backend: %d updated bit width: %d and "
3620 "sample rate: %d", __func__, backend_idx, bit_width, sample_rate);
3621
3622 // Force routing if the expected bitwdith or samplerate
3623 // is not same as current backend comfiguration
3624 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3625 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate) ||
3626 (channels != my_data->current_backend_cfg[backend_idx].channels)) {
3627 backend_cfg->bit_width = bit_width;
3628 backend_cfg->sample_rate= sample_rate;
3629 backend_cfg->channels = channels;
3630 backend_change = true;
3631 ALOGI("%s:txbecf: afe: Codec backend needs to be updated. new bit width: %d "
3632 "new sample rate: %d new channel: %d",
3633 __func__, backend_cfg->bit_width,
3634 backend_cfg->sample_rate, backend_cfg->channels);
3635 }
3636
3637 return backend_change;
3638}
3639
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003640static void pick_playback_cfg_for_uc(struct audio_device *adev,
3641 struct audio_usecase *usecase,
3642 snd_device_t snd_device,
3643 unsigned int *bit_width,
3644 unsigned int *sample_rate,
3645 unsigned int *channels)
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003646{
3647 int i =0;
3648 struct listnode *node;
3649 list_for_each(node, &adev->usecase_list) {
3650 struct audio_usecase *uc;
3651 uc = node_to_item(node, struct audio_usecase, list);
3652 struct stream_out *out = (struct stream_out*) uc->stream.out;
3653 if (uc->type == PCM_PLAYBACK && out && usecase != uc) {
3654 unsigned int out_channels = audio_channel_count_from_out_mask(out->channel_mask);
3655 ALOGV("%s:napb: (%d) - (%s)id (%d) sr %d bw "
3656 "(%d) ch (%d) device %s", __func__, i++, use_case_table[uc->id],
3657 uc->id, out->sample_rate,
3658 pcm_format_to_bits(out->config.format), out_channels,
3659 platform_get_snd_device_name(uc->out_snd_device));
3660
3661 if (platform_check_backends_match(snd_device, uc->out_snd_device)) {
3662 if (*bit_width < pcm_format_to_bits(out->config.format))
3663 *bit_width = pcm_format_to_bits(out->config.format);
3664 if (*sample_rate < out->sample_rate)
3665 *sample_rate = out->sample_rate;
3666 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3667 *sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3668 if (*channels < out_channels)
3669 *channels = out_channels;
3670 }
3671 }
3672 }
3673 return;
3674}
3675
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003676static void headset_is_config_supported(unsigned int *bit_width,
3677 unsigned int *sample_rate,
3678 unsigned int *channels) {
3679 switch (*bit_width) {
3680 case 16:
3681 case 24:
3682 break;
3683 default:
3684 *bit_width = 16;
3685 break;
3686 }
3687
3688 if (*sample_rate > 192000) {
3689 *sample_rate = 192000;
3690 }
3691
3692 if (*channels > 2) {
3693 *channels = 2;
3694 }
3695}
3696
David Linee3fe402017-03-13 10:00:42 -07003697static bool platform_check_playback_backend_cfg(struct audio_device* adev,
3698 struct audio_usecase* usecase,
3699 snd_device_t snd_device,
3700 struct audio_backend_cfg *backend_cfg)
3701{
3702 bool backend_change = false;
David Linee3fe402017-03-13 10:00:42 -07003703 unsigned int bit_width;
3704 unsigned int sample_rate;
3705 unsigned int channels;
David Linee3fe402017-03-13 10:00:42 -07003706 int backend_idx = DEFAULT_CODEC_BACKEND;
3707 struct platform_data *my_data = (struct platform_data *)adev->platform;
David Linee3fe402017-03-13 10:00:42 -07003708
3709 if (snd_device == SND_DEVICE_OUT_BT_SCO ||
3710 snd_device == SND_DEVICE_OUT_BT_SCO_WB) {
3711 backend_change = false;
3712 return backend_change;
3713 }
3714
3715 backend_idx = platform_get_backend_index(snd_device);
3716 bit_width = backend_cfg->bit_width;
3717 sample_rate = backend_cfg->sample_rate;
3718 channels = backend_cfg->channels;
3719
3720 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3721 ", backend_idx %d usecase = %d device (%s)", __func__, bit_width,
3722 sample_rate, channels, backend_idx, usecase->id,
3723 platform_get_snd_device_name(snd_device));
3724
3725 if (backend_idx == platform_get_voice_call_backend(adev)) {
3726 ALOGW("%s:becf: afe:Use default bw and sr for voice/voip calls ",
3727 __func__);
3728 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3729 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3730 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3731 } else {
3732 /*
3733 * The backend should be configured at highest bit width and/or
3734 * sample rate amongst all playback usecases.
3735 * If the selected sample rate and/or bit width differ with
3736 * current backend sample rate and/or bit width, then, we set the
3737 * backend re-configuration flag.
3738 *
3739 * Exception: 16 bit playbacks is allowed through 16 bit/48/44.1 khz backend only
3740 */
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003741 pick_playback_cfg_for_uc(adev, usecase, snd_device,
3742 &bit_width,
3743 &sample_rate,
3744 &channels);
David Linee3fe402017-03-13 10:00:42 -07003745 }
3746
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003747 switch (backend_idx) {
3748 case USB_AUDIO_RX_BACKEND:
3749 audio_extn_usb_is_config_supported(&bit_width,
3750 &sample_rate, &channels, true);
3751 ALOGV("%s: USB BE configured as bit_width(%d)sample_rate(%d)channels(%d)",
3752 __func__, bit_width, sample_rate, channels);
3753 break;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003754 case HEADPHONE_BACKEND:
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003755 headset_is_config_supported(&bit_width, &sample_rate, &channels);
3756 break;
3757 case DEFAULT_CODEC_BACKEND:
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003758 default:
3759 bit_width = platform_get_snd_device_bit_width(snd_device);
3760 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3761 channels = CODEC_BACKEND_DEFAULT_CHANNELS;
3762 break;
David Linee3fe402017-03-13 10:00:42 -07003763 }
3764
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003765 ALOGV("%s:becf: afe: Codec selected backend: %d updated bit width: %d and"
3766 "sample rate: %d",
David Linee3fe402017-03-13 10:00:42 -07003767 __func__, backend_idx , bit_width, sample_rate);
3768
3769 // Force routing if the expected bitwdith or samplerate
3770 // is not same as current backend comfiguration
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003771 if (bit_width != my_data->current_backend_cfg[backend_idx].bit_width ||
3772 sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate ||
3773 channels != my_data->current_backend_cfg[backend_idx].channels) {
David Linee3fe402017-03-13 10:00:42 -07003774 backend_cfg->bit_width = bit_width;
3775 backend_cfg->sample_rate = sample_rate;
3776 backend_cfg->channels = channels;
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003777 backend_cfg->passthrough_enabled = false;
David Linee3fe402017-03-13 10:00:42 -07003778 backend_change = true;
3779 ALOGV("%s:becf: afe: Codec backend needs to be updated. new bit width: %d"
3780 "new sample rate: %d new channels: %d",
3781 __func__, backend_cfg->bit_width, backend_cfg->sample_rate, backend_cfg->channels);
3782 }
3783
3784 return backend_change;
3785}
3786
3787bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev,
3788 struct audio_usecase *usecase, snd_device_t snd_device)
3789{
3790 int backend_idx = DEFAULT_CODEC_BACKEND;
3791 int new_snd_devices[SND_DEVICE_OUT_END];
3792 int i, num_devices = 1;
3793 bool ret = false;
3794 struct platform_data *my_data = (struct platform_data *)adev->platform;
3795 struct audio_backend_cfg backend_cfg;
3796
3797 backend_idx = platform_get_backend_index(snd_device);
3798
3799 backend_cfg.bit_width = pcm_format_to_bits(usecase->stream.out->config.format);
3800 backend_cfg.sample_rate = usecase->stream.out->sample_rate;
3801 backend_cfg.format = usecase->stream.out->format;
3802 backend_cfg.channels = audio_channel_count_from_out_mask(usecase->stream.out->channel_mask);
3803 /*this is populated by check_codec_backend_cfg hence set default value to false*/
3804 backend_cfg.passthrough_enabled = false;
3805
3806 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d"
3807 ", backend_idx %d usecase = %d device (%s)", __func__, backend_cfg.bit_width,
3808 backend_cfg.sample_rate, backend_cfg.channels, backend_idx, usecase->id,
3809 platform_get_snd_device_name(snd_device));
3810
3811 if (platform_can_split_snd_device(snd_device, &num_devices, new_snd_devices) < 0)
3812 new_snd_devices[0] = snd_device;
3813
3814 for (i = 0; i < num_devices; i++) {
3815 ALOGV("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
3816 if ((platform_check_playback_backend_cfg(adev, usecase, new_snd_devices[i],
3817 &backend_cfg))) {
3818 platform_set_backend_cfg(adev, new_snd_devices[i],
3819 &backend_cfg);
3820 ret = true;
3821 }
3822 }
3823 return ret;
3824}
3825
3826bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev,
3827 struct audio_usecase *usecase, snd_device_t snd_device)
3828{
3829 int backend_idx = platform_get_backend_index(snd_device);
3830 int ret = 0;
3831 struct audio_backend_cfg backend_cfg;
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003832 memset(&backend_cfg, 0, sizeof(struct audio_backend_cfg));
David Linee3fe402017-03-13 10:00:42 -07003833
Haynes Mathew George4bd47992017-03-09 17:59:38 -08003834 if (usecase->type == PCM_CAPTURE) {
3835 backend_cfg.format = usecase->stream.in->format;
David Linee3fe402017-03-13 10:00:42 -07003836 backend_cfg.channels = audio_channel_count_from_in_mask(usecase->stream.in->channel_mask);
3837 } else {
3838 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3839 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3840 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
3841 backend_cfg.channels = 1;
3842 }
3843
3844 ALOGV("%s:txbecf: afe: bitwidth %d, samplerate %d, channel %d"
3845 ", backend_idx %d usecase = %d device (%s)", __func__,
3846 backend_cfg.bit_width,
3847 backend_cfg.sample_rate,
3848 backend_cfg.channels,
3849 backend_idx, usecase->id,
3850 platform_get_snd_device_name(snd_device));
3851
3852 if (platform_check_capture_backend_cfg(adev, backend_idx, &backend_cfg)) {
3853 ret = platform_set_backend_cfg(adev, snd_device,
3854 &backend_cfg);
3855 if(!ret)
3856 return true;
3857 }
3858
3859 return false;
3860}
3861
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003862static int max_be_dai_names = 0;
3863static const struct be_dai_name_struct *be_dai_name_table;
3864
3865/*
3866 * Retrieves the be_dai_name_table from kernel to enable a mapping
3867 * between sound device hw interfaces and backend IDs. This allows HAL to
3868 * specify the backend a specific calibration is needed for.
3869 */
3870static int init_be_dai_name_table(struct audio_device *adev)
3871{
3872 const char *mixer_ctl_name = "Backend DAI Name Table";
3873 struct mixer_ctl *ctl;
3874 int i, j, ret, size;
3875 bool valid_hw_interface;
3876
3877 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3878 if (!ctl) {
3879 ALOGE("%s: Could not get ctl for mixer name %s\n",
3880 __func__, mixer_ctl_name);
3881 ret = -EINVAL;
3882 goto done;
3883 }
3884
3885 mixer_ctl_update(ctl);
3886
3887 size = mixer_ctl_get_num_values(ctl);
3888 if (size <= 0){
3889 ALOGE("%s: Failed to get %s size %d\n",
3890 __func__, mixer_ctl_name, size);
3891 ret = -EFAULT;
3892 goto done;
3893 }
3894
vivek mehtaa68fea62017-06-08 19:04:02 -07003895 be_dai_name_table =
3896 (const struct be_dai_name_struct *)calloc(1, size);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003897 if (be_dai_name_table == NULL) {
3898 ALOGE("%s: Failed to allocate memory for %s\n",
3899 __func__, mixer_ctl_name);
3900 ret = -ENOMEM;
3901 goto freeMem;
3902 }
3903
3904 ret = mixer_ctl_get_array(ctl, (void *)be_dai_name_table, size);
3905 if (ret) {
3906 ALOGE("%s: Failed to get %s, ret %d\n",
3907 __func__, mixer_ctl_name, ret);
3908 ret = -EFAULT;
3909 goto freeMem;
3910 }
3911
3912 if (be_dai_name_table != NULL) {
3913 max_be_dai_names = size / sizeof(struct be_dai_name_struct);
3914 ALOGV("%s: Successfully got %s, number of be dais is %d\n",
3915 __func__, mixer_ctl_name, max_be_dai_names);
3916 ret = 0;
3917 } else {
3918 ALOGE("%s: Failed to get %s\n", __func__, mixer_ctl_name);
3919 ret = -EFAULT;
3920 goto freeMem;
3921 }
3922
3923 /*
3924 * Validate all sound devices have a valid backend set to catch
3925 * errors for uncommon sound devices
3926 */
3927 for (i = 0; i < SND_DEVICE_MAX; i++) {
3928 valid_hw_interface = false;
3929
3930 if (hw_interface_table[i] == NULL) {
3931 ALOGW("%s: sound device %s has no hw interface set\n",
3932 __func__, platform_get_snd_device_name(i));
3933 continue;
3934 }
3935
3936 for (j = 0; j < max_be_dai_names; j++) {
3937 if (strcmp(hw_interface_table[i], be_dai_name_table[j].be_name)
3938 == 0) {
3939 valid_hw_interface = true;
3940 break;
3941 }
3942 }
3943 if (!valid_hw_interface)
3944 ALOGD("%s: sound device %s does not have a valid hw interface set "
3945 "(disregard for combo devices) %s\n",
3946 __func__, platform_get_snd_device_name(i),
3947 hw_interface_table[i]);
3948 }
3949
3950 goto done;
3951
3952freeMem:
3953 if (be_dai_name_table) {
3954 free((void *)be_dai_name_table);
3955 be_dai_name_table = NULL;
3956 }
3957
3958done:
3959 return ret;
3960}
3961
3962int platform_get_snd_device_backend_index(snd_device_t device)
3963{
3964 int i, be_dai_id;
3965 const char * hw_interface_name = NULL;
3966
3967 ALOGV("%s: enter with device %d\n", __func__, device);
3968
vivek mehtaa68fea62017-06-08 19:04:02 -07003969 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08003970 ALOGE("%s: Invalid snd_device = %d",
3971 __func__, device);
3972 be_dai_id = -EINVAL;
3973 goto done;
3974 }
3975
3976 /* Get string value of necessary backend for device */
3977 hw_interface_name = hw_interface_table[device];
3978 if (hw_interface_name == NULL) {
3979 ALOGE("%s: no hw_interface set for device %d\n", __func__, device);
3980 be_dai_id = -EINVAL;
3981 goto done;
3982 }
3983
3984 /* Check if be dai name table was retrieved successfully */
3985 if (be_dai_name_table == NULL) {
3986 ALOGE("%s: BE DAI Name Table is not present\n", __func__);
3987 be_dai_id = -EFAULT;
3988 goto done;
3989 }
3990
3991 /* Get backend ID for device specified */
3992 for (i = 0; i < max_be_dai_names; i++) {
3993 if (strcmp(hw_interface_name, be_dai_name_table[i].be_name) == 0) {
3994 be_dai_id = be_dai_name_table[i].be_id;
3995 goto done;
3996 }
3997 }
3998 ALOGE("%s: no interface matching name %s\n", __func__, hw_interface_name);
3999 be_dai_id = -EINVAL;
4000 goto done;
4001
4002done:
4003 return be_dai_id;
4004}
4005
4006void platform_check_and_update_copp_sample_rate(void* platform, snd_device_t snd_device,
4007 unsigned int stream_sr, int* sample_rate)
4008{
4009 struct platform_data* my_data = (struct platform_data *)platform;
4010 int backend_idx = platform_get_backend_index(snd_device);
4011 int device_sr = my_data->current_backend_cfg[backend_idx].sample_rate;
4012 /*
4013 *Check if device SR is multiple of 8K or 11.025 Khz
4014 *check if the stream SR is multiple of same base, if yes
4015 *then have copp SR equal to stream SR, this ensures that
4016 *post processing happens at stream SR, else have
4017 *copp SR equal to device SR.
4018 */
4019 if (!(((sample_rate_multiple(device_sr, SAMPLE_RATE_8000)) &&
4020 (sample_rate_multiple(stream_sr, SAMPLE_RATE_8000))) ||
4021 ((sample_rate_multiple(device_sr, SAMPLE_RATE_11025)) &&
4022 (sample_rate_multiple(stream_sr, SAMPLE_RATE_11025))))) {
4023 *sample_rate = device_sr;
4024 } else
4025 *sample_rate = stream_sr;
4026
4027 ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
4028 , *sample_rate);
4029
4030}
4031
4032// called from info parser
vivek mehtaa68fea62017-06-08 19:04:02 -07004033void platform_add_app_type(const char *uc_type,
4034 const char *mode,
4035 int bw,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004036 int app_type, int max_rate) {
4037 struct app_type_entry *ap =
4038 (struct app_type_entry *)calloc(1, sizeof(struct app_type_entry));
4039
4040 if (!ap) {
4041 ALOGE("%s failed to allocate mem for app type", __func__);
4042 return;
4043 }
4044
4045 ap->uc_type = -1;
4046 for (int i=0; i<USECASE_TYPE_MAX; i++) {
4047 if (!strcmp(uc_type, usecase_type_index[i].name)) {
4048 ap->uc_type = usecase_type_index[i].index;
4049 break;
4050 }
4051 }
4052
4053 if (ap->uc_type == -1) {
4054 free(ap);
4055 return;
4056 }
4057
vivek mehtaa68fea62017-06-08 19:04:02 -07004058 ALOGI("%s uc %s mode %s bw %d app_type %d max_rate %d",
4059 __func__, uc_type, mode, bw, app_type, max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004060 ap->bit_width = bw;
4061 ap->app_type = app_type;
4062 ap->max_rate = max_rate;
vivek mehtaa68fea62017-06-08 19:04:02 -07004063 ap->mode = strdup(mode);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004064 list_add_tail(&app_type_entry_list, &ap->node);
4065}
4066
4067
4068int platform_get_default_app_type_v2(void *platform __unused,
4069 usecase_type_t type,
4070 int *app_type )
4071{
4072 if (type == PCM_PLAYBACK)
4073 *app_type = DEFAULT_APP_TYPE_RX_PATH;
4074 else
4075 *app_type = DEFAULT_APP_TYPE_TX_PATH;
4076 return 0;
4077}
4078
vivek mehtaa68fea62017-06-08 19:04:02 -07004079int platform_get_app_type_v2(void *platform,
4080 usecase_type_t uc_type,
4081 const char *mode,
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004082 int bw, int sr __unused,
4083 int *app_type)
4084{
4085 struct listnode *node;
4086 struct app_type_entry *entry;
4087 *app_type = -1;
vivek mehtaa68fea62017-06-08 19:04:02 -07004088
4089 ALOGV("%s find match for uc %d mode %s bw %d rate %d",
4090 __func__, uc_type, mode, bw, sr);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004091 list_for_each(node, &app_type_entry_list) {
4092 entry = node_to_item(node, struct app_type_entry, node);
vivek mehtaa68fea62017-06-08 19:04:02 -07004093 ALOGV("%s uc %d mode %s bw %d app_type %d max_rate %d",
4094 __func__, entry->uc_type, entry->mode, entry->bit_width,
4095 entry->app_type, entry->max_rate);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004096 if (entry->bit_width == bw &&
vivek mehtaa68fea62017-06-08 19:04:02 -07004097 entry->uc_type == uc_type &&
4098 sr <= entry->max_rate &&
4099 entry->mode && !strcmp(mode, entry->mode)) {
4100 ALOGV("%s found match %d", __func__, entry->app_type);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004101 *app_type = entry->app_type;
4102 break;
4103 }
4104 }
4105
4106 if (*app_type == -1) {
vivek mehtaa68fea62017-06-08 19:04:02 -07004107 ALOGV("%s no match found, return default", __func__);
Haynes Mathew Georgee5ff0fc2017-02-16 20:33:38 -08004108 return platform_get_default_app_type_v2(platform, uc_type, app_type);
4109 }
4110 return 0;
4111}
vivek mehta90933872017-06-15 18:04:39 -07004112
4113int platform_set_sidetone(struct audio_device *adev,
4114 snd_device_t out_snd_device,
4115 bool enable, char *str)
4116{
4117 int ret;
4118 if (out_snd_device == SND_DEVICE_OUT_USB_HEADSET ||
4119 out_snd_device == SND_DEVICE_OUT_VOICE_USB_HEADSET) {
4120 ret = audio_extn_usb_enable_sidetone(out_snd_device, enable);
4121 if (ret)
4122 ALOGI("%s: usb device %d does not support device sidetone\n",
4123 __func__, out_snd_device);
4124 } else {
4125 ALOGV("%s: sidetone out device(%d) mixer cmd = %s\n",
4126 __func__, out_snd_device, str);
4127 if (enable)
4128 audio_route_apply_and_update_path(adev->audio_route, str);
4129 else
4130 audio_route_reset_and_update_path(adev->audio_route, str);
4131 }
4132 return 0;
4133}
Haynes Mathew George96483a22017-03-28 14:52:47 -07004134
4135int platform_get_mmap_data_fd(void *platform __unused, int fe_dev __unused, int dir __unused,
4136 int *fd __unused, uint32_t *size __unused)
4137{
Alexey Polyudove920d4b2017-09-15 17:09:07 -07004138#if defined (PLATFORM_MSM8996) || (PLATFORM_MSM8998) || (PLATFORM_SDM845)
Haynes Mathew George96483a22017-03-28 14:52:47 -07004139 struct platform_data *my_data = (struct platform_data *)platform;
4140 struct audio_device *adev = my_data->adev;
4141 int hw_fd = -1;
4142 char dev_name[128];
4143 struct snd_pcm_mmap_fd mmap_fd;
4144 memset(&mmap_fd, 0, sizeof(mmap_fd));
4145 mmap_fd.dir = dir;
4146 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
4147 adev->snd_card, HWDEP_FE_BASE+fe_dev);
4148 hw_fd = open(dev_name, O_RDONLY);
4149 if (hw_fd < 0) {
4150 ALOGE("fe hw dep node open %d/%d failed", adev->snd_card, fe_dev);
4151 return -1;
4152 }
4153 if (ioctl(hw_fd, SNDRV_PCM_IOCTL_MMAP_DATA_FD, &mmap_fd) < 0) {
4154 ALOGE("fe hw dep node ioctl failed");
4155 close(hw_fd);
4156 return -1;
4157 }
4158 *fd = mmap_fd.fd;
4159 *size = mmap_fd.size;
4160 close(hw_fd); // mmap_fd should still be valid
4161 return 0;
4162#else
4163 return -1;
4164#endif
4165}