blob: 1e1a5899daac93f0a8cd5fc2e2e0409c2ebe54c9 [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 */
ApurupaPattapub57da782014-04-08 10:41:07 -070068#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 1000 /* 1 sec */
69#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 80 /* 80 millisecs */
Alexy Josephaa54c872014-12-03 02:46:47 -080070#define PCM_OFFLOAD_BUFFER_DURATION_FOR_SMALL_BUFFERS 20 /* 20 millisecs */
71#define PCM_OFFLOAD_BUFFER_DURATION_MAX 1200 /* 1200 millisecs */
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080072
73/* MAX PCM fragment size cannot be increased further due
74 * to flinger's cblk size of 1mb,and it has to be a multiple of
75 * 24 - lcm of channels supported by DSP
76 */
77#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
ApurupaPattapub57da782014-04-08 10:41:07 -070078#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (4 * 1024)
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -080079
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -070080/*
81 * Offload buffer size for compress passthrough
82 */
83#define MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (2 * 1024)
84#define MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (8 * 1024)
85
Amit Shekhar45fbfa92015-02-26 17:48:00 -080086#define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
87#define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
Eric Laurentb23d5282013-05-14 15:27:20 -070088/*
Eric Laurentb23d5282013-05-14 15:27:20 -070089 * This file will have a maximum of 38 bytes:
90 *
91 * 4 bytes: number of audio blocks
92 * 4 bytes: total length of Short Audio Descriptor (SAD) blocks
93 * Maximum 10 * 3 bytes: SAD blocks
94 */
95#define MAX_SAD_BLOCKS 10
96#define SAD_BLOCK_SIZE 3
97
Walter Yang6f800052014-07-14 16:15:38 -070098#define MAX_CVD_VERSION_STRING_SIZE 100
99
Eric Laurentb23d5282013-05-14 15:27:20 -0700100/* EDID format ID for LPCM audio */
101#define EDID_FORMAT_LPCM 1
102
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700103/* fallback app type if the default app type from acdb loader fails */
104#define DEFAULT_APP_TYPE 0x11130
105
sangwoo1b9f4b32013-06-21 18:22:55 -0700106/* Retry for delay in FW loading*/
107#define RETRY_NUMBER 10
108#define RETRY_US 500000
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -0800109#define MAX_SND_CARD 8
sangwoo1b9f4b32013-06-21 18:22:55 -0700110
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700111#define SAMPLE_RATE_8KHZ 8000
112#define SAMPLE_RATE_16KHZ 16000
113
Ben Rombergera04fabc2014-11-14 12:16:03 -0800114#define MAX_SET_CAL_BYTE_SIZE 65536
115
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700116#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700117#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530118#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800119#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Ben Rombergera04fabc2014-11-14 12:16:03 -0800120#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
121#define AUDIO_PARAMETER_KEY_AUD_CALRESULT "cal_result"
122
123
Tanya Finkel00130052014-07-14 04:26:56 -0700124/* Query external audio device connection status */
125#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
126
127#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
128#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
129#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Anish Kumar55e6df22014-08-26 17:38:05 -0700130#define MAX_CAL_NAME 20
131
132char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
133 [WCD9XXX_ANC_CAL] = "anc_cal",
134 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
135 [WCD9XXX_MAD_CAL] = "mad_cal",
136};
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800137
138enum {
139 VOICE_FEATURE_SET_DEFAULT,
140 VOICE_FEATURE_SET_VOLUME_BOOST
141};
sangwoo53b2cf02013-07-25 19:18:44 -0700142
Eric Laurentb23d5282013-05-14 15:27:20 -0700143struct audio_block_header
144{
145 int reserved;
146 int length;
147};
148
Ben Rombergera04fabc2014-11-14 12:16:03 -0800149typedef struct acdb_audio_cal_cfg {
150 uint32_t persist;
151 uint32_t snd_dev_id;
152 audio_devices_t dev_id;
153 int32_t acdb_dev_id;
154 uint32_t app_type;
155 uint32_t topo_id;
156 uint32_t sampling_rate;
157 uint32_t cal_type;
158 uint32_t module_id;
159 uint32_t param_id;
160} acdb_audio_cal_cfg_t;
161
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800162/* Audio calibration related functions */
Eric Laurentb23d5282013-05-14 15:27:20 -0700163typedef void (*acdb_deallocate_t)();
Dhananjay Kumara3565b32014-07-23 01:12:48 +0530164typedef int (*acdb_init_t)(const char *, char *, int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700165typedef void (*acdb_send_audio_cal_t)(int, int, int , int);
Eric Laurentb23d5282013-05-14 15:27:20 -0700166typedef void (*acdb_send_voice_cal_t)(int, int);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800167typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700168typedef int (*acdb_get_default_app_type_t)(void);
Anish Kumar55e6df22014-08-26 17:38:05 -0700169typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data);
170acdb_loader_get_calibration_t acdb_loader_get_calibration;
Ben Rombergera04fabc2014-11-14 12:16:03 -0800171typedef int (*acdb_set_audio_cal_t) (void *, void *, uint32_t);
172typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*);
Eric Laurentb23d5282013-05-14 15:27:20 -0700173
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800174typedef struct codec_backend_cfg {
175 uint32_t sample_rate;
176 uint32_t bit_width;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530177 char *bitwidth_mixer_ctl;
178 char *samplerate_mixer_ctl;
179} codec_backend_cfg_t;
180
181typedef struct {
182 bool platform_na_prop_enabled;
183 bool ui_na_prop_enabled;
184} native_audio_prop;
185
186static native_audio_prop na_props = {0, 0};
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800187
Eric Laurentb23d5282013-05-14 15:27:20 -0700188struct platform_data {
189 struct audio_device *adev;
190 bool fluence_in_spkr_mode;
191 bool fluence_in_voice_call;
192 bool fluence_in_voice_rec;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800193 bool fluence_in_audio_rec;
Tanya Finkel00130052014-07-14 04:26:56 -0700194 bool external_spk_1;
195 bool external_spk_2;
196 bool external_mic;
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700197 int fluence_type;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800198 int fluence_mode;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530199 char fluence_cap[PROPERTY_VALUE_MAX];
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700200 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530201 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530202 bool ec_ref_enabled;
Helen Zeng6a16ad72014-02-23 22:04:44 -0800203 bool is_i2s_ext_modem;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700204 /* Audio calibration related functions */
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800205 void *acdb_handle;
206 int voice_feature_set;
207 acdb_init_t acdb_init;
208 acdb_deallocate_t acdb_deallocate;
209 acdb_send_audio_cal_t acdb_send_audio_cal;
Ben Rombergera04fabc2014-11-14 12:16:03 -0800210 acdb_set_audio_cal_t acdb_set_audio_cal;
211 acdb_get_audio_cal_t acdb_get_audio_cal;
Ben Rombergerc1dc70d2013-12-19 15:11:17 -0800212 acdb_send_voice_cal_t acdb_send_voice_cal;
213 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700214 acdb_get_default_app_type_t acdb_get_default_app_type;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700215
216 void *hw_info;
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800217 struct csd_data *csd;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -0700218 void *edid_info;
219 bool edid_valid;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530220 codec_backend_cfg_t current_backend_cfg[MAX_CODEC_BACKENDS];
Eric Laurentb23d5282013-05-14 15:27:20 -0700221};
222
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700223static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700224 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
225 DEEP_BUFFER_PCM_DEVICE},
226 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700227 LOWLATENCY_PCM_DEVICE},
228 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
229 MULTIMEDIA2_PCM_DEVICE},
Krishnankutty Kolathappillya43f96e2013-11-01 12:17:53 -0700230 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
231 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Subhash Chandra Bose Naripeddy16ff4f82014-04-01 21:03:10 -0700232#ifdef MULTIPLE_OFFLOAD_ENABLED
233 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] =
234 {PLAYBACK_OFFLOAD_DEVICE2, PLAYBACK_OFFLOAD_DEVICE2},
235 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] =
236 {PLAYBACK_OFFLOAD_DEVICE3, PLAYBACK_OFFLOAD_DEVICE3},
237 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] =
238 {PLAYBACK_OFFLOAD_DEVICE4, PLAYBACK_OFFLOAD_DEVICE4},
239 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] =
240 {PLAYBACK_OFFLOAD_DEVICE5, PLAYBACK_OFFLOAD_DEVICE5},
241 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] =
242 {PLAYBACK_OFFLOAD_DEVICE6, PLAYBACK_OFFLOAD_DEVICE6},
243 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] =
244 {PLAYBACK_OFFLOAD_DEVICE7, PLAYBACK_OFFLOAD_DEVICE7},
245 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] =
246 {PLAYBACK_OFFLOAD_DEVICE8, PLAYBACK_OFFLOAD_DEVICE8},
247 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] =
248 {PLAYBACK_OFFLOAD_DEVICE9, PLAYBACK_OFFLOAD_DEVICE9},
249#endif
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700250 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
Mingming Yine62d7842013-10-25 16:26:03 -0700251 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700252 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
253 LOWLATENCY_PCM_DEVICE},
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -0700254 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
255 MULTIMEDIA2_PCM_DEVICE},
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700256 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
Vimal Puthanveed5b4d3f12013-11-05 15:57:39 -0800257 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
Vimal Puthanveed47e64852013-12-20 13:23:39 -0800258 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700259 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
260 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
261 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
262 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Vicky Sehrawat7e4fc152014-02-12 17:58:59 -0800263 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Vidyakumar Athota0e109352015-02-12 17:38:22 -0800264 [USECASE_VOICEMMODE1_CALL] = {VOICEMMODE1_CALL_PCM_DEVICE,
265 VOICEMMODE1_CALL_PCM_DEVICE},
266 [USECASE_VOICEMMODE2_CALL] = {VOICEMMODE2_CALL_PCM_DEVICE,
267 VOICEMMODE2_CALL_PCM_DEVICE},
Narsinga Rao Chella05573b72013-11-15 15:21:40 -0800268 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
Shiv Maliyappanahallida107642013-10-17 11:16:13 -0700269 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
270 AUDIO_RECORD_PCM_DEVICE},
271 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
272 AUDIO_RECORD_PCM_DEVICE},
273 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
274 AUDIO_RECORD_PCM_DEVICE},
Helen Zenge56b4852013-12-03 16:54:40 -0800275 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
276 COMPRESS_CAPTURE_DEVICE},
277 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
278 COMPRESS_CAPTURE_DEVICE},
279 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
280 COMPRESS_CAPTURE_DEVICE},
Shiv Maliyappanahallif3b9a422013-10-22 16:38:08 -0700281 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
282 INCALL_MUSIC_UPLINK_PCM_DEVICE},
283 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
284 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700285 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
286 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700287
288 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
289 AFE_PROXY_RECORD_PCM_DEVICE},
290 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
291 AFE_PROXY_RECORD_PCM_DEVICE},
292
Eric Laurentb23d5282013-05-14 15:27:20 -0700293};
294
295/* Array to store sound devices */
296static const char * const device_table[SND_DEVICE_MAX] = {
297 [SND_DEVICE_NONE] = "none",
298 /* Playback sound devices */
299 [SND_DEVICE_OUT_HANDSET] = "handset",
300 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Tanya Finkel00130052014-07-14 04:26:56 -0700301 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
302 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Eric Laurentb23d5282013-05-14 15:27:20 -0700303 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
304 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800305 [SND_DEVICE_OUT_HEADPHONES_44_1] = "headphones-44.1",
Eric Laurentb23d5282013-05-14 15:27:20 -0700306 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Tanya Finkel00130052014-07-14 04:26:56 -0700307 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
308 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Eric Laurentb23d5282013-05-14 15:27:20 -0700309 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
310 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
311 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
312 [SND_DEVICE_OUT_HDMI] = "hdmi",
313 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
314 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700315 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700316 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
317 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
318 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700319 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700320 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
321 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
322 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700323 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700324 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
325 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
326 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
327 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
328 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
329 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700330 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Anish Kumar46c7b872014-09-09 01:49:44 -0700331 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Eric Laurentb23d5282013-05-14 15:27:20 -0700332
333 /* Capture sound devices */
334 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Tanya Finkel00130052014-07-14 04:26:56 -0700335 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Eric Laurentb23d5282013-05-14 15:27:20 -0700336 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800337 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
338 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
339 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800340 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800341 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
342 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
343 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800344 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800345 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
346 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
347 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800348 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800349 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
350 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
351 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
352 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700353 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
354 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
355 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
356 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700357 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700358 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700359 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Eric Laurentb23d5282013-05-14 15:27:20 -0700360 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700361 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700362 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800363 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700364 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
365 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
366 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700367 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
368
Eric Laurentb23d5282013-05-14 15:27:20 -0700369 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800370 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800371 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700372 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700373 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700374 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700375 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700376 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700377 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
378 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700379 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800380 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
381 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
382 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
383 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
384 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700385 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
386 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
387 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
388 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Eric Laurentb23d5282013-05-14 15:27:20 -0700389};
390
Amit Shekhar5a39c912014-10-14 15:39:30 -0700391// Platform specific backend bit width table
392static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
393
Eric Laurentb23d5282013-05-14 15:27:20 -0700394/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Ben Romberger55886882014-01-10 13:49:02 -0800395static int acdb_device_table[SND_DEVICE_MAX] = {
Eric Laurentb23d5282013-05-14 15:27:20 -0700396 [SND_DEVICE_NONE] = -1,
397 [SND_DEVICE_OUT_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800398 [SND_DEVICE_OUT_SPEAKER] = 14,
Tanya Finkel87af1a52015-03-27 14:54:23 -0700399 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 130,
400 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 130,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800401 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700402 [SND_DEVICE_OUT_HEADPHONES] = 10,
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800403 [SND_DEVICE_OUT_HEADPHONES_44_1] = 10,
Eric Laurentb23d5282013-05-14 15:27:20 -0700404 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530405 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 130,
406 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 130,
Eric Laurentb23d5282013-05-14 15:27:20 -0700407 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800408 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700409 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
410 [SND_DEVICE_OUT_HDMI] = 18,
Vidyakumar Athotac29d4ab2013-11-14 16:58:02 -0800411 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Eric Laurentb23d5282013-05-14 15:27:20 -0700412 [SND_DEVICE_OUT_BT_SCO] = 22,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700413 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Eric Laurentb23d5282013-05-14 15:27:20 -0700414 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
415 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
416 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700417 [SND_DEVICE_OUT_VOICE_TX] = 45,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700418 [SND_DEVICE_OUT_AFE_PROXY] = 0,
Vidyakumar Athotab9522202014-01-14 20:08:27 -0800419 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700420 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700421 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700422 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700423 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700424 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -0700425 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700426 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
427 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Anish Kumar46c7b872014-09-09 01:49:44 -0700428 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
429 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Eric Laurentb23d5282013-05-14 15:27:20 -0700430
431 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Tanya Finkel00130052014-07-14 04:26:56 -0700432 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800433 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
434 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
435 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800436 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800437 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
438 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
439 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800440 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800441 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
442 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
443 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800444 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800445 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
446 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
447 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Eric Laurentb23d5282013-05-14 15:27:20 -0700448 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800449 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Eric Laurentb23d5282013-05-14 15:27:20 -0700450 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
451 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
452 [SND_DEVICE_IN_HDMI_MIC] = 4,
453 [SND_DEVICE_IN_BT_SCO_MIC] = 21,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700454 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = 122,
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700455 [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700456 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = 123,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800457 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700458 [SND_DEVICE_IN_VOICE_DMIC] = 41,
Mingming Yin8e5a4f62013-10-07 15:23:41 -0700459 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
Vidyakumar Athotaadfe4e32013-12-13 14:51:26 -0800460 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Eric Laurentb23d5282013-05-14 15:27:20 -0700461 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
462 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
463 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700464 [SND_DEVICE_IN_VOICE_RX] = 44,
465
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800466 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -0800467 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -0800468 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
469 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -0700470 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700471 [SND_DEVICE_IN_CAPTURE_FM] = 0,
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -0700472 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -0700473 [SND_DEVICE_IN_QUAD_MIC] = 46,
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -0700474 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
475 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -0700476 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800477 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
478 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
479 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
480 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
481 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700482 [SND_DEVICE_IN_HANDSET_QMIC] = 125,
483 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
484 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
485 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = 129,
Eric Laurentb23d5282013-05-14 15:27:20 -0700486};
487
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700488struct name_to_index {
Ben Romberger61764e32014-01-10 13:49:02 -0800489 char name[100];
490 unsigned int index;
491};
492
493#define TO_NAME_INDEX(X) #X, X
494
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800495/* Used to get index from parsed string */
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700496static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Ben Romberger61764e32014-01-10 13:49:02 -0800497 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
498 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Tanya Finkel00130052014-07-14 04:26:56 -0700499 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
500 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Ben Romberger61764e32014-01-10 13:49:02 -0800501 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
502 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800503 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES_44_1)},
Ben Romberger61764e32014-01-10 13:49:02 -0800504 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Tanya Finkel00130052014-07-14 04:26:56 -0700505 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
506 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Ben Romberger61764e32014-01-10 13:49:02 -0800507 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
508 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
509 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
510 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
511 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
512 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
513 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
514 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
515 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
517 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
518 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
519 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
520 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
521 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
522 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
523 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
524 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
525 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
526 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
527 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Anish Kumar46c7b872014-09-09 01:49:44 -0700528 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Ben Romberger61764e32014-01-10 13:49:02 -0800529 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Tanya Finkel00130052014-07-14 04:26:56 -0700530 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Ben Romberger61764e32014-01-10 13:49:02 -0800531 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
532 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
533 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
534 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
535 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
536 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
537 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
538 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
539 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
545 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700552 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Ben Romberger61764e32014-01-10 13:49:02 -0800553 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700554 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Ben Romberger61764e32014-01-10 13:49:02 -0800555 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
556 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
559 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
560 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
561 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
562 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
568 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
569 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
570 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
571 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -0800573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
574 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
576 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Narsinga Rao Chella975572e2014-10-21 11:49:00 -0700578 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
579 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
580 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
581 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Ben Romberger61764e32014-01-10 13:49:02 -0800582};
583
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700584static char * backend_table[SND_DEVICE_MAX] = {0};
585
586static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
587 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
588 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
589 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
590 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
Alexy Joseph2f89cfa2014-10-06 12:15:01 -0700591#ifdef MULTIPLE_OFFLOAD_ENABLED
592 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
593 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
594 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
595 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
596 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
597 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
598 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
599 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
600#endif
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700601 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
602 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
603 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
604 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
605 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
606 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
607 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
608 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
609 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
610 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
611 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
612};
613
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700614#define NO_COLS 2
615#ifdef PLATFORM_APQ8084
616static int msm_device_to_be_id [][NO_COLS] = {
617 {AUDIO_DEVICE_OUT_EARPIECE , 2},
618 {AUDIO_DEVICE_OUT_SPEAKER , 2},
619 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
620 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
621 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
622 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
623 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
624 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
625 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
626 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
627 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
628 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
629 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
630 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
631 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
632 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
633 {AUDIO_DEVICE_OUT_PROXY , 9},
634 {AUDIO_DEVICE_OUT_FM , 7},
635 {AUDIO_DEVICE_OUT_FM_TX , 8},
636 {AUDIO_DEVICE_OUT_ALL , -1},
637 {AUDIO_DEVICE_NONE , -1},
638 {AUDIO_DEVICE_OUT_DEFAULT , -1},
639};
640#elif PLATFORM_MSM8994
641static int msm_device_to_be_id [][NO_COLS] = {
642 {AUDIO_DEVICE_OUT_EARPIECE , 2},
643 {AUDIO_DEVICE_OUT_SPEAKER , 2},
644 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
645 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
646 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 38},
647 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 38},
648 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 38},
649 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
650 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
651 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
652 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
653 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
654 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
655 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
656 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
657 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
658 {AUDIO_DEVICE_OUT_PROXY , 9},
659/* Add the correct be ids */
660 {AUDIO_DEVICE_OUT_FM , 7},
661 {AUDIO_DEVICE_OUT_FM_TX , 8},
662 {AUDIO_DEVICE_OUT_ALL , -1},
663 {AUDIO_DEVICE_NONE , -1},
664 {AUDIO_DEVICE_OUT_DEFAULT , -1},
665};
Pradnya Chaphekarf0b1cfe2015-04-15 16:52:49 -0700666#elif PLATFORM_MSM8996
667static int msm_device_to_be_id [][NO_COLS] = {
668 {AUDIO_DEVICE_OUT_EARPIECE , 2},
669 {AUDIO_DEVICE_OUT_SPEAKER , 2},
670 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
671 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
672 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
673 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
674 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
675 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
676 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
677 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
678 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
679 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
680 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
681 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
682 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
683 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
684 {AUDIO_DEVICE_OUT_PROXY , 9},
685/* Add the correct be ids */
686 {AUDIO_DEVICE_OUT_FM , 7},
687 {AUDIO_DEVICE_OUT_FM_TX , 8},
688 {AUDIO_DEVICE_OUT_ALL , -1},
689 {AUDIO_DEVICE_NONE , -1},
690 {AUDIO_DEVICE_OUT_DEFAULT , -1},
691};
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700692#else
693static int msm_device_to_be_id [][NO_COLS] = {
694 {AUDIO_DEVICE_NONE, -1},
695};
696#endif
697static int msm_be_id_array_len =
698 sizeof(msm_device_to_be_id) / sizeof(msm_device_to_be_id[0]);
699
700
Haynes Mathew George7ff216f2013-09-11 19:51:41 -0700701#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
702#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
703
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530704void platform_set_echo_reference(void *platform, bool enable)
Eric Laurentb23d5282013-05-14 15:27:20 -0700705{
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530706 struct platform_data *my_data = (struct platform_data *)platform;
707 struct audio_device *adev = my_data->adev;
708
Ravi Kumar Alamandad1c85bb2014-11-17 18:36:24 -0800709 if (my_data->ec_ref_enabled) {
710 my_data->ec_ref_enabled = false;
711 ALOGV("%s: disabling echo-reference", __func__);
712 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530713 }
Eric Laurentb23d5282013-05-14 15:27:20 -0700714
Ravi Kumar Alamandad1c85bb2014-11-17 18:36:24 -0800715 if (enable) {
716 my_data->ec_ref_enabled = true;
717 ALOGD("%s: enabling echo-reference", __func__);
718 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
719 }
720
Eric Laurentb23d5282013-05-14 15:27:20 -0700721}
722
Helen Zeng6a16ad72014-02-23 22:04:44 -0800723static struct csd_data *open_csd_client(bool i2s_ext_modem)
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800724{
725 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
726
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -0700727 if (!csd) {
728 ALOGE("failed to allocate csd_data mem");
729 return NULL;
730 }
731
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800732 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
733 if (csd->csd_client == NULL) {
734 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
735 goto error;
736 } else {
737 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
738
739 csd->deinit = (deinit_t)dlsym(csd->csd_client,
740 "csd_client_deinit");
741 if (csd->deinit == NULL) {
742 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
743 dlerror());
744 goto error;
745 }
746 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
747 "csd_client_disable_device");
748 if (csd->disable_device == NULL) {
749 ALOGE("%s: dlsym error %s for csd_client_disable_device",
750 __func__, dlerror());
751 goto error;
752 }
Vidyakumar Athota545dbd32013-11-13 17:30:53 -0800753 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
754 "csd_client_enable_device_config");
755 if (csd->enable_device_config == NULL) {
756 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
757 __func__, dlerror());
758 goto error;
759 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800760 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
761 "csd_client_enable_device");
762 if (csd->enable_device == NULL) {
763 ALOGE("%s: dlsym error %s for csd_client_enable_device",
764 __func__, dlerror());
765 goto error;
766 }
767 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
768 "csd_client_start_voice");
769 if (csd->start_voice == NULL) {
770 ALOGE("%s: dlsym error %s for csd_client_start_voice",
771 __func__, dlerror());
772 goto error;
773 }
774 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
775 "csd_client_stop_voice");
776 if (csd->stop_voice == NULL) {
777 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
778 __func__, dlerror());
779 goto error;
780 }
781 csd->volume = (volume_t)dlsym(csd->csd_client,
782 "csd_client_volume");
783 if (csd->volume == NULL) {
784 ALOGE("%s: dlsym error %s for csd_client_volume",
785 __func__, dlerror());
786 goto error;
787 }
788 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
789 "csd_client_mic_mute");
790 if (csd->mic_mute == NULL) {
791 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
792 __func__, dlerror());
793 goto error;
794 }
795 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
796 "csd_client_slow_talk");
797 if (csd->slow_talk == NULL) {
798 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
799 __func__, dlerror());
800 goto error;
801 }
802 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
803 "csd_client_start_playback");
804 if (csd->start_playback == NULL) {
805 ALOGE("%s: dlsym error %s for csd_client_start_playback",
806 __func__, dlerror());
807 goto error;
808 }
809 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
810 "csd_client_stop_playback");
811 if (csd->stop_playback == NULL) {
812 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
813 __func__, dlerror());
814 goto error;
815 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700816 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
817 if (csd->set_lch == NULL) {
818 ALOGE("%s: dlsym error %s for csd_client_set_lch",
819 __func__, dlerror());
820 /* Ignore the error as this is not mandatory function for
821 * basic voice call to work.
822 */
823 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800824 csd->start_record = (start_record_t)dlsym(csd->csd_client,
825 "csd_client_start_record");
826 if (csd->start_record == NULL) {
827 ALOGE("%s: dlsym error %s for csd_client_start_record",
828 __func__, dlerror());
829 goto error;
830 }
831 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
832 "csd_client_stop_record");
833 if (csd->stop_record == NULL) {
834 ALOGE("%s: dlsym error %s for csd_client_stop_record",
835 __func__, dlerror());
836 goto error;
837 }
Helen Zeng6a16ad72014-02-23 22:04:44 -0800838
839 csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
840 "csd_client_get_sample_rate");
841 if (csd->get_sample_rate == NULL) {
842 ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
843 __func__, dlerror());
844
845 goto error;
846 }
847
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800848 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
849
850 if (csd->init == NULL) {
851 ALOGE("%s: dlsym error %s for csd_client_init",
852 __func__, dlerror());
853 goto error;
854 } else {
Helen Zeng6a16ad72014-02-23 22:04:44 -0800855 csd->init(i2s_ext_modem);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -0800856 }
857 }
858 return csd;
859
860error:
861 free(csd);
862 csd = NULL;
863 return csd;
864}
865
866void close_csd_client(struct csd_data *csd)
867{
868 if (csd != NULL) {
869 csd->deinit();
870 dlclose(csd->csd_client);
871 free(csd);
872 csd = NULL;
873 }
874}
875
Helen Zeng6a16ad72014-02-23 22:04:44 -0800876static bool platform_is_i2s_ext_modem(const char *snd_card_name,
877 struct platform_data *plat_data)
878{
879 plat_data->is_i2s_ext_modem = false;
880
881 if (!strncmp(snd_card_name, "apq8084-taiko-i2s-mtp-snd-card",
882 sizeof("apq8084-taiko-i2s-mtp-snd-card")) ||
883 !strncmp(snd_card_name, "apq8084-taiko-i2s-cdp-snd-card",
884 sizeof("apq8084-taiko-i2s-cdp-snd-card"))) {
885 plat_data->is_i2s_ext_modem = true;
886 }
887 ALOGV("%s, is_i2s_ext_modem:%d",__func__, plat_data->is_i2s_ext_modem);
888
889 return plat_data->is_i2s_ext_modem;
Helen Zeng008aebd2014-02-23 19:13:12 -0800890}
891
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -0700892static void set_platform_defaults()
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700893{
894 int32_t dev;
895 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
896 backend_table[dev] = NULL;
897 }
Amit Shekhar5a39c912014-10-14 15:39:30 -0700898 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +0530899 backend_bit_width_table[dev] = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Amit Shekhar5a39c912014-10-14 15:39:30 -0700900 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700901
902 // TBD - do these go to the platform-info.xml file.
903 // will help in avoiding strdups here
904 backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
905 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700906 backend_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
907 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700908 backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
909 backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
910 backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
911 backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -0700912 backend_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
913 backend_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
914
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700915 backend_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
916 backend_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones");
917 backend_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
918 strdup("speaker-and-usb-headphones");
919 backend_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
920 backend_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
921 backend_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -0800922 backend_table[SND_DEVICE_OUT_HEADPHONES] = strdup("headphones");
923 backend_table[SND_DEVICE_OUT_HEADPHONES_44_1] = strdup("headphones-44.1");
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -0700924}
925
Walter Yang6f800052014-07-14 16:15:38 -0700926void get_cvd_version(char *cvd_version, struct audio_device *adev)
927{
928 struct mixer_ctl *ctl;
929 int count;
930 int ret = 0;
931
932 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
933 if (!ctl) {
934 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
935 goto done;
936 }
937 mixer_ctl_update(ctl);
938
939 count = mixer_ctl_get_num_values(ctl);
940 if (count > MAX_CVD_VERSION_STRING_SIZE)
941 count = MAX_CVD_VERSION_STRING_SIZE;
942
943 ret = mixer_ctl_get_array(ctl, cvd_version, count);
944 if (ret != 0) {
945 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
946 goto done;
947 }
948
949done:
950 return;
951}
952
Anish Kumar55e6df22014-08-26 17:38:05 -0700953static int hw_util_open(int card_no)
954{
955 int fd = -1;
956 char dev_name[256];
957
958 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
959 card_no, WCD9XXX_CODEC_HWDEP_NODE);
960 ALOGD("%s Opening device %s\n", __func__, dev_name);
961 fd = open(dev_name, O_WRONLY);
962 if (fd < 0) {
963 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
964 return fd;
965 }
966 ALOGD("%s success", __func__);
967 return fd;
968}
969
970struct param_data {
971 int use_case;
972 int acdb_id;
973 int get_size;
974 int buff_size;
975 int data_size;
976 void *buff;
977};
978
979static int send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration, int fd)
980{
981 int ret = 0, type;
982
983 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
984 struct wcdcal_ioctl_buffer codec_buffer;
985 struct param_data calib;
986
987 if (!strcmp(cal_name_info[type], "mad_cal"))
988 calib.acdb_id = SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID;
989 calib.get_size = 1;
990 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
991 &calib);
992 if (ret < 0) {
993 ALOGE("%s get_calibration failed\n", __func__);
994 return ret;
995 }
996 calib.get_size = 0;
997 calib.buff = malloc(calib.buff_size);
998 ret = acdb_loader_get_calibration(cal_name_info[type],
999 sizeof(struct param_data), &calib);
1000 if (ret < 0) {
1001 ALOGE("%s get_calibration failed\n", __func__);
1002 free(calib.buff);
1003 return ret;
1004 }
1005 codec_buffer.buffer = calib.buff;
1006 codec_buffer.size = calib.data_size;
1007 codec_buffer.cal_type = type;
1008 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
1009 ALOGE("Failed to call ioctl for %s err=%d",
1010 cal_name_info[type], errno);
1011 ALOGD("%s cal sent for %s", __func__, cal_name_info[type]);
1012 free(calib.buff);
1013 }
1014 return ret;
1015}
1016
1017static void audio_hwdep_send_cal(struct platform_data *plat_data)
1018{
1019 int fd;
1020
1021 fd = hw_util_open(plat_data->adev->snd_card);
1022 if (fd == -1) {
1023 ALOGE("%s error open\n", __func__);
1024 return;
1025 }
1026
1027 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
1028 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
1029
1030 if (acdb_loader_get_calibration == NULL) {
1031 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
1032 dlerror());
1033 return;
1034 }
1035 if (send_codec_cal(acdb_loader_get_calibration, fd) < 0)
1036 ALOGE("%s: Could not send anc cal", __FUNCTION__);
1037}
1038
Eric Laurentb23d5282013-05-14 15:27:20 -07001039void *platform_init(struct audio_device *adev)
1040{
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07001041 char platform[PROPERTY_VALUE_MAX];
1042 char baseband[PROPERTY_VALUE_MAX];
Eric Laurentb23d5282013-05-14 15:27:20 -07001043 char value[PROPERTY_VALUE_MAX];
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001044 struct platform_data *my_data = NULL;
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -07001045 int retry_num = 0, snd_card_num = 0, key = 0, ret = 0;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001046 const char *snd_card_name;
Walter Yang6f800052014-07-14 16:15:38 -07001047 char *cvd_version = NULL;
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -07001048 char *snd_internal_name = NULL;
1049 char *tmp = NULL;
1050 char mixer_xml_file[MIXER_PATH_MAX_LENGTH]= {0};
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05301051 const char *mixer_ctl_name = "Set HPX ActiveBe";
1052 struct mixer_ctl *ctl = NULL;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08001053 int idx;
sangwoo1b9f4b32013-06-21 18:22:55 -07001054
Eric Laurentb23d5282013-05-14 15:27:20 -07001055 my_data = calloc(1, sizeof(struct platform_data));
1056
Haynes Mathew Georgeb51ceb12014-06-30 13:56:18 -07001057 if (!my_data) {
1058 ALOGE("failed to allocate platform data");
1059 return NULL;
1060 }
1061
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001062 while (snd_card_num < MAX_SND_CARD) {
1063 adev->mixer = mixer_open(snd_card_num);
1064
1065 while (!adev->mixer && retry_num < RETRY_NUMBER) {
1066 usleep(RETRY_US);
1067 adev->mixer = mixer_open(snd_card_num);
1068 retry_num++;
1069 }
1070
1071 if (!adev->mixer) {
1072 ALOGE("%s: Unable to open the mixer card: %d", __func__,
1073 snd_card_num);
1074 retry_num = 0;
1075 snd_card_num++;
1076 continue;
1077 }
1078
1079 snd_card_name = mixer_get_name(adev->mixer);
1080 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
1081
1082 my_data->hw_info = hw_info_init(snd_card_name);
1083 if (!my_data->hw_info) {
1084 ALOGE("%s: Failed to init hardware info", __func__);
1085 } else {
Helen Zeng6a16ad72014-02-23 22:04:44 -08001086 if (platform_is_i2s_ext_modem(snd_card_name, my_data)) {
1087 ALOGD("%s: Call MIXER_XML_PATH_I2S", __func__);
1088
1089 adev->audio_route = audio_route_init(snd_card_num,
1090 MIXER_XML_PATH_I2S);
Apoorv Raghuvanshia433fb52015-03-16 15:22:30 -07001091 } else {
1092 /* Get the codec internal name from the sound card name
1093 * and form the mixer paths file name dynamically. This
1094 * is generic way of picking any codec name based mixer
1095 * files in future with no code change. This code
1096 * assumes mixer files are formed with format as
1097 * mixer_paths_internalcodecname.xml
1098
1099 * If this dynamically read mixer files fails to open then it
1100 * falls back to default mixer file i.e mixer_paths.xml. This is
1101 * done to preserve backward compatibility but not mandatory as
1102 * long as the mixer files are named as per above assumption.
1103 */
1104
1105 snd_internal_name = strtok_r(snd_card_name, "-", &tmp);
1106 if (snd_internal_name != NULL)
1107 snd_internal_name = strtok_r(NULL, "-", &tmp);
1108
1109 if (snd_internal_name != NULL) {
1110 strlcpy(mixer_xml_file, MIXER_XML_BASE_STRING,
1111 MIXER_PATH_MAX_LENGTH);
1112 strlcat(mixer_xml_file, MIXER_FILE_DELIMITER,
1113 MIXER_PATH_MAX_LENGTH);
1114 strlcat(mixer_xml_file, snd_internal_name,
1115 MIXER_PATH_MAX_LENGTH);
1116 strlcat(mixer_xml_file, MIXER_FILE_EXT,
1117 MIXER_PATH_MAX_LENGTH);
1118 } else {
1119 strlcpy(mixer_xml_file, MIXER_XML_DEFAULT_PATH,
1120 MIXER_PATH_MAX_LENGTH);
1121 }
1122
1123 if (F_OK == access(mixer_xml_file, 0)) {
1124 ALOGD("%s: Loading mixer file: %s", __func__, mixer_xml_file);
1125 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_file,
1126 MIXER_XML_PATH_AUXPCM) == -ENOSYS)
1127 adev->audio_route = audio_route_init(snd_card_num,
1128 mixer_xml_file);
1129 } else {
1130 ALOGD("%s: Loading default mixer file", __func__);
1131 if(audio_extn_read_xml(adev, snd_card_num, MIXER_XML_DEFAULT_PATH,
1132 MIXER_XML_PATH_AUXPCM) == -ENOSYS)
1133 adev->audio_route = audio_route_init(snd_card_num,
1134 MIXER_XML_DEFAULT_PATH);
1135 }
Helen Zeng6a16ad72014-02-23 22:04:44 -08001136 }
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001137 if (!adev->audio_route) {
1138 ALOGE("%s: Failed to init audio route controls, aborting.",
1139 __func__);
1140 free(my_data);
1141 return NULL;
1142 }
1143 adev->snd_card = snd_card_num;
1144 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1145 break;
1146 }
1147 retry_num = 0;
1148 snd_card_num++;
1149 }
1150
1151 if (snd_card_num >= MAX_SND_CARD) {
1152 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1153 free(my_data);
1154 return NULL;
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001155 }
1156
Eric Laurentb23d5282013-05-14 15:27:20 -07001157 my_data->adev = adev;
Eric Laurentb23d5282013-05-14 15:27:20 -07001158 my_data->fluence_in_spkr_mode = false;
1159 my_data->fluence_in_voice_call = false;
1160 my_data->fluence_in_voice_rec = false;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001161 my_data->fluence_in_audio_rec = false;
Tanya Finkel00130052014-07-14 04:26:56 -07001162 my_data->external_spk_1 = false;
1163 my_data->external_spk_2 = false;
1164 my_data->external_mic = false;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001165 my_data->fluence_type = FLUENCE_NONE;
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001166 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301167 my_data->slowtalk = false;
1168 my_data->hd_voice = false;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07001169 my_data->edid_info = NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001170
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301171 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
1172 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001173 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301174 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001175 my_data->fluence_type = FLUENCE_DUAL_MIC;
1176 } else {
1177 my_data->fluence_type = FLUENCE_NONE;
Eric Laurentb23d5282013-05-14 15:27:20 -07001178 }
1179
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001180 if (my_data->fluence_type != FLUENCE_NONE) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001181 property_get("persist.audio.fluence.voicecall",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001182 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001183 my_data->fluence_in_voice_call = true;
1184 }
1185
1186 property_get("persist.audio.fluence.voicerec",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001187 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001188 my_data->fluence_in_voice_rec = true;
1189 }
1190
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08001191 property_get("persist.audio.fluence.audiorec",value,"");
1192 if (!strncmp("true", value, sizeof("true"))) {
1193 my_data->fluence_in_audio_rec = true;
1194 }
1195
Eric Laurentb23d5282013-05-14 15:27:20 -07001196 property_get("persist.audio.fluence.speaker",value,"");
Mingming Yin8e5a4f62013-10-07 15:23:41 -07001197 if (!strncmp("true", value, sizeof("true"))) {
Eric Laurentb23d5282013-05-14 15:27:20 -07001198 my_data->fluence_in_spkr_mode = true;
1199 }
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08001200
1201 property_get("persist.audio.fluence.mode",value,"");
1202 if (!strncmp("broadside", value, sizeof("broadside"))) {
1203 my_data->fluence_mode = FLUENCE_BROADSIDE;
1204 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001205 }
Dhananjay Kumara3565b32014-07-23 01:12:48 +05301206 property_get("audio.ds1.metainfo.key",value,"0");
1207 key = atoi(value);
Eric Laurentb23d5282013-05-14 15:27:20 -07001208
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001209 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Eric Laurentb23d5282013-05-14 15:27:20 -07001210 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1211 if (my_data->acdb_handle == NULL) {
1212 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1213 } else {
1214 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1215 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1216 "acdb_loader_deallocate_ACDB");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001217 if (!my_data->acdb_deallocate)
1218 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1219 __func__, LIB_ACDB_LOADER);
1220
Eric Laurentb23d5282013-05-14 15:27:20 -07001221 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 -07001222 "acdb_loader_send_audio_cal_v2");
Eric Laurentb23d5282013-05-14 15:27:20 -07001223 if (!my_data->acdb_send_audio_cal)
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001224 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Eric Laurentb23d5282013-05-14 15:27:20 -07001225 __func__, LIB_ACDB_LOADER);
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001226
Ben Rombergera04fabc2014-11-14 12:16:03 -08001227 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1228 "acdb_loader_set_audio_cal_v2");
1229 if (!my_data->acdb_set_audio_cal)
1230 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1231 __func__, LIB_ACDB_LOADER);
1232
1233 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
1234 "acdb_loader_get_audio_cal_v2");
1235 if (!my_data->acdb_get_audio_cal)
1236 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
1237 __func__, LIB_ACDB_LOADER);
1238
Eric Laurentb23d5282013-05-14 15:27:20 -07001239 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1240 "acdb_loader_send_voice_cal");
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08001241 if (!my_data->acdb_send_voice_cal)
1242 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1243 __func__, LIB_ACDB_LOADER);
1244
1245 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1246 "acdb_loader_reload_vocvoltable");
1247 if (!my_data->acdb_reload_vocvoltable)
1248 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1249 __func__, LIB_ACDB_LOADER);
1250
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001251 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
1252 my_data->acdb_handle,
1253 "acdb_loader_get_default_app_type");
1254 if (!my_data->acdb_get_default_app_type)
1255 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1256 __func__, LIB_ACDB_LOADER);
1257
Eric Laurentb23d5282013-05-14 15:27:20 -07001258 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Ben Romberger490d3472014-01-15 17:11:59 -08001259 "acdb_loader_init_v2");
Walter Yang6f800052014-07-14 16:15:38 -07001260 if (my_data->acdb_init == NULL) {
Ben Romberger490d3472014-01-15 17:11:59 -08001261 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Walter Yang6f800052014-07-14 16:15:38 -07001262 goto acdb_init_fail;
1263 }
1264
1265 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1266 if (!cvd_version)
1267 ALOGE("failed to allocate cvd_version");
Eric Laurentb23d5282013-05-14 15:27:20 -07001268 else
Walter Yang6f800052014-07-14 16:15:38 -07001269 get_cvd_version(cvd_version, adev);
1270
Dhananjay Kumara3565b32014-07-23 01:12:48 +05301271 my_data->acdb_init(snd_card_name, cvd_version, key);
Walter Yang6f800052014-07-14 16:15:38 -07001272 if (cvd_version)
1273 free(cvd_version);
Eric Laurentb23d5282013-05-14 15:27:20 -07001274 }
1275
Satish Babu Patakokilabbd4e9d2015-05-13 22:08:06 +05301276 /* Configure active back end for HPX*/
1277 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1278 if (ctl) {
1279 ALOGI(" sending HPX Active BE information ");
1280 mixer_ctl_set_value(ctl, 0, true);
1281 }
1282
Walter Yang6f800052014-07-14 16:15:38 -07001283acdb_init_fail:
1284
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001285 set_platform_defaults();
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001286
Ben Romberger55886882014-01-10 13:49:02 -08001287 /* Initialize ACDB ID's */
Helen Zeng6a16ad72014-02-23 22:04:44 -08001288 if (my_data->is_i2s_ext_modem)
1289 platform_info_init(PLATFORM_INFO_XML_PATH_I2S);
1290 else
1291 platform_info_init(PLATFORM_INFO_XML_PATH);
Ben Romberger55886882014-01-10 13:49:02 -08001292
Vidyakumar Athota77327dd2014-08-07 16:44:25 -07001293 /* If platform is apq8084 and baseband is MDM, load CSD Client specific
1294 * symbols. Voice call is handled by MDM and apps processor talks to
1295 * MDM through CSD Client
1296 */
1297 property_get("ro.board.platform", platform, "");
1298 property_get("ro.baseband", baseband, "");
1299 if (!strncmp("apq8084", platform, sizeof("apq8084")) &&
1300 !strncmp("mdm", baseband, (sizeof("mdm")-1))) {
1301 my_data->csd = open_csd_client(my_data->is_i2s_ext_modem);
1302 } else {
1303 my_data->csd = NULL;
1304 }
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001305
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001306 /* init usb */
1307 audio_extn_usb_init(adev);
Apoorv Raghuvanshi84fa2fe2013-12-04 11:57:47 -08001308 /* update sound cards appropriately */
1309 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001310
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001311 /* init dap hal */
1312 audio_extn_dap_hal_init(adev->snd_card);
1313
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07001314 /* Read one time ssr property */
Mingming Yin49be8032013-12-19 12:51:25 -08001315 audio_extn_ssr_update_enabled();
Gopikrishnaiah Anandanf538cef2013-10-28 14:06:03 -07001316 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301317
1318 audio_extn_dolby_set_license(adev);
Anish Kumar55e6df22014-08-26 17:38:05 -07001319 audio_hwdep_send_cal(my_data);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301320
Lior Barenboim0b61bc72014-05-13 13:01:37 +03001321 /* init audio device arbitration */
1322 audio_extn_dev_arbi_init();
1323
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08001324 /* initialize backend config */
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301325 for (idx = 0; idx < MAX_CODEC_BACKENDS; idx++) {
1326 my_data->current_backend_cfg[idx].sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
1327 if (idx == HEADPHONE_44_1_BACKEND)
1328 my_data->current_backend_cfg[idx].sample_rate = OUTPUT_SAMPLING_RATE_44100;
1329 my_data->current_backend_cfg[idx].bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08001330 }
1331
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301332 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].bitwidth_mixer_ctl =
1333 strdup("SLIM_0_RX Format");
1334 my_data->current_backend_cfg[DEFAULT_CODEC_BACKEND].samplerate_mixer_ctl =
1335 strdup("SLIM_0_RX SampleRate");
1336
1337 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].bitwidth_mixer_ctl =
1338 strdup("SLIM_5_RX Format");
1339 my_data->current_backend_cfg[HEADPHONE_44_1_BACKEND].samplerate_mixer_ctl =
1340 strdup("SLIM_5_RX SampleRate");
1341
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07001342 my_data->edid_info = NULL;
Eric Laurentb23d5282013-05-14 15:27:20 -07001343 return my_data;
1344}
1345
1346void platform_deinit(void *platform)
1347{
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001348 struct platform_data *my_data = (struct platform_data *)platform;
1349
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07001350 if (my_data->edid_info) {
1351 free(my_data->edid_info);
1352 my_data->edid_info = NULL;
1353 }
1354
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001355 hw_info_deinit(my_data->hw_info);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001356 close_csd_client(my_data->csd);
1357
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001358 int32_t dev;
1359 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1360 if (backend_table[dev]) {
1361 free(backend_table[dev]);
1362 backend_table[dev]= NULL;
1363 }
1364 }
1365
Lior Barenboim0b61bc72014-05-13 13:01:37 +03001366 /* deinit audio device arbitration */
1367 audio_extn_dev_arbi_deinit();
1368
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07001369 if (my_data->edid_info) {
1370 free(my_data->edid_info);
1371 my_data->edid_info = NULL;
1372 }
1373
Eric Laurentb23d5282013-05-14 15:27:20 -07001374 free(platform);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07001375 /* deinit usb */
1376 audio_extn_usb_deinit();
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07001377 audio_extn_dap_hal_deinit();
Eric Laurentb23d5282013-05-14 15:27:20 -07001378}
1379
1380const char *platform_get_snd_device_name(snd_device_t snd_device)
1381{
1382 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1383 return device_table[snd_device];
1384 else
1385 return "";
1386}
1387
Laxminath Kasam44f49402015-05-29 18:37:11 +05301388const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
1389{
1390 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1391 return speaker_device_tz_names.spkr_1_tz_name;
1392 else
1393 return "";
1394}
1395
1396const char *platform_get_spkr_2_tz_name(snd_device_t snd_device)
1397{
1398 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1399 return speaker_device_tz_names.spkr_2_tz_name;
1400 else
1401 return "";
1402}
1403
Ravi Kumar Alamanda48c921d2013-10-29 06:07:44 -07001404int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1405 char *device_name)
1406{
1407 struct platform_data *my_data = (struct platform_data *)platform;
1408
1409 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1410 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1411 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1412 } else {
1413 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
1414 return -EINVAL;
1415 }
1416
1417 return 0;
1418}
1419
Eric Laurentb23d5282013-05-14 15:27:20 -07001420void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
1421{
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001422 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1423 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1424 return;
1425 }
1426
1427 const char * suffix = backend_table[snd_device];
1428
1429 if (suffix != NULL) {
1430 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
1431 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001432 }
Eric Laurentb23d5282013-05-14 15:27:20 -07001433}
1434
1435int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1436{
1437 int device_id;
1438 if (device_type == PCM_PLAYBACK)
1439 device_id = pcm_device_table[usecase][0];
1440 else
1441 device_id = pcm_device_table[usecase][1];
1442 return device_id;
1443}
1444
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001445static int find_index(struct name_to_index * table, int32_t len, const char * name)
Ben Romberger61764e32014-01-10 13:49:02 -08001446{
1447 int ret = 0;
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001448 int32_t i;
Ben Romberger61764e32014-01-10 13:49:02 -08001449
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001450 if (table == NULL) {
1451 ALOGE("%s: table is NULL", __func__);
Ben Romberger61764e32014-01-10 13:49:02 -08001452 ret = -ENODEV;
1453 goto done;
1454 }
1455
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001456 if (name == NULL) {
1457 ALOGE("null key");
1458 ret = -ENODEV;
1459 goto done;
1460 }
1461
1462 for (i=0; i < len; i++) {
1463 const char* tn = table[i].name;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001464 size_t len = strlen(tn);
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001465 if (strncmp(tn, name, len) == 0) {
1466 if (strlen(name) != len) {
1467 continue; // substring
1468 }
1469 ret = table[i].index;
Ben Romberger61764e32014-01-10 13:49:02 -08001470 goto done;
1471 }
1472 }
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001473 ALOGE("%s: Could not find index for name = %s",
1474 __func__, name);
Ben Romberger61764e32014-01-10 13:49:02 -08001475 ret = -ENODEV;
1476done:
1477 return ret;
1478}
1479
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301480int platform_set_fluence_type(void *platform, char *value)
1481{
1482 int ret = 0;
1483 int fluence_type = FLUENCE_NONE;
1484 int fluence_flag = NONE_FLAG;
1485 struct platform_data *my_data = (struct platform_data *)platform;
1486 struct audio_device *adev = my_data->adev;
1487
1488 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
1489
1490 /* only dual mic turn on and off is supported as of now through setparameters */
1491 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
1492 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
1493 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
1494 ALOGV("fluence dualmic feature enabled \n");
1495 fluence_type = FLUENCE_DUAL_MIC;
1496 fluence_flag = DMIC_FLAG;
1497 } else {
1498 ALOGE("%s: Failed to set DUALMIC", __func__);
1499 ret = -1;
1500 goto done;
1501 }
1502 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
1503 ALOGV("fluence disabled");
1504 fluence_type = FLUENCE_NONE;
1505 } else {
1506 ALOGE("Invalid fluence value : %s",value);
1507 ret = -1;
1508 goto done;
1509 }
1510
1511 if (fluence_type != my_data->fluence_type) {
1512 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
1513 my_data->fluence_type = fluence_type;
1514 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
1515 }
1516done:
1517 return ret;
1518}
1519
1520int platform_get_fluence_type(void *platform, char *value, uint32_t len)
1521{
1522 int ret = 0;
1523 struct platform_data *my_data = (struct platform_data *)platform;
1524
1525 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1526 strlcpy(value, "quadmic", len);
1527 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1528 strlcpy(value, "dualmic", len);
1529 } else if (my_data->fluence_type == FLUENCE_NONE) {
1530 strlcpy(value, "none", len);
1531 } else
1532 ret = -1;
1533
1534 return ret;
1535}
1536
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07001537int platform_get_snd_device_index(char *device_name)
1538{
1539 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1540}
1541
1542int platform_get_usecase_index(const char *usecase_name)
1543{
1544 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1545}
1546
Ben Romberger55886882014-01-10 13:49:02 -08001547int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1548{
1549 int ret = 0;
1550
1551 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1552 ALOGE("%s: Invalid snd_device = %d",
1553 __func__, snd_device);
1554 ret = -EINVAL;
1555 goto done;
1556 }
1557
1558 acdb_device_table[snd_device] = acdb_id;
1559done:
1560 return ret;
1561}
1562
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001563int platform_get_default_app_type(void *platform)
1564{
1565 struct platform_data *my_data = (struct platform_data *)platform;
1566
1567 if (my_data->acdb_get_default_app_type)
1568 return my_data->acdb_get_default_app_type();
1569 else
1570 return DEFAULT_APP_TYPE;
1571}
1572
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001573int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1574{
1575 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1576 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1577 return -EINVAL;
1578 }
1579 return acdb_device_table[snd_device];
1580}
1581
Amit Shekhar5a39c912014-10-14 15:39:30 -07001582int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
1583{
1584 int ret = 0;
1585
1586 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1587 ALOGE("%s: Invalid snd_device = %d",
1588 __func__, snd_device);
1589 ret = -EINVAL;
1590 goto done;
1591 }
1592
1593 backend_bit_width_table[snd_device] = bit_width;
1594done:
1595 return ret;
1596}
1597
1598int platform_get_snd_device_bit_width(snd_device_t snd_device)
1599{
1600 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1601 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1602 return DEFAULT_OUTPUT_SAMPLING_RATE;
1603 }
1604 return backend_bit_width_table[snd_device];
1605}
1606
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05301607int platform_set_native_support(bool codec_support)
1608{
1609 na_props.platform_na_prop_enabled = na_props.ui_na_prop_enabled
1610 = codec_support;
1611 ALOGV("%s: na_props.platform_na_prop_enabled: %d", __func__,
1612 na_props.platform_na_prop_enabled);
1613 return 0;
1614}
1615
1616int platform_get_native_support()
1617{
1618 int ret;
1619 if (na_props.platform_na_prop_enabled) {
1620 ret = na_props.ui_na_prop_enabled;
1621 } else {
1622 ret = na_props.platform_na_prop_enabled;
1623 }
1624 ALOGV("%s: na_props.ui_na_prop_enabled: %d", __func__,
1625 na_props.ui_na_prop_enabled);
1626 return ret;
1627}
1628
1629void native_audio_get_params(struct str_parms *query,
1630 struct str_parms *reply,
1631 char *value, int len)
1632{
1633 int ret;
1634 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1635 value, len);
1636 if (ret >= 0) {
1637 if (na_props.platform_na_prop_enabled) {
1638 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1639 na_props.ui_na_prop_enabled ? "true" : "false");
1640 ALOGV("%s: na_props.ui_na_prop_enabled: %d", __func__,
1641 na_props.ui_na_prop_enabled);
1642 } else {
1643 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1644 "false");
1645 ALOGV("%s: native audio not supported: %d", __func__,
1646 na_props.platform_na_prop_enabled);
1647 }
1648 }
1649}
1650
1651int native_audio_set_params(struct platform_data *platform,
1652 struct str_parms *parms, char *value, int len)
1653{
1654 int ret = 0;
1655 struct audio_usecase *usecase;
1656 struct listnode *node;
1657
1658 ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO,
1659 value, len);
1660 if (ret >= 0) {
1661 if (na_props.platform_na_prop_enabled) {
1662 if (!strncmp("true", value, sizeof("true")))
1663 na_props.ui_na_prop_enabled = true;
1664 else
1665 na_props.ui_na_prop_enabled = false;
1666
1667 str_parms_del(parms, AUDIO_PARAMETER_KEY_NATIVE_AUDIO);
1668
1669 /*
1670 * Iterate through the usecase list and trigger device switch for
1671 * all the appropriate usecases
1672 */
1673 list_for_each(node, &(platform->adev)->usecase_list) {
1674 usecase = node_to_item(node, struct audio_usecase, list);
1675
1676 if (is_offload_usecase(usecase->id) &&
1677 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
1678 usecase->stream.out->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) &&
1679 OUTPUT_SAMPLING_RATE_44100 == usecase->stream.out->sample_rate) {
1680 select_devices(platform->adev, usecase->id);
1681 ALOGV("%s: triggering dynamic device switch for usecase: "
1682 "%d, device: %d", __func__, usecase->id,
1683 usecase->stream.out->devices);
1684 }
1685 }
1686 } else {
1687 ALOGV("%s: native audio not supported: %d", __func__,
1688 na_props.platform_na_prop_enabled);
1689 }
1690 }
1691 return ret;
1692}
1693
1694int platform_get_backend_index(snd_device_t snd_device)
1695{
1696 int32_t port = DEFAULT_CODEC_BACKEND;
1697
1698 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1699 if (backend_table[snd_device] != NULL &&
1700 strcmp(backend_table[snd_device], "headphones-44.1") == 0)
1701 port = HEADPHONE_44_1_BACKEND;
1702 else
1703 port = DEFAULT_CODEC_BACKEND;
1704 } else {
1705 ALOGV("%s: Invalid device - %d ", __func__, snd_device);
1706 }
1707
1708 ALOGV("%s: backend port - %d", __func__, port);
1709 return port;
1710}
1711
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301712int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001713 int app_type, int sample_rate)
Eric Laurentb23d5282013-05-14 15:27:20 -07001714{
1715 struct platform_data *my_data = (struct platform_data *)platform;
1716 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301717 struct audio_device *adev = my_data->adev;
1718 int snd_device = SND_DEVICE_OUT_SPEAKER;
Eric Laurentb23d5282013-05-14 15:27:20 -07001719
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301720 if (usecase->type == PCM_PLAYBACK)
1721 snd_device = platform_get_output_snd_device(adev->platform,
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08001722 usecase->stream.out);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301723 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
1724 snd_device = platform_get_input_snd_device(adev->platform,
1725 adev->primary_output->devices);
Anish Kumarf16721c2014-08-01 15:09:25 -07001726 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Eric Laurentb23d5282013-05-14 15:27:20 -07001727 if (acdb_dev_id < 0) {
1728 ALOGE("%s: Could not find acdb id for device(%d)",
1729 __func__, snd_device);
1730 return -EINVAL;
1731 }
1732 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001733 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Eric Laurentb23d5282013-05-14 15:27:20 -07001734 __func__, snd_device, acdb_dev_id);
1735 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1736 snd_device < SND_DEVICE_OUT_END)
1737 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1738 else
1739 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001740 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
1741 sample_rate);
Eric Laurentb23d5282013-05-14 15:27:20 -07001742 }
1743 return 0;
1744}
1745
1746int platform_switch_voice_call_device_pre(void *platform)
1747{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001748 struct platform_data *my_data = (struct platform_data *)platform;
1749 int ret = 0;
1750
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001751 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07001752 voice_is_in_call(my_data->adev)) {
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001753 /* This must be called before disabling mixer controls on APQ side */
1754 ret = my_data->csd->disable_device();
1755 if (ret < 0) {
1756 ALOGE("%s: csd_client_disable_device, failed, error %d",
1757 __func__, ret);
1758 }
1759 }
1760 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001761}
1762
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001763int platform_switch_voice_call_enable_device_config(void *platform,
1764 snd_device_t out_snd_device,
1765 snd_device_t in_snd_device)
1766{
1767 struct platform_data *my_data = (struct platform_data *)platform;
1768 int acdb_rx_id, acdb_tx_id;
1769 int ret = 0;
1770
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001771 if (my_data->csd == NULL)
1772 return ret;
1773
1774 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1775 audio_extn_spkr_prot_is_enabled())
1776 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1777 else
1778 acdb_rx_id = acdb_device_table[out_snd_device];
1779
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001780 acdb_tx_id = acdb_device_table[in_snd_device];
1781
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001782 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1783 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1784 if (ret < 0) {
1785 ALOGE("%s: csd_enable_device_config, failed, error %d",
1786 __func__, ret);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001787 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001788 } else {
1789 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1790 acdb_rx_id, acdb_tx_id);
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001791 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001792
Vidyakumar Athota545dbd32013-11-13 17:30:53 -08001793 return ret;
1794}
1795
Eric Laurentb23d5282013-05-14 15:27:20 -07001796int platform_switch_voice_call_device_post(void *platform,
1797 snd_device_t out_snd_device,
1798 snd_device_t in_snd_device)
1799{
1800 struct platform_data *my_data = (struct platform_data *)platform;
1801 int acdb_rx_id, acdb_tx_id;
1802
1803 if (my_data->acdb_send_voice_cal == NULL) {
1804 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1805 } else {
Anish Kumar46c7b872014-09-09 01:49:44 -07001806 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1807 audio_extn_spkr_prot_is_enabled())
1808 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1809
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001810 acdb_rx_id = acdb_device_table[out_snd_device];
1811 acdb_tx_id = acdb_device_table[in_snd_device];
1812
Eric Laurentb23d5282013-05-14 15:27:20 -07001813 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1814 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1815 else
1816 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1817 acdb_rx_id, acdb_tx_id);
1818 }
1819
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001820 return 0;
1821}
1822
1823int platform_switch_voice_call_usecase_route_post(void *platform,
1824 snd_device_t out_snd_device,
1825 snd_device_t in_snd_device)
1826{
1827 struct platform_data *my_data = (struct platform_data *)platform;
1828 int acdb_rx_id, acdb_tx_id;
1829 int ret = 0;
1830
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001831 if (my_data->csd == NULL)
1832 return ret;
1833
1834 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1835 audio_extn_spkr_prot_is_enabled())
1836 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1837 else
1838 acdb_rx_id = acdb_device_table[out_snd_device];
1839
Vidyakumar Athota1fd21792013-11-15 14:50:57 -08001840 acdb_tx_id = acdb_device_table[in_snd_device];
1841
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001842 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1843 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1844 my_data->adev->acdb_settings);
1845 if (ret < 0) {
1846 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001847 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001848 } else {
1849 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1850 acdb_rx_id, acdb_tx_id);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001851 }
Vidyakumar Athota1c6419a2014-01-10 14:47:34 -08001852
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001853 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001854}
1855
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001856int platform_start_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001857{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001858 struct platform_data *my_data = (struct platform_data *)platform;
1859 int ret = 0;
1860
1861 if (my_data->csd != NULL) {
1862 ret = my_data->csd->start_voice(vsid);
1863 if (ret < 0) {
1864 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1865 }
1866 }
1867 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001868}
1869
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001870int platform_stop_voice_call(void *platform, uint32_t vsid)
Eric Laurentb23d5282013-05-14 15:27:20 -07001871{
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001872 struct platform_data *my_data = (struct platform_data *)platform;
1873 int ret = 0;
1874
1875 if (my_data->csd != NULL) {
1876 ret = my_data->csd->stop_voice(vsid);
1877 if (ret < 0) {
1878 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1879 }
1880 }
1881 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001882}
1883
Helen Zeng6a16ad72014-02-23 22:04:44 -08001884int platform_get_sample_rate(void *platform, uint32_t *rate)
1885{
1886 struct platform_data *my_data = (struct platform_data *)platform;
1887 int ret = 0;
1888
1889 if ((my_data->csd != NULL) && my_data->is_i2s_ext_modem) {
1890 ret = my_data->csd->get_sample_rate(rate);
1891 if (ret < 0) {
1892 ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
1893 }
1894 }
1895 return ret;
1896}
1897
Eric Laurentb23d5282013-05-14 15:27:20 -07001898int platform_set_voice_volume(void *platform, int volume)
1899{
1900 struct platform_data *my_data = (struct platform_data *)platform;
1901 struct audio_device *adev = my_data->adev;
1902 struct mixer_ctl *ctl;
sangwoo53b2cf02013-07-25 19:18:44 -07001903 const char *mixer_ctl_name = "Voice Rx Gain";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001904 int vol_index = 0, ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001905 uint32_t set_values[ ] = {0,
1906 ALL_SESSION_VSID,
1907 DEFAULT_VOLUME_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001908
1909 // Voice volume levels are mapped to adsp volume levels as follows.
1910 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1911 // But this values don't changed in kernel. So, below change is need.
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001912 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1913 set_values[0] = vol_index;
Eric Laurentb23d5282013-05-14 15:27:20 -07001914
1915 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1916 if (!ctl) {
1917 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1918 __func__, mixer_ctl_name);
1919 return -EINVAL;
1920 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001921 ALOGV("Setting voice volume index: %d", set_values[0]);
1922 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07001923
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001924 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07001925 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1926 DEFAULT_VOLUME_RAMP_DURATION_MS);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001927 if (ret < 0) {
1928 ALOGE("%s: csd_volume error %d", __func__, ret);
1929 }
1930 }
1931 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001932}
1933
1934int platform_set_mic_mute(void *platform, bool state)
1935{
1936 struct platform_data *my_data = (struct platform_data *)platform;
1937 struct audio_device *adev = my_data->adev;
1938 struct mixer_ctl *ctl;
1939 const char *mixer_ctl_name = "Voice Tx Mute";
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001940 int ret = 0;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07001941 uint32_t set_values[ ] = {0,
1942 ALL_SESSION_VSID,
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07001943 DEFAULT_MUTE_RAMP_DURATION_MS};
Eric Laurentb23d5282013-05-14 15:27:20 -07001944
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001945 set_values[0] = state;
1946 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1947 if (!ctl) {
1948 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1949 __func__, mixer_ctl_name);
1950 return -EINVAL;
1951 }
1952 ALOGV("Setting voice mute state: %d", state);
1953 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Eric Laurentb23d5282013-05-14 15:27:20 -07001954
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001955 if (my_data->csd != NULL) {
Vidyakumar Athotac37f42a2014-03-11 11:57:48 -07001956 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1957 DEFAULT_MUTE_RAMP_DURATION_MS);
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08001958 if (ret < 0) {
1959 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08001960 }
1961 }
1962 return ret;
Eric Laurentb23d5282013-05-14 15:27:20 -07001963}
1964
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001965int platform_set_device_mute(void *platform, bool state, char *dir)
1966{
1967 struct platform_data *my_data = (struct platform_data *)platform;
1968 struct audio_device *adev = my_data->adev;
1969 struct mixer_ctl *ctl;
1970 char *mixer_ctl_name = NULL;
1971 int ret = 0;
1972 uint32_t set_values[ ] = {0,
1973 ALL_SESSION_VSID,
1974 0};
1975 if(dir == NULL) {
1976 ALOGE("%s: Invalid direction:%s", __func__, dir);
1977 return -EINVAL;
1978 }
1979
1980 if (!strncmp("rx", dir, sizeof("rx"))) {
1981 mixer_ctl_name = "Voice Rx Device Mute";
1982 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1983 mixer_ctl_name = "Voice Tx Device Mute";
1984 } else {
1985 return -EINVAL;
1986 }
1987
1988 set_values[0] = state;
1989 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1990 if (!ctl) {
1991 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1992 __func__, mixer_ctl_name);
1993 return -EINVAL;
1994 }
1995
1996 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1997 __func__,state, mixer_ctl_name);
1998 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1999
2000 return ret;
2001}
2002
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002003snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
Eric Laurentb23d5282013-05-14 15:27:20 -07002004{
2005 struct platform_data *my_data = (struct platform_data *)platform;
2006 struct audio_device *adev = my_data->adev;
2007 audio_mode_t mode = adev->mode;
2008 snd_device_t snd_device = SND_DEVICE_NONE;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002009 audio_devices_t devices = out->devices;
2010 unsigned int sample_rate = out->sample_rate;
Eric Laurentb23d5282013-05-14 15:27:20 -07002011
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002012 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2013 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2014 int channel_count = popcount(channel_mask);
2015
Eric Laurentb23d5282013-05-14 15:27:20 -07002016 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2017 if (devices == AUDIO_DEVICE_NONE ||
2018 devices & AUDIO_DEVICE_BIT_IN) {
2019 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2020 goto exit;
2021 }
2022
Mingming Yin4a72d652014-01-03 18:54:18 -08002023 if (popcount(devices) == 2) {
2024 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2025 AUDIO_DEVICE_OUT_SPEAKER)) {
Tanya Finkel00130052014-07-14 04:26:56 -07002026 if (my_data->external_spk_1)
2027 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2028 else if (my_data->external_spk_2)
2029 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
2030 else
2031 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Mingming Yin4a72d652014-01-03 18:54:18 -08002032 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2033 AUDIO_DEVICE_OUT_SPEAKER)) {
2034 if (audio_extn_get_anc_enabled())
2035 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Tanya Finkel00130052014-07-14 04:26:56 -07002036 else if (my_data->external_spk_1)
2037 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2038 else if (my_data->external_spk_2)
2039 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Mingming Yin4a72d652014-01-03 18:54:18 -08002040 else
2041 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
2042 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2043 AUDIO_DEVICE_OUT_SPEAKER)) {
2044 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
2045 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
2046 AUDIO_DEVICE_OUT_SPEAKER)) {
2047 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
2048 } else {
2049 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2050 goto exit;
2051 }
2052 if (snd_device != SND_DEVICE_NONE) {
2053 goto exit;
2054 }
2055 }
2056
2057 if (popcount(devices) != 1) {
2058 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2059 goto exit;
2060 }
2061
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07002062 if (voice_is_in_call(adev) ||
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002063 voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002064 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2065 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002066 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2067 !voice_extn_compress_voip_is_active(adev)) {
2068 switch (adev->voice.tty_mode) {
2069 case TTY_MODE_FULL:
2070 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
2071 break;
2072 case TTY_MODE_VCO:
2073 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
2074 break;
2075 case TTY_MODE_HCO:
2076 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2077 break;
2078 default:
2079 ALOGE("%s: Invalid TTY mode (%#x)",
2080 __func__, adev->voice.tty_mode);
2081 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002082 } else if (audio_extn_get_anc_enabled()) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002083 if (audio_extn_should_use_fb_anc())
2084 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
2085 else
2086 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002087 } else {
Eric Laurentb23d5282013-05-14 15:27:20 -07002088 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002089 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002090 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002091 if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002092 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2093 else
2094 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -07002095 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
2096 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002097 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2098 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2099 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002100 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2101 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07002102 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -08002103 if (audio_extn_should_use_handset_anc(channel_count))
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002104 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
Eric Laurentb23d5282013-05-14 15:27:20 -07002105 else
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002106 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07002107 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2108 snd_device = SND_DEVICE_OUT_VOICE_TX;
2109
Eric Laurentb23d5282013-05-14 15:27:20 -07002110 if (snd_device != SND_DEVICE_NONE) {
2111 goto exit;
2112 }
2113 }
2114
Eric Laurentb23d5282013-05-14 15:27:20 -07002115 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2116 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002117 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
2118 && audio_extn_get_anc_enabled()) {
2119 if (audio_extn_should_use_fb_anc())
2120 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
2121 else
2122 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302123 } else if (platform_get_native_support() &&
2124 OUTPUT_SAMPLING_RATE_44100 == sample_rate)
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002125 snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302126 else
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002127 snd_device = SND_DEVICE_OUT_HEADPHONES;
Eric Laurentb23d5282013-05-14 15:27:20 -07002128 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Tanya Finkel00130052014-07-14 04:26:56 -07002129 if (my_data->external_spk_1)
2130 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_1;
2131 else if (my_data->external_spk_2)
2132 snd_device = SND_DEVICE_OUT_SPEAKER_EXTERNAL_2;
2133 else if (adev->speaker_lr_swap)
Eric Laurentb23d5282013-05-14 15:27:20 -07002134 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2135 else
2136 snd_device = SND_DEVICE_OUT_SPEAKER;
2137 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002138 if (adev->bt_wb_speech_enabled)
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002139 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2140 else
2141 snd_device = SND_DEVICE_OUT_BT_SCO;
Eric Laurentb23d5282013-05-14 15:27:20 -07002142 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2143 snd_device = SND_DEVICE_OUT_HDMI ;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002144 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2145 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002146 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
2147 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002148 snd_device = SND_DEVICE_OUT_USB_HEADSET;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002149 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2150 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07002151 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
2152 snd_device = SND_DEVICE_OUT_HANDSET;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002153 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002154 channel_count = audio_extn_get_afe_proxy_channel_count();
2155 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
2156 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002157 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Eric Laurentb23d5282013-05-14 15:27:20 -07002158 } else {
2159 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2160 }
2161exit:
2162 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2163 return snd_device;
2164}
2165
2166snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2167{
2168 struct platform_data *my_data = (struct platform_data *)platform;
2169 struct audio_device *adev = my_data->adev;
2170 audio_source_t source = (adev->active_input == NULL) ?
2171 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2172
2173 audio_mode_t mode = adev->mode;
2174 audio_devices_t in_device = ((adev->active_input == NULL) ?
2175 AUDIO_DEVICE_NONE : adev->active_input->device)
2176 & ~AUDIO_DEVICE_BIT_IN;
2177 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2178 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2179 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002180 int channel_count = popcount(channel_mask);
Eric Laurentb23d5282013-05-14 15:27:20 -07002181
2182 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
2183 __func__, out_device, in_device);
Tanya Finkel00130052014-07-14 04:26:56 -07002184 if (my_data->external_mic) {
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07002185 if ((out_device != AUDIO_DEVICE_NONE && voice_is_in_call(adev)) ||
Tanya Finkel00130052014-07-14 04:26:56 -07002186 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev)) {
2187 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2188 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2189 out_device & AUDIO_DEVICE_OUT_SPEAKER )
2190 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2191 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2192 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2193 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2194 }
2195 }
2196
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002197 if (snd_device != AUDIO_DEVICE_NONE)
Tanya Finkel00130052014-07-14 04:26:56 -07002198 goto exit;
2199
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07002200 if ((out_device != AUDIO_DEVICE_NONE) && ((voice_is_in_call(adev)) ||
Satya Krishna Pindiproli071950f2014-05-21 14:45:28 +05302201 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Narsinga Rao Chella05573b72013-11-15 15:21:40 -08002202 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2203 !voice_extn_compress_voip_is_active(adev)) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002204 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2205 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002206 switch (adev->voice.tty_mode) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002207 case TTY_MODE_FULL:
2208 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2209 break;
2210 case TTY_MODE_VCO:
2211 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2212 break;
2213 case TTY_MODE_HCO:
2214 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2215 break;
2216 default:
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002217 ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
Eric Laurentb23d5282013-05-14 15:27:20 -07002218 }
2219 goto exit;
2220 }
2221 }
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07002222 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2223 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002224 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
2225 audio_extn_should_use_handset_anc(channel_count)) {
2226 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
Banajit Goswamide0ea452014-04-07 12:11:47 -07002227 adev->acdb_settings |= ANC_FLAG;
Apoorv Raghuvanshi9eaf94e2013-10-04 16:13:44 -07002228 } else if (my_data->fluence_type == FLUENCE_NONE ||
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002229 my_data->fluence_in_voice_call == false) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002230 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302231 if (audio_extn_hfp_is_active(adev))
2232 platform_set_echo_reference(adev->platform, true);
Eric Laurentb23d5282013-05-14 15:27:20 -07002233 } else {
Ravi Kumar Alamandaceb40822013-11-06 11:01:47 -08002234 snd_device = SND_DEVICE_IN_VOICE_DMIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002235 }
2236 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2237 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302238 if (audio_extn_hfp_is_active(adev))
2239 platform_set_echo_reference(adev->platform, true);
Eric Laurentb23d5282013-05-14 15:27:20 -07002240 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002241 if (adev->bt_wb_speech_enabled) {
2242 if (adev->bluetooth_nrec)
2243 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2244 else
2245 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2246 } else {
2247 if (adev->bluetooth_nrec)
2248 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2249 else
2250 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2251 }
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07002252 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002253 if (my_data->fluence_type != FLUENCE_NONE &&
2254 my_data->fluence_in_voice_call &&
2255 my_data->fluence_in_spkr_mode) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002256 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002257 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002258 } else {
Narsinga Rao Chella61e0f9b2014-03-06 21:25:22 -08002259 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2260 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
2261 else
2262 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Mingming Yin8e5a4f62013-10-07 15:23:41 -07002263 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002264 } else {
2265 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302266 if (audio_extn_hfp_is_active(adev))
2267 platform_set_echo_reference(adev->platform, true);
Eric Laurentb23d5282013-05-14 15:27:20 -07002268 }
Ravi Kumar Alamanda060bc5a2014-09-05 13:51:35 -07002269 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2270 snd_device = SND_DEVICE_IN_VOICE_RX;
Eric Laurentb23d5282013-05-14 15:27:20 -07002271 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2272 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2273 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2274 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
2275 }
2276 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2277 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002278 if (channel_count == 2) {
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002279 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002280 } else if (adev->active_input->enable_ns)
2281 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2282 else if (my_data->fluence_type != FLUENCE_NONE &&
2283 my_data->fluence_in_voice_rec) {
2284 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002285 } else {
2286 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
2287 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002288 }
2289 } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
2290 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
2291 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2292 if (adev->active_input) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002293 if (adev->active_input->enable_aec &&
2294 adev->active_input->enable_ns) {
Eric Laurentb23d5282013-05-14 15:27:20 -07002295 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002296 if (my_data->fluence_in_spkr_mode) {
2297 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2298 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
2299 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2300 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2301 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
2302 else
2303 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
2304 }
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002305 } else
2306 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002307 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002308 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2309 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002310 } else
2311 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Eric Laurentb23d5282013-05-14 15:27:20 -07002312 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002313 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Eric Laurentb23d5282013-05-14 15:27:20 -07002314 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302315 platform_set_echo_reference(adev->platform, true);
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002316 } else if (adev->active_input->enable_aec) {
2317 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002318 if (my_data->fluence_in_spkr_mode) {
2319 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2320 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
2321 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2322 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2323 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
2324 else
2325 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
2326 }
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002327 } else
2328 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
2329 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2330 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2331 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002332 } else
2333 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
2334 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2335 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
2336 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302337 platform_set_echo_reference(adev->platform, true);
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002338 } else if (adev->active_input->enable_ns) {
2339 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002340 if (my_data->fluence_in_spkr_mode) {
2341 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2342 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
2343 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2344 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2345 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
2346 else
2347 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
2348 }
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002349 } else
2350 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
2351 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2352 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2353 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002354 } else
2355 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
2356 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2357 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
2358 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302359 platform_set_echo_reference(adev->platform, false);
Eric Laurentb23d5282013-05-14 15:27:20 -07002360 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302361 platform_set_echo_reference(adev->platform, false);
Eric Laurentb23d5282013-05-14 15:27:20 -07002362 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002363 } else if (source == AUDIO_SOURCE_MIC) {
Apoorv Raghuvanshic0536542013-11-14 16:25:59 -08002364 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
2365 channel_count == 1 ) {
Narsinga Rao Chella975572e2014-10-21 11:49:00 -07002366 if(my_data->fluence_in_audio_rec) {
2367 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
2368 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
2369 platform_set_echo_reference(adev->platform, true);
2370 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2371 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
2372 platform_set_echo_reference(adev->platform, true);
2373 }
Ravi Kumar Alamanda7076b162014-03-07 11:40:24 -08002374 }
Ravi Kumar Alamandab034ddb2013-11-06 15:52:18 -08002375 }
Mingming Yinab429782013-11-07 11:16:55 -08002376 } else if (source == AUDIO_SOURCE_FM_RX ||
Ravi Kumar Alamanda198185e2013-11-07 15:42:19 -08002377 source == AUDIO_SOURCE_FM_RX_A2DP) {
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07002378 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07002379 } else if (source == AUDIO_SOURCE_DEFAULT) {
2380 goto exit;
2381 }
2382
2383
2384 if (snd_device != SND_DEVICE_NONE) {
2385 goto exit;
2386 }
2387
2388 if (in_device != AUDIO_DEVICE_NONE &&
2389 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2390 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2391 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002392 if (audio_extn_ssr_get_enabled() && channel_count == 6)
2393 snd_device = SND_DEVICE_IN_QUAD_MIC;
Walter Yangbc136bd2014-01-17 11:24:23 +08002394 else if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) &&
2395 channel_count == 2)
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -07002396 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
Apoorv Raghuvanshi6178a3f2013-10-19 12:38:54 -07002397 else
2398 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002399 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2400 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2401 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2402 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2403 } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002404 if (adev->bt_wb_speech_enabled) {
2405 if (adev->bluetooth_nrec)
2406 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2407 else
2408 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2409 } else {
2410 if (adev->bluetooth_nrec)
2411 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2412 else
2413 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2414 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002415 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2416 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002417 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
2418 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
2419 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -07002420 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
2421 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Eric Laurentb23d5282013-05-14 15:27:20 -07002422 } else {
2423 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2424 ALOGW("%s: Using default handset-mic", __func__);
2425 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2426 }
2427 } else {
2428 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2429 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2430 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2431 snd_device = SND_DEVICE_IN_HEADSET_MIC;
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07002432 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002433 if (channel_count == 2)
Apoorv Raghuvanshi6bd8dbf2013-10-19 18:37:52 -07002434 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
2435 else
2436 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Narsinga Rao Chella97db8702014-10-03 13:34:45 -07002437 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
2438 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002439 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002440 if (adev->bt_wb_speech_enabled) {
2441 if (adev->bluetooth_nrec)
2442 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2443 else
2444 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2445 } else {
2446 if (adev->bluetooth_nrec)
2447 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2448 else
2449 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2450 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002451 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2452 snd_device = SND_DEVICE_IN_HDMI_MIC;
Apoorv Raghuvanshi5792d4b2013-10-07 18:40:05 -07002453 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2454 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2455 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Eric Laurentb23d5282013-05-14 15:27:20 -07002456 } else {
2457 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2458 ALOGW("%s: Using default handset-mic", __func__);
2459 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2460 }
2461 }
2462exit:
2463 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2464 return snd_device;
2465}
2466
2467int platform_set_hdmi_channels(void *platform, int channel_count)
2468{
2469 struct platform_data *my_data = (struct platform_data *)platform;
2470 struct audio_device *adev = my_data->adev;
2471 struct mixer_ctl *ctl;
2472 const char *channel_cnt_str = NULL;
2473 const char *mixer_ctl_name = "HDMI_RX Channels";
2474 switch (channel_count) {
2475 case 8:
2476 channel_cnt_str = "Eight"; break;
2477 case 7:
2478 channel_cnt_str = "Seven"; break;
2479 case 6:
2480 channel_cnt_str = "Six"; break;
2481 case 5:
2482 channel_cnt_str = "Five"; break;
2483 case 4:
2484 channel_cnt_str = "Four"; break;
2485 case 3:
2486 channel_cnt_str = "Three"; break;
2487 default:
2488 channel_cnt_str = "Two"; break;
2489 }
2490 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2491 if (!ctl) {
2492 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2493 __func__, mixer_ctl_name);
2494 return -EINVAL;
2495 }
2496 ALOGV("HDMI channel count: %s", channel_cnt_str);
2497 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2498 return 0;
2499}
2500
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002501int platform_edid_get_max_channels(void *platform)
Eric Laurentb23d5282013-05-14 15:27:20 -07002502{
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07002503 int channel_count;
2504 int max_channels = 2;
2505 int i = 0, ret = 0;
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002506 struct platform_data *my_data = (struct platform_data *)platform;
2507 struct audio_device *adev = my_data->adev;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07002508 edid_audio_info *info = NULL;
2509 ret = platform_get_edid_info(platform);
2510 info = (edid_audio_info *)my_data->edid_info;
Eric Laurentb23d5282013-05-14 15:27:20 -07002511
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07002512 if(ret == 0 && info != NULL) {
2513 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
2514 ALOGV("%s:format %d channel %d", __func__,
2515 info->audio_blocks_array[i].format_id,
2516 info->audio_blocks_array[i].channels);
2517 if (info->audio_blocks_array[i].format_id == LPCM) {
2518 channel_count = info->audio_blocks_array[i].channels;
2519 if (channel_count > max_channels) {
2520 max_channels = channel_count;
2521 }
2522 }
Haynes Mathew George47cd4cb2013-07-19 11:58:50 -07002523 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002524 }
Eric Laurentb23d5282013-05-14 15:27:20 -07002525 return max_channels;
2526}
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002527
2528static int platform_set_slowtalk(struct platform_data *my_data, bool state)
2529{
2530 int ret = 0;
2531 struct audio_device *adev = my_data->adev;
2532 struct mixer_ctl *ctl;
2533 const char *mixer_ctl_name = "Slowtalk Enable";
2534 uint32_t set_values[ ] = {0,
2535 ALL_SESSION_VSID};
2536
2537 set_values[0] = state;
2538 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2539 if (!ctl) {
2540 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2541 __func__, mixer_ctl_name);
2542 ret = -EINVAL;
2543 } else {
2544 ALOGV("Setting slowtalk state: %d", state);
2545 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2546 my_data->slowtalk = state;
2547 }
2548
Vidyakumar Athotad9d9ff32013-11-13 11:46:52 -08002549 if (my_data->csd != NULL) {
2550 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
2551 if (ret < 0) {
2552 ALOGE("%s: csd_client_disable_device, failed, error %d",
2553 __func__, ret);
2554 }
2555 }
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002556 return ret;
2557}
2558
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302559static int set_hd_voice(struct platform_data *my_data, bool state)
2560{
2561 struct audio_device *adev = my_data->adev;
2562 struct mixer_ctl *ctl;
2563 char *mixer_ctl_name = "HD Voice Enable";
2564 int ret = 0;
2565 uint32_t set_values[ ] = {0,
2566 ALL_SESSION_VSID};
2567
2568 set_values[0] = state;
2569 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2570 if (!ctl) {
2571 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2572 __func__, mixer_ctl_name);
2573 return -EINVAL;
2574 } else {
2575 ALOGV("Setting HD Voice state: %d", state);
2576 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2577 my_data->hd_voice = state;
2578 }
2579
2580 return ret;
2581}
Tanya Finkel00130052014-07-14 04:26:56 -07002582
2583static int update_external_device_status(struct platform_data *my_data,
2584 char* event_name, bool status)
2585{
2586 int ret = 0;
2587 struct audio_usecase *usecase;
2588 struct listnode *node;
2589
2590 ALOGD("Recieved external event switch %s", event_name);
2591
2592 if (!strcmp(event_name, EVENT_EXTERNAL_SPK_1))
2593 my_data->external_spk_1 = status;
2594 else if (!strcmp(event_name, EVENT_EXTERNAL_SPK_2))
2595 my_data->external_spk_2 = status;
2596 else if (!strcmp(event_name, EVENT_EXTERNAL_MIC))
2597 my_data->external_mic = status;
2598 else {
2599 ALOGE("The audio event type is not found");
2600 return -EINVAL;
2601 }
2602
2603 list_for_each(node, &my_data->adev->usecase_list) {
2604 usecase = node_to_item(node, struct audio_usecase, list);
2605 select_devices(my_data->adev, usecase->id);
2606 }
2607
2608 return ret;
2609}
2610
Ben Rombergera04fabc2014-11-14 12:16:03 -08002611static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
2612{
2613 int err;
2614 unsigned int val;
2615 char value[64];
2616 int ret = 0;
2617
2618 if(parms == NULL || cal == NULL)
2619 return ret;
2620
2621 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
2622 if (err >= 0) {
2623 str_parms_del(parms, "cal_persist");
2624 cal->persist = (uint32_t) strtoul(value, NULL, 0);
2625 ret = ret | 0x1;
2626 }
2627 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
2628 if (err >= 0) {
2629 str_parms_del(parms, "cal_apptype");
2630 cal->app_type = (uint32_t) strtoul(value, NULL, 0);
2631 ret = ret | 0x2;
2632 }
2633 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
2634 if (err >= 0) {
2635 str_parms_del(parms, "cal_caltype");
2636 cal->cal_type = (uint32_t) strtoul(value, NULL, 0);
2637 ret = ret | 0x4;
2638 }
2639 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
2640 if (err >= 0) {
2641 str_parms_del(parms, "cal_samplerate");
2642 cal->sampling_rate = (uint32_t) strtoul(value, NULL, 0);
2643 ret = ret | 0x8;
2644 }
2645 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
2646 if (err >= 0) {
2647 str_parms_del(parms, "cal_devid");
2648 cal->dev_id = (uint32_t) strtoul(value, NULL, 0);
2649 ret = ret | 0x10;
2650 }
2651 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
2652 if (err >= 0) {
2653 str_parms_del(parms, "cal_snddevid");
2654 cal->snd_dev_id = (uint32_t) strtoul(value, NULL, 0);
2655 ret = ret | 0x20;
2656 }
2657 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
2658 if (err >= 0) {
2659 str_parms_del(parms, "cal_topoid");
2660 cal->topo_id = (uint32_t) strtoul(value, NULL, 0);
2661 ret = ret | 0x40;
2662 }
2663 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
2664 if (err >= 0) {
2665 str_parms_del(parms, "cal_moduleid");
2666 cal->module_id = (uint32_t) strtoul(value, NULL, 0);
2667 ret = ret | 0x80;
2668 }
2669 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
2670 if (err >= 0) {
2671 str_parms_del(parms, "cal_paramid");
2672 cal->param_id = (uint32_t) strtoul(value, NULL, 0);
2673 ret = ret | 0x100;
2674 }
2675 return ret;
2676}
2677
2678static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len) {
2679 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302680 struct stream_out out;
Ben Rombergera04fabc2014-11-14 12:16:03 -08002681 acdb_audio_cal_cfg_t cal={0};
2682 uint8_t *dptr = NULL;
2683 int32_t dlen;
2684 int err, ret;
2685 if(value == NULL || platform == NULL || parms == NULL) {
2686 ALOGE("[%s] received null pointer, failed",__func__);
2687 goto done_key_audcal;
2688 }
2689
2690 /* parse audio calibration keys */
2691 ret = parse_audiocal_cfg(parms, &cal);
2692
2693 /* handle audio calibration data now */
2694 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
2695 if (err >= 0) {
2696 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
2697 dlen = strlen(value);
2698 if(dlen <= 0) {
2699 ALOGE("[%s] null data received",__func__);
2700 goto done_key_audcal;
2701 }
2702 dptr = (uint8_t*) calloc(dlen, sizeof(uint8_t));
2703 if(dptr == NULL) {
2704 ALOGE("[%s] memory allocation failed for %d",__func__, dlen);
2705 goto done_key_audcal;
2706 }
2707 dlen = b64decode(value, strlen(value), dptr);
2708 if(dlen<=0) {
2709 ALOGE("[%s] data decoding failed %d", __func__, dlen);
2710 goto done_key_audcal;
2711 }
2712
2713 if(cal.dev_id) {
2714 if(audio_is_input_device(cal.dev_id)) {
2715 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
2716 } else {
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002717 out.devices = cal.dev_id;
2718 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Ben Rombergera04fabc2014-11-14 12:16:03 -08002719 }
2720 }
2721 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
2722 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
2723 cal.snd_dev_id, cal.acdb_dev_id);
2724 if(cal.acdb_dev_id == -EINVAL) {
2725 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
2726 __func__, cal.acdb_dev_id, cal.snd_dev_id);
2727 goto done_key_audcal;
2728 }
2729 if(my_data->acdb_set_audio_cal) {
2730 ret = my_data->acdb_set_audio_cal((void *)&cal, (void*)dptr, dlen);
2731 }
2732 }
2733done_key_audcal:
2734 if(dptr != NULL)
2735 free(dptr);
2736}
2737
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002738int platform_set_parameters(void *platform, struct str_parms *parms)
2739{
2740 struct platform_data *my_data = (struct platform_data *)platform;
2741 char *str;
Ben Rombergera04fabc2014-11-14 12:16:03 -08002742 char *value=NULL;
2743 int val, len;
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002744 int ret = 0, err;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002745 char *kv_pairs = str_parms_to_str(parms);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002746
Mingming Yin7b762e72015-03-04 13:47:32 -08002747 if(kv_pairs == NULL) {
2748 ret = -ENOMEM;
2749 ALOGE("[%s] key-value pair is NULL",__func__);
2750 goto done;
2751 }
2752
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08002753 ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002754
Ben Rombergera04fabc2014-11-14 12:16:03 -08002755 len = strlen(kv_pairs);
2756 value = (char*)calloc(len, sizeof(char));
2757 if(value == NULL) {
2758 ret = -ENOMEM;
2759 ALOGE("[%s] failed to allocate memory",__func__);
2760 goto done;
2761 }
2762 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, len);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002763 if (err >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08002764 bool state = false;
2765 if (!strncmp("true", value, sizeof("true"))) {
2766 state = true;
2767 }
2768
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002769 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08002770 ret = platform_set_slowtalk(my_data, state);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002771 if (ret)
2772 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002773 }
2774
Ben Rombergera04fabc2014-11-14 12:16:03 -08002775 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, len);
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302776 if (err >= 0) {
2777 bool state = false;
2778 if (!strncmp("true", value, sizeof("true"))) {
2779 state = true;
2780 }
2781
2782 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
2783 if (my_data->hd_voice != state) {
2784 ret = set_hd_voice(my_data, state);
2785 if (ret)
2786 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
2787 } else {
2788 ALOGV("%s: HD Voice already set to %d", __func__, state);
2789 }
2790 }
2791
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002792 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
Ben Rombergera04fabc2014-11-14 12:16:03 -08002793 value, len);
Shiv Maliyappanahalli3e064fd2013-12-16 15:54:40 -08002794 if (err >= 0) {
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08002795 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
2796
2797 if (my_data->acdb_reload_vocvoltable == NULL) {
2798 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
2799 } else if (!strcmp(value, "on")) {
2800 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
2801 my_data->voice_feature_set = 1;
2802 }
2803 } else {
2804 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
2805 my_data->voice_feature_set = 0;
2806 }
2807 }
2808 }
2809
Tanya Finkel00130052014-07-14 04:26:56 -07002810 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE,
Ben Rombergera04fabc2014-11-14 12:16:03 -08002811 value, len);
Tanya Finkel00130052014-07-14 04:26:56 -07002812 if (err >= 0) {
2813 char *event_name, *status_str;
2814 bool status = false;
2815 str_parms_del(parms, AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE);
2816 event_name = strtok_r(value, ",", &status_str);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -08002817 if (!event_name) {
2818 ret = -EINVAL;
2819 ALOGE("%s: event_name is NULL", __func__);
2820 goto done;
2821 }
Tanya Finkel00130052014-07-14 04:26:56 -07002822 ALOGV("%s: recieved update of external audio device %s %s",
2823 __func__,
2824 event_name, status_str);
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002825 if (!strncmp(status_str, "ON", sizeof("ON")))
Tanya Finkel00130052014-07-14 04:26:56 -07002826 status = true;
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07002827 else if (!strncmp(status_str, "OFF", sizeof("OFF")))
Tanya Finkel00130052014-07-14 04:26:56 -07002828 status = false;
2829 update_external_device_status(my_data, event_name, status);
2830 }
2831
Ben Rombergera04fabc2014-11-14 12:16:03 -08002832 /* handle audio calibration parameters */
2833 set_audiocal(platform, parms, value, len);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302834 native_audio_set_params(platform, parms, value, len);
Ben Rombergera04fabc2014-11-14 12:16:03 -08002835done:
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002836 ALOGV("%s: exit with code(%d)", __func__, ret);
Mingming Yin7b762e72015-03-04 13:47:32 -08002837 if(kv_pairs != NULL)
2838 free(kv_pairs);
Ben Rombergera04fabc2014-11-14 12:16:03 -08002839 if(value != NULL)
2840 free(value);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002841 return ret;
2842}
2843
Vidyakumar Athota2850d532013-11-19 16:02:12 -08002844int platform_set_incall_recording_session_id(void *platform,
2845 uint32_t session_id, int rec_mode)
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07002846{
2847 int ret = 0;
2848 struct platform_data *my_data = (struct platform_data *)platform;
2849 struct audio_device *adev = my_data->adev;
2850 struct mixer_ctl *ctl;
2851 const char *mixer_ctl_name = "Voc VSID";
2852 int num_ctl_values;
2853 int i;
2854
2855 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2856 if (!ctl) {
2857 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2858 __func__, mixer_ctl_name);
2859 ret = -EINVAL;
2860 } else {
2861 num_ctl_values = mixer_ctl_get_num_values(ctl);
2862 for (i = 0; i < num_ctl_values; i++) {
2863 if (mixer_ctl_set_value(ctl, i, session_id)) {
2864 ALOGV("Error: invalid session_id: %x", session_id);
2865 ret = -EINVAL;
2866 break;
2867 }
2868 }
2869 }
2870
Vidyakumar Athota2850d532013-11-19 16:02:12 -08002871 if (my_data->csd != NULL) {
2872 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2873 if (ret < 0) {
2874 ALOGE("%s: csd_client_start_record failed, error %d",
2875 __func__, ret);
2876 }
2877 }
2878
2879 return ret;
2880}
2881
2882int platform_stop_incall_recording_usecase(void *platform)
2883{
2884 int ret = 0;
2885 struct platform_data *my_data = (struct platform_data *)platform;
2886
2887 if (my_data->csd != NULL) {
2888 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2889 if (ret < 0) {
2890 ALOGE("%s: csd_client_stop_record failed, error %d",
2891 __func__, ret);
2892 }
2893 }
2894
2895 return ret;
2896}
2897
2898int platform_start_incall_music_usecase(void *platform)
2899{
2900 int ret = 0;
2901 struct platform_data *my_data = (struct platform_data *)platform;
2902
2903 if (my_data->csd != NULL) {
2904 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2905 if (ret < 0) {
2906 ALOGE("%s: csd_client_start_playback failed, error %d",
2907 __func__, ret);
2908 }
2909 }
2910
2911 return ret;
2912}
2913
2914int platform_stop_incall_music_usecase(void *platform)
2915{
2916 int ret = 0;
2917 struct platform_data *my_data = (struct platform_data *)platform;
2918
2919 if (my_data->csd != NULL) {
2920 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2921 if (ret < 0) {
2922 ALOGE("%s: csd_client_stop_playback failed, error %d",
2923 __func__, ret);
2924 }
2925 }
2926
Shiv Maliyappanahallida107642013-10-17 11:16:13 -07002927 return ret;
2928}
2929
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07002930int platform_update_lch(void *platform, struct voice_session *session,
2931 enum voice_lch_mode lch_mode)
2932{
2933 int ret = 0;
2934 struct platform_data *my_data = (struct platform_data *)platform;
2935
2936 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
2937 ret = my_data->csd->set_lch(session->vsid, lch_mode);
2938 else
2939 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
2940
2941 return ret;
2942}
2943
Ben Rombergera04fabc2014-11-14 12:16:03 -08002944static void get_audiocal(void *platform, void *keys, void *pReply) {
2945 struct platform_data *my_data = (struct platform_data *)platform;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05302946 struct stream_out out;
Ben Rombergera04fabc2014-11-14 12:16:03 -08002947 struct str_parms *query = (struct str_parms *)keys;
2948 struct str_parms *reply=(struct str_parms *)pReply;
2949 acdb_audio_cal_cfg_t cal={0};
2950 uint8_t *dptr = NULL;
2951 char value[512] = {0};
2952 char *rparms=NULL;
2953 int ret=0, err;
2954 uint32_t param_len;
2955
2956 if(query==NULL || platform==NULL || reply==NULL) {
2957 ALOGE("[%s] received null pointer",__func__);
2958 ret=-EINVAL;
2959 goto done;
2960 }
2961 /* parse audiocal configuration keys */
2962 ret = parse_audiocal_cfg(query, &cal);
2963 if(ret == 0) {
2964 /* No calibration keys found */
2965 goto done;
2966 }
2967 err = str_parms_get_str(query, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, sizeof(value));
2968 if (err >= 0) {
2969 str_parms_del(query, AUDIO_PARAMETER_KEY_AUD_CALDATA);
2970 } else {
2971 goto done;
2972 }
2973
2974 if(cal.dev_id & AUDIO_DEVICE_BIT_IN) {
2975 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
2976 } else if(cal.dev_id) {
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08002977 out.devices = cal.dev_id;
2978 cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
Ben Rombergera04fabc2014-11-14 12:16:03 -08002979 }
2980 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
2981 if (cal.acdb_dev_id < 0) {
2982 ALOGE("%s: Failed. Could not find acdb id for snd device(%d)",
2983 __func__, cal.snd_dev_id);
2984 ret = -EINVAL;
2985 goto done_key_audcal;
2986 }
2987 ALOGD("[%s] Getting audio calibration for snd_device(%d) acdb_id(%d)",
2988 __func__, cal.snd_dev_id, cal.acdb_dev_id);
2989
2990 param_len = MAX_SET_CAL_BYTE_SIZE;
2991 dptr = (uint8_t*)calloc(param_len, sizeof(uint8_t));
2992 if(dptr == NULL) {
2993 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
2994 ret = -ENOMEM;
2995 goto done_key_audcal;
2996 }
2997 if (my_data->acdb_get_audio_cal != NULL) {
2998 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
2999 if (ret == 0) {
3000 int dlen;
3001 if(param_len == 0 || param_len == MAX_SET_CAL_BYTE_SIZE) {
3002 ret = -EINVAL;
3003 goto done_key_audcal;
3004 }
3005 /* Allocate memory for encoding */
3006 rparms = (char*)calloc((param_len*2), sizeof(char));
3007 if(rparms == NULL) {
3008 ALOGE("[%s] Memory allocation failed for size %d",
3009 __func__, param_len*2);
3010 ret = -ENOMEM;
3011 goto done_key_audcal;
3012 }
3013 if(cal.persist==0 && cal.module_id && cal.param_id) {
3014 err = b64encode(dptr+12, param_len-12, rparms);
3015 } else {
3016 err = b64encode(dptr, param_len, rparms);
3017 }
3018 if(err < 0) {
3019 ALOGE("[%s] failed to convert data to string", __func__);
3020 ret = -EINVAL;
3021 goto done_key_audcal;
3022 }
3023 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
3024 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, rparms);
3025 }
3026 }
3027done_key_audcal:
3028 if(ret != 0) {
3029 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
3030 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, "");
3031 }
3032done:
3033 if(dptr != NULL)
3034 free(dptr);
3035 if(rparms != NULL)
3036 free(rparms);
3037}
3038
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003039void platform_get_parameters(void *platform,
3040 struct str_parms *query,
3041 struct str_parms *reply)
3042{
3043 struct platform_data *my_data = (struct platform_data *)platform;
3044 char *str = NULL;
Ben Rombergera04fabc2014-11-14 12:16:03 -08003045 char value[512] = {0};
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003046 int ret;
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08003047 char *kv_pairs = NULL;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003048
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08003049 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
3050 value, sizeof(value));
3051 if (ret >= 0) {
Vidyakumar Athota3ade2792013-12-02 11:02:20 -08003052 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
3053 my_data->slowtalk?"true":"false");
Shiv Maliyappanahalli9d899292013-11-20 14:43:01 -08003054 }
3055
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303056 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
3057 value, sizeof(value));
3058 if (ret >= 0) {
3059 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
3060 my_data->hd_voice?"true":"false");
3061 }
3062
Ben Rombergerc1dc70d2013-12-19 15:11:17 -08003063 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3064 value, sizeof(value));
3065 if (ret >= 0) {
3066 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
3067 strlcpy(value, "on", sizeof(value));
3068 } else {
3069 strlcpy(value, "off", sizeof(value));
3070 }
3071
3072 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
3073 }
3074
Ben Rombergera04fabc2014-11-14 12:16:03 -08003075 /* Handle audio calibration keys */
3076 get_audiocal(platform, query, reply);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303077 native_audio_get_params(query, reply, value, sizeof(value));
Ben Rombergera04fabc2014-11-14 12:16:03 -08003078
3079done:
Krishnankutty Kolathappilly061a9492014-01-31 18:12:13 -08003080 kv_pairs = str_parms_to_str(reply);
3081 ALOGV_IF(kv_pairs != NULL, "%s: exit: returns - %s", __func__, kv_pairs);
Narsinga Rao Chellacde45d12014-02-13 11:44:31 -08003082 free(kv_pairs);
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07003083}
3084
Haynes Mathew George7ff216f2013-09-11 19:51:41 -07003085/* Delay in Us */
3086int64_t platform_render_latency(audio_usecase_t usecase)
3087{
3088 switch (usecase) {
3089 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3090 return DEEP_BUFFER_PLATFORM_DELAY;
3091 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3092 return LOW_LATENCY_PLATFORM_DELAY;
3093 default:
3094 return 0;
3095 }
3096}
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07003097
Mingming Yine62d7842013-10-25 16:26:03 -07003098int platform_update_usecase_from_source(int source, int usecase)
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07003099{
Mingming Yinab429782013-11-07 11:16:55 -08003100 ALOGV("%s: input source :%d", __func__, source);
3101 if(source == AUDIO_SOURCE_FM_RX_A2DP)
Mingming Yine62d7842013-10-25 16:26:03 -07003102 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
3103 return usecase;
Preetam Singh Ranawatde84f1a2013-11-01 14:58:16 -07003104}
Kiran Kandide144c82013-11-20 15:58:32 -08003105
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303106bool platform_listen_device_needs_event(snd_device_t snd_device)
Kiran Kandide144c82013-11-20 15:58:32 -08003107{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303108 bool needs_event = false;
3109
Kiran Kandide144c82013-11-20 15:58:32 -08003110 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3111 (snd_device < SND_DEVICE_IN_END) &&
3112 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3113 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303114 needs_event = true;
3115
3116 return needs_event;
3117}
3118
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003119bool platform_listen_usecase_needs_event(audio_usecase_t uc_id __unused)
3120{
3121 return false;
3122}
3123
3124bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
3125{
3126 bool needs_event = false;
3127
3128 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3129 (snd_device < SND_DEVICE_IN_END) &&
3130 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3131 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
3132 needs_event = true;
3133
3134 return needs_event;
3135}
3136
3137bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id __unused)
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303138{
3139 return false;
Kiran Kandide144c82013-11-20 15:58:32 -08003140}
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003141
3142/* Read offload buffer size from a property.
3143 * If value is not power of 2 round it to
3144 * power of 2.
3145 */
3146uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
3147{
3148 char value[PROPERTY_VALUE_MAX] = {0};
3149 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3150 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
3151 atoi(value)) {
3152 fragment_size = atoi(value) * 1024;
3153 }
3154
Mingming Yin3ee55c62014-08-04 14:23:35 -07003155 // For FLAC use max size since it is loss less, and has sampling rates
3156 // upto 192kHZ
3157 if (info != NULL && !info->has_video &&
3158 info->format == AUDIO_FORMAT_FLAC) {
3159 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3160 ALOGV("FLAC fragment size %d", fragment_size);
3161 }
3162
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003163 if (info != NULL && info->has_video && info->is_streaming) {
3164 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
3165 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
ApurupaPattapu31d09d72014-03-05 11:13:32 -08003166 __func__, fragment_size);
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003167 }
3168
3169 fragment_size = ALIGN( fragment_size, 1024);
3170
3171 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3172 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3173 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3174 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3175 ALOGV("%s: fragment_size %d", __func__, fragment_size);
3176 return fragment_size;
3177}
3178
3179uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
3180{
Alexy Josephaa54c872014-12-03 02:46:47 -08003181 uint32_t fragment_size = 0;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003182 uint32_t bits_per_sample = 16;
Alexy Josephaa54c872014-12-03 02:46:47 -08003183 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION_FOR_SMALL_BUFFERS;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003184
3185 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
3186 bits_per_sample = 32;
3187 }
3188
Alexy Josephaa54c872014-12-03 02:46:47 -08003189 if (info->use_small_bufs) {
3190 pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION_FOR_SMALL_BUFFERS;
3191 } else {
3192 if (!info->has_video) {
3193 pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION_MAX;
3194 } else if (info->has_video && info->is_streaming) {
3195 pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING;
3196 } else if (info->has_video) {
3197 pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION_FOR_AV;
3198 }
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003199 }
3200
Alexy Josephaa54c872014-12-03 02:46:47 -08003201 //duration is set to 20 ms worth of stereo data at 48Khz
3202 //with 16 bit per sample, modify this when the channel
3203 //configuration is different
3204 fragment_size = (pcm_offload_time
3205 * info->sample_rate
3206 * (bits_per_sample >> 3)
3207 * popcount(info->channel_mask))/1000;
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003208 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
3209 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
3210 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
3211 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
Preetam Singh Ranawat15668f02015-05-27 11:14:03 +05303212 // To have same PCM samples for all channels, the buffer size requires to
3213 // be multiple of (number of channels * bytes per sample)
3214 // For writes to succeed, the buffer must be written at address which is multiple of 32
3215 fragment_size = ALIGN(fragment_size, ((bits_per_sample >> 3)* popcount(info->channel_mask) * 32));
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003216
Alexy Josephaa54c872014-12-03 02:46:47 -08003217 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
ApurupaPattapuc6a3a9e2014-01-10 14:46:02 -08003218 return fragment_size;
3219}
3220
Mingming Yin3ee55c62014-08-04 14:23:35 -07003221int platform_set_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303222 snd_device_t snd_device,
Mingming Yin3ee55c62014-08-04 14:23:35 -07003223 unsigned int bit_width, unsigned int sample_rate)
3224{
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003225 int ret = 0;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303226 int backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003227 struct platform_data *my_data = (struct platform_data *)adev->platform;
3228
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303229 backend_idx = platform_get_backend_index(snd_device);
3230 ALOGV("%s bit width: %d, sample rate: %d backend_idx - %d",
3231 __func__, bit_width, sample_rate, backend_idx);
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003232
3233 if (bit_width !=
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303234 my_data->current_backend_cfg[backend_idx].bit_width) {
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003235
Mingming Yin3ee55c62014-08-04 14:23:35 -07003236 struct mixer_ctl *ctl;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303237 ctl = mixer_get_ctl_by_name(adev->mixer,
3238 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003239 if (!ctl) {
3240 ALOGE("%s: Could not get ctl for mixer command - %s",
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303241 __func__, my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003242 return -EINVAL;
3243 }
3244
3245 if (bit_width == 24) {
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303246 mixer_ctl_set_enum_by_string(ctl, "S24_LE");
Mingming Yin3ee55c62014-08-04 14:23:35 -07003247 } else {
3248 mixer_ctl_set_enum_by_string(ctl, "S16_LE");
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303249 if (backend_idx != HEADPHONE_44_1_BACKEND)
3250 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003251 }
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303252 my_data->current_backend_cfg[backend_idx].bit_width = bit_width;
3253 ALOGD("%s: %s mixer set to %d bit", __func__,
3254 my_data->current_backend_cfg[backend_idx].bitwidth_mixer_ctl, bit_width);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003255 }
3256
Amit Shekhared7fb5c2014-08-01 17:18:53 -07003257 /*
3258 * Backend sample rate configuration follows:
3259 * 16 bit playback - 48khz for streams at any valid sample rate
3260 * 24 bit playback - 48khz for stream sample rate less than 48khz
3261 * 24 bit playback - 96khz for sample rate range of 48khz to 96khz
3262 * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz
3263 * Upper limit is inclusive in the sample rate range.
3264 */
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003265 if (sample_rate !=
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303266 my_data->current_backend_cfg[backend_idx].sample_rate) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07003267 char *rate_str = NULL;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003268 struct mixer_ctl *ctl;
3269
3270 switch (sample_rate) {
3271 case 8000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003272 case 11025:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003273 case 16000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003274 case 22050:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003275 case 32000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003276 case 48000:
3277 rate_str = "KHZ_48";
3278 break;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303279 case 44100:
3280 rate_str = "KHZ_44P1";
3281 break;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003282 case 64000:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003283 case 88200:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003284 case 96000:
3285 rate_str = "KHZ_96";
3286 break;
3287 case 176400:
Mingming Yin3ee55c62014-08-04 14:23:35 -07003288 case 192000:
3289 rate_str = "KHZ_192";
3290 break;
3291 default:
3292 rate_str = "KHZ_48";
3293 break;
3294 }
3295
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303296 ctl = mixer_get_ctl_by_name(adev->mixer,
3297 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003298 if(!ctl) {
3299 ALOGE("%s: Could not get ctl for mixer command - %s",
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303300 __func__, my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003301 return -EINVAL;
3302 }
3303
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303304 ALOGD("%s: %s set to %s", __func__,
3305 my_data->current_backend_cfg[backend_idx].samplerate_mixer_ctl, rate_str);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003306 mixer_ctl_set_enum_by_string(ctl, rate_str);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303307 my_data->current_backend_cfg[backend_idx].sample_rate = sample_rate;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003308 }
3309
3310 return ret;
3311}
3312
3313bool platform_check_codec_backend_cfg(struct audio_device* adev,
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303314 struct audio_usecase* usecase,
3315 snd_device_t snd_device,
Mingming Yin3ee55c62014-08-04 14:23:35 -07003316 unsigned int* new_bit_width,
3317 unsigned int* new_sample_rate)
3318{
3319 bool backend_change = false;
3320 struct listnode *node;
3321 struct stream_out *out = NULL;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303322 unsigned int bit_width;
3323 unsigned int sample_rate;
Manish Dewanganf48adb42015-05-27 10:17:41 +05303324 char value[PROPERTY_VALUE_MAX] = {0};
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303325 int backend_idx = DEFAULT_CODEC_BACKEND;
3326 int usecase_backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003327 struct platform_data *my_data = (struct platform_data *)adev->platform;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003328
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303329 backend_idx = platform_get_backend_index(snd_device);
3330
3331 bit_width = *new_bit_width;
3332 sample_rate = *new_sample_rate;
3333
3334 ALOGI("%s Codec selected backend: %d current bit width: %d and sample rate: %d",
3335 __func__, backend_idx, bit_width, sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003336 // For voice calls use default configuration
3337 // force routing is not required here, caller will do it anyway
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07003338 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07003339 ALOGW("%s:Use default bw and sr for voice/voip calls ",__func__);
Narsinga Rao Chella44376cc2014-10-24 13:27:14 -07003340 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3341 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3342 } else {
3343 /*
3344 * The backend should be configured at highest bit width and/or
3345 * sample rate amongst all playback usecases.
3346 * If the selected sample rate and/or bit width differ with
3347 * current backend sample rate and/or bit width, then, we set the
3348 * backend re-configuration flag.
3349 *
3350 * Exception: 16 bit playbacks is allowed through 16 bit/48 khz backend only
3351 */
Mingming Yin3ee55c62014-08-04 14:23:35 -07003352 list_for_each(node, &adev->usecase_list) {
3353 struct audio_usecase *curr_usecase;
3354 curr_usecase = node_to_item(node, struct audio_usecase, list);
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303355 if (curr_usecase->type == PCM_PLAYBACK &&
3356 usecase != curr_usecase) {
Mingming Yin3ee55c62014-08-04 14:23:35 -07003357 struct stream_out *out =
3358 (struct stream_out*) curr_usecase->stream.out;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303359 usecase_backend_idx = platform_get_backend_index(curr_usecase->out_snd_device);
3360
3361 if (out != NULL &&
3362 usecase_backend_idx == backend_idx) {
3363 ALOGV("%s: usecase Offload playback running bw %d sr %d device %s be_idx %d",
3364 __func__, out->bit_width, out->sample_rate,
3365 platform_get_snd_device_name(curr_usecase->out_snd_device), usecase_backend_idx);
Amit Shekhar278e3362014-09-08 14:08:19 -07003366 if (bit_width < out->bit_width)
3367 bit_width = out->bit_width;
3368 if (sample_rate < out->sample_rate)
3369 sample_rate = out->sample_rate;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303370 if (out->sample_rate < OUTPUT_SAMPLING_RATE_44100)
3371 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003372 }
3373 }
3374 }
3375 }
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303376 if (backend_idx != HEADPHONE_44_1_BACKEND) {
3377 // 16 bit playbacks are allowed through 16 bit/48 khz backend only for
3378 // all non-native streams
3379 if (16 == bit_width) {
Manish Dewanganf48adb42015-05-27 10:17:41 +05303380 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303381 ALOGD("%s: resetting sample_rate back to default, "
3382 "backend_idx: %d", __func__, backend_idx);
3383 }
3384
3385 //check if mulitchannel clip needs to be down sampled to 48k
3386 property_get("audio.playback.mch.downsample",value,"");
3387 if (!strncmp("true", value, sizeof("true"))) {
3388 out = usecase->stream.out;
3389 if ((popcount(out->channel_mask) > 2) &&
3390 (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
3391 !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
3392 /* update out sample rate to reflect current backend sample rate */
3393 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3394 ALOGD("%s: MCH session defaulting sample rate to %d",
3395 __func__, sample_rate);
3396 }
3397 }
3398 // 24 bit playback on speakers is allowed through 48 khz backend only
3399 // bit width re-configured based on platform info
3400 if ((24 == bit_width) &&
3401 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
3402 bit_width = (uint32_t)platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
3403 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
Manish Dewanganf48adb42015-05-27 10:17:41 +05303404 }
3405 }
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303406 ALOGI("%s Codec selected backend: %d updated bit width: %d and sample rate: %d",
3407 __func__, backend_idx, bit_width, sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003408 // Force routing if the expected bitwdith or samplerate
3409 // is not same as current backend comfiguration
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303410 if ((bit_width != my_data->current_backend_cfg[backend_idx].bit_width) ||
3411 (sample_rate != my_data->current_backend_cfg[backend_idx].sample_rate)) {
Amit Shekhar278e3362014-09-08 14:08:19 -07003412 *new_bit_width = bit_width;
3413 *new_sample_rate = sample_rate;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003414 backend_change = true;
Amit Shekhar278e3362014-09-08 14:08:19 -07003415 ALOGI("%s Codec backend needs to be updated. new bit width: %d new sample rate: %d",
3416 __func__, *new_bit_width, *new_sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003417 }
3418
3419 return backend_change;
3420}
3421
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303422bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
3423 struct audio_usecase *usecase, snd_device_t snd_device)
Mingming Yin3ee55c62014-08-04 14:23:35 -07003424{
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303425 unsigned int new_bit_width;
3426 unsigned int new_sample_rate;
3427 int backend_idx = DEFAULT_CODEC_BACKEND;
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003428 struct platform_data *my_data = (struct platform_data *)adev->platform;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003429
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303430 ALOGV("%s: usecase = %d", __func__, usecase->id );
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003431
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303432 backend_idx = platform_get_backend_index(snd_device);
Preetam Singh Ranawat1871ddb2015-02-18 12:23:23 -08003433
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303434 new_bit_width = usecase->stream.out->bit_width;
3435 new_sample_rate = usecase->stream.out->sample_rate;
Mingming Yin3ee55c62014-08-04 14:23:35 -07003436
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303437 ALOGI("%s: Usecase bitwidth %d, samplerate %d, backend_idx %d",
3438 __func__, new_bit_width, new_sample_rate, backend_idx);
3439 if (platform_check_codec_backend_cfg(adev, usecase, snd_device,
Mingming Yin3ee55c62014-08-04 14:23:35 -07003440 &new_bit_width, &new_sample_rate)) {
Preetam Singh Ranawat36f3d372015-06-18 22:59:53 +05303441 platform_set_codec_backend_cfg(adev, snd_device,
3442 new_bit_width, new_sample_rate);
Mingming Yin3ee55c62014-08-04 14:23:35 -07003443 return true;
3444 }
3445
3446 return false;
3447}
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003448
3449int platform_set_snd_device_backend(snd_device_t device, const char *backend)
3450{
3451 int ret = 0;
3452
3453 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3454 ALOGE("%s: Invalid snd_device = %d",
3455 __func__, device);
3456 ret = -EINVAL;
3457 goto done;
3458 }
3459
3460 if (backend_table[device]) {
3461 free(backend_table[device]);
3462 }
3463 backend_table[device] = strdup(backend);
3464done:
3465 return ret;
3466}
3467
3468int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3469{
3470 int ret = 0;
3471 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3472 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3473 ret = -EINVAL;
3474 goto done;
3475 }
3476
3477 if ((type != 0) && (type != 1)) {
3478 ALOGE("%s: invalid usecase type", __func__);
3479 ret = -EINVAL;
3480 }
3481 pcm_device_table[usecase][type] = pcm_id;
3482done:
3483 return ret;
3484}
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003485
3486void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
3487{
3488 *device_to_be_id = msm_device_to_be_id;
3489 *length = msm_be_id_array_len;
3490}
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003491int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask, int snd_id)
3492{
3493 int ret = 0;
3494 int channels = audio_channel_count_from_out_mask(channel_mask);
3495
3496 char channel_map[8];
3497 memset(channel_map, 0, sizeof(channel_map));
3498 /* Following are all most common standard WAV channel layouts
3499 overridden by channel mask if its allowed and different */
3500 switch (channels) {
3501 case 1:
3502 /* AUDIO_CHANNEL_OUT_MONO */
3503 channel_map[0] = PCM_CHANNEL_FC;
Alexy Josephe844aad2014-12-01 16:06:34 -08003504 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003505 case 2:
3506 /* AUDIO_CHANNEL_OUT_STEREO */
3507 channel_map[0] = PCM_CHANNEL_FL;
3508 channel_map[1] = PCM_CHANNEL_FR;
Alexy Josephe844aad2014-12-01 16:06:34 -08003509 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003510 case 3:
3511 /* AUDIO_CHANNEL_OUT_2POINT1 */
3512 channel_map[0] = PCM_CHANNEL_FL;
3513 channel_map[1] = PCM_CHANNEL_FR;
3514 channel_map[2] = PCM_CHANNEL_FC;
3515 break;
3516 case 4:
3517 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
3518 channel_map[0] = PCM_CHANNEL_FL;
3519 channel_map[1] = PCM_CHANNEL_FR;
3520 channel_map[2] = PCM_CHANNEL_LS;
3521 channel_map[3] = PCM_CHANNEL_RS;
3522 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK)
3523 {
3524 channel_map[2] = PCM_CHANNEL_LB;
3525 channel_map[3] = PCM_CHANNEL_RB;
3526 }
3527 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND)
3528 {
3529 channel_map[2] = PCM_CHANNEL_FC;
3530 channel_map[3] = PCM_CHANNEL_CS;
3531 }
3532 break;
3533 case 5:
3534 /* AUDIO_CHANNEL_OUT_PENTA */
3535 channel_map[0] = PCM_CHANNEL_FL;
3536 channel_map[1] = PCM_CHANNEL_FR;
3537 channel_map[2] = PCM_CHANNEL_FC;
3538 channel_map[3] = PCM_CHANNEL_LB;
3539 channel_map[4] = PCM_CHANNEL_RB;
3540 break;
3541 case 6:
3542 /* AUDIO_CHANNEL_OUT_5POINT1 */
3543 channel_map[0] = PCM_CHANNEL_FL;
3544 channel_map[1] = PCM_CHANNEL_FR;
3545 channel_map[2] = PCM_CHANNEL_FC;
3546 channel_map[3] = PCM_CHANNEL_LFE;
3547 channel_map[4] = PCM_CHANNEL_LB;
3548 channel_map[5] = PCM_CHANNEL_RB;
3549 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE)
3550 {
3551 channel_map[4] = PCM_CHANNEL_LS;
3552 channel_map[5] = PCM_CHANNEL_RS;
3553 }
3554 break;
3555 case 7:
3556 /* AUDIO_CHANNEL_OUT_6POINT1 */
3557 channel_map[0] = PCM_CHANNEL_FL;
3558 channel_map[1] = PCM_CHANNEL_FR;
3559 channel_map[2] = PCM_CHANNEL_FC;
3560 channel_map[3] = PCM_CHANNEL_LFE;
3561 channel_map[4] = PCM_CHANNEL_LB;
3562 channel_map[5] = PCM_CHANNEL_RB;
3563 channel_map[6] = PCM_CHANNEL_CS;
Alexy Josephe844aad2014-12-01 16:06:34 -08003564 break;
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003565 case 8:
3566 /* AUDIO_CHANNEL_OUT_7POINT1 */
3567 channel_map[0] = PCM_CHANNEL_FL;
3568 channel_map[1] = PCM_CHANNEL_FR;
3569 channel_map[2] = PCM_CHANNEL_FC;
3570 channel_map[3] = PCM_CHANNEL_LFE;
3571 channel_map[4] = PCM_CHANNEL_LB;
3572 channel_map[5] = PCM_CHANNEL_RB;
3573 channel_map[6] = PCM_CHANNEL_LS;
3574 channel_map[7] = PCM_CHANNEL_RS;
3575 break;
3576 default:
3577 ALOGE("unsupported channels %d for setting channel map", channels);
3578 return -1;
3579 }
3580 ret = platform_set_channel_map(platform, channels, channel_map, snd_id);
3581 return ret;
3582}
3583
3584int platform_get_edid_info(void *platform)
3585{
3586 struct platform_data *my_data = (struct platform_data *)platform;
3587 struct audio_device *adev = my_data->adev;
3588 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3589 char *sad = block;
3590 int num_audio_blocks;
3591 int channel_count = 2;
3592 int i, ret, count;
3593
3594 struct mixer_ctl *ctl;
3595 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
3596 edid_audio_info *info;
3597
3598 if (my_data->edid_valid) {
3599 /* use cached edid */
3600 return 0;
3601 }
3602
3603 if (my_data->edid_info == NULL) {
3604 my_data->edid_info =
3605 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
3606 }
3607
3608 info = my_data->edid_info;
3609
3610 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3611 if (!ctl) {
3612 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3613 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
3614 goto fail;
3615 }
3616
3617 mixer_ctl_update(ctl);
3618
3619 count = mixer_ctl_get_num_values(ctl);
3620
3621 /* Read SAD blocks, clamping the maximum size for safety */
3622 if (count > (int)sizeof(block))
3623 count = (int)sizeof(block);
3624
3625 ret = mixer_ctl_get_array(ctl, block, count);
3626 if (ret != 0) {
3627 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3628 goto fail;
3629 }
3630 edid_data[0] = count;
3631 memcpy(&edid_data[1], block, count);
3632
3633 if (!edid_get_sink_caps(info, edid_data)) {
3634 ALOGE("%s: Failed to get HDMI sink capabilities", __func__);
3635 goto fail;
3636 }
3637 my_data->edid_valid = true;
3638 return 0;
3639fail:
3640 if (my_data->edid_info) {
3641 free(my_data->edid_info);
3642 my_data->edid_info = NULL;
3643 my_data->edid_valid = false;
3644 }
3645 ALOGE("%s: return -EINVAL", __func__);
3646 return -EINVAL;
3647}
3648
3649
3650int platform_set_channel_allocation(void *platform, int channel_alloc)
3651{
3652 struct mixer_ctl *ctl;
3653 const char *mixer_ctl_name = "HDMI RX CA";
3654 int ret;
3655 struct platform_data *my_data = (struct platform_data *)platform;
3656 struct audio_device *adev = my_data->adev;
3657
3658 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3659 if (!ctl) {
3660 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3661 __func__, mixer_ctl_name);
3662 ret = EINVAL;
3663 }
3664 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
3665 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
3666
3667 if (ret < 0) {
3668 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
3669 }
3670
3671 return ret;
3672}
3673
3674int platform_set_channel_map(void *platform, int ch_count, char *ch_map, int snd_id)
3675{
3676 struct mixer_ctl *ctl;
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -08003677 char mixer_ctl_name[44] = {0}; // max length of name is 44 as defined
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003678 int ret;
3679 unsigned int i;
3680 int set_values[8] = {0};
3681 char device_num[13]; // device number up to 2 digit
3682 struct platform_data *my_data = (struct platform_data *)platform;
3683 struct audio_device *adev = my_data->adev;
3684 ALOGV("%s channel_count:%d",__func__, ch_count);
3685 if (NULL == ch_map) {
3686 ALOGE("%s: Invalid channel mapping used", __func__);
3687 return -EINVAL;
3688 }
Fred Ohe0479682015-03-25 16:30:26 -07003689
3690 /*
3691 * If snd_id is greater than 0, stream channel mapping
3692 * If snd_id is below 0, typically -1, device channel mapping
3693 */
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003694 if (snd_id >= 0) {
Fred Ohe0479682015-03-25 16:30:26 -07003695 snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), "Playback Channel Map%d", snd_id);
3696 } else {
3697 strlcpy(mixer_ctl_name, "Playback Device Channel Map", sizeof(mixer_ctl_name));
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003698 }
3699
3700 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
3701
3702 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3703 if (!ctl) {
3704 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3705 __func__, mixer_ctl_name);
3706 return -EINVAL;
3707 }
3708 for (i = 0; i< ARRAY_SIZE(set_values); i++) {
3709 set_values[i] = ch_map[i];
3710 }
3711
3712 ALOGD("%s: set mapping(%d %d %d %d %d %d %d %d) for channel:%d", __func__,
3713 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
3714 set_values[5], set_values[6], set_values[7], ch_count);
3715
3716 ret = mixer_ctl_set_array(ctl, set_values, ch_count);
3717 if (ret < 0) {
3718 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
3719 __func__, ret, ch_count);
3720 }
3721 return ret;
3722}
3723
3724unsigned char platform_map_to_edid_format(int audio_format)
3725{
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003726 unsigned char format;
3727 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
3728 case AUDIO_FORMAT_AC3:
3729 ALOGV("%s: AC3", __func__);
3730 format = AC3;
3731 break;
3732 case AUDIO_FORMAT_AAC:
3733 ALOGV("%s:AAC", __func__);
3734 format = AAC;
3735 break;
3736 case AUDIO_FORMAT_E_AC3:
3737 ALOGV("%s:E_AC3", __func__);
3738 format = DOLBY_DIGITAL_PLUS;
3739 break;
3740 case AUDIO_FORMAT_PCM_16_BIT:
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003741 case AUDIO_FORMAT_PCM_16_BIT_OFFLOAD:
3742 case AUDIO_FORMAT_PCM_24_BIT_OFFLOAD:
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003743 default:
3744 ALOGV("%s:PCM", __func__);
3745 format = LPCM;
3746 break;
3747 }
3748 return format;
3749}
3750
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003751uint32_t platform_get_compress_passthrough_buffer_size(
3752 audio_offload_info_t* info)
3753{
3754 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
3755 if (!info->has_video)
3756 fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
3757
3758 return fragment_size;
3759}
3760
3761void platform_reset_edid_info(void *platform) {
3762
3763 ALOGV("%s:", __func__);
3764 struct platform_data *my_data = (struct platform_data *)platform;
3765 if (my_data->edid_info) {
3766 ALOGV("%s :free edid", __func__);
3767 free(my_data->edid_info);
3768 my_data->edid_info = NULL;
3769 }
3770}
3771
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003772bool platform_is_edid_supported_format(void *platform, int format)
3773{
3774 struct platform_data *my_data = (struct platform_data *)platform;
3775 struct audio_device *adev = my_data->adev;
3776 edid_audio_info *info = NULL;
3777 int num_audio_blocks;
3778 int i, ret, count;
3779 unsigned char format_id = platform_map_to_edid_format(format);
3780
3781 ret = platform_get_edid_info(platform);
3782 info = (edid_audio_info *)my_data->edid_info;
3783 if (ret == 0 && info != NULL) {
3784 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003785 /*
3786 * To check
3787 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
3788 * & DOLBY_DIGITAL_PLUS
3789 */
3790 if (info->audio_blocks_array[i].format_id == format_id) {
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003791 ALOGV("%s:platform_is_edid_supported_format true %x",
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003792 __func__, format);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003793 return true;
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003794 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003795 }
3796 }
3797 ALOGV("%s:platform_is_edid_supported_format false %x",
3798 __func__, format);
3799 return false;
3800}
3801
3802int platform_set_edid_channels_configuration(void *platform, int channels) {
3803
3804 struct platform_data *my_data = (struct platform_data *)platform;
3805 struct audio_device *adev = my_data->adev;
3806 edid_audio_info *info = NULL;
3807 int num_audio_blocks;
3808 int channel_count = 2;
3809 int i, ret, count;
3810 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
3811
3812 ret = platform_get_edid_info(platform);
3813 info = (edid_audio_info *)my_data->edid_info;
3814 if(ret == 0 && info != NULL) {
3815 if (channels > 2) {
3816
3817 ALOGV("%s:able to get HDMI sink capabilities multi channel playback",
3818 __func__);
3819 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
3820 if (info->audio_blocks_array[i].format_id == LPCM &&
3821 info->audio_blocks_array[i].channels > channel_count &&
3822 info->audio_blocks_array[i].channels <= MAX_HDMI_CHANNEL_CNT) {
3823 channel_count = info->audio_blocks_array[i].channels;
3824 }
3825 }
3826 ALOGVV("%s:channel_count:%d", __func__, channel_count);
3827 /*
3828 * Channel map is set for supported hdmi max channel count even
3829 * though the input channel count set on adm is less than or equal to
3830 * max supported channel count
3831 */
3832 platform_set_channel_map(platform, channel_count, info->channel_map, -1);
3833 platform_set_channel_allocation(platform, info->channel_allocation);
3834 } else {
3835 default_channelMap[0] = PCM_CHANNEL_FL;
3836 default_channelMap[1] = PCM_CHANNEL_FR;
3837 platform_set_channel_map(platform,2,default_channelMap,-1);
3838 platform_set_channel_allocation(platform,0);
3839 }
3840 }
3841
3842 return 0;
3843}
3844
3845void platform_cache_edid(void * platform)
3846{
3847 platform_get_edid_info(platform);
3848}
3849
3850void platform_invalidate_edid(void * platform)
3851{
3852 struct platform_data *my_data = (struct platform_data *)platform;
3853 my_data->edid_valid = false;
3854 if (my_data->edid_info) {
3855 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
3856 }
3857}
Pradnya Chaphekar80a8cfb2014-10-20 16:17:01 -07003858
3859int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
3860 const char *mixer_val)
3861{
3862 struct audio_device *adev = out->dev;
3863 struct mixer_ctl *ctl = NULL;
3864 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
3865 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3866 if (!ctl) {
3867 ALOGE("%s: could not get ctl for mixer cmd - %s",
3868 __func__, mixer_ctl_name);
3869 return -EINVAL;
3870 }
3871
3872 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
3873}
3874
3875int platform_set_hdmi_config(struct stream_out *out)
3876{
3877 struct listnode *node;
3878 struct audio_usecase *usecase;
3879 struct audio_device *adev = out->dev;
3880 const char *hdmi_format_ctrl = "HDMI RX Format";
3881 const char *hdmi_rate_ctrl = "HDMI_RX SampleRate";
3882 int sample_rate = out->sample_rate;
3883 /*TODO: Add rules and check if this needs to be done.*/
3884 if((is_offload_usecase(out->usecase)) &&
3885 (out->compr_config.codec->compr_passthr == PASSTHROUGH ||
3886 out->compr_config.codec->compr_passthr == PASSTHROUGH_CONVERT)) {
3887 /* TODO: can we add mixer control for channels here avoid setting */
3888 if ((out->format == AUDIO_FORMAT_E_AC3 ||
3889 out->format == AUDIO_FORMAT_E_AC3_JOC) &&
3890 (out->compr_config.codec->compr_passthr == PASSTHROUGH))
3891 sample_rate = out->sample_rate * 4;
3892 ALOGD("%s:HDMI compress format and samplerate %d, sample_rate %d",
3893 __func__, out->sample_rate, sample_rate);
3894 platform_set_mixer_control(out, hdmi_format_ctrl, "Compr");
3895 switch (sample_rate) {
3896 case 32000:
3897 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_32");
3898 break;
3899 case 44100:
3900 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_44_1");
3901 break;
3902 case 96000:
3903 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_96");
3904 break;
3905 case 176400:
3906 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_176_4");
3907 break;
3908 case 192000:
3909 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_192");
3910 break;
3911 case 128000:
3912 if (out->format != AUDIO_FORMAT_E_AC3) {
3913 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_128");
3914 break;
3915 } else
3916 ALOGW("Unsupported sample rate for E_AC3 32K");
3917 default:
3918 case 48000:
3919 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_48");
3920 break;
3921 }
3922 } else {
3923 ALOGD("%s: HDMI pcm and samplerate %d", __func__,
3924 out->sample_rate);
3925 platform_set_mixer_control(out, hdmi_format_ctrl, "LPCM");
3926 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_48");
3927 }
3928
3929 /*
3930 * Deroute all the playback streams routed to HDMI so that
3931 * the back end is deactivated. Note that backend will not
3932 * be deactivated if any one stream is connected to it.
3933 */
3934 list_for_each(node, &adev->usecase_list) {
3935 usecase = node_to_item(node, struct audio_usecase, list);
3936 ALOGV("%s:disable: usecase type %d, devices 0x%x", __func__,
3937 usecase->type, usecase->devices);
3938 if (usecase->type == PCM_PLAYBACK &&
3939 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3940 disable_audio_route(adev, usecase);
3941 }
3942 }
3943
3944 /*
3945 * Enable all the streams disabled above. Now the HDMI backend
3946 * will be activated with new channel configuration
3947 */
3948 list_for_each(node, &adev->usecase_list) {
3949 usecase = node_to_item(node, struct audio_usecase, list);
3950 ALOGV("%s:enable: usecase type %d, devices 0x%x", __func__,
3951 usecase->type, usecase->devices);
3952 if (usecase->type == PCM_PLAYBACK &&
3953 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3954 enable_audio_route(adev, usecase);
3955 }
3956 }
3957
3958 return 0;
3959}
3960
3961int platform_set_device_params(struct stream_out *out, int param, int value)
3962{
3963 struct audio_device *adev = out->dev;
3964 struct mixer_ctl *ctl;
3965 char *mixer_ctl_name = "Device PP Params";
3966 int ret = 0;
3967 uint32_t set_values[] = {0,0};
3968
3969 set_values[0] = param;
3970 set_values[1] = value;
3971
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 ret = -EINVAL;
3977 goto end;
3978 }
3979
3980 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
3981 __func__,param, value, mixer_ctl_name);
3982 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
3983
3984end:
3985 return ret;
3986}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08003987
3988/*
Laxminath Kasam44f49402015-05-29 18:37:11 +05303989 * This is a lookup table to map names of speaker device with respective left and right TZ names.
3990 * Also the tz names for a particular left or right speaker can be overriden by adding
3991 * corresponding entry in audio_platform_info.xml file.
3992 */
3993struct speaker_device_to_tz_names speaker_device_tz_names = {
3994 {SND_DEVICE_OUT_SPEAKER, "", ""},
3995};
3996
3997/*
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08003998 * This is a lookup table to map android audio input device to audio h/w interface (backend).
3999 * The table can be extended for other input devices by adding appropriate entries.
4000 * Also the audio interface for a particular input device can be overriden by adding
4001 * corresponding entry in audio_platform_info.xml file.
4002 */
4003struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
4004 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), "SLIMBUS_0"},
4005 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), "SLIMBUS_0"},
4006};
4007
4008int audio_device_to_interface_table_len =
4009 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
4010
Karthik Reddy Kattaeef44a92015-05-11 13:43:18 +05304011int platform_set_audio_device_interface(const char *device_name, const char *intf_name,
4012 const char *codec_type __unused)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004013{
4014 int ret = 0;
4015 int i;
4016
4017 if (device_name == NULL || intf_name == NULL) {
4018 ALOGE("%s: Invalid input", __func__);
4019
4020 ret = -EINVAL;
4021 goto done;
4022 }
4023
4024 ALOGD("%s: Enter, device name:%s, intf name:%s", __func__, device_name, intf_name);
4025
4026 size_t device_name_len = strlen(device_name);
4027 for (i = 0; i < audio_device_to_interface_table_len; i++) {
4028 char* name = audio_device_to_interface_table[i].device_name;
4029 size_t name_len = strlen(name);
4030 if ((name_len == device_name_len) &&
4031 (strncmp(device_name, name, name_len) == 0)) {
4032 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
4033 __func__, device_name, intf_name);
4034
4035 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
4036 sizeof(audio_device_to_interface_table[i].interface_name));
4037 goto done;
4038 }
4039 }
4040 ALOGE("%s: Could not find matching device name %s",
4041 __func__, device_name);
4042
4043 ret = -EINVAL;
4044
4045done:
4046 return ret;
4047}
Laxminath Kasam44f49402015-05-29 18:37:11 +05304048
4049int platform_set_spkr_device_tz_names(snd_device_t index,
4050 const char *spkr_1_tz_name, const char *spkr_2_tz_name)
4051{
4052 int ret = 0;
4053 int i;
4054
4055 if (spkr_1_tz_name == NULL && spkr_2_tz_name == NULL) {
4056 ALOGE("%s: Invalid input", __func__);
4057 ret = -EINVAL;
4058 goto done;
4059 }
4060 if (index != speaker_device_tz_names.snd_device) {
4061 ALOGE("%s: not matching speaker device\n");
4062 ret = -EINVAL;
4063 goto done;
4064 }
4065 ALOGD("%s: Enter, spkr_1_tz_name :%s, spkr_2_tz_name:%s",
4066 __func__, spkr_1_tz_name, spkr_2_tz_name);
4067
4068 if (spkr_1_tz_name != NULL)
4069 strlcpy(speaker_device_tz_names.spkr_1_tz_name, spkr_1_tz_name,
4070 sizeof(speaker_device_tz_names.spkr_1_tz_name));
4071
4072 if (spkr_2_tz_name != NULL)
4073 strlcpy(speaker_device_tz_names.spkr_2_tz_name, spkr_2_tz_name,
4074 sizeof(speaker_device_tz_names.spkr_2_tz_name));
4075done:
4076 return ret;
4077}
Zhou Song68624eb2015-06-17 18:45:35 +08004078
4079int platform_get_wsa_mode (void *platform)
4080{
4081 return 0;
4082}