blob: 6f4882825b0ad69f54fb55145f3cbb507d2ccc5d [file] [log] [blame]
Eric Laurentb23d5282013-05-14 15:27:20 -07001/*
Fred Ohe0479682015-03-25 16:30:26 -07002 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07003 * Not a Contribution.
4 *
Shiv Maliyappanahalli8911f282014-01-10 15:56:19 -08005 * Copyright (C) 2013 The Android Open Source Project
Eric Laurentb23d5282013-05-14 15:27:20 -07006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#define LOG_TAG "msm8974_platform"
21/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070023/*#define VERY_VERY_VERBOSE_LOGGING*/
24#ifdef VERY_VERY_VERBOSE_LOGGING
25#define ALOGVV ALOGV
26#else
27#define ALOGVV(a...) do { } while(0)
28#endif
Eric Laurentb23d5282013-05-14 15:27:20 -070029
30#include <stdlib.h>
31#include <dlfcn.h>
Anish Kumar55e6df22014-08-26 17:38:05 -070032#include <fcntl.h>
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -070033#include <sys/ioctl.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070034#include <cutils/log.h>
35#include <cutils/properties.h>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070036#include <cutils/str_parms.h>
Eric Laurentb23d5282013-05-14 15:27:20 -070037#include <audio_hw.h>
38#include <platform_api.h>
39#include "platform.h"
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -070040#include "audio_extn.h"
Narsinga Rao Chella05573b72013-11-15 15:21:40 -080041#include "voice_extn.h"
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -070042#include "edid.h"
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080043#include "sound/compress_params.h"
Anish Kumar55e6df22014-08-26 17:38:05 -070044#include "sound/msmcal-hwdep.h"
Eric Laurentb23d5282013-05-14 15:27:20 -070045
Anish Kumar55e6df22014-08-26 17:38:05 -070046#define SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID (100)
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -070047#define MIXER_XML_DEFAULT_PATH "/system/etc/mixer_paths.xml"
Damir Didjustof1d46c72013-11-06 17:59:04 -080048#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Helen Zeng6a16ad72014-02-23 22:04:44 -080049#define MIXER_XML_PATH_I2S "/system/etc/mixer_paths_i2s.xml"
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -070050#define MIXER_XML_BASE_STRING "/system/etc/mixer_paths"
51#define MIXER_FILE_DELIMITER "_"
52#define MIXER_FILE_EXT ".xml"
53
Helen Zeng6a16ad72014-02-23 22:04:44 -080054
55#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
56#define PLATFORM_INFO_XML_PATH_I2S "/system/etc/audio_platform_info_i2s.xml"
57
Eric Laurentb23d5282013-05-14 15:27:20 -070058#define LIB_ACDB_LOADER "libacdbloader.so"
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -070059#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Walter Yang6f800052014-07-14 16:15:38 -070060#define CVD_VERSION_MIXER_CTL "CVD Version"
Eric Laurentb23d5282013-05-14 15:27:20 -070061
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080062#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
63#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
64#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
65#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
66
67/* Used in calculating fragment size for pcm offload */
Alexy Joseph68011492015-06-18 12:02:01 -070068#define PCM_OFFLOAD_BUFFER_DURATION 40 /* 40 millisecs */
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080069
70/* MAX PCM fragment size cannot be increased further due
71 * to flinger's cblk size of 1mb,and it has to be a multiple of
72 * 24 - lcm of channels supported by DSP
73 */
74#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
Naresh Tanniru80ea8562015-07-01 15:07:46 +053075#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE 512
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080076
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070077/*
78 * Offload buffer size for compress passthrough
79 */
80#define MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (2 * 1024)
81#define MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (8 * 1024)
82
Amit Shekhar45fbfa92015-02-26 17:48:00 -080083#define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
84#define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
Eric Laurentb23d5282013-05-14 15:27:20 -070085/*
Eric Laurentb23d5282013-05-14 15:27:20 -070086 * This file will have a maximum of 38 bytes:
87 *
88 * 4 bytes: number of audio blocks
89 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
90 * Maximum 10 * 3 bytes: SAD blocks
91 */
92#define MAX_SAD_BLOCKS 10
93#define SAD_BLOCK_SIZE 3
94
Walter Yang6f800052014-07-14 16:15:38 -070095#define MAX_CVD_VERSION_STRING_SIZE 100
96
Eric Laurentb23d5282013-05-14 15:27:20 -070097/* EDID format ID for LPCM audio */
98#define EDID_FORMAT_LPCM 1
99
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700100/* fallback app type if the default app type from acdb loader fails */
101#define DEFAULT_APP_TYPE 0x11130
102
sangwoo1b9f4b32013-06-21 18:22:55 -0700103/* Retry for delay in FW loading*/
104#define RETRY_NUMBER 10
105#define RETRY_US 500000
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800106#define MAX_SND_CARD 8
sangwoo1b9f4b32013-06-21 18:22:55 -0700107
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700108#define SAMPLE_RATE_8KHZ 8000
109#define SAMPLE_RATE_16KHZ 16000
110
Ben Rombergera04fabc2014-11-14 12:16:03 -0800111#define MAX_SET_CAL_BYTE_SIZE 65536
112
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700113#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700114#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530115#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800116#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Ben Rombergera04fabc2014-11-14 12:16:03 -0800117#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
118#define AUDIO_PARAMETER_KEY_AUD_CALRESULT "cal_result"
119
120
Tanya Finkel00130052014-07-14 04:26:56 -0700121/* Query external audio device connection status */
122#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
123
124#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
125#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
126#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Anish Kumar55e6df22014-08-26 17:38:05 -0700127#define MAX_CAL_NAME 20
128
129char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
130 [WCD9XXX_ANC_CAL] = "anc_cal",
131 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
Anish Kumar55e6df22014-08-26 17:38:05 -0700132};
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800133
Sidipotu Ashok1b502902015-09-08 10:21:44 +0530134#define AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED "is_hw_dec_session_allowed"
135
136char * dsp_only_decoders_mime[] = {
137 "audio/x-ms-wma" /* wma*/ ,
138 "audio/x-ms-wma-lossless" /* wma lossless */ ,
139 "audio/x-ms-wma-pro" /* wma prop */ ,
140 "audio/amr-wb-plus" /* amr wb plus */ ,
141 "audio/alac" /*alac */ ,
142 "audio/x-ape" /*ape */,
143};
144
145
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800146enum {
147 VOICE_FEATURE_SET_DEFAULT,
148 VOICE_FEATURE_SET_VOLUME_BOOST
149};
sangwoo53b2cf02013-07-25 19:18:44 -0700150
Eric Laurentb23d5282013-05-14 15:27:20 -0700151struct audio_block_header
152{
153 int reserved;
154 int length;
155};
156
Ben Rombergera04fabc2014-11-14 12:16:03 -0800157typedef struct acdb_audio_cal_cfg {
158 uint32_t persist;
159 uint32_t snd_dev_id;
160 audio_devices_t dev_id;
161 int32_t acdb_dev_id;
162 uint32_t app_type;
163 uint32_t topo_id;
164 uint32_t sampling_rate;
165 uint32_t cal_type;
166 uint32_t module_id;
167 uint32_t param_id;
168} acdb_audio_cal_cfg_t;
169
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800170/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700171typedef void (*acdb_deallocate_t)();
Dhananjay Kumara3565b32014-07-23 01:12:48 +0530172typedef int (*acdb_init_t)(const char *, char *, int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700173typedef void (*acdb_send_audio_cal_t)(int, int, int , int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700174typedef void (*acdb_send_voice_cal_t)(int, int);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800175typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700176typedef int (*acdb_get_default_app_type_t)(void);
Anish Kumar55e6df22014-08-26 17:38:05 -0700177typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data);
178acdb_loader_get_calibration_t acdb_loader_get_calibration;
Ben Rombergera04fabc2014-11-14 12:16:03 -0800179typedef int (*acdb_set_audio_cal_t) (void *, void *, uint32_t);
180typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*);
Eric Laurentb23d5282013-05-14 15:27:20 -0700181
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800182typedef struct codec_backend_cfg {
183 uint32_t sample_rate;
184 uint32_t bit_width;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530185 char *bitwidth_mixer_ctl;
186 char *samplerate_mixer_ctl;
187} codec_backend_cfg_t;
188
189typedef struct {
190 bool platform_na_prop_enabled;
191 bool ui_na_prop_enabled;
192} native_audio_prop;
193
194static native_audio_prop na_props = {0, 0};
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800195
Eric Laurentb23d5282013-05-14 15:27:20 -0700196struct platform_data {
197 struct audio_device *adev;
198 bool fluence_in_spkr_mode;
199 bool fluence_in_voice_call;
200 bool fluence_in_voice_rec;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800201 bool fluence_in_audio_rec;
Tanya Finkel00130052014-07-14 04:26:56 -0700202 bool external_spk_1;
203 bool external_spk_2;
204 bool external_mic;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700205 int fluence_type;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800206 int fluence_mode;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530207 char fluence_cap[PROPERTY_VALUE_MAX];
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700208 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530209 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530210 bool ec_ref_enabled;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800211 bool is_i2s_ext_modem;
Ramjee Singheb9127a2015-06-09 15:18:42 +0530212 bool is_acdb_initialized;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700213 /* Audio calibration related functions */
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800214 void *acdb_handle;
215 int voice_feature_set;
216 acdb_init_t acdb_init;
217 acdb_deallocate_t acdb_deallocate;
218 acdb_send_audio_cal_t acdb_send_audio_cal;
Ben Rombergera04fabc2014-11-14 12:16:03 -0800219 acdb_set_audio_cal_t acdb_set_audio_cal;
220 acdb_get_audio_cal_t acdb_get_audio_cal;
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800221 acdb_send_voice_cal_t acdb_send_voice_cal;
222 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700223 acdb_get_default_app_type_t acdb_get_default_app_type;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700224
225 void *hw_info;
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800226 struct csd_data *csd;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -0700227 void *edid_info;
228 bool edid_valid;
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -0700229 char ec_ref_mixer_path[64];
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530230 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Eric Laurentb23d5282013-05-14 15:27:20 -0700231};
232
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700233static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700234 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
235 DEEP_BUFFER_PCM_DEVICE},
236 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700237 LOWLATENCY_PCM_DEVICE},
238 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700239 MULTIMEDIA2_PCM_DEVICE},
Krishnankutty Kolathappillya43f96e2013-11-01 12:17:53 -0700240 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
241 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -0700242#ifdef MULTIPLE_OFFLOAD_ENABLED
243 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] =
244 {PLAYBACK_OFFLOAD_DEVICE2, PLAYBACK_OFFLOAD_DEVICE2},
245 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] =
246 {PLAYBACK_OFFLOAD_DEVICE3, PLAYBACK_OFFLOAD_DEVICE3},
247 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] =
248 {PLAYBACK_OFFLOAD_DEVICE4, PLAYBACK_OFFLOAD_DEVICE4},
249 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] =
250 {PLAYBACK_OFFLOAD_DEVICE5, PLAYBACK_OFFLOAD_DEVICE5},
251 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] =
252 {PLAYBACK_OFFLOAD_DEVICE6, PLAYBACK_OFFLOAD_DEVICE6},
253 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] =
254 {PLAYBACK_OFFLOAD_DEVICE7, PLAYBACK_OFFLOAD_DEVICE7},
255 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] =
256 {PLAYBACK_OFFLOAD_DEVICE8, PLAYBACK_OFFLOAD_DEVICE8},
257 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] =
258 {PLAYBACK_OFFLOAD_DEVICE9, PLAYBACK_OFFLOAD_DEVICE9},
259#endif
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700260 [USECASE_AUDIO_PLAYBACK_ULL] = {MULTIMEDIA3_PCM_DEVICE,
261 MULTIMEDIA3_PCM_DEVICE},
262
Naresh Tanniru06f99432015-08-26 14:01:20 -0700263 [USECASE_AUDIO_DIRECT_PCM_OFFLOAD] =
264 {PLAYBACK_OFFLOAD_DEVICE2, PLAYBACK_OFFLOAD_DEVICE2},
265
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700266 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
Mingming Yine62d7842013-10-25 16:26:03 -0700267 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700268 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
269 LOWLATENCY_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700270 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
271 MULTIMEDIA2_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700272 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800273 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800274 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700275 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
276 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
277 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
278 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Vicky Sehrawat7e4fc152014-02-12 17:58:59 -0800279 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Vidyakumar Athota0e109352015-02-12 17:38:22 -0800280 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
281 VOICEMMODE1_CALL_PCM_DEVICE},
282 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
283 VOICEMMODE2_CALL_PCM_DEVICE},
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800284 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700285 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
286 AUDIO_RECORD_PCM_DEVICE},
287 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
288 AUDIO_RECORD_PCM_DEVICE},
289 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
290 AUDIO_RECORD_PCM_DEVICE},
Helen Zenge56b4852013-12-03 16:54:40 -0800291 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
292 COMPRESS_CAPTURE_DEVICE},
293 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
294 COMPRESS_CAPTURE_DEVICE},
295 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
296 COMPRESS_CAPTURE_DEVICE},
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700297 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
298 INCALL_MUSIC_UPLINK_PCM_DEVICE},
299 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
300 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700301 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
302 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700303
304 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
305 AFE_PROXY_RECORD_PCM_DEVICE},
306 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
307 AFE_PROXY_RECORD_PCM_DEVICE},
308
Eric Laurentb23d5282013-05-14 15:27:20 -0700309};
310
311/* Array to store sound devices */
312static const char * const device_table[SND_DEVICE_MAX] = {
313 [SND_DEVICE_NONE] = "none",
314 /* Playback sound devices */
315 [SND_DEVICE_OUT_HANDSET] = "handset",
316 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Tanya Finkel00130052014-07-14 04:26:56 -0700317 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
318 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Eric Laurentb23d5282013-05-14 15:27:20 -0700319 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
320 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800321 [SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
Eric Laurentb23d5282013-05-14 15:27:20 -0700322 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Tanya Finkel00130052014-07-14 04:26:56 -0700323 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
324 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Eric Laurentb23d5282013-05-14 15:27:20 -0700325 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
326 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
327 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
328 [SND_DEVICE_OUT_HDMI] = "hdmi",
329 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
330 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700331 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700332 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
333 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
334 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700335 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700336 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
337 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
338 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700339 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700340 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
341 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
342 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
343 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
344 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
345 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700346 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Anish Kumar46c7b872014-09-09 01:49:44 -0700347 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Eric Laurentb23d5282013-05-14 15:27:20 -0700348
349 /* Capture sound devices */
350 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Tanya Finkel00130052014-07-14 04:26:56 -0700351 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Eric Laurentb23d5282013-05-14 15:27:20 -0700352 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800353 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
354 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
355 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800356 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800357 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
358 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
359 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800360 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800361 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
362 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
363 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800364 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800365 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
366 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
367 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
368 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
370 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
371 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
372 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700373 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700374 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700375 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700376 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700377 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700378 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800379 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700380 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
381 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
382 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700383 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
384
Eric Laurentb23d5282013-05-14 15:27:20 -0700385 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800386 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800387 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700388 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700389 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700390 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700391 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700392 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700393 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
394 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700395 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800396 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
397 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
398 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
399 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
400 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700401 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
402 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
403 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
404 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700405};
406
Amit Shekhar5a39c912014-10-14 15:39:30 -0700407// Platform specific backend bit width table
408static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
409
Eric Laurentb23d5282013-05-14 15:27:20 -0700410/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ben Romberger55886882014-01-10 13:49:02 -0800411static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700412 [SND_DEVICE_NONE] = -1,
413 [SND_DEVICE_OUT_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800414 [SND_DEVICE_OUT_SPEAKER] = 14,
Tanya Finkel87af1a52015-03-27 14:54:23 -0700415 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 130,
416 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 130,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800417 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700418 [SND_DEVICE_OUT_HEADPHONES] = 10,
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800419 [SND_DEVICE_OUT_HEADPHONES_44_1] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700420 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Tanya Finkel87af1a52015-03-27 14:54:23 -0700421 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 130,
422 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 130,
Eric Laurentb23d5282013-05-14 15:27:20 -0700423 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800424 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700425 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
426 [SND_DEVICE_OUT_HDMI] = 18,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800427 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700428 [SND_DEVICE_OUT_BT_SCO] = 22,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700429 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700430 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
431 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
432 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700433 [SND_DEVICE_OUT_VOICE_TX] = 45,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700434 [SND_DEVICE_OUT_AFE_PROXY] = 0,
Vidyakumar Athotab9522202014-01-14 20:08:27 -0800435 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700436 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700437 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700438 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700439 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700440 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700441 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700442 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
443 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Anish Kumar46c7b872014-09-09 01:49:44 -0700444 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
445 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Eric Laurentb23d5282013-05-14 15:27:20 -0700446
447 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Tanya Finkel00130052014-07-14 04:26:56 -0700448 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800449 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
450 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
451 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800452 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800453 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
454 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
455 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800456 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800457 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
458 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
459 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800460 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800461 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
462 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
463 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Eric Laurentb23d5282013-05-14 15:27:20 -0700464 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800465 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Eric Laurentb23d5282013-05-14 15:27:20 -0700466 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
467 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
468 [SND_DEVICE_IN_HDMI_MIC] = 4,
469 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700470 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700471 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700472 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800473 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700474 [SND_DEVICE_IN_VOICE_DMIC] = 41,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700475 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800476 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Eric Laurentb23d5282013-05-14 15:27:20 -0700477 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
478 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
479 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700480 [SND_DEVICE_IN_VOICE_RX] = 44,
481
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800482 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800483 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800484 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
485 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700486 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700487 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700488 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700489 [SND_DEVICE_IN_QUAD_MIC] = 46,
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700490 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
491 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700492 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800493 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
494 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
495 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
496 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
497 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700498 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
499 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
500 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
501 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Eric Laurentb23d5282013-05-14 15:27:20 -0700502};
503
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700504struct name_to_index {
Ben Romberger61764e32014-01-10 13:49:02 -0800505 char name[100];
506 unsigned int index;
507};
508
509#define TO_NAME_INDEX(X) #X, X
510
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800511/* Used to get index from parsed string */
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700512static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Ben Romberger61764e32014-01-10 13:49:02 -0800513 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
514 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Tanya Finkel00130052014-07-14 04:26:56 -0700515 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
516 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Ben Romberger61764e32014-01-10 13:49:02 -0800517 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
518 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800519 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
Ben Romberger61764e32014-01-10 13:49:02 -0800520 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Tanya Finkel00130052014-07-14 04:26:56 -0700521 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
522 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Ben Romberger61764e32014-01-10 13:49:02 -0800523 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
524 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
525 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
526 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
527 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
528 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
529 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
530 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
531 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
532 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
533 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
534 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
535 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
536 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
537 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
538 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
539 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
540 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
541 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
542 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
543 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Anish Kumar46c7b872014-09-09 01:49:44 -0700544 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Ben Romberger61764e32014-01-10 13:49:02 -0800545 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Tanya Finkel00130052014-07-14 04:26:56 -0700546 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Ben Romberger61764e32014-01-10 13:49:02 -0800547 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
556 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
559 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
560 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
562 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700568 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Ben Romberger61764e32014-01-10 13:49:02 -0800569 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700570 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Ben Romberger61764e32014-01-10 13:49:02 -0800571 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
574 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
576 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
578 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
579 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
580 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
581 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
582 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
583 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
584 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
586 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
587 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800589 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
590 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
591 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
592 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
593 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700594 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
595 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
596 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
597 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Ben Romberger61764e32014-01-10 13:49:02 -0800598};
599
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700600static char * backend_table[SND_DEVICE_MAX] = {0};
601
602static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
603 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
604 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
605 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
606 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Alexy Joseph2f89cfa2014-10-06 12:15:01 -0700607#ifdef MULTIPLE_OFFLOAD_ENABLED
608 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
609 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
610 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
611 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
612 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
613 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
614 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
615 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
616#endif
Naresh Tanniru3a7dbe72015-06-25 20:08:01 -0700617 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_ULL)},
Naresh Tanniru06f99432015-08-26 14:01:20 -0700618 {TO_NAME_INDEX(USECASE_AUDIO_DIRECT_PCM_OFFLOAD)},
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700619 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
620 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
621 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
622 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
623 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
624 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
625 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
626 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
627 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
628 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
629 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
630};
631
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700632#define NO_COLS 2
633#ifdef PLATFORM_APQ8084
634static int msm_device_to_be_id [][NO_COLS] = {
635 {AUDIO_DEVICE_OUT_EARPIECE , 2},
636 {AUDIO_DEVICE_OUT_SPEAKER , 2},
637 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
638 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
639 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
640 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
641 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
642 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
643 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
644 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
645 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
646 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
647 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
648 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
649 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
650 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
651 {AUDIO_DEVICE_OUT_PROXY , 9},
652 {AUDIO_DEVICE_OUT_FM , 7},
653 {AUDIO_DEVICE_OUT_FM_TX , 8},
654 {AUDIO_DEVICE_OUT_ALL , -1},
655 {AUDIO_DEVICE_NONE , -1},
656 {AUDIO_DEVICE_OUT_DEFAULT , -1},
657};
658#elif PLATFORM_MSM8994
659static int msm_device_to_be_id [][NO_COLS] = {
660 {AUDIO_DEVICE_OUT_EARPIECE , 2},
661 {AUDIO_DEVICE_OUT_SPEAKER , 2},
662 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
663 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
664 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 38},
665 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 38},
666 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 38},
667 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
668 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
669 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
670 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
671 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
672 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
673 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
674 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
675 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
676 {AUDIO_DEVICE_OUT_PROXY , 9},
677/* Add the correct be ids */
678 {AUDIO_DEVICE_OUT_FM , 7},
679 {AUDIO_DEVICE_OUT_FM_TX , 8},
680 {AUDIO_DEVICE_OUT_ALL , -1},
681 {AUDIO_DEVICE_NONE , -1},
682 {AUDIO_DEVICE_OUT_DEFAULT , -1},
683};
Pradnya Chaphekarf0b1cfe2015-04-15 16:52:49 -0700684#elif PLATFORM_MSM8996
685static int msm_device_to_be_id [][NO_COLS] = {
686 {AUDIO_DEVICE_OUT_EARPIECE , 2},
687 {AUDIO_DEVICE_OUT_SPEAKER , 2},
688 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
689 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
690 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
691 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
692 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
693 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
694 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
695 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
696 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
697 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
698 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
699 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
700 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
701 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
702 {AUDIO_DEVICE_OUT_PROXY , 9},
703/* Add the correct be ids */
704 {AUDIO_DEVICE_OUT_FM , 7},
705 {AUDIO_DEVICE_OUT_FM_TX , 8},
706 {AUDIO_DEVICE_OUT_ALL , -1},
707 {AUDIO_DEVICE_NONE , -1},
708 {AUDIO_DEVICE_OUT_DEFAULT , -1},
709};
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700710#else
711static int msm_device_to_be_id [][NO_COLS] = {
712 {AUDIO_DEVICE_NONE, -1},
713};
714#endif
715static int msm_be_id_array_len =
716 sizeof(msm_device_to_be_id) / sizeof(msm_device_to_be_id[0]);
717
718
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700719#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
720#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
721
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -0700722void platform_set_echo_reference(struct audio_device *adev, bool enable,
723 audio_devices_t out_device)
Eric Laurentb23d5282013-05-14 15:27:20 -0700724{
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -0700725 struct platform_data *my_data = (struct platform_data *)adev->platform;
726 snd_device_t snd_device = SND_DEVICE_NONE;
727 struct stream_out out;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530728
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -0700729 out.devices = out_device;
730
731 if (strcmp(my_data->ec_ref_mixer_path, "")) {
732 ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
733 audio_route_reset_and_update_path(adev->audio_route,
734 my_data->ec_ref_mixer_path);
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530735 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700736
Ravi Kumar Alamandad1c85bb2014-11-17 18:36:24 -0800737 if (enable) {
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -0700738 strlcpy(my_data->ec_ref_mixer_path, "echo-reference",
739 sizeof(my_data->ec_ref_mixer_path));
740 snd_device = platform_get_output_snd_device(adev->platform, &out);
741 /*
742 * If native audio device reference count > 0, then apply codec EC otherwise
743 * fallback to headphones if so or default
744 */
745 if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_HEADPHONES_44_1] > 0)
746 platform_add_backend_name(my_data->ec_ref_mixer_path,
747 SND_DEVICE_OUT_HEADPHONES_44_1);
748 else
749 platform_add_backend_name(my_data->ec_ref_mixer_path, snd_device);
Ravi Kumar Alamandad1c85bb2014-11-17 18:36:24 -0800750
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -0700751 ALOGD("%s: enabling %s", __func__, my_data->ec_ref_mixer_path);
752 audio_route_apply_and_update_path(adev->audio_route,
753 my_data->ec_ref_mixer_path);
754 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700755}
756
Helen Zeng6a16ad72014-02-23 22:04:44 -0800757static struct csd_data *open_csd_client(bool i2s_ext_modem)
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800758{
759 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
760
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700761 if (!csd) {
762 ALOGE("failed to allocate csd_data mem");
763 return NULL;
764 }
765
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800766 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
767 if (csd->csd_client == NULL) {
768 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
769 goto error;
770 } else {
771 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
772
773 csd->deinit = (deinit_t)dlsym(csd->csd_client,
774 "csd_client_deinit");
775 if (csd->deinit == NULL) {
776 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
777 dlerror());
778 goto error;
779 }
780 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
781 "csd_client_disable_device");
782 if (csd->disable_device == NULL) {
783 ALOGE("%s: dlsym error %s for csd_client_disable_device",
784 __func__, dlerror());
785 goto error;
786 }
Vidyakumar Athota545dbd32013-11-13 17:30:53 -0800787 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
788 "csd_client_enable_device_config");
789 if (csd->enable_device_config == NULL) {
790 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
791 __func__, dlerror());
792 goto error;
793 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800794 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
795 "csd_client_enable_device");
796 if (csd->enable_device == NULL) {
797 ALOGE("%s: dlsym error %s for csd_client_enable_device",
798 __func__, dlerror());
799 goto error;
800 }
801 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
802 "csd_client_start_voice");
803 if (csd->start_voice == NULL) {
804 ALOGE("%s: dlsym error %s for csd_client_start_voice",
805 __func__, dlerror());
806 goto error;
807 }
808 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
809 "csd_client_stop_voice");
810 if (csd->stop_voice == NULL) {
811 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
812 __func__, dlerror());
813 goto error;
814 }
815 csd->volume = (volume_t)dlsym(csd->csd_client,
816 "csd_client_volume");
817 if (csd->volume == NULL) {
818 ALOGE("%s: dlsym error %s for csd_client_volume",
819 __func__, dlerror());
820 goto error;
821 }
822 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
823 "csd_client_mic_mute");
824 if (csd->mic_mute == NULL) {
825 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
826 __func__, dlerror());
827 goto error;
828 }
829 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
830 "csd_client_slow_talk");
831 if (csd->slow_talk == NULL) {
832 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
833 __func__, dlerror());
834 goto error;
835 }
836 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
837 "csd_client_start_playback");
838 if (csd->start_playback == NULL) {
839 ALOGE("%s: dlsym error %s for csd_client_start_playback",
840 __func__, dlerror());
841 goto error;
842 }
843 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
844 "csd_client_stop_playback");
845 if (csd->stop_playback == NULL) {
846 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
847 __func__, dlerror());
848 goto error;
849 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700850 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
851 if (csd->set_lch == NULL) {
852 ALOGE("%s: dlsym error %s for csd_client_set_lch",
853 __func__, dlerror());
854 /* Ignore the error as this is not mandatory function for
855 * basic voice call to work.
856 */
857 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800858 csd->start_record = (start_record_t)dlsym(csd->csd_client,
859 "csd_client_start_record");
860 if (csd->start_record == NULL) {
861 ALOGE("%s: dlsym error %s for csd_client_start_record",
862 __func__, dlerror());
863 goto error;
864 }
865 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
866 "csd_client_stop_record");
867 if (csd->stop_record == NULL) {
868 ALOGE("%s: dlsym error %s for csd_client_stop_record",
869 __func__, dlerror());
870 goto error;
871 }
Helen Zeng6a16ad72014-02-23 22:04:44 -0800872
873 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
874 "csd_client_get_sample_rate");
875 if (csd->get_sample_rate == NULL) {
876 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
877 __func__, dlerror());
878
879 goto error;
880 }
881
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800882 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
883
884 if (csd->init == NULL) {
885 ALOGE("%s: dlsym error %s for csd_client_init",
886 __func__, dlerror());
887 goto error;
888 } else {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800889 csd->init(i2s_ext_modem);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800890 }
891 }
892 return csd;
893
894error:
895 free(csd);
896 csd = NULL;
897 return csd;
898}
899
900void close_csd_client(struct csd_data *csd)
901{
902 if (csd != NULL) {
903 csd->deinit();
904 dlclose(csd->csd_client);
905 free(csd);
906 csd = NULL;
907 }
908}
909
Helen Zeng6a16ad72014-02-23 22:04:44 -0800910static bool platform_is_i2s_ext_modem(const char *snd_card_name,
911 struct platform_data *plat_data)
912{
913 plat_data->is_i2s_ext_modem = false;
914
915 if (!strncmp(snd_card_name, "apq8084-taiko-i2s-mtp-snd-card",
916 sizeof("apq8084-taiko-i2s-mtp-snd-card")) ||
917 !strncmp(snd_card_name, "apq8084-taiko-i2s-cdp-snd-card",
918 sizeof("apq8084-taiko-i2s-cdp-snd-card"))) {
919 plat_data->is_i2s_ext_modem = true;
920 }
921 ALOGV("%s, is_i2s_ext_modem:%d",__func__, plat_data->is_i2s_ext_modem);
922
923 return plat_data->is_i2s_ext_modem;
Helen Zeng008aebd2014-02-23 19:13:12 -0800924}
925
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700926static void set_platform_defaults()
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700927{
928 int32_t dev;
929 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
930 backend_table[dev] = NULL;
931 }
Amit Shekhar5a39c912014-10-14 15:39:30 -0700932 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530933 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Amit Shekhar5a39c912014-10-14 15:39:30 -0700934 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700935
936 // TBD - do these go to the platform-info.xml file.
937 // will help in avoiding strdups here
938 backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
939 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700940 backend_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
941 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700942 backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
943 backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
944 backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
945 backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700946 backend_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
947 backend_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
948
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700949 backend_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
950 backend_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones");
951 backend_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
952 strdup("speaker-and-usb-headphones");
953 backend_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
954 backend_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
955 backend_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800956 backend_table[SND_DEVICE_OUT_HEADPHONES] = strdup("headphones");
957 backend_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700958}
959
Walter Yang6f800052014-07-14 16:15:38 -0700960void get_cvd_version(char *cvd_version, struct audio_device *adev)
961{
962 struct mixer_ctl *ctl;
963 int count;
964 int ret = 0;
965
966 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
967 if (!ctl) {
968 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
969 goto done;
970 }
971 mixer_ctl_update(ctl);
972
973 count = mixer_ctl_get_num_values(ctl);
974 if (count > MAX_CVD_VERSION_STRING_SIZE)
975 count = MAX_CVD_VERSION_STRING_SIZE;
976
977 ret = mixer_ctl_get_array(ctl, cvd_version, count);
978 if (ret != 0) {
979 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
980 goto done;
981 }
982
983done:
984 return;
985}
986
Anish Kumar55e6df22014-08-26 17:38:05 -0700987static int hw_util_open(int card_no)
988{
989 int fd = -1;
990 char dev_name[256];
991
992 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
993 card_no, WCD9XXX_CODEC_HWDEP_NODE);
994 ALOGD("%s Opening device %s\n", __func__, dev_name);
995 fd = open(dev_name, O_WRONLY);
996 if (fd < 0) {
997 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
998 return fd;
999 }
1000 ALOGD("%s success", __func__);
1001 return fd;
1002}
1003
1004struct param_data {
1005 int use_case;
1006 int acdb_id;
1007 int get_size;
1008 int buff_size;
1009 int data_size;
1010 void *buff;
1011};
1012
1013static int send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration, int fd)
1014{
1015 int ret = 0, type;
1016
1017 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
1018 struct wcdcal_ioctl_buffer codec_buffer;
1019 struct param_data calib;
1020
Chaithanya Krishna Bacharaju82b16a42015-08-31 17:41:46 -07001021 /* MAD calibration is handled by sound trigger HAL, skip here */
1022 if (type == WCD9XXX_MAD_CAL)
1023 continue;
1024
Anish Kumar55e6df22014-08-26 17:38:05 -07001025 calib.get_size = 1;
1026 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
1027 &calib);
1028 if (ret < 0) {
1029 ALOGE("%s get_calibration failed\n", __func__);
1030 return ret;
1031 }
1032 calib.get_size = 0;
1033 calib.buff = malloc(calib.buff_size);
1034 ret = acdb_loader_get_calibration(cal_name_info[type],
1035 sizeof(struct param_data), &calib);
1036 if (ret < 0) {
1037 ALOGE("%s get_calibration failed\n", __func__);
1038 free(calib.buff);
1039 return ret;
1040 }
1041 codec_buffer.buffer = calib.buff;
1042 codec_buffer.size = calib.data_size;
1043 codec_buffer.cal_type = type;
1044 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
1045 ALOGE("Failed to call ioctl for %s err=%d",
1046 cal_name_info[type], errno);
1047 ALOGD("%s cal sent for %s", __func__, cal_name_info[type]);
1048 free(calib.buff);
1049 }
1050 return ret;
1051}
1052
1053static void audio_hwdep_send_cal(struct platform_data *plat_data)
1054{
1055 int fd;
1056
1057 fd = hw_util_open(plat_data->adev->snd_card);
1058 if (fd == -1) {
1059 ALOGE("%s error open\n", __func__);
1060 return;
1061 }
1062
1063 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
1064 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
1065
1066 if (acdb_loader_get_calibration == NULL) {
1067 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
1068 dlerror());
1069 return;
1070 }
1071 if (send_codec_cal(acdb_loader_get_calibration, fd) < 0)
1072 ALOGE("%s: Could not send anc cal", __FUNCTION__);
1073}
1074
Ramjee Singheb9127a2015-06-09 15:18:42 +05301075int platform_acdb_init(void *platform)
1076{
1077 struct platform_data *my_data = (struct platform_data *)platform;
1078 char *cvd_version = NULL;
1079 int key = 0;
1080 const char *snd_card_name;
1081 int result;
1082 char value[PROPERTY_VALUE_MAX];
1083 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1084 if (!cvd_version)
1085 ALOGE("Failed to allocate cvd version");
1086 else
1087 get_cvd_version(cvd_version, my_data->adev);
1088
1089 property_get("audio.ds1.metainfo.key",value,"0");
1090 key = atoi(value);
1091 snd_card_name = mixer_get_name(my_data->adev->mixer);
1092 result = my_data->acdb_init(snd_card_name, cvd_version, key);
1093 if (cvd_version)
1094 free(cvd_version);
1095 if (!result) {
1096 my_data->is_acdb_initialized = true;
1097 ALOGD("ACDB initialized");
1098 audio_hwdep_send_cal(my_data);
1099 } else {
1100 my_data->is_acdb_initialized = false;
1101 ALOGD("ACDB initialization failed");
1102 }
1103 return result;
1104}
1105
Eric Laurentb23d5282013-05-14 15:27:20 -07001106void *platform_init(struct audio_device *adev)
1107{
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07001108 char platform[PROPERTY_VALUE_MAX];
1109 char baseband[PROPERTY_VALUE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -07001110 char value[PROPERTY_VALUE_MAX];
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001111 struct platform_data *my_data = NULL;
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -07001112 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001113 const char *snd_card_name;
Walter Yang6f800052014-07-14 16:15:38 -07001114 char *cvd_version = NULL;
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -07001115 char *snd_internal_name = NULL;
1116 char *tmp = NULL;
1117 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05301118 const char *mixer_ctl_name = "Set HPX ActiveBe";
1119 struct mixer_ctl *ctl = NULL;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08001120 int idx;
sangwoo1b9f4b32013-06-21 18:22:55 -07001121
Eric Laurentb23d5282013-05-14 15:27:20 -07001122 my_data = calloc(1, sizeof(struct platform_data));
1123
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07001124 if (!my_data) {
1125 ALOGE("failed to allocate platform data");
1126 return NULL;
1127 }
1128
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001129 while (snd_card_num < MAX_SND_CARD) {
1130 adev->mixer = mixer_open(snd_card_num);
1131
1132 while (!adev->mixer && retry_num < RETRY_NUMBER) {
1133 usleep(RETRY_US);
1134 adev->mixer = mixer_open(snd_card_num);
1135 retry_num++;
1136 }
1137
1138 if (!adev->mixer) {
1139 ALOGE("%s: Unable to open the mixer card: %d", __func__,
1140 snd_card_num);
1141 retry_num = 0;
1142 snd_card_num++;
1143 continue;
1144 }
1145
1146 snd_card_name = mixer_get_name(adev->mixer);
1147 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
1148
1149 my_data->hw_info = hw_info_init(snd_card_name);
1150 if (!my_data->hw_info) {
1151 ALOGE("%s: Failed to init hardware info", __func__);
1152 } else {
Helen Zeng6a16ad72014-02-23 22:04:44 -08001153 if (platform_is_i2s_ext_modem(snd_card_name, my_data)) {
1154 ALOGD("%s: Call MIXER_XML_PATH_I2S", __func__);
1155
1156 adev->audio_route = audio_route_init(snd_card_num,
1157 MIXER_XML_PATH_I2S);
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -07001158 } else {
1159 /* Get the codec internal name from the sound card name
1160 * and form the mixer paths file name dynamically. This
1161 * is generic way of picking any codec name based mixer
1162 * files in future with no code change. This code
1163 * assumes mixer files are formed with format as
1164 * mixer_paths_internalcodecname.xml
1165
1166 * If this dynamically read mixer files fails to open then it
1167 * falls back to default mixer file i.e mixer_paths.xml. This is
1168 * done to preserve backward compatibility but not mandatory as
1169 * long as the mixer files are named as per above assumption.
1170 */
1171
1172 snd_internal_name = strtok_r(snd_card_name, "-", &tmp);
1173 if (snd_internal_name != NULL)
1174 snd_internal_name = strtok_r(NULL, "-", &tmp);
1175
1176 if (snd_internal_name != NULL) {
1177 strlcpy(mixer_xml_file, MIXER_XML_BASE_STRING,
1178 MIXER_PATH_MAX_LENGTH);
1179 strlcat(mixer_xml_file, MIXER_FILE_DELIMITER,
1180 MIXER_PATH_MAX_LENGTH);
1181 strlcat(mixer_xml_file, snd_internal_name,
1182 MIXER_PATH_MAX_LENGTH);
1183 strlcat(mixer_xml_file, MIXER_FILE_EXT,
1184 MIXER_PATH_MAX_LENGTH);
1185 } else {
1186 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH,
1187 MIXER_PATH_MAX_LENGTH);
1188 }
1189
1190 if (F_OK == access(mixer_xml_file, 0)) {
1191 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1192 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_file,
1193 MIXER_XML_PATH_AUXPCM) == -ENOSYS)
1194 adev->audio_route = audio_route_init(snd_card_num,
1195 mixer_xml_file);
1196 } else {
1197 ALOGD("%s: Loading default mixer file", __func__);
1198 if(audio_extn_read_xml(adev, snd_card_num, MIXER_XML_DEFAULT_PATH,
1199 MIXER_XML_PATH_AUXPCM) == -ENOSYS)
1200 adev->audio_route = audio_route_init(snd_card_num,
1201 MIXER_XML_DEFAULT_PATH);
1202 }
Helen Zeng6a16ad72014-02-23 22:04:44 -08001203 }
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001204 if (!adev->audio_route) {
1205 ALOGE("%s: Failed to init audio route controls, aborting.",
1206 __func__);
1207 free(my_data);
1208 return NULL;
1209 }
1210 adev->snd_card = snd_card_num;
1211 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1212 break;
1213 }
1214 retry_num = 0;
1215 snd_card_num++;
1216 }
1217
1218 if (snd_card_num >= MAX_SND_CARD) {
1219 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1220 free(my_data);
1221 return NULL;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001222 }
1223
Eric Laurentb23d5282013-05-14 15:27:20 -07001224 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07001225 my_data->fluence_in_spkr_mode = false;
1226 my_data->fluence_in_voice_call = false;
1227 my_data->fluence_in_voice_rec = false;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001228 my_data->fluence_in_audio_rec = false;
Tanya Finkel00130052014-07-14 04:26:56 -07001229 my_data->external_spk_1 = false;
1230 my_data->external_spk_2 = false;
1231 my_data->external_mic = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001232 my_data->fluence_type = FLUENCE_NONE;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001233 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301234 my_data->slowtalk = false;
1235 my_data->hd_voice = false;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07001236 my_data->edid_info = NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001237
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301238 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
1239 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001240 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301241 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001242 my_data->fluence_type = FLUENCE_DUAL_MIC;
1243 } else {
1244 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001245 }
1246
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001247 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001248 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001249 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001250 my_data->fluence_in_voice_call = true;
1251 }
1252
1253 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001254 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001255 my_data->fluence_in_voice_rec = true;
1256 }
1257
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001258 property_get("persist.audio.fluence.audiorec",value,"");
1259 if (!strncmp("true", value, sizeof("true"))) {
1260 my_data->fluence_in_audio_rec = true;
1261 }
1262
Eric Laurentb23d5282013-05-14 15:27:20 -07001263 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001264 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001265 my_data->fluence_in_spkr_mode = true;
1266 }
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001267
1268 property_get("persist.audio.fluence.mode",value,"");
1269 if (!strncmp("broadside", value, sizeof("broadside"))) {
1270 my_data->fluence_mode = FLUENCE_BROADSIDE;
1271 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001272 }
1273
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001274 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Eric Laurentb23d5282013-05-14 15:27:20 -07001275 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1276 if (my_data->acdb_handle == NULL) {
1277 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1278 } else {
1279 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1280 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1281 "acdb_loader_deallocate_ACDB");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001282 if (!my_data->acdb_deallocate)
1283 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1284 __func__, LIB_ACDB_LOADER);
1285
Eric Laurentb23d5282013-05-14 15:27:20 -07001286 my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001287 "acdb_loader_send_audio_cal_v2");
Eric Laurentb23d5282013-05-14 15:27:20 -07001288 if (!my_data->acdb_send_audio_cal)
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001289 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001290 __func__, LIB_ACDB_LOADER);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001291
Ben Rombergera04fabc2014-11-14 12:16:03 -08001292 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1293 "acdb_loader_set_audio_cal_v2");
1294 if (!my_data->acdb_set_audio_cal)
1295 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1296 __func__, LIB_ACDB_LOADER);
1297
1298 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
1299 "acdb_loader_get_audio_cal_v2");
1300 if (!my_data->acdb_get_audio_cal)
1301 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
1302 __func__, LIB_ACDB_LOADER);
1303
Eric Laurentb23d5282013-05-14 15:27:20 -07001304 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1305 "acdb_loader_send_voice_cal");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001306 if (!my_data->acdb_send_voice_cal)
1307 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1308 __func__, LIB_ACDB_LOADER);
1309
1310 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1311 "acdb_loader_reload_vocvoltable");
1312 if (!my_data->acdb_reload_vocvoltable)
1313 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1314 __func__, LIB_ACDB_LOADER);
1315
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001316 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
1317 my_data->acdb_handle,
1318 "acdb_loader_get_default_app_type");
1319 if (!my_data->acdb_get_default_app_type)
1320 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1321 __func__, LIB_ACDB_LOADER);
1322
Eric Laurentb23d5282013-05-14 15:27:20 -07001323 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Ben Romberger490d3472014-01-15 17:11:59 -08001324 "acdb_loader_init_v2");
Walter Yang6f800052014-07-14 16:15:38 -07001325 if (my_data->acdb_init == NULL) {
Ben Romberger490d3472014-01-15 17:11:59 -08001326 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Walter Yang6f800052014-07-14 16:15:38 -07001327 goto acdb_init_fail;
1328 }
1329
Ramjee Singheb9127a2015-06-09 15:18:42 +05301330 platform_acdb_init(my_data);
Eric Laurentb23d5282013-05-14 15:27:20 -07001331 }
1332
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05301333 /* Configure active back end for HPX*/
1334 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1335 if (ctl) {
1336 ALOGI(" sending HPX Active BE information ");
1337 mixer_ctl_set_value(ctl, 0, true);
1338 }
1339
Walter Yang6f800052014-07-14 16:15:38 -07001340acdb_init_fail:
1341
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001342 set_platform_defaults();
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001343
Ben Romberger55886882014-01-10 13:49:02 -08001344 /* Initialize ACDB ID's */
Helen Zeng6a16ad72014-02-23 22:04:44 -08001345 if (my_data->is_i2s_ext_modem)
1346 platform_info_init(PLATFORM_INFO_XML_PATH_I2S);
1347 else
1348 platform_info_init(PLATFORM_INFO_XML_PATH);
Ben Romberger55886882014-01-10 13:49:02 -08001349
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07001350 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
1351 * symbols. Voice call is handled by MDM and apps processor talks to
1352 * MDM through CSD Client
1353 */
1354 property_get("ro.board.platform", platform, "");
1355 property_get("ro.baseband", baseband, "");
1356 if (!strncmp("apq8084", platform, sizeof("apq8084")) &&
1357 !strncmp("mdm", baseband, (sizeof("mdm")-1))) {
1358 my_data->csd = open_csd_client(my_data->is_i2s_ext_modem);
1359 } else {
1360 my_data->csd = NULL;
1361 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001362
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001363 /* init usb */
1364 audio_extn_usb_init(adev);
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001365 /* update sound cards appropriately */
1366 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001367
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001368 /* init dap hal */
1369 audio_extn_dap_hal_init(adev->snd_card);
1370
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07001371 /* Read one time ssr property */
Mingming Yin49be8032013-12-19 12:51:25 -08001372 audio_extn_ssr_update_enabled();
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -07001373 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301374
1375 audio_extn_dolby_set_license(adev);
Anish Kumar55e6df22014-08-26 17:38:05 -07001376 audio_hwdep_send_cal(my_data);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301377
Lior Barenboim0b61bc72014-05-13 13:01:37 +03001378 /* init audio device arbitration */
1379 audio_extn_dev_arbi_init();
1380
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08001381 /* initialize backend config */
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301382 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
1383 my_data->current_backend_cfg[idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1384 if (idx == HEADPHONE_44_1_BACKEND)
1385 my_data->current_backend_cfg[idx].sample_rate = OUTPUT_SAMPLING_RATE_44100;
1386 my_data->current_backend_cfg[idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08001387 }
1388
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301389 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1390 strdup("SLIM_0_RX Format");
1391 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1392 strdup("SLIM_0_RX SampleRate");
1393
1394 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].bitwidth_mixer_ctl =
1395 strdup("SLIM_5_RX Format");
1396 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].samplerate_mixer_ctl =
1397 strdup("SLIM_5_RX SampleRate");
1398
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07001399 my_data->edid_info = NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001400 return my_data;
1401}
1402
1403void platform_deinit(void *platform)
1404{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001405 struct platform_data *my_data = (struct platform_data *)platform;
1406
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07001407 if (my_data->edid_info) {
1408 free(my_data->edid_info);
1409 my_data->edid_info = NULL;
1410 }
1411
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001412 hw_info_deinit(my_data->hw_info);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001413 close_csd_client(my_data->csd);
1414
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001415 int32_t dev;
1416 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1417 if (backend_table[dev]) {
1418 free(backend_table[dev]);
1419 backend_table[dev]= NULL;
1420 }
1421 }
1422
Lior Barenboim0b61bc72014-05-13 13:01:37 +03001423 /* deinit audio device arbitration */
1424 audio_extn_dev_arbi_deinit();
1425
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07001426 if (my_data->edid_info) {
1427 free(my_data->edid_info);
1428 my_data->edid_info = NULL;
1429 }
1430
Eric Laurentb23d5282013-05-14 15:27:20 -07001431 free(platform);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001432 /* deinit usb */
1433 audio_extn_usb_deinit();
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001434 audio_extn_dap_hal_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001435}
1436
Ramjee Singheb9127a2015-06-09 15:18:42 +05301437int platform_is_acdb_initialized(void *platform)
1438{
1439 struct platform_data *my_data = (struct platform_data *)platform;
1440 ALOGD("%s: acdb initialized %d\n", __func__, my_data->is_acdb_initialized);
1441 return my_data->is_acdb_initialized;
1442}
1443
Eric Laurentb23d5282013-05-14 15:27:20 -07001444const char *platform_get_snd_device_name(snd_device_t snd_device)
1445{
1446 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1447 return device_table[snd_device];
1448 else
1449 return "";
1450}
1451
Laxminath Kasam44f49402015-05-29 18:37:11 +05301452const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
1453{
1454 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1455 return speaker_device_tz_names.spkr_1_tz_name;
1456 else
1457 return "";
1458}
1459
1460const char *platform_get_spkr_2_tz_name(snd_device_t snd_device)
1461{
1462 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1463 return speaker_device_tz_names.spkr_2_tz_name;
1464 else
1465 return "";
1466}
1467
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001468int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1469 char *device_name)
1470{
1471 struct platform_data *my_data = (struct platform_data *)platform;
1472
1473 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1474 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1475 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1476 } else {
1477 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
1478 return -EINVAL;
1479 }
1480
1481 return 0;
1482}
1483
Venkata Narendra Kumar Gutta55def542015-06-16 13:59:08 +05301484void platform_add_backend_name(char *mixer_path, snd_device_t snd_device, struct audio_usecase *usecase)
Eric Laurentb23d5282013-05-14 15:27:20 -07001485{
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001486 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1487 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1488 return;
1489 }
1490
1491 const char * suffix = backend_table[snd_device];
1492
1493 if (suffix != NULL) {
1494 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
1495 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001496 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001497}
1498
1499int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1500{
1501 int device_id;
1502 if (device_type == PCM_PLAYBACK)
1503 device_id = pcm_device_table[usecase][0];
1504 else
1505 device_id = pcm_device_table[usecase][1];
1506 return device_id;
1507}
1508
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001509static int find_index(struct name_to_index * table, int32_t len, const char * name)
Ben Romberger61764e32014-01-10 13:49:02 -08001510{
1511 int ret = 0;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001512 int32_t i;
Ben Romberger61764e32014-01-10 13:49:02 -08001513
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001514 if (table == NULL) {
1515 ALOGE("%s: table is NULL", __func__);
Ben Romberger61764e32014-01-10 13:49:02 -08001516 ret = -ENODEV;
1517 goto done;
1518 }
1519
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001520 if (name == NULL) {
1521 ALOGE("null key");
1522 ret = -ENODEV;
1523 goto done;
1524 }
1525
1526 for (i=0; i < len; i++) {
1527 const char* tn = table[i].name;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001528 size_t len = strlen(tn);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001529 if (strncmp(tn, name, len) == 0) {
1530 if (strlen(name) != len) {
1531 continue; // substring
1532 }
1533 ret = table[i].index;
Ben Romberger61764e32014-01-10 13:49:02 -08001534 goto done;
1535 }
1536 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001537 ALOGE("%s: Could not find index for name = %s",
1538 __func__, name);
Ben Romberger61764e32014-01-10 13:49:02 -08001539 ret = -ENODEV;
1540done:
1541 return ret;
1542}
1543
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301544int platform_set_fluence_type(void *platform, char *value)
1545{
1546 int ret = 0;
1547 int fluence_type = FLUENCE_NONE;
1548 int fluence_flag = NONE_FLAG;
1549 struct platform_data *my_data = (struct platform_data *)platform;
1550 struct audio_device *adev = my_data->adev;
1551
1552 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
1553
1554 /* only dual mic turn on and off is supported as of now through setparameters */
1555 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
1556 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
1557 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
1558 ALOGV("fluence dualmic feature enabled \n");
1559 fluence_type = FLUENCE_DUAL_MIC;
1560 fluence_flag = DMIC_FLAG;
1561 } else {
1562 ALOGE("%s: Failed to set DUALMIC", __func__);
1563 ret = -1;
1564 goto done;
1565 }
1566 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
1567 ALOGV("fluence disabled");
1568 fluence_type = FLUENCE_NONE;
1569 } else {
1570 ALOGE("Invalid fluence value : %s",value);
1571 ret = -1;
1572 goto done;
1573 }
1574
1575 if (fluence_type != my_data->fluence_type) {
1576 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
1577 my_data->fluence_type = fluence_type;
1578 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
1579 }
1580done:
1581 return ret;
1582}
1583
1584int platform_get_fluence_type(void *platform, char *value, uint32_t len)
1585{
1586 int ret = 0;
1587 struct platform_data *my_data = (struct platform_data *)platform;
1588
1589 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1590 strlcpy(value, "quadmic", len);
1591 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1592 strlcpy(value, "dualmic", len);
1593 } else if (my_data->fluence_type == FLUENCE_NONE) {
1594 strlcpy(value, "none", len);
1595 } else
1596 ret = -1;
1597
1598 return ret;
1599}
1600
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001601int platform_get_snd_device_index(char *device_name)
1602{
1603 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1604}
1605
1606int platform_get_usecase_index(const char *usecase_name)
1607{
1608 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1609}
1610
Ben Romberger55886882014-01-10 13:49:02 -08001611int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1612{
1613 int ret = 0;
1614
1615 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1616 ALOGE("%s: Invalid snd_device = %d",
1617 __func__, snd_device);
1618 ret = -EINVAL;
1619 goto done;
1620 }
1621
1622 acdb_device_table[snd_device] = acdb_id;
1623done:
1624 return ret;
1625}
1626
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001627int platform_get_default_app_type(void *platform)
1628{
1629 struct platform_data *my_data = (struct platform_data *)platform;
1630
1631 if (my_data->acdb_get_default_app_type)
1632 return my_data->acdb_get_default_app_type();
1633 else
1634 return DEFAULT_APP_TYPE;
1635}
1636
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001637int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1638{
1639 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1640 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1641 return -EINVAL;
1642 }
1643 return acdb_device_table[snd_device];
1644}
1645
Amit Shekhar5a39c912014-10-14 15:39:30 -07001646int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
1647{
1648 int ret = 0;
1649
1650 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1651 ALOGE("%s: Invalid snd_device = %d",
1652 __func__, snd_device);
1653 ret = -EINVAL;
1654 goto done;
1655 }
1656
1657 backend_bit_width_table[snd_device] = bit_width;
1658done:
1659 return ret;
1660}
1661
1662int platform_get_snd_device_bit_width(snd_device_t snd_device)
1663{
1664 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1665 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1666 return DEFAULT_OUTPUT_SAMPLING_RATE;
1667 }
1668 return backend_bit_width_table[snd_device];
1669}
1670
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301671int platform_set_native_support(bool codec_support)
1672{
1673 na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled
1674 = codec_support;
Sidipotu Ashokce33cdc2015-07-06 18:35:03 +05301675 ALOGD("%s: na_props.platform_na_prop_enabled: %d", __func__,
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301676 na_props.platform_na_prop_enabled);
1677 return 0;
1678}
1679
1680int platform_get_native_support()
1681{
1682 int ret;
1683 if (na_props.platform_na_prop_enabled) {
1684 ret = na_props.ui_na_prop_enabled;
1685 } else {
1686 ret = na_props.platform_na_prop_enabled;
1687 }
1688 ALOGV("%s: na_props.ui_na_prop_enabled: %d", __func__,
1689 na_props.ui_na_prop_enabled);
1690 return ret;
1691}
1692
1693void native_audio_get_params(struct str_parms *query,
1694 struct str_parms *reply,
1695 char *value, int len)
1696{
1697 int ret;
1698 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1699 value, len);
1700 if (ret >= 0) {
1701 if (na_props.platform_na_prop_enabled) {
1702 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1703 na_props.ui_na_prop_enabled ? "true" : "false");
1704 ALOGV("%s: na_props.ui_na_prop_enabled: %d", __func__,
1705 na_props.ui_na_prop_enabled);
1706 } else {
1707 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1708 "false");
1709 ALOGV("%s: native audio not supported: %d", __func__,
1710 na_props.platform_na_prop_enabled);
1711 }
1712 }
1713}
1714
1715int native_audio_set_params(struct platform_data *platform,
1716 struct str_parms *parms, char *value, int len)
1717{
1718 int ret = 0;
1719 struct audio_usecase *usecase;
1720 struct listnode *node;
1721
1722 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1723 value, len);
1724 if (ret >= 0) {
1725 if (na_props.platform_na_prop_enabled) {
Sidipotu Ashokce33cdc2015-07-06 18:35:03 +05301726 if (!strncmp("true", value, sizeof("true"))) {
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301727 na_props.ui_na_prop_enabled = true;
Sidipotu Ashokce33cdc2015-07-06 18:35:03 +05301728 ALOGD("%s: native audio feature enabled from UI",__func__);
1729 }
1730 else {
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301731 na_props.ui_na_prop_enabled = false;
Sidipotu Ashokce33cdc2015-07-06 18:35:03 +05301732 ALOGD("%s: native audio feature disabled from UI",__func__);
1733
1734 }
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301735
1736 str_parms_del(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
1737
1738 /*
1739 * Iterate through the usecase list and trigger device switch for
1740 * all the appropriate usecases
1741 */
1742 list_for_each(node, &(platform->adev)->usecase_list) {
1743 usecase = node_to_item(node, struct audio_usecase, list);
1744
1745 if (is_offload_usecase(usecase->id) &&
1746 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1747 usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
1748 OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
Sidipotu Ashokce33cdc2015-07-06 18:35:03 +05301749 ALOGD("%s: triggering dynamic device switch for usecase(%d: %s)"
1750 " stream(%p), device(%d)", __func__, usecase->id,
1751 use_case_table[usecase->id], usecase->stream,
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301752 usecase->stream.out->devices);
Sidipotu Ashokce33cdc2015-07-06 18:35:03 +05301753 select_devices(platform->adev, usecase->id);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301754 }
1755 }
1756 } else {
Sidipotu Ashokce33cdc2015-07-06 18:35:03 +05301757 ALOGD("%s: native audio not supported: %d", __func__,
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301758 na_props.platform_na_prop_enabled);
1759 }
1760 }
1761 return ret;
1762}
1763
1764int platform_get_backend_index(snd_device_t snd_device)
1765{
1766 int32_t port = DEFAULT_CODEC_BACKEND;
1767
1768 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1769 if (backend_table[snd_device] != NULL &&
1770 strcmp(backend_table[snd_device], "headphones-44.1") == 0)
1771 port = HEADPHONE_44_1_BACKEND;
1772 else
1773 port = DEFAULT_CODEC_BACKEND;
1774 } else {
1775 ALOGV("%s: Invalid device - %d ", __func__, snd_device);
1776 }
1777
1778 ALOGV("%s: backend port - %d", __func__, port);
1779 return port;
1780}
1781
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301782int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001783 int app_type, int sample_rate)
Eric Laurentb23d5282013-05-14 15:27:20 -07001784{
1785 struct platform_data *my_data = (struct platform_data *)platform;
1786 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301787 struct audio_device *adev = my_data->adev;
1788 int snd_device = SND_DEVICE_OUT_SPEAKER;
Eric Laurentb23d5282013-05-14 15:27:20 -07001789
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301790 if (usecase->type == PCM_PLAYBACK)
1791 snd_device = platform_get_output_snd_device(adev->platform,
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08001792 usecase->stream.out);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301793 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
1794 snd_device = platform_get_input_snd_device(adev->platform,
1795 adev->primary_output->devices);
Anish Kumarf16721c2014-08-01 15:09:25 -07001796 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001797 if (acdb_dev_id < 0) {
1798 ALOGE("%s: Could not find acdb id for device(%d)",
1799 __func__, snd_device);
1800 return -EINVAL;
1801 }
1802 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001803 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001804 __func__, snd_device, acdb_dev_id);
1805 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1806 snd_device < SND_DEVICE_OUT_END)
1807 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1808 else
1809 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001810 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
1811 sample_rate);
Eric Laurentb23d5282013-05-14 15:27:20 -07001812 }
1813 return 0;
1814}
1815
1816int platform_switch_voice_call_device_pre(void *platform)
1817{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001818 struct platform_data *my_data = (struct platform_data *)platform;
1819 int ret = 0;
1820
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001821 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07001822 voice_is_in_call(my_data->adev)) {
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001823 /* This must be called before disabling mixer controls on APQ side */
1824 ret = my_data->csd->disable_device();
1825 if (ret < 0) {
1826 ALOGE("%s: csd_client_disable_device, failed, error %d",
1827 __func__, ret);
1828 }
1829 }
1830 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001831}
1832
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001833int platform_switch_voice_call_enable_device_config(void *platform,
1834 snd_device_t out_snd_device,
1835 snd_device_t in_snd_device)
1836{
1837 struct platform_data *my_data = (struct platform_data *)platform;
1838 int acdb_rx_id, acdb_tx_id;
1839 int ret = 0;
1840
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001841 if (my_data->csd == NULL)
1842 return ret;
1843
1844 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1845 audio_extn_spkr_prot_is_enabled())
1846 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1847 else
1848 acdb_rx_id = acdb_device_table[out_snd_device];
1849
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001850 acdb_tx_id = acdb_device_table[in_snd_device];
1851
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001852 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1853 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1854 if (ret < 0) {
1855 ALOGE("%s: csd_enable_device_config, failed, error %d",
1856 __func__, ret);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001857 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001858 } else {
1859 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1860 acdb_rx_id, acdb_tx_id);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001861 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001862
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001863 return ret;
1864}
1865
Eric Laurentb23d5282013-05-14 15:27:20 -07001866int platform_switch_voice_call_device_post(void *platform,
1867 snd_device_t out_snd_device,
1868 snd_device_t in_snd_device)
1869{
1870 struct platform_data *my_data = (struct platform_data *)platform;
1871 int acdb_rx_id, acdb_tx_id;
1872
1873 if (my_data->acdb_send_voice_cal == NULL) {
1874 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1875 } else {
Anish Kumar46c7b872014-09-09 01:49:44 -07001876 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1877 audio_extn_spkr_prot_is_enabled())
1878 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1879
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001880 acdb_rx_id = acdb_device_table[out_snd_device];
1881 acdb_tx_id = acdb_device_table[in_snd_device];
1882
Eric Laurentb23d5282013-05-14 15:27:20 -07001883 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1884 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1885 else
1886 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1887 acdb_rx_id, acdb_tx_id);
1888 }
1889
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001890 return 0;
1891}
1892
1893int platform_switch_voice_call_usecase_route_post(void *platform,
1894 snd_device_t out_snd_device,
1895 snd_device_t in_snd_device)
1896{
1897 struct platform_data *my_data = (struct platform_data *)platform;
1898 int acdb_rx_id, acdb_tx_id;
1899 int ret = 0;
1900
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001901 if (my_data->csd == NULL)
1902 return ret;
1903
1904 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1905 audio_extn_spkr_prot_is_enabled())
1906 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1907 else
1908 acdb_rx_id = acdb_device_table[out_snd_device];
1909
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001910 acdb_tx_id = acdb_device_table[in_snd_device];
1911
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001912 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1913 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1914 my_data->adev->acdb_settings);
1915 if (ret < 0) {
1916 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001917 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001918 } else {
1919 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1920 acdb_rx_id, acdb_tx_id);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001921 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001922
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001923 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001924}
1925
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001926int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001927{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001928 struct platform_data *my_data = (struct platform_data *)platform;
1929 int ret = 0;
1930
1931 if (my_data->csd != NULL) {
1932 ret = my_data->csd->start_voice(vsid);
1933 if (ret < 0) {
1934 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1935 }
1936 }
1937 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001938}
1939
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001940int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001941{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001942 struct platform_data *my_data = (struct platform_data *)platform;
1943 int ret = 0;
1944
1945 if (my_data->csd != NULL) {
1946 ret = my_data->csd->stop_voice(vsid);
1947 if (ret < 0) {
1948 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1949 }
1950 }
1951 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001952}
1953
Helen Zeng6a16ad72014-02-23 22:04:44 -08001954int platform_get_sample_rate(void *platform, uint32_t *rate)
1955{
1956 struct platform_data *my_data = (struct platform_data *)platform;
1957 int ret = 0;
1958
1959 if ((my_data->csd != NULL) && my_data->is_i2s_ext_modem) {
1960 ret = my_data->csd->get_sample_rate(rate);
1961 if (ret < 0) {
1962 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1963 }
1964 }
1965 return ret;
1966}
1967
Eric Laurentb23d5282013-05-14 15:27:20 -07001968int platform_set_voice_volume(void *platform, int volume)
1969{
1970 struct platform_data *my_data = (struct platform_data *)platform;
1971 struct audio_device *adev = my_data->adev;
1972 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001973 const char *mixer_ctl_name = "Voice Rx Gain";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001974 int vol_index = 0, ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001975 uint32_t set_values[ ] = {0,
1976 ALL_SESSION_VSID,
1977 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001978
1979 // Voice volume levels are mapped to adsp volume levels as follows.
1980 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1981 // But this values don't changed in kernel. So, below change is need.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001982 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1983 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001984
1985 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1986 if (!ctl) {
1987 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1988 __func__, mixer_ctl_name);
1989 return -EINVAL;
1990 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001991 ALOGV("Setting voice volume index: %d", set_values[0]);
1992 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07001993
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001994 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07001995 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1996 DEFAULT_VOLUME_RAMP_DURATION_MS);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001997 if (ret < 0) {
1998 ALOGE("%s: csd_volume error %d", __func__, ret);
1999 }
2000 }
2001 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002002}
2003
2004int platform_set_mic_mute(void *platform, bool state)
2005{
2006 struct platform_data *my_data = (struct platform_data *)platform;
2007 struct audio_device *adev = my_data->adev;
2008 struct mixer_ctl *ctl;
2009 const char *mixer_ctl_name = "Voice Tx Mute";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08002010 int ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002011 uint32_t set_values[ ] = {0,
2012 ALL_SESSION_VSID,
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07002013 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07002014
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002015 set_values[0] = state;
2016 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2017 if (!ctl) {
2018 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2019 __func__, mixer_ctl_name);
2020 return -EINVAL;
2021 }
2022 ALOGV("Setting voice mute state: %d", state);
2023 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07002024
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002025 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07002026 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
2027 DEFAULT_MUTE_RAMP_DURATION_MS);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002028 if (ret < 0) {
2029 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08002030 }
2031 }
2032 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07002033}
2034
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08002035int platform_set_device_mute(void *platform, bool state, char *dir)
2036{
2037 struct platform_data *my_data = (struct platform_data *)platform;
2038 struct audio_device *adev = my_data->adev;
2039 struct mixer_ctl *ctl;
2040 char *mixer_ctl_name = NULL;
2041 int ret = 0;
2042 uint32_t set_values[ ] = {0,
2043 ALL_SESSION_VSID,
2044 0};
2045 if(dir == NULL) {
2046 ALOGE("%s: Invalid direction:%s", __func__, dir);
2047 return -EINVAL;
2048 }
2049
2050 if (!strncmp("rx", dir, sizeof("rx"))) {
2051 mixer_ctl_name = "Voice Rx Device Mute";
2052 } else if (!strncmp("tx", dir, sizeof("tx"))) {
2053 mixer_ctl_name = "Voice Tx Device Mute";
2054 } else {
2055 return -EINVAL;
2056 }
2057
2058 set_values[0] = state;
2059 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2060 if (!ctl) {
2061 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2062 __func__, mixer_ctl_name);
2063 return -EINVAL;
2064 }
2065
2066 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
2067 __func__,state, mixer_ctl_name);
2068 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2069
2070 return ret;
2071}
2072
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002073snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
Eric Laurentb23d5282013-05-14 15:27:20 -07002074{
2075 struct platform_data *my_data = (struct platform_data *)platform;
2076 struct audio_device *adev = my_data->adev;
2077 audio_mode_t mode = adev->mode;
2078 snd_device_t snd_device = SND_DEVICE_NONE;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002079 audio_devices_t devices = out->devices;
2080 unsigned int sample_rate = out->sample_rate;
Eric Laurentb23d5282013-05-14 15:27:20 -07002081
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002082 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2083 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2084 int channel_count = popcount(channel_mask);
2085
Eric Laurentb23d5282013-05-14 15:27:20 -07002086 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2087 if (devices == AUDIO_DEVICE_NONE ||
2088 devices & AUDIO_DEVICE_BIT_IN) {
2089 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2090 goto exit;
2091 }
2092
Shiv Maliyappanahallica36cb12015-08-17 11:02:21 -07002093 if (popcount(devices) == 2) {
Mingming Yin4a72d652014-01-03 18:54:18 -08002094 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2095 AUDIO_DEVICE_OUT_SPEAKER)) {
Tanya Finkel00130052014-07-14 04:26:56 -07002096 if (my_data->external_spk_1)
2097 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2098 else if (my_data->external_spk_2)
2099 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
2100 else
2101 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Mingming Yin4a72d652014-01-03 18:54:18 -08002102 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2103 AUDIO_DEVICE_OUT_SPEAKER)) {
2104 if (audio_extn_get_anc_enabled())
2105 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Tanya Finkel00130052014-07-14 04:26:56 -07002106 else if (my_data->external_spk_1)
2107 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2108 else if (my_data->external_spk_2)
2109 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Mingming Yin4a72d652014-01-03 18:54:18 -08002110 else
2111 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2112 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2113 AUDIO_DEVICE_OUT_SPEAKER)) {
2114 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
2115 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
2116 AUDIO_DEVICE_OUT_SPEAKER)) {
2117 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
2118 } else {
2119 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2120 goto exit;
2121 }
2122 if (snd_device != SND_DEVICE_NONE) {
2123 goto exit;
2124 }
2125 }
2126
2127 if (popcount(devices) != 1) {
2128 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2129 goto exit;
2130 }
2131
Venkata Narendra Kumar Gutta5cd79b82015-06-22 14:25:35 +05302132 if ((mode == AUDIO_MODE_IN_CALL) ||
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002133 voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002134 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2135 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002136 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2137 !voice_extn_compress_voip_is_active(adev)) {
2138 switch (adev->voice.tty_mode) {
2139 case TTY_MODE_FULL:
2140 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
2141 break;
2142 case TTY_MODE_VCO:
2143 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
2144 break;
2145 case TTY_MODE_HCO:
2146 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2147 break;
2148 default:
2149 ALOGE("%s: Invalid TTY mode (%#x)",
2150 __func__, adev->voice.tty_mode);
2151 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002152 } else if (audio_extn_get_anc_enabled()) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002153 if (audio_extn_should_use_fb_anc())
2154 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
2155 else
2156 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002157 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -07002158 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002159 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002160 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002161 if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002162 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2163 else
2164 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -07002165 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
2166 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002167 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2168 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2169 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002170 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2171 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07002172 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -08002173 if (audio_extn_should_use_handset_anc(channel_count))
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002174 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002175 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002176 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07002177 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2178 snd_device = SND_DEVICE_OUT_VOICE_TX;
2179
Eric Laurentb23d5282013-05-14 15:27:20 -07002180 if (snd_device != SND_DEVICE_NONE) {
2181 goto exit;
2182 }
2183 }
2184
Eric Laurentb23d5282013-05-14 15:27:20 -07002185 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2186 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002187 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
2188 && audio_extn_get_anc_enabled()) {
2189 if (audio_extn_should_use_fb_anc())
2190 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
2191 else
2192 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302193 } else if (platform_get_native_support() &&
2194 OUTPUT_SAMPLING_RATE_44100 == sample_rate)
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002195 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302196 else
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002197 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -07002198 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Tanya Finkel00130052014-07-14 04:26:56 -07002199 if (my_data->external_spk_1)
2200 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_1;
2201 else if (my_data->external_spk_2)
2202 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_2;
2203 else if (adev->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002204 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2205 else
2206 snd_device = SND_DEVICE_OUT_SPEAKER;
2207 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002208 if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002209 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2210 else
2211 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -07002212 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2213 snd_device = SND_DEVICE_OUT_HDMI ;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002214 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2215 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002216 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
2217 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002218 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002219 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2220 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07002221 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
2222 snd_device = SND_DEVICE_OUT_HANDSET;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002223 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002224 channel_count = audio_extn_get_afe_proxy_channel_count();
2225 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
2226 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002227 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Eric Laurentb23d5282013-05-14 15:27:20 -07002228 } else {
2229 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2230 }
2231exit:
2232 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2233 return snd_device;
2234}
2235
2236snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2237{
2238 struct platform_data *my_data = (struct platform_data *)platform;
2239 struct audio_device *adev = my_data->adev;
2240 audio_source_t source = (adev->active_input == NULL) ?
2241 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2242
2243 audio_mode_t mode = adev->mode;
2244 audio_devices_t in_device = ((adev->active_input == NULL) ?
2245 AUDIO_DEVICE_NONE : adev->active_input->device)
2246 & ~AUDIO_DEVICE_BIT_IN;
2247 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2248 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2249 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002250 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002251
2252 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
2253 __func__, out_device, in_device);
Tanya Finkel00130052014-07-14 04:26:56 -07002254 if (my_data->external_mic) {
Venkata Narendra Kumar Gutta5cd79b82015-06-22 14:25:35 +05302255 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
2256 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Tanya Finkel00130052014-07-14 04:26:56 -07002257 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2258 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2259 out_device & AUDIO_DEVICE_OUT_SPEAKER )
2260 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2261 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2262 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2263 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2264 }
2265 }
2266
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002267 if (snd_device != AUDIO_DEVICE_NONE)
Tanya Finkel00130052014-07-14 04:26:56 -07002268 goto exit;
2269
Venkata Narendra Kumar Gutta5cd79b82015-06-22 14:25:35 +05302270 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli071950f2014-05-21 14:45:28 +05302271 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002272 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2273 !voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002274 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2275 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002276 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002277 case TTY_MODE_FULL:
2278 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2279 break;
2280 case TTY_MODE_VCO:
2281 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2282 break;
2283 case TTY_MODE_HCO:
2284 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2285 break;
2286 default:
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002287 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002288 }
2289 goto exit;
2290 }
2291 }
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07002292 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2293 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002294 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
2295 audio_extn_should_use_handset_anc(channel_count)) {
2296 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
Banajit Goswamide0ea452014-04-07 12:11:47 -07002297 adev->acdb_settings |= ANC_FLAG;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002298 } else if (my_data->fluence_type == FLUENCE_NONE ||
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002299 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002300 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302301 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002302 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002303 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -08002304 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002305 }
2306 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2307 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302308 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002309 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002310 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002311 if (adev->bt_wb_speech_enabled) {
2312 if (adev->bluetooth_nrec)
2313 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2314 else
2315 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2316 } else {
2317 if (adev->bluetooth_nrec)
2318 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2319 else
2320 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2321 }
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07002322 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002323 if (my_data->fluence_type != FLUENCE_NONE &&
2324 my_data->fluence_in_voice_call &&
2325 my_data->fluence_in_spkr_mode) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002326 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002327 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002328 } else {
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08002329 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2330 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
2331 else
2332 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002333 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002334 } else {
2335 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302336 if (audio_extn_hfp_is_active(adev))
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002337 platform_set_echo_reference(adev, true, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002338 }
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07002339 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2340 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurentb23d5282013-05-14 15:27:20 -07002341 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2342 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2343 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2344 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2345 }
2346 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2347 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002348 if (channel_count == 2) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002349 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002350 } else if (adev->active_input->enable_ns)
2351 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2352 else if (my_data->fluence_type != FLUENCE_NONE &&
2353 my_data->fluence_in_voice_rec) {
2354 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002355 } else {
2356 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
2357 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002358 }
2359 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
2360 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
2361 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2362 if (adev->active_input) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002363 if (adev->active_input->enable_aec &&
2364 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002365 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002366 if (my_data->fluence_in_spkr_mode) {
2367 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2368 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
2369 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2370 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2371 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
2372 else
2373 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
2374 }
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002375 } else
2376 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002377 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002378 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2379 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002380 } else
2381 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002382 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002383 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002384 }
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002385 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002386 } else if (adev->active_input->enable_aec) {
2387 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002388 if (my_data->fluence_in_spkr_mode) {
2389 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2390 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
2391 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2392 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2393 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
2394 else
2395 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
2396 }
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002397 } else
2398 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
2399 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2400 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2401 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002402 } else
2403 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
2404 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2405 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
2406 }
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002407 platform_set_echo_reference(adev, true, out_device);
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002408 } else if (adev->active_input->enable_ns) {
2409 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002410 if (my_data->fluence_in_spkr_mode) {
2411 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2412 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
2413 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2414 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2415 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
2416 else
2417 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
2418 }
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002419 } else
2420 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
2421 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2422 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2423 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002424 } else
2425 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
2426 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2427 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
2428 }
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002429 platform_set_echo_reference(adev, false, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002430 } else
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002431 platform_set_echo_reference(adev, false, out_device);
Eric Laurentb23d5282013-05-14 15:27:20 -07002432 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002433 } else if (source == AUDIO_SOURCE_MIC) {
Apoorv Raghuvanshic0536542013-11-14 16:25:59 -08002434 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
2435 channel_count == 1 ) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002436 if(my_data->fluence_in_audio_rec) {
2437 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
2438 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002439 platform_set_echo_reference(adev, true, out_device);
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002440 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2441 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07002442 platform_set_echo_reference(adev, true, out_device);
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002443 }
Ravi Kumar Alamanda7076b162014-03-07 11:40:24 -08002444 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002445 }
Yamit Mehtaaafda4b2015-07-13 12:51:33 +05302446 } else if (source == AUDIO_SOURCE_FM_TUNER) {
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07002447 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07002448 } else if (source == AUDIO_SOURCE_DEFAULT) {
2449 goto exit;
2450 }
2451
2452
2453 if (snd_device != SND_DEVICE_NONE) {
2454 goto exit;
2455 }
2456
2457 if (in_device != AUDIO_DEVICE_NONE &&
2458 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2459 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2460 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002461 if (audio_extn_ssr_get_enabled() && channel_count == 6)
2462 snd_device = SND_DEVICE_IN_QUAD_MIC;
Walter Yangbc136bd2014-01-17 11:24:23 +08002463 else if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) &&
2464 channel_count == 2)
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -07002465 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002466 else
2467 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002468 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2469 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2470 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2471 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2472 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002473 if (adev->bt_wb_speech_enabled) {
2474 if (adev->bluetooth_nrec)
2475 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2476 else
2477 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2478 } else {
2479 if (adev->bluetooth_nrec)
2480 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2481 else
2482 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2483 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002484 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2485 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002486 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
2487 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
2488 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Yamit Mehtaaafda4b2015-07-13 12:51:33 +05302489 } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002490 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07002491 } else {
2492 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2493 ALOGW("%s: Using default handset-mic", __func__);
2494 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2495 }
2496 } else {
2497 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2498 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2499 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2500 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07002501 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002502 if (channel_count == 2)
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -07002503 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
2504 else
2505 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07002506 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
2507 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002508 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002509 if (adev->bt_wb_speech_enabled) {
2510 if (adev->bluetooth_nrec)
2511 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2512 else
2513 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2514 } else {
2515 if (adev->bluetooth_nrec)
2516 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2517 else
2518 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2519 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002520 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2521 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002522 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2523 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2524 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002525 } else {
2526 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2527 ALOGW("%s: Using default handset-mic", __func__);
2528 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2529 }
2530 }
2531exit:
2532 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2533 return snd_device;
2534}
2535
2536int platform_set_hdmi_channels(void *platform, int channel_count)
2537{
2538 struct platform_data *my_data = (struct platform_data *)platform;
2539 struct audio_device *adev = my_data->adev;
2540 struct mixer_ctl *ctl;
2541 const char *channel_cnt_str = NULL;
2542 const char *mixer_ctl_name = "HDMI_RX Channels";
2543 switch (channel_count) {
2544 case 8:
2545 channel_cnt_str = "Eight"; break;
2546 case 7:
2547 channel_cnt_str = "Seven"; break;
2548 case 6:
2549 channel_cnt_str = "Six"; break;
2550 case 5:
2551 channel_cnt_str = "Five"; break;
2552 case 4:
2553 channel_cnt_str = "Four"; break;
2554 case 3:
2555 channel_cnt_str = "Three"; break;
2556 default:
2557 channel_cnt_str = "Two"; break;
2558 }
2559 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2560 if (!ctl) {
2561 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2562 __func__, mixer_ctl_name);
2563 return -EINVAL;
2564 }
2565 ALOGV("HDMI channel count: %s", channel_cnt_str);
2566 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2567 return 0;
2568}
2569
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002570int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002571{
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07002572 int channel_count;
2573 int max_channels = 2;
2574 int i = 0, ret = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002575 struct platform_data *my_data = (struct platform_data *)platform;
2576 struct audio_device *adev = my_data->adev;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07002577 edid_audio_info *info = NULL;
2578 ret = platform_get_edid_info(platform);
2579 info = (edid_audio_info *)my_data->edid_info;
Eric Laurentb23d5282013-05-14 15:27:20 -07002580
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07002581 if(ret == 0 && info != NULL) {
2582 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
2583 ALOGV("%s:format %d channel %d", __func__,
2584 info->audio_blocks_array[i].format_id,
2585 info->audio_blocks_array[i].channels);
2586 if (info->audio_blocks_array[i].format_id == LPCM) {
2587 channel_count = info->audio_blocks_array[i].channels;
2588 if (channel_count > max_channels) {
2589 max_channels = channel_count;
2590 }
2591 }
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002592 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002593 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002594 return max_channels;
2595}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002596
2597static int platform_set_slowtalk(struct platform_data *my_data, bool state)
2598{
2599 int ret = 0;
2600 struct audio_device *adev = my_data->adev;
2601 struct mixer_ctl *ctl;
2602 const char *mixer_ctl_name = "Slowtalk Enable";
2603 uint32_t set_values[ ] = {0,
2604 ALL_SESSION_VSID};
2605
2606 set_values[0] = state;
2607 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2608 if (!ctl) {
2609 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2610 __func__, mixer_ctl_name);
2611 ret = -EINVAL;
2612 } else {
2613 ALOGV("Setting slowtalk state: %d", state);
2614 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2615 my_data->slowtalk = state;
2616 }
2617
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08002618 if (my_data->csd != NULL) {
2619 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
2620 if (ret < 0) {
2621 ALOGE("%s: csd_client_disable_device, failed, error %d",
2622 __func__, ret);
2623 }
2624 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002625 return ret;
2626}
2627
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302628static int set_hd_voice(struct platform_data *my_data, bool state)
2629{
2630 struct audio_device *adev = my_data->adev;
2631 struct mixer_ctl *ctl;
2632 char *mixer_ctl_name = "HD Voice Enable";
2633 int ret = 0;
2634 uint32_t set_values[ ] = {0,
2635 ALL_SESSION_VSID};
2636
2637 set_values[0] = state;
2638 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2639 if (!ctl) {
2640 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2641 __func__, mixer_ctl_name);
2642 return -EINVAL;
2643 } else {
2644 ALOGV("Setting HD Voice state: %d", state);
2645 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2646 my_data->hd_voice = state;
2647 }
2648
2649 return ret;
2650}
Tanya Finkel00130052014-07-14 04:26:56 -07002651
2652static int update_external_device_status(struct platform_data *my_data,
2653 char* event_name, bool status)
2654{
2655 int ret = 0;
2656 struct audio_usecase *usecase;
2657 struct listnode *node;
2658
2659 ALOGD("Recieved external event switch %s", event_name);
2660
2661 if (!strcmp(event_name, EVENT_EXTERNAL_SPK_1))
2662 my_data->external_spk_1 = status;
2663 else if (!strcmp(event_name, EVENT_EXTERNAL_SPK_2))
2664 my_data->external_spk_2 = status;
2665 else if (!strcmp(event_name, EVENT_EXTERNAL_MIC))
2666 my_data->external_mic = status;
2667 else {
2668 ALOGE("The audio event type is not found");
2669 return -EINVAL;
2670 }
2671
2672 list_for_each(node, &my_data->adev->usecase_list) {
2673 usecase = node_to_item(node, struct audio_usecase, list);
2674 select_devices(my_data->adev, usecase->id);
2675 }
2676
2677 return ret;
2678}
2679
Ben Rombergera04fabc2014-11-14 12:16:03 -08002680static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
2681{
2682 int err;
2683 unsigned int val;
2684 char value[64];
2685 int ret = 0;
2686
2687 if(parms == NULL || cal == NULL)
2688 return ret;
2689
2690 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
2691 if (err >= 0) {
2692 str_parms_del(parms, "cal_persist");
2693 cal->persist = (uint32_t) strtoul(value, NULL, 0);
2694 ret = ret | 0x1;
2695 }
2696 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
2697 if (err >= 0) {
2698 str_parms_del(parms, "cal_apptype");
2699 cal->app_type = (uint32_t) strtoul(value, NULL, 0);
2700 ret = ret | 0x2;
2701 }
2702 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
2703 if (err >= 0) {
2704 str_parms_del(parms, "cal_caltype");
2705 cal->cal_type = (uint32_t) strtoul(value, NULL, 0);
2706 ret = ret | 0x4;
2707 }
2708 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
2709 if (err >= 0) {
2710 str_parms_del(parms, "cal_samplerate");
2711 cal->sampling_rate = (uint32_t) strtoul(value, NULL, 0);
2712 ret = ret | 0x8;
2713 }
2714 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
2715 if (err >= 0) {
2716 str_parms_del(parms, "cal_devid");
2717 cal->dev_id = (uint32_t) strtoul(value, NULL, 0);
2718 ret = ret | 0x10;
2719 }
2720 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
2721 if (err >= 0) {
2722 str_parms_del(parms, "cal_snddevid");
2723 cal->snd_dev_id = (uint32_t) strtoul(value, NULL, 0);
2724 ret = ret | 0x20;
2725 }
2726 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
2727 if (err >= 0) {
2728 str_parms_del(parms, "cal_topoid");
2729 cal->topo_id = (uint32_t) strtoul(value, NULL, 0);
2730 ret = ret | 0x40;
2731 }
2732 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
2733 if (err >= 0) {
2734 str_parms_del(parms, "cal_moduleid");
2735 cal->module_id = (uint32_t) strtoul(value, NULL, 0);
2736 ret = ret | 0x80;
2737 }
2738 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
2739 if (err >= 0) {
2740 str_parms_del(parms, "cal_paramid");
2741 cal->param_id = (uint32_t) strtoul(value, NULL, 0);
2742 ret = ret | 0x100;
2743 }
2744 return ret;
2745}
2746
2747static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len) {
2748 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302749 struct stream_out out;
Ben Rombergera04fabc2014-11-14 12:16:03 -08002750 acdb_audio_cal_cfg_t cal={0};
2751 uint8_t *dptr = NULL;
2752 int32_t dlen;
2753 int err, ret;
2754 if(value == NULL || platform == NULL || parms == NULL) {
2755 ALOGE("[%s] received null pointer, failed",__func__);
2756 goto done_key_audcal;
2757 }
2758
2759 /* parse audio calibration keys */
2760 ret = parse_audiocal_cfg(parms, &cal);
2761
2762 /* handle audio calibration data now */
2763 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
2764 if (err >= 0) {
2765 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
2766 dlen = strlen(value);
2767 if(dlen <= 0) {
2768 ALOGE("[%s] null data received",__func__);
2769 goto done_key_audcal;
2770 }
2771 dptr = (uint8_t*) calloc(dlen, sizeof(uint8_t));
2772 if(dptr == NULL) {
2773 ALOGE("[%s] memory allocation failed for %d",__func__, dlen);
2774 goto done_key_audcal;
2775 }
2776 dlen = b64decode(value, strlen(value), dptr);
2777 if(dlen<=0) {
2778 ALOGE("[%s] data decoding failed %d", __func__, dlen);
2779 goto done_key_audcal;
2780 }
2781
2782 if(cal.dev_id) {
2783 if(audio_is_input_device(cal.dev_id)) {
2784 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
2785 } else {
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002786 out.devices = cal.dev_id;
2787 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Ben Rombergera04fabc2014-11-14 12:16:03 -08002788 }
2789 }
2790 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
2791 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
2792 cal.snd_dev_id, cal.acdb_dev_id);
2793 if(cal.acdb_dev_id == -EINVAL) {
2794 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
2795 __func__, cal.acdb_dev_id, cal.snd_dev_id);
2796 goto done_key_audcal;
2797 }
2798 if(my_data->acdb_set_audio_cal) {
2799 ret = my_data->acdb_set_audio_cal((void *)&cal, (void*)dptr, dlen);
2800 }
2801 }
2802done_key_audcal:
2803 if(dptr != NULL)
2804 free(dptr);
2805}
2806
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002807int platform_set_parameters(void *platform, struct str_parms *parms)
2808{
2809 struct platform_data *my_data = (struct platform_data *)platform;
2810 char *str;
Ben Rombergera04fabc2014-11-14 12:16:03 -08002811 char *value=NULL;
2812 int val, len;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002813 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002814 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002815
Mingming Yin7b762e72015-03-04 13:47:32 -08002816 if(kv_pairs == NULL) {
2817 ret = -ENOMEM;
2818 ALOGE("[%s] key-value pair is NULL",__func__);
2819 goto done;
2820 }
2821
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002822 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002823
Ben Rombergera04fabc2014-11-14 12:16:03 -08002824 len = strlen(kv_pairs);
2825 value = (char*)calloc(len, sizeof(char));
2826 if(value == NULL) {
2827 ret = -ENOMEM;
2828 ALOGE("[%s] failed to allocate memory",__func__);
2829 goto done;
2830 }
2831 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, len);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002832 if (err >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08002833 bool state = false;
2834 if (!strncmp("true", value, sizeof("true"))) {
2835 state = true;
2836 }
2837
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002838 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08002839 ret = platform_set_slowtalk(my_data, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002840 if (ret)
2841 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002842 }
2843
Ben Rombergera04fabc2014-11-14 12:16:03 -08002844 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, len);
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302845 if (err >= 0) {
2846 bool state = false;
2847 if (!strncmp("true", value, sizeof("true"))) {
2848 state = true;
2849 }
2850
2851 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
2852 if (my_data->hd_voice != state) {
2853 ret = set_hd_voice(my_data, state);
2854 if (ret)
2855 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
2856 } else {
2857 ALOGV("%s: HD Voice already set to %d", __func__, state);
2858 }
2859 }
2860
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002861 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
Ben Rombergera04fabc2014-11-14 12:16:03 -08002862 value, len);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002863 if (err >= 0) {
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08002864 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
2865
2866 if (my_data->acdb_reload_vocvoltable == NULL) {
2867 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
2868 } else if (!strcmp(value, "on")) {
2869 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
2870 my_data->voice_feature_set = 1;
2871 }
2872 } else {
2873 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
2874 my_data->voice_feature_set = 0;
2875 }
2876 }
2877 }
2878
Tanya Finkel00130052014-07-14 04:26:56 -07002879 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE,
Ben Rombergera04fabc2014-11-14 12:16:03 -08002880 value, len);
Tanya Finkel00130052014-07-14 04:26:56 -07002881 if (err >= 0) {
2882 char *event_name, *status_str;
2883 bool status = false;
2884 str_parms_del(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE);
2885 event_name = strtok_r(value, ",", &status_str);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -08002886 if (!event_name) {
2887 ret = -EINVAL;
2888 ALOGE("%s: event_name is NULL", __func__);
2889 goto done;
2890 }
Tanya Finkel00130052014-07-14 04:26:56 -07002891 ALOGV("%s: recieved update of external audio device %s %s",
2892 __func__,
2893 event_name, status_str);
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002894 if (!strncmp(status_str, "ON", sizeof("ON")))
Tanya Finkel00130052014-07-14 04:26:56 -07002895 status = true;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002896 else if (!strncmp(status_str, "OFF", sizeof("OFF")))
Tanya Finkel00130052014-07-14 04:26:56 -07002897 status = false;
2898 update_external_device_status(my_data, event_name, status);
2899 }
2900
Ben Rombergera04fabc2014-11-14 12:16:03 -08002901 /* handle audio calibration parameters */
2902 set_audiocal(platform, parms, value, len);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302903 native_audio_set_params(platform, parms, value, len);
Ben Rombergera04fabc2014-11-14 12:16:03 -08002904done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002905 ALOGV("%s: exit with code(%d)", __func__, ret);
Mingming Yin7b762e72015-03-04 13:47:32 -08002906 if(kv_pairs != NULL)
2907 free(kv_pairs);
Ben Rombergera04fabc2014-11-14 12:16:03 -08002908 if(value != NULL)
2909 free(value);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002910 return ret;
2911}
2912
Vidyakumar Athota2850d532013-11-19 16:02:12 -08002913int platform_set_incall_recording_session_id(void *platform,
2914 uint32_t session_id, int rec_mode)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07002915{
2916 int ret = 0;
2917 struct platform_data *my_data = (struct platform_data *)platform;
2918 struct audio_device *adev = my_data->adev;
2919 struct mixer_ctl *ctl;
2920 const char *mixer_ctl_name = "Voc VSID";
2921 int num_ctl_values;
2922 int i;
2923
2924 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2925 if (!ctl) {
2926 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2927 __func__, mixer_ctl_name);
2928 ret = -EINVAL;
2929 } else {
2930 num_ctl_values = mixer_ctl_get_num_values(ctl);
2931 for (i = 0; i < num_ctl_values; i++) {
2932 if (mixer_ctl_set_value(ctl, i, session_id)) {
2933 ALOGV("Error: invalid session_id: %x", session_id);
2934 ret = -EINVAL;
2935 break;
2936 }
2937 }
2938 }
2939
Vidyakumar Athota2850d532013-11-19 16:02:12 -08002940 if (my_data->csd != NULL) {
2941 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2942 if (ret < 0) {
2943 ALOGE("%s: csd_client_start_record failed, error %d",
2944 __func__, ret);
2945 }
2946 }
2947
2948 return ret;
2949}
2950
2951int platform_stop_incall_recording_usecase(void *platform)
2952{
2953 int ret = 0;
2954 struct platform_data *my_data = (struct platform_data *)platform;
2955
2956 if (my_data->csd != NULL) {
2957 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2958 if (ret < 0) {
2959 ALOGE("%s: csd_client_stop_record failed, error %d",
2960 __func__, ret);
2961 }
2962 }
2963
2964 return ret;
2965}
2966
2967int platform_start_incall_music_usecase(void *platform)
2968{
2969 int ret = 0;
2970 struct platform_data *my_data = (struct platform_data *)platform;
2971
2972 if (my_data->csd != NULL) {
2973 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2974 if (ret < 0) {
2975 ALOGE("%s: csd_client_start_playback failed, error %d",
2976 __func__, ret);
2977 }
2978 }
2979
2980 return ret;
2981}
2982
2983int platform_stop_incall_music_usecase(void *platform)
2984{
2985 int ret = 0;
2986 struct platform_data *my_data = (struct platform_data *)platform;
2987
2988 if (my_data->csd != NULL) {
2989 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2990 if (ret < 0) {
2991 ALOGE("%s: csd_client_stop_playback failed, error %d",
2992 __func__, ret);
2993 }
2994 }
2995
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07002996 return ret;
2997}
2998
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07002999int platform_update_lch(void *platform, struct voice_session *session,
3000 enum voice_lch_mode lch_mode)
3001{
3002 int ret = 0;
3003 struct platform_data *my_data = (struct platform_data *)platform;
3004
3005 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
3006 ret = my_data->csd->set_lch(session->vsid, lch_mode);
3007 else
3008 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
3009
3010 return ret;
3011}
3012
Ben Rombergera04fabc2014-11-14 12:16:03 -08003013static void get_audiocal(void *platform, void *keys, void *pReply) {
3014 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303015 struct stream_out out;
Ben Rombergera04fabc2014-11-14 12:16:03 -08003016 struct str_parms *query = (struct str_parms *)keys;
3017 struct str_parms *reply=(struct str_parms *)pReply;
3018 acdb_audio_cal_cfg_t cal={0};
3019 uint8_t *dptr = NULL;
3020 char value[512] = {0};
3021 char *rparms=NULL;
3022 int ret=0, err;
3023 uint32_t param_len;
3024
3025 if(query==NULL || platform==NULL || reply==NULL) {
3026 ALOGE("[%s] received null pointer",__func__);
3027 ret=-EINVAL;
3028 goto done;
3029 }
3030 /* parse audiocal configuration keys */
3031 ret = parse_audiocal_cfg(query, &cal);
3032 if(ret == 0) {
3033 /* No calibration keys found */
3034 goto done;
3035 }
3036 err = str_parms_get_str(query, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, sizeof(value));
3037 if (err >= 0) {
3038 str_parms_del(query, AUDIO_PARAMETER_KEY_AUD_CALDATA);
3039 } else {
3040 goto done;
3041 }
3042
3043 if(cal.dev_id & AUDIO_DEVICE_BIT_IN) {
3044 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
3045 } else if(cal.dev_id) {
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003046 out.devices = cal.dev_id;
3047 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Ben Rombergera04fabc2014-11-14 12:16:03 -08003048 }
3049 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
3050 if (cal.acdb_dev_id < 0) {
3051 ALOGE("%s: Failed. Could not find acdb id for snd device(%d)",
3052 __func__, cal.snd_dev_id);
3053 ret = -EINVAL;
3054 goto done_key_audcal;
3055 }
3056 ALOGD("[%s] Getting audio calibration for snd_device(%d) acdb_id(%d)",
3057 __func__, cal.snd_dev_id, cal.acdb_dev_id);
3058
3059 param_len = MAX_SET_CAL_BYTE_SIZE;
3060 dptr = (uint8_t*)calloc(param_len, sizeof(uint8_t));
3061 if(dptr == NULL) {
3062 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
3063 ret = -ENOMEM;
3064 goto done_key_audcal;
3065 }
3066 if (my_data->acdb_get_audio_cal != NULL) {
3067 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
3068 if (ret == 0) {
3069 int dlen;
3070 if(param_len == 0 || param_len == MAX_SET_CAL_BYTE_SIZE) {
3071 ret = -EINVAL;
3072 goto done_key_audcal;
3073 }
3074 /* Allocate memory for encoding */
3075 rparms = (char*)calloc((param_len*2), sizeof(char));
3076 if(rparms == NULL) {
3077 ALOGE("[%s] Memory allocation failed for size %d",
3078 __func__, param_len*2);
3079 ret = -ENOMEM;
3080 goto done_key_audcal;
3081 }
3082 if(cal.persist==0 && cal.module_id && cal.param_id) {
3083 err = b64encode(dptr+12, param_len-12, rparms);
3084 } else {
3085 err = b64encode(dptr, param_len, rparms);
3086 }
3087 if(err < 0) {
3088 ALOGE("[%s] failed to convert data to string", __func__);
3089 ret = -EINVAL;
3090 goto done_key_audcal;
3091 }
3092 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
3093 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, rparms);
3094 }
3095 }
3096done_key_audcal:
3097 if(ret != 0) {
3098 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
3099 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, "");
3100 }
3101done:
3102 if(dptr != NULL)
3103 free(dptr);
3104 if(rparms != NULL)
3105 free(rparms);
3106}
3107
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003108void platform_get_parameters(void *platform,
3109 struct str_parms *query,
3110 struct str_parms *reply)
3111{
3112 struct platform_data *my_data = (struct platform_data *)platform;
3113 char *str = NULL;
Ben Rombergera04fabc2014-11-14 12:16:03 -08003114 char value[512] = {0};
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003115 int ret;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08003116 char *kv_pairs = NULL;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003117
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08003118 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
3119 value, sizeof(value));
3120 if (ret >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08003121 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
3122 my_data->slowtalk?"true":"false");
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08003123 }
3124
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303125 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
3126 value, sizeof(value));
3127 if (ret >= 0) {
3128 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
3129 my_data->hd_voice?"true":"false");
3130 }
3131
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003132 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3133 value, sizeof(value));
3134 if (ret >= 0) {
3135 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
3136 strlcpy(value, "on", sizeof(value));
3137 } else {
3138 strlcpy(value, "off", sizeof(value));
3139 }
3140
3141 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
3142 }
3143
Ben Rombergera04fabc2014-11-14 12:16:03 -08003144 /* Handle audio calibration keys */
3145 get_audiocal(platform, query, reply);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303146 native_audio_get_params(query, reply, value, sizeof(value));
Ben Rombergera04fabc2014-11-14 12:16:03 -08003147
Sidipotu Ashok1b502902015-09-08 10:21:44 +05303148 ret = str_parms_get_str(query, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED,
3149 value, sizeof(value));
3150 if (ret >= 0) {
3151 int isallowed = 1; /*true*/
3152
3153 if (property_get("voice.playback.conc.disabled", propValue, NULL)) {
3154 prop_playback_enabled = atoi(propValue) ||
3155 !strncmp("true", propValue, 4);
3156 }
3157
3158 if (prop_playback_enabled && (voice_is_in_call(my_data->adev) ||
3159 (SND_CARD_STATE_OFFLINE == get_snd_card_state(my_data->adev)))) {
3160 char *decoder_mime_type = value;
3161
3162 //check if unsupported mime type or not
3163 if(decoder_mime_type) {
3164 int i = 0;
3165 for (i = 0; i < sizeof(dsp_only_decoders_mime)/sizeof(dsp_only_decoders_mime[0]); i++) {
3166 if (!strncmp(decoder_mime_type, dsp_only_decoders_mime[i],
3167 strlen(dsp_only_decoders_mime[i]))) {
3168 ALOGD("Rejecting request for DSP only session from HAL during voice call/SSR state");
3169 isallowed = 0;
3170 break;
3171 }
3172 }
3173 }
3174 }
3175 str_parms_add_int(reply, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED, isallowed);
3176 }
3177
Ben Rombergera04fabc2014-11-14 12:16:03 -08003178done:
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08003179 kv_pairs = str_parms_to_str(reply);
3180 ALOGV_IF(kv_pairs != NULL, "%s: exit: returns - %s", __func__, kv_pairs);
Narsinga Rao Chellacde45d12014-02-13 11:44:31 -08003181 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003182}
3183
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003184/* Delay in Us */
3185int64_t platform_render_latency(audio_usecase_t usecase)
3186{
3187 switch (usecase) {
3188 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3189 return DEEP_BUFFER_PLATFORM_DELAY;
3190 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3191 return LOW_LATENCY_PLATFORM_DELAY;
3192 default:
3193 return 0;
3194 }
3195}
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07003196
Mingming Yine62d7842013-10-25 16:26:03 -07003197int platform_update_usecase_from_source(int source, int usecase)
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07003198{
Mingming Yinab429782013-11-07 11:16:55 -08003199 ALOGV("%s: input source :%d", __func__, source);
Yamit Mehtaaafda4b2015-07-13 12:51:33 +05303200 if(source == AUDIO_SOURCE_FM_TUNER)
Mingming Yine62d7842013-10-25 16:26:03 -07003201 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
3202 return usecase;
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07003203}
Kiran Kandide144c82013-11-20 15:58:32 -08003204
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303205bool platform_listen_device_needs_event(snd_device_t snd_device)
Kiran Kandide144c82013-11-20 15:58:32 -08003206{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303207 bool needs_event = false;
3208
Kiran Kandide144c82013-11-20 15:58:32 -08003209 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3210 (snd_device < SND_DEVICE_IN_END) &&
3211 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3212 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303213 needs_event = true;
3214
3215 return needs_event;
3216}
3217
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003218bool platform_listen_usecase_needs_event(audio_usecase_t uc_id __unused)
3219{
3220 return false;
3221}
3222
3223bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
3224{
3225 bool needs_event = false;
3226
3227 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3228 (snd_device < SND_DEVICE_IN_END) &&
3229 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3230 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
3231 needs_event = true;
3232
3233 return needs_event;
3234}
3235
3236bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id __unused)
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303237{
3238 return false;
Kiran Kandide144c82013-11-20 15:58:32 -08003239}
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003240
3241/* Read offload buffer size from a property.
3242 * If value is not power of 2 round it to
3243 * power of 2.
3244 */
3245uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
3246{
3247 char value[PROPERTY_VALUE_MAX] = {0};
3248 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3249 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
3250 atoi(value)) {
3251 fragment_size = atoi(value) * 1024;
3252 }
3253
vivek mehtaf110e7f2015-08-10 12:58:10 -07003254 /* Use incoming offload buffer size if default buffer size is less */
3255 if ((info != NULL) && (fragment_size < info->offload_buffer_size)) {
3256 ALOGI("%s:: Overwriting offload buffer size default:%d new:%d", __func__,
3257 fragment_size,
3258 info->offload_buffer_size);
3259 fragment_size = info->offload_buffer_size;
3260 }
3261
Mingming Yin3ee55c62014-08-04 14:23:35 -07003262 // For FLAC use max size since it is loss less, and has sampling rates
3263 // upto 192kHZ
3264 if (info != NULL && !info->has_video &&
3265 info->format == AUDIO_FORMAT_FLAC) {
3266 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3267 ALOGV("FLAC fragment size %d", fragment_size);
3268 }
3269
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003270 if (info != NULL && info->has_video && info->is_streaming) {
3271 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
3272 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
ApurupaPattapu31d09d72014-03-05 11:13:32 -08003273 __func__, fragment_size);
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003274 }
3275
3276 fragment_size = ALIGN( fragment_size, 1024);
3277
3278 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3279 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3280 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3281 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3282 ALOGV("%s: fragment_size %d", __func__, fragment_size);
3283 return fragment_size;
3284}
3285
3286uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
3287{
Alexy Josephaa54c872014-12-03 02:46:47 -08003288 uint32_t fragment_size = 0;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003289 uint32_t bits_per_sample = 16;
Alexy Joseph68011492015-06-18 12:02:01 -07003290 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003291
3292 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
3293 bits_per_sample = 32;
3294 }
3295
Alexy Joseph68011492015-06-18 12:02:01 -07003296 //duration is set to 40 ms worth of stereo data at 48Khz
Alexy Josephaa54c872014-12-03 02:46:47 -08003297 //with 16 bit per sample, modify this when the channel
3298 //configuration is different
3299 fragment_size = (pcm_offload_time
3300 * info->sample_rate
3301 * (bits_per_sample >> 3)
3302 * popcount(info->channel_mask))/1000;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003303 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
3304 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
3305 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
3306 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
Preetam Singh Ranawat15668f02015-05-27 11:14:03 +05303307 // To have same PCM samples for all channels, the buffer size requires to
3308 // be multiple of (number of channels * bytes per sample)
3309 // For writes to succeed, the buffer must be written at address which is multiple of 32
3310 fragment_size = ALIGN(fragment_size, ((bits_per_sample >> 3)* popcount(info->channel_mask) * 32));
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003311
Alexy Josephaa54c872014-12-03 02:46:47 -08003312 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003313 return fragment_size;
3314}
3315
Sharad Sangleb27354b2015-06-18 15:58:55 +05303316bool platform_use_small_buffer(audio_offload_info_t* info)
3317{
3318 return OFFLOAD_USE_SMALL_BUFFER;
3319}
3320
Mingming Yin3ee55c62014-08-04 14:23:35 -07003321int platform_set_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303322 snd_device_t snd_device,
Mingming Yin3ee55c62014-08-04 14:23:35 -07003323 unsigned int bit_width, unsigned int sample_rate)
3324{
Mingming Yin3ee55c62014-08-04 14:23:35 -07003325 int ret = 0;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303326 int backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003327 struct platform_data *my_data = (struct platform_data *)adev->platform;
3328
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303329 backend_idx = platform_get_backend_index(snd_device);
3330 ALOGV("%s bit width: %d, sample rate: %d backend_idx - %d",
3331 __func__, bit_width, sample_rate, backend_idx);
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003332
3333 if (bit_width !=
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303334 my_data->current_backend_cfg[backend_idx].bit_width) {
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003335
Mingming Yin3ee55c62014-08-04 14:23:35 -07003336 struct mixer_ctl *ctl;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303337 ctl = mixer_get_ctl_by_name(adev->mixer,
3338 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003339 if (!ctl) {
3340 ALOGE("%s: Could not get ctl for mixer command - %s",
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303341 __func__, my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003342 return -EINVAL;
3343 }
3344
3345 if (bit_width == 24) {
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303346 mixer_ctl_set_enum_by_string(ctl, "S24_LE");
Mingming Yin3ee55c62014-08-04 14:23:35 -07003347 } else {
3348 mixer_ctl_set_enum_by_string(ctl, "S16_LE");
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303349 if (backend_idx != HEADPHONE_44_1_BACKEND)
3350 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003351 }
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303352 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3353 ALOGD("%s: %s mixer set to %d bit", __func__,
3354 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003355 }
3356
Amit Shekhared7fb5c2014-08-01 17:18:53 -07003357 /*
3358 * Backend sample rate configuration follows:
3359 * 16 bit playback - 48khz for streams at any valid sample rate
3360 * 24 bit playback - 48khz for stream sample rate less than 48khz
3361 * 24 bit playback - 96khz for sample rate range of 48khz to 96khz
3362 * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz
3363 * Upper limit is inclusive in the sample rate range.
3364 */
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003365 if (sample_rate !=
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303366 my_data->current_backend_cfg[backend_idx].sample_rate) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07003367 char *rate_str = NULL;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003368 struct mixer_ctl *ctl;
3369
3370 switch (sample_rate) {
3371 case 8000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003372 case 11025:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003373 case 16000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003374 case 22050:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003375 case 32000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003376 case 48000:
3377 rate_str = "KHZ_48";
3378 break;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303379 case 44100:
3380 rate_str = "KHZ_44P1";
3381 break;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003382 case 64000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003383 case 88200:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003384 case 96000:
3385 rate_str = "KHZ_96";
3386 break;
3387 case 176400:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003388 case 192000:
3389 rate_str = "KHZ_192";
3390 break;
3391 default:
3392 rate_str = "KHZ_48";
3393 break;
3394 }
3395
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303396 ctl = mixer_get_ctl_by_name(adev->mixer,
3397 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003398 if(!ctl) {
3399 ALOGE("%s: Could not get ctl for mixer command - %s",
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303400 __func__, my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003401 return -EINVAL;
3402 }
3403
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303404 ALOGD("%s: %s set to %s", __func__,
3405 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003406 mixer_ctl_set_enum_by_string(ctl, rate_str);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303407 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003408 }
3409
3410 return ret;
3411}
3412
3413bool platform_check_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303414 struct audio_usecase* usecase,
3415 snd_device_t snd_device,
Mingming Yin3ee55c62014-08-04 14:23:35 -07003416 unsigned int* new_bit_width,
3417 unsigned int* new_sample_rate)
3418{
3419 bool backend_change = false;
3420 struct listnode *node;
3421 struct stream_out *out = NULL;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303422 unsigned int bit_width;
3423 unsigned int sample_rate;
Manish Dewanganf48adb42015-05-27 10:17:41 +05303424 char value[PROPERTY_VALUE_MAX] = {0};
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303425 int backend_idx = DEFAULT_CODEC_BACKEND;
3426 int usecase_backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003427 struct platform_data *my_data = (struct platform_data *)adev->platform;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003428
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303429 backend_idx = platform_get_backend_index(snd_device);
3430
3431 bit_width = *new_bit_width;
3432 sample_rate = *new_sample_rate;
3433
3434 ALOGI("%s Codec selected backend: %d current bit width: %d and sample rate: %d",
3435 __func__, backend_idx, bit_width, sample_rate);
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07003436
3437 // For voice calls use default configuration i.e. 16b/48K, only applicable to
3438 // default backend
Mingming Yin3ee55c62014-08-04 14:23:35 -07003439 // force routing is not required here, caller will do it anyway
Apoorv Raghuvanshi95333352015-07-06 15:07:14 -07003440 if ((voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
3441 backend_idx == DEFAULT_CODEC_BACKEND) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07003442 ALOGW("%s:Use default bw and sr for voice/voip calls ",__func__);
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07003443 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3444 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3445 } else {
3446 /*
3447 * The backend should be configured at highest bit width and/or
3448 * sample rate amongst all playback usecases.
3449 * If the selected sample rate and/or bit width differ with
3450 * current backend sample rate and/or bit width, then, we set the
3451 * backend re-configuration flag.
3452 *
3453 * Exception: 16 bit playbacks is allowed through 16 bit/48 khz backend only
3454 */
Mingming Yin3ee55c62014-08-04 14:23:35 -07003455 list_for_each(node, &adev->usecase_list) {
3456 struct audio_usecase *curr_usecase;
3457 curr_usecase = node_to_item(node, struct audio_usecase, list);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303458 if (curr_usecase->type == PCM_PLAYBACK &&
3459 usecase != curr_usecase) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07003460 struct stream_out *out =
3461 (struct stream_out*) curr_usecase->stream.out;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303462 usecase_backend_idx = platform_get_backend_index(curr_usecase->out_snd_device);
3463
3464 if (out != NULL &&
3465 usecase_backend_idx == backend_idx) {
3466 ALOGV("%s: usecase Offload playback running bw %d sr %d device %s be_idx %d",
3467 __func__, out->bit_width, out->sample_rate,
3468 platform_get_snd_device_name(curr_usecase->out_snd_device), usecase_backend_idx);
Amit Shekhar278e3362014-09-08 14:08:19 -07003469 if (bit_width < out->bit_width)
3470 bit_width = out->bit_width;
3471 if (sample_rate < out->sample_rate)
3472 sample_rate = out->sample_rate;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303473 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3474 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003475 }
3476 }
3477 }
3478 }
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303479 if (backend_idx != HEADPHONE_44_1_BACKEND) {
3480 // 16 bit playbacks are allowed through 16 bit/48 khz backend only for
3481 // all non-native streams
3482 if (16 == bit_width) {
Manish Dewanganf48adb42015-05-27 10:17:41 +05303483 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303484 ALOGD("%s: resetting sample_rate back to default, "
3485 "backend_idx: %d", __func__, backend_idx);
3486 }
3487
3488 //check if mulitchannel clip needs to be down sampled to 48k
3489 property_get("audio.playback.mch.downsample",value,"");
3490 if (!strncmp("true", value, sizeof("true"))) {
3491 out = usecase->stream.out;
3492 if ((popcount(out->channel_mask) > 2) &&
3493 (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
3494 !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
3495 /* update out sample rate to reflect current backend sample rate */
3496 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3497 ALOGD("%s: MCH session defaulting sample rate to %d",
3498 __func__, sample_rate);
3499 }
3500 }
3501 // 24 bit playback on speakers is allowed through 48 khz backend only
3502 // bit width re-configured based on platform info
3503 if ((24 == bit_width) &&
3504 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
3505 bit_width = (uint32_t)platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
3506 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Manish Dewanganf48adb42015-05-27 10:17:41 +05303507 }
3508 }
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303509 ALOGI("%s Codec selected backend: %d updated bit width: %d and sample rate: %d",
3510 __func__, backend_idx, bit_width, sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003511 // Force routing if the expected bitwdith or samplerate
3512 // is not same as current backend comfiguration
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303513 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3514 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate)) {
Amit Shekhar278e3362014-09-08 14:08:19 -07003515 *new_bit_width = bit_width;
3516 *new_sample_rate = sample_rate;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003517 backend_change = true;
Amit Shekhar278e3362014-09-08 14:08:19 -07003518 ALOGI("%s Codec backend needs to be updated. new bit width: %d new sample rate: %d",
3519 __func__, *new_bit_width, *new_sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003520 }
3521
3522 return backend_change;
3523}
3524
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303525bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
3526 struct audio_usecase *usecase, snd_device_t snd_device)
Mingming Yin3ee55c62014-08-04 14:23:35 -07003527{
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303528 unsigned int new_bit_width;
3529 unsigned int new_sample_rate;
3530 int backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003531 struct platform_data *my_data = (struct platform_data *)adev->platform;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003532
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303533 ALOGV("%s: usecase = %d", __func__, usecase->id );
Mingming Yin3ee55c62014-08-04 14:23:35 -07003534
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303535 backend_idx = platform_get_backend_index(snd_device);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003536
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303537 new_bit_width = usecase->stream.out->bit_width;
3538 new_sample_rate = usecase->stream.out->sample_rate;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003539
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303540 ALOGI("%s: Usecase bitwidth %d, samplerate %d, backend_idx %d",
3541 __func__, new_bit_width, new_sample_rate, backend_idx);
3542 if (platform_check_codec_backend_cfg(adev, usecase, snd_device,
Mingming Yin3ee55c62014-08-04 14:23:35 -07003543 &new_bit_width, &new_sample_rate)) {
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303544 platform_set_codec_backend_cfg(adev, snd_device,
3545 new_bit_width, new_sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003546 return true;
3547 }
3548
3549 return false;
3550}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003551
3552int platform_set_snd_device_backend(snd_device_t device, const char *backend)
3553{
3554 int ret = 0;
3555
3556 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3557 ALOGE("%s: Invalid snd_device = %d",
3558 __func__, device);
3559 ret = -EINVAL;
3560 goto done;
3561 }
3562
3563 if (backend_table[device]) {
3564 free(backend_table[device]);
3565 }
3566 backend_table[device] = strdup(backend);
3567done:
3568 return ret;
3569}
3570
3571int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3572{
3573 int ret = 0;
3574 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3575 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3576 ret = -EINVAL;
3577 goto done;
3578 }
3579
3580 if ((type != 0) && (type != 1)) {
3581 ALOGE("%s: invalid usecase type", __func__);
3582 ret = -EINVAL;
3583 }
3584 pcm_device_table[usecase][type] = pcm_id;
3585done:
3586 return ret;
3587}
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003588
3589void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
3590{
3591 *device_to_be_id = msm_device_to_be_id;
3592 *length = msm_be_id_array_len;
3593}
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003594int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask, int snd_id)
3595{
3596 int ret = 0;
3597 int channels = audio_channel_count_from_out_mask(channel_mask);
3598
3599 char channel_map[8];
3600 memset(channel_map, 0, sizeof(channel_map));
3601 /* Following are all most common standard WAV channel layouts
3602 overridden by channel mask if its allowed and different */
3603 switch (channels) {
3604 case 1:
3605 /* AUDIO_CHANNEL_OUT_MONO */
3606 channel_map[0] = PCM_CHANNEL_FC;
Alexy Josephe844aad2014-12-01 16:06:34 -08003607 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003608 case 2:
3609 /* AUDIO_CHANNEL_OUT_STEREO */
3610 channel_map[0] = PCM_CHANNEL_FL;
3611 channel_map[1] = PCM_CHANNEL_FR;
Alexy Josephe844aad2014-12-01 16:06:34 -08003612 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003613 case 3:
3614 /* AUDIO_CHANNEL_OUT_2POINT1 */
3615 channel_map[0] = PCM_CHANNEL_FL;
3616 channel_map[1] = PCM_CHANNEL_FR;
3617 channel_map[2] = PCM_CHANNEL_FC;
3618 break;
3619 case 4:
3620 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
3621 channel_map[0] = PCM_CHANNEL_FL;
3622 channel_map[1] = PCM_CHANNEL_FR;
3623 channel_map[2] = PCM_CHANNEL_LS;
3624 channel_map[3] = PCM_CHANNEL_RS;
3625 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK)
3626 {
3627 channel_map[2] = PCM_CHANNEL_LB;
3628 channel_map[3] = PCM_CHANNEL_RB;
3629 }
3630 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND)
3631 {
3632 channel_map[2] = PCM_CHANNEL_FC;
3633 channel_map[3] = PCM_CHANNEL_CS;
3634 }
3635 break;
3636 case 5:
3637 /* AUDIO_CHANNEL_OUT_PENTA */
3638 channel_map[0] = PCM_CHANNEL_FL;
3639 channel_map[1] = PCM_CHANNEL_FR;
3640 channel_map[2] = PCM_CHANNEL_FC;
3641 channel_map[3] = PCM_CHANNEL_LB;
3642 channel_map[4] = PCM_CHANNEL_RB;
3643 break;
3644 case 6:
3645 /* AUDIO_CHANNEL_OUT_5POINT1 */
3646 channel_map[0] = PCM_CHANNEL_FL;
3647 channel_map[1] = PCM_CHANNEL_FR;
3648 channel_map[2] = PCM_CHANNEL_FC;
3649 channel_map[3] = PCM_CHANNEL_LFE;
3650 channel_map[4] = PCM_CHANNEL_LB;
3651 channel_map[5] = PCM_CHANNEL_RB;
3652 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE)
3653 {
3654 channel_map[4] = PCM_CHANNEL_LS;
3655 channel_map[5] = PCM_CHANNEL_RS;
3656 }
3657 break;
3658 case 7:
3659 /* AUDIO_CHANNEL_OUT_6POINT1 */
3660 channel_map[0] = PCM_CHANNEL_FL;
3661 channel_map[1] = PCM_CHANNEL_FR;
3662 channel_map[2] = PCM_CHANNEL_FC;
3663 channel_map[3] = PCM_CHANNEL_LFE;
3664 channel_map[4] = PCM_CHANNEL_LB;
3665 channel_map[5] = PCM_CHANNEL_RB;
3666 channel_map[6] = PCM_CHANNEL_CS;
Alexy Josephe844aad2014-12-01 16:06:34 -08003667 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003668 case 8:
3669 /* AUDIO_CHANNEL_OUT_7POINT1 */
3670 channel_map[0] = PCM_CHANNEL_FL;
3671 channel_map[1] = PCM_CHANNEL_FR;
3672 channel_map[2] = PCM_CHANNEL_FC;
3673 channel_map[3] = PCM_CHANNEL_LFE;
3674 channel_map[4] = PCM_CHANNEL_LB;
3675 channel_map[5] = PCM_CHANNEL_RB;
3676 channel_map[6] = PCM_CHANNEL_LS;
3677 channel_map[7] = PCM_CHANNEL_RS;
3678 break;
3679 default:
3680 ALOGE("unsupported channels %d for setting channel map", channels);
3681 return -1;
3682 }
3683 ret = platform_set_channel_map(platform, channels, channel_map, snd_id);
3684 return ret;
3685}
3686
3687int platform_get_edid_info(void *platform)
3688{
3689 struct platform_data *my_data = (struct platform_data *)platform;
3690 struct audio_device *adev = my_data->adev;
3691 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3692 char *sad = block;
3693 int num_audio_blocks;
3694 int channel_count = 2;
3695 int i, ret, count;
3696
3697 struct mixer_ctl *ctl;
3698 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
3699 edid_audio_info *info;
3700
3701 if (my_data->edid_valid) {
3702 /* use cached edid */
3703 return 0;
3704 }
3705
3706 if (my_data->edid_info == NULL) {
3707 my_data->edid_info =
3708 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
3709 }
3710
3711 info = my_data->edid_info;
3712
3713 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3714 if (!ctl) {
3715 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3716 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
3717 goto fail;
3718 }
3719
3720 mixer_ctl_update(ctl);
3721
3722 count = mixer_ctl_get_num_values(ctl);
3723
3724 /* Read SAD blocks, clamping the maximum size for safety */
3725 if (count > (int)sizeof(block))
3726 count = (int)sizeof(block);
3727
3728 ret = mixer_ctl_get_array(ctl, block, count);
3729 if (ret != 0) {
3730 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3731 goto fail;
3732 }
3733 edid_data[0] = count;
3734 memcpy(&edid_data[1], block, count);
3735
3736 if (!edid_get_sink_caps(info, edid_data)) {
3737 ALOGE("%s: Failed to get HDMI sink capabilities", __func__);
3738 goto fail;
3739 }
3740 my_data->edid_valid = true;
3741 return 0;
3742fail:
3743 if (my_data->edid_info) {
3744 free(my_data->edid_info);
3745 my_data->edid_info = NULL;
3746 my_data->edid_valid = false;
3747 }
3748 ALOGE("%s: return -EINVAL", __func__);
3749 return -EINVAL;
3750}
3751
3752
3753int platform_set_channel_allocation(void *platform, int channel_alloc)
3754{
3755 struct mixer_ctl *ctl;
3756 const char *mixer_ctl_name = "HDMI RX CA";
3757 int ret;
3758 struct platform_data *my_data = (struct platform_data *)platform;
3759 struct audio_device *adev = my_data->adev;
3760
3761 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3762 if (!ctl) {
3763 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3764 __func__, mixer_ctl_name);
3765 ret = EINVAL;
3766 }
3767 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
3768 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
3769
3770 if (ret < 0) {
3771 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
3772 }
3773
3774 return ret;
3775}
3776
3777int platform_set_channel_map(void *platform, int ch_count, char *ch_map, int snd_id)
3778{
3779 struct mixer_ctl *ctl;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -08003780 char mixer_ctl_name[44] = {0}; // max length of name is 44 as defined
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003781 int ret;
3782 unsigned int i;
3783 int set_values[8] = {0};
3784 char device_num[13]; // device number up to 2 digit
3785 struct platform_data *my_data = (struct platform_data *)platform;
3786 struct audio_device *adev = my_data->adev;
3787 ALOGV("%s channel_count:%d",__func__, ch_count);
3788 if (NULL == ch_map) {
3789 ALOGE("%s: Invalid channel mapping used", __func__);
3790 return -EINVAL;
3791 }
Fred Ohe0479682015-03-25 16:30:26 -07003792
3793 /*
3794 * If snd_id is greater than 0, stream channel mapping
3795 * If snd_id is below 0, typically -1, device channel mapping
3796 */
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003797 if (snd_id >= 0) {
Fred Ohe0479682015-03-25 16:30:26 -07003798 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Playback Channel Map%d", snd_id);
3799 } else {
3800 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003801 }
3802
3803 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
3804
3805 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3806 if (!ctl) {
3807 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3808 __func__, mixer_ctl_name);
3809 return -EINVAL;
3810 }
3811 for (i = 0; i< ARRAY_SIZE(set_values); i++) {
3812 set_values[i] = ch_map[i];
3813 }
3814
3815 ALOGD("%s: set mapping(%d %d %d %d %d %d %d %d) for channel:%d", __func__,
3816 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
3817 set_values[5], set_values[6], set_values[7], ch_count);
3818
3819 ret = mixer_ctl_set_array(ctl, set_values, ch_count);
3820 if (ret < 0) {
3821 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
3822 __func__, ret, ch_count);
3823 }
3824 return ret;
3825}
3826
3827unsigned char platform_map_to_edid_format(int audio_format)
3828{
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003829 unsigned char format;
3830 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
3831 case AUDIO_FORMAT_AC3:
3832 ALOGV("%s: AC3", __func__);
3833 format = AC3;
3834 break;
3835 case AUDIO_FORMAT_AAC:
3836 ALOGV("%s:AAC", __func__);
3837 format = AAC;
3838 break;
Manish Dewangan93672f12015-08-24 20:30:31 +05303839 case AUDIO_FORMAT_AAC_ADTS:
3840 ALOGV("%s:AAC_ADTS", __func__);
3841 format = AAC;
3842 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003843 case AUDIO_FORMAT_E_AC3:
3844 ALOGV("%s:E_AC3", __func__);
3845 format = DOLBY_DIGITAL_PLUS;
3846 break;
3847 case AUDIO_FORMAT_PCM_16_BIT:
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003848 case AUDIO_FORMAT_PCM_16_BIT_OFFLOAD:
3849 case AUDIO_FORMAT_PCM_24_BIT_OFFLOAD:
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003850 default:
3851 ALOGV("%s:PCM", __func__);
3852 format = LPCM;
3853 break;
3854 }
3855 return format;
3856}
3857
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003858uint32_t platform_get_compress_passthrough_buffer_size(
3859 audio_offload_info_t* info)
3860{
3861 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
3862 if (!info->has_video)
3863 fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
3864
3865 return fragment_size;
3866}
3867
3868void platform_reset_edid_info(void *platform) {
3869
3870 ALOGV("%s:", __func__);
3871 struct platform_data *my_data = (struct platform_data *)platform;
3872 if (my_data->edid_info) {
3873 ALOGV("%s :free edid", __func__);
3874 free(my_data->edid_info);
3875 my_data->edid_info = NULL;
3876 }
3877}
3878
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003879bool platform_is_edid_supported_format(void *platform, int format)
3880{
3881 struct platform_data *my_data = (struct platform_data *)platform;
3882 struct audio_device *adev = my_data->adev;
3883 edid_audio_info *info = NULL;
3884 int num_audio_blocks;
3885 int i, ret, count;
3886 unsigned char format_id = platform_map_to_edid_format(format);
3887
3888 ret = platform_get_edid_info(platform);
3889 info = (edid_audio_info *)my_data->edid_info;
3890 if (ret == 0 && info != NULL) {
3891 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003892 /*
3893 * To check
3894 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
3895 * & DOLBY_DIGITAL_PLUS
3896 */
3897 if (info->audio_blocks_array[i].format_id == format_id) {
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003898 ALOGV("%s:platform_is_edid_supported_format true %x",
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003899 __func__, format);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003900 return true;
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003901 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003902 }
3903 }
3904 ALOGV("%s:platform_is_edid_supported_format false %x",
3905 __func__, format);
3906 return false;
3907}
3908
3909int platform_set_edid_channels_configuration(void *platform, int channels) {
3910
3911 struct platform_data *my_data = (struct platform_data *)platform;
3912 struct audio_device *adev = my_data->adev;
3913 edid_audio_info *info = NULL;
3914 int num_audio_blocks;
3915 int channel_count = 2;
3916 int i, ret, count;
3917 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
3918
3919 ret = platform_get_edid_info(platform);
3920 info = (edid_audio_info *)my_data->edid_info;
3921 if(ret == 0 && info != NULL) {
3922 if (channels > 2) {
3923
3924 ALOGV("%s:able to get HDMI sink capabilities multi channel playback",
3925 __func__);
3926 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
3927 if (info->audio_blocks_array[i].format_id == LPCM &&
3928 info->audio_blocks_array[i].channels > channel_count &&
3929 info->audio_blocks_array[i].channels <= MAX_HDMI_CHANNEL_CNT) {
3930 channel_count = info->audio_blocks_array[i].channels;
3931 }
3932 }
3933 ALOGVV("%s:channel_count:%d", __func__, channel_count);
3934 /*
3935 * Channel map is set for supported hdmi max channel count even
3936 * though the input channel count set on adm is less than or equal to
3937 * max supported channel count
3938 */
3939 platform_set_channel_map(platform, channel_count, info->channel_map, -1);
3940 platform_set_channel_allocation(platform, info->channel_allocation);
3941 } else {
3942 default_channelMap[0] = PCM_CHANNEL_FL;
3943 default_channelMap[1] = PCM_CHANNEL_FR;
3944 platform_set_channel_map(platform,2,default_channelMap,-1);
3945 platform_set_channel_allocation(platform,0);
3946 }
3947 }
3948
3949 return 0;
3950}
3951
3952void platform_cache_edid(void * platform)
3953{
3954 platform_get_edid_info(platform);
3955}
3956
3957void platform_invalidate_edid(void * platform)
3958{
3959 struct platform_data *my_data = (struct platform_data *)platform;
3960 my_data->edid_valid = false;
3961 if (my_data->edid_info) {
3962 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
3963 }
3964}
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003965
3966int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
3967 const char *mixer_val)
3968{
3969 struct audio_device *adev = out->dev;
3970 struct mixer_ctl *ctl = NULL;
3971 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
3972 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3973 if (!ctl) {
3974 ALOGE("%s: could not get ctl for mixer cmd - %s",
3975 __func__, mixer_ctl_name);
3976 return -EINVAL;
3977 }
3978
3979 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
3980}
3981
3982int platform_set_hdmi_config(struct stream_out *out)
3983{
3984 struct listnode *node;
3985 struct audio_usecase *usecase;
3986 struct audio_device *adev = out->dev;
3987 const char *hdmi_format_ctrl = "HDMI RX Format";
3988 const char *hdmi_rate_ctrl = "HDMI_RX SampleRate";
3989 int sample_rate = out->sample_rate;
3990 /*TODO: Add rules and check if this needs to be done.*/
3991 if((is_offload_usecase(out->usecase)) &&
3992 (out->compr_config.codec->compr_passthr == PASSTHROUGH ||
3993 out->compr_config.codec->compr_passthr == PASSTHROUGH_CONVERT)) {
3994 /* TODO: can we add mixer control for channels here avoid setting */
3995 if ((out->format == AUDIO_FORMAT_E_AC3 ||
3996 out->format == AUDIO_FORMAT_E_AC3_JOC) &&
3997 (out->compr_config.codec->compr_passthr == PASSTHROUGH))
3998 sample_rate = out->sample_rate * 4;
3999 ALOGD("%s:HDMI compress format and samplerate %d, sample_rate %d",
4000 __func__, out->sample_rate, sample_rate);
4001 platform_set_mixer_control(out, hdmi_format_ctrl, "Compr");
4002 switch (sample_rate) {
4003 case 32000:
4004 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_32");
4005 break;
4006 case 44100:
4007 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_44_1");
4008 break;
4009 case 96000:
4010 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_96");
4011 break;
4012 case 176400:
4013 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_176_4");
4014 break;
4015 case 192000:
4016 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_192");
4017 break;
4018 case 128000:
4019 if (out->format != AUDIO_FORMAT_E_AC3) {
4020 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_128");
4021 break;
4022 } else
4023 ALOGW("Unsupported sample rate for E_AC3 32K");
4024 default:
4025 case 48000:
4026 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_48");
4027 break;
4028 }
4029 } else {
4030 ALOGD("%s: HDMI pcm and samplerate %d", __func__,
4031 out->sample_rate);
4032 platform_set_mixer_control(out, hdmi_format_ctrl, "LPCM");
4033 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_48");
4034 }
4035
4036 /*
4037 * Deroute all the playback streams routed to HDMI so that
4038 * the back end is deactivated. Note that backend will not
4039 * be deactivated if any one stream is connected to it.
4040 */
4041 list_for_each(node, &adev->usecase_list) {
4042 usecase = node_to_item(node, struct audio_usecase, list);
4043 ALOGV("%s:disable: usecase type %d, devices 0x%x", __func__,
4044 usecase->type, usecase->devices);
4045 if (usecase->type == PCM_PLAYBACK &&
4046 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
4047 disable_audio_route(adev, usecase);
4048 }
4049 }
4050
4051 /*
4052 * Enable all the streams disabled above. Now the HDMI backend
4053 * will be activated with new channel configuration
4054 */
4055 list_for_each(node, &adev->usecase_list) {
4056 usecase = node_to_item(node, struct audio_usecase, list);
4057 ALOGV("%s:enable: usecase type %d, devices 0x%x", __func__,
4058 usecase->type, usecase->devices);
4059 if (usecase->type == PCM_PLAYBACK &&
4060 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
4061 enable_audio_route(adev, usecase);
4062 }
4063 }
4064
4065 return 0;
4066}
4067
4068int platform_set_device_params(struct stream_out *out, int param, int value)
4069{
4070 struct audio_device *adev = out->dev;
4071 struct mixer_ctl *ctl;
4072 char *mixer_ctl_name = "Device PP Params";
4073 int ret = 0;
4074 uint32_t set_values[] = {0,0};
4075
4076 set_values[0] = param;
4077 set_values[1] = value;
4078
4079 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
4080 if (!ctl) {
4081 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4082 __func__, mixer_ctl_name);
4083 ret = -EINVAL;
4084 goto end;
4085 }
4086
4087 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
4088 __func__,param, value, mixer_ctl_name);
4089 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
4090
4091end:
4092 return ret;
4093}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004094
4095/*
Laxminath Kasam44f49402015-05-29 18:37:11 +05304096 * This is a lookup table to map names of speaker device with respective left and right TZ names.
4097 * Also the tz names for a particular left or right speaker can be overriden by adding
4098 * corresponding entry in audio_platform_info.xml file.
4099 */
4100struct speaker_device_to_tz_names speaker_device_tz_names = {
4101 {SND_DEVICE_OUT_SPEAKER, "", ""},
4102};
4103
4104/*
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004105 * This is a lookup table to map android audio input device to audio h/w interface (backend).
4106 * The table can be extended for other input devices by adding appropriate entries.
4107 * Also the audio interface for a particular input device can be overriden by adding
4108 * corresponding entry in audio_platform_info.xml file.
4109 */
4110struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
4111 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), "SLIMBUS_0"},
4112 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), "SLIMBUS_0"},
4113};
4114
4115int audio_device_to_interface_table_len =
4116 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
4117
Karthik Reddy Kattaeef44a92015-05-11 13:43:18 +05304118int platform_set_audio_device_interface(const char *device_name, const char *intf_name,
4119 const char *codec_type __unused)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004120{
4121 int ret = 0;
4122 int i;
4123
4124 if (device_name == NULL || intf_name == NULL) {
4125 ALOGE("%s: Invalid input", __func__);
4126
4127 ret = -EINVAL;
4128 goto done;
4129 }
4130
4131 ALOGD("%s: Enter, device name:%s, intf name:%s", __func__, device_name, intf_name);
4132
4133 size_t device_name_len = strlen(device_name);
4134 for (i = 0; i < audio_device_to_interface_table_len; i++) {
4135 char* name = audio_device_to_interface_table[i].device_name;
4136 size_t name_len = strlen(name);
4137 if ((name_len == device_name_len) &&
4138 (strncmp(device_name, name, name_len) == 0)) {
4139 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
4140 __func__, device_name, intf_name);
4141
4142 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
4143 sizeof(audio_device_to_interface_table[i].interface_name));
4144 goto done;
4145 }
4146 }
4147 ALOGE("%s: Could not find matching device name %s",
4148 __func__, device_name);
4149
4150 ret = -EINVAL;
4151
4152done:
4153 return ret;
4154}
Laxminath Kasam44f49402015-05-29 18:37:11 +05304155
4156int platform_set_spkr_device_tz_names(snd_device_t index,
4157 const char *spkr_1_tz_name, const char *spkr_2_tz_name)
4158{
4159 int ret = 0;
4160 int i;
4161
4162 if (spkr_1_tz_name == NULL && spkr_2_tz_name == NULL) {
4163 ALOGE("%s: Invalid input", __func__);
4164 ret = -EINVAL;
4165 goto done;
4166 }
4167 if (index != speaker_device_tz_names.snd_device) {
4168 ALOGE("%s: not matching speaker device\n");
4169 ret = -EINVAL;
4170 goto done;
4171 }
4172 ALOGD("%s: Enter, spkr_1_tz_name :%s, spkr_2_tz_name:%s",
4173 __func__, spkr_1_tz_name, spkr_2_tz_name);
4174
4175 if (spkr_1_tz_name != NULL)
4176 strlcpy(speaker_device_tz_names.spkr_1_tz_name, spkr_1_tz_name,
4177 sizeof(speaker_device_tz_names.spkr_1_tz_name));
4178
4179 if (spkr_2_tz_name != NULL)
4180 strlcpy(speaker_device_tz_names.spkr_2_tz_name, spkr_2_tz_name,
4181 sizeof(speaker_device_tz_names.spkr_2_tz_name));
4182done:
4183 return ret;
4184}
Zhou Song68624eb2015-06-17 18:45:35 +08004185
Laxminath Kasambe641ab2015-07-24 20:27:42 +05304186int platform_get_wsa_mode (void *adev)
Zhou Song68624eb2015-06-17 18:45:35 +08004187{
4188 return 0;
4189}