blob: 779ae3396dcc22d2273cd0c9bb86b6d44a303fd4 [file] [log] [blame]
Naresh Tannirue3b18452014-03-04 14:44:27 +05301/*
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08002 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303 * Not a Contribution.
4 *
Naresh Tannirue3b18452014-03-04 14:44:27 +05305 * Copyright (C) 2013 The Android Open Source Project
6 *
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
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053020#define LOG_TAG "msm8916_platform"
Naresh Tannirue3b18452014-03-04 14:44:27 +053021/*#define LOG_NDEBUG 0*/
22#define LOG_NDDEBUG 0
23
24#include <stdlib.h>
25#include <dlfcn.h>
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053026#include <fcntl.h>
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -070027#include <sys/ioctl.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053028#include <cutils/log.h>
29#include <cutils/properties.h>
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053030#include <cutils/str_parms.h>
Naresh Tannirue3b18452014-03-04 14:44:27 +053031#include <audio_hw.h>
32#include <platform_api.h>
33#include "platform.h"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053034#include "audio_extn.h"
35#include "voice_extn.h"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053036#include "edid.h"
37#include "sound/compress_params.h"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053038#include "sound/msmcal-hwdep.h"
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +053039#include <dirent.h>
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +053040#define SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID (100)
Naresh Tannirue3b18452014-03-04 14:44:27 +053041
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053042#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
Asish Bhattacharya4ff24802014-04-24 17:46:54 +053043#define MIXER_XML_PATH_MTP "/system/etc/mixer_paths_mtp.xml"
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +053044#define MIXER_XML_PATH_MSM8909_PM8916 "/system/etc/mixer_paths_msm8909_pm8916.xml"
Walter Yang7ca90d92014-05-06 17:48:02 +080045#define MIXER_XML_PATH_QRD_SKUH "/system/etc/mixer_paths_qrd_skuh.xml"
46#define MIXER_XML_PATH_QRD_SKUI "/system/etc/mixer_paths_qrd_skui.xml"
Walter Yang19f244a2014-06-17 13:30:08 +080047#define MIXER_XML_PATH_QRD_SKUHF "/system/etc/mixer_paths_qrd_skuhf.xml"
Meng Wangf00485b2014-06-03 19:44:38 +080048#define MIXER_XML_PATH_SKUK "/system/etc/mixer_paths_skuk.xml"
Walter Yang42886c52014-10-23 14:31:48 +080049#define MIXER_XML_PATH_SKUA "/system/etc/mixer_paths_skua.xml"
50#define MIXER_XML_PATH_SKUC "/system/etc/mixer_paths_skuc.xml"
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +053051#define MIXER_XML_PATH_SKUE "/system/etc/mixer_paths_skue.xml"
Meng Wangcfefb8b2014-12-05 14:35:55 +080052#define MIXER_XML_PATH_SKUL "/system/etc/mixer_paths_skul.xml"
Walter Yangcd132722015-04-08 16:04:30 +080053#define MIXER_XML_PATH_SKUM "/system/etc/mixer_paths_qrd_skum.xml"
Meng Wangf00485b2014-06-03 19:44:38 +080054#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053055#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053056#define MIXER_XML_PATH_I2S "/system/etc/mixer_paths_i2s.xml"
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +053057#define MIXER_XML_PATH_WCD9306 "/system/etc/mixer_paths_wcd9306.xml"
Aviral Gupta8ed0eec2014-08-25 10:22:11 +053058#define MIXER_XML_PATH_WCD9330 "/system/etc/mixer_paths_wcd9330.xml"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053059#define PLATFORM_INFO_XML_PATH "/system/etc/audio_platform_info.xml"
Dhananjay Kumara68d7af2015-05-25 19:11:30 +053060#define PLATFORM_INFO_XML_PATH_EXTCODEC "/system/etc/audio_platform_info_extcodec.xml"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053061
Naresh Tannirue3b18452014-03-04 14:44:27 +053062#define LIB_ACDB_LOADER "libacdbloader.so"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053063#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
Avinash Vaish71c066d2014-08-27 12:32:35 +053064#define CVD_VERSION_MIXER_CTL "CVD Version"
Naresh Tannirue3b18452014-03-04 14:44:27 +053065
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053066#define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
67#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
68#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
69#define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
70/* Used in calculating fragment size for pcm offload */
Alexy Joseph2ce25e22015-06-18 12:02:01 -070071#define PCM_OFFLOAD_BUFFER_DURATION 40 /* 40 millisecs */
Naresh Tannirue3b18452014-03-04 14:44:27 +053072
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053073/* 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
Naresh Tannirue3b18452014-03-04 14:44:27 +053076 */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +053077#define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
Naresh Tannirude7d1752015-07-01 15:07:46 +053078#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE 512
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +053079
80/*
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)
Naresh Tannirue3b18452014-03-04 14:44:27 +053085
Preetam Singh Ranawat6efde5c2015-04-24 11:04:22 +053086#define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
87#define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
Naresh Tannirue3b18452014-03-04 14:44:27 +053088/*
89 * 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
Avinash Vaish71c066d2014-08-27 12:32:35 +053097#define MAX_CVD_VERSION_STRING_SIZE 100
Naresh Tannirue3b18452014-03-04 14:44:27 +053098
99/* EDID format ID for LPCM audio */
100#define EDID_FORMAT_LPCM 1
101
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700102/* fallback app type if the default app type from acdb loader fails */
103#define DEFAULT_APP_TYPE 0x11130
Naresh Tanniru2727f822015-05-11 15:27:08 +0530104#define DEFAULT_APP_TYPE_RX_PATH 0x11130
105#define DEFAULT_APP_TYPE_TX_PATH 0x11132
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700106
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530107/* Retry for delay in FW loading*/
108#define RETRY_NUMBER 20
109#define RETRY_US 500000
110#define MAX_SND_CARD 8
111
112#define SAMPLE_RATE_8KHZ 8000
113#define SAMPLE_RATE_16KHZ 16000
114
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530115#define MAX_SET_CAL_BYTE_SIZE 65536
116
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530117#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530118#define AUDIO_PARAMETER_KEY_SLOWTALK "st_enable"
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530119#define AUDIO_PARAMETER_KEY_HD_VOICE "hd_voice"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530120#define AUDIO_PARAMETER_KEY_VOLUME_BOOST "volume_boost"
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530121#define AUDIO_PARAMETER_KEY_AUD_CALDATA "cal_data"
122#define AUDIO_PARAMETER_KEY_AUD_CALRESULT "cal_result"
123
124
125/* Query external audio device connection status */
126#define AUDIO_PARAMETER_KEY_EXT_AUDIO_DEVICE "ext_audio_device"
127
128#define EVENT_EXTERNAL_SPK_1 "qc_ext_spk_1"
129#define EVENT_EXTERNAL_SPK_2 "qc_ext_spk_2"
130#define EVENT_EXTERNAL_MIC "qc_ext_mic"
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530131#define MAX_CAL_NAME 20
132
133char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = {
134 [WCD9XXX_ANC_CAL] = "anc_cal",
135 [WCD9XXX_MBHC_CAL] = "mbhc_cal",
136 [WCD9XXX_MAD_CAL] = "mad_cal",
137};
138
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530139#define AUDIO_PARAMETER_KEY_REC_PLAY_CONC "rec_play_conc_on"
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530140
141enum {
142 VOICE_FEATURE_SET_DEFAULT,
143 VOICE_FEATURE_SET_VOLUME_BOOST
144};
145
Naresh Tannirue3b18452014-03-04 14:44:27 +0530146struct audio_block_header
147{
148 int reserved;
149 int length;
150};
151
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530152typedef struct acdb_audio_cal_cfg {
153 uint32_t persist;
154 uint32_t snd_dev_id;
155 audio_devices_t dev_id;
156 int32_t acdb_dev_id;
157 uint32_t app_type;
158 uint32_t topo_id;
159 uint32_t sampling_rate;
160 uint32_t cal_type;
161 uint32_t module_id;
162 uint32_t param_id;
163} acdb_audio_cal_cfg_t;
164
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530165/* Audio calibration related functions */
Naresh Tannirue3b18452014-03-04 14:44:27 +0530166typedef void (*acdb_deallocate_t)();
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530167typedef int (*acdb_init_t)(const char *, char *, int);
168typedef void (*acdb_send_audio_cal_t)(int, int, int , int);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530169typedef void (*acdb_send_voice_cal_t)(int, int);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530170typedef int (*acdb_reload_vocvoltable_t)(int);
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700171typedef int (*acdb_get_default_app_type_t)(void);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +0530172typedef int (*acdb_loader_get_calibration_t)(char *attr, int size, void *data);
173acdb_loader_get_calibration_t acdb_loader_get_calibration;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530174typedef int (*acdb_set_audio_cal_t) (void *, void *, uint32_t);
175typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*);
Naresh Tannirue3b18452014-03-04 14:44:27 +0530176
Naresh Tannirue3b18452014-03-04 14:44:27 +0530177struct platform_data {
178 struct audio_device *adev;
179 bool fluence_in_spkr_mode;
180 bool fluence_in_voice_call;
181 bool fluence_in_voice_rec;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530182 bool fluence_in_audio_rec;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530183 bool external_spk_1;
184 bool external_spk_2;
185 bool external_mic;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530186 int fluence_type;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +0530187 char fluence_cap[PROPERTY_VALUE_MAX];
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530188 int fluence_mode;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530189 bool slowtalk;
Avinash Vaishd5fa4572014-09-15 14:41:14 +0530190 bool hd_voice;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530191 bool ec_ref_enabled;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530192 bool is_wsa_speaker;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530193 /* Audio calibration related functions */
194 void *acdb_handle;
195 int voice_feature_set;
196 acdb_init_t acdb_init;
197 acdb_deallocate_t acdb_deallocate;
198 acdb_send_audio_cal_t acdb_send_audio_cal;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530199 acdb_set_audio_cal_t acdb_set_audio_cal;
200 acdb_get_audio_cal_t acdb_get_audio_cal;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530201 acdb_send_voice_cal_t acdb_send_voice_cal;
202 acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -0700203 acdb_get_default_app_type_t acdb_get_default_app_type;
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530204#ifdef RECORD_PLAY_CONCURRENCY
205 bool rec_play_conc_set;
206#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530207 void *hw_info;
208 struct csd_data *csd;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530209 void *edid_info;
210 bool edid_valid;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530211};
212
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530213static bool is_external_codec = false;
214static const int pcm_device_table_of_ext_codec[AUDIO_USECASE_MAX][2] = {
215 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE_OF_EXT_CODEC, QCHAT_CALL_PCM_DEVICE_OF_EXT_CODEC}
216};
217
218/* List of use cases that has different PCM device ID's for internal and external codecs */
219static const int misc_usecase[AUDIO_USECASE_MAX] = { USECASE_QCHAT_CALL };
220
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530221int pcm_device_table[AUDIO_USECASE_MAX][2] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530222 [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
223 DEEP_BUFFER_PCM_DEVICE},
224 [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
225 LOWLATENCY_PCM_DEVICE},
226 [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
227 MULTIMEDIA2_PCM_DEVICE},
228 [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
229 {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530230#ifdef MULTIPLE_OFFLOAD_ENABLED
Dhananjay Kumara68d7af2015-05-25 19:11:30 +0530231 /* Below entries are initialized with invalid values
232 * Valid values should be updated from fnc platform_info_init()
233 * based on pcm ids defined in audio_platform_info.xml.
234 */
235 [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = {-1, -1},
236 [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = {-1, -1},
237 [USECASE_AUDIO_PLAYBACK_OFFLOAD4] = {-1, -1},
238 [USECASE_AUDIO_PLAYBACK_OFFLOAD5] = {-1, -1},
239 [USECASE_AUDIO_PLAYBACK_OFFLOAD6] = {-1, -1},
240 [USECASE_AUDIO_PLAYBACK_OFFLOAD7] = {-1, -1},
241 [USECASE_AUDIO_PLAYBACK_OFFLOAD8] = {-1, -1},
242 [USECASE_AUDIO_PLAYBACK_OFFLOAD9] = {-1, -1},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530243#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530244 [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
245 [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
246 [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
247 LOWLATENCY_PCM_DEVICE},
248 [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
249 MULTIMEDIA2_PCM_DEVICE},
250 [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
251 [USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
252 [USECASE_AUDIO_HFP_SCO_WB] = {HFP_PCM_RX, HFP_SCO_RX},
253 [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
254 [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
255 [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
256 [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
Karthik Reddy Katta3b0a60c2014-04-06 14:52:37 +0530257 [USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530258 [USECASE_COMPRESS_VOIP_CALL] = {COMPRESS_VOIP_CALL_PCM_DEVICE, COMPRESS_VOIP_CALL_PCM_DEVICE},
259 [USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
260 AUDIO_RECORD_PCM_DEVICE},
261 [USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
262 AUDIO_RECORD_PCM_DEVICE},
263 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
264 AUDIO_RECORD_PCM_DEVICE},
265 [USECASE_INCALL_REC_UPLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
266 COMPRESS_CAPTURE_DEVICE},
267 [USECASE_INCALL_REC_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
268 COMPRESS_CAPTURE_DEVICE},
269 [USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS] = {COMPRESS_CAPTURE_DEVICE,
270 COMPRESS_CAPTURE_DEVICE},
271 [USECASE_INCALL_MUSIC_UPLINK] = {INCALL_MUSIC_UPLINK_PCM_DEVICE,
272 INCALL_MUSIC_UPLINK_PCM_DEVICE},
273 [USECASE_INCALL_MUSIC_UPLINK2] = {INCALL_MUSIC_UPLINK2_PCM_DEVICE,
274 INCALL_MUSIC_UPLINK2_PCM_DEVICE},
275 [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
276 [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530277 [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
278 AFE_PROXY_RECORD_PCM_DEVICE},
279 [USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
280 AFE_PROXY_RECORD_PCM_DEVICE},
Naresh Tannirue3b18452014-03-04 14:44:27 +0530281};
282
283/* Array to store sound devices */
284static const char * const device_table[SND_DEVICE_MAX] = {
285 [SND_DEVICE_NONE] = "none",
286 /* Playback sound devices */
287 [SND_DEVICE_OUT_HANDSET] = "handset",
288 [SND_DEVICE_OUT_SPEAKER] = "speaker",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530289 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = "speaker-ext-1",
290 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = "speaker-ext-2",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530291 [SND_DEVICE_OUT_SPEAKER_WSA] = "wsa-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530292 [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
293 [SND_DEVICE_OUT_HEADPHONES] = "headphones",
294 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530295 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = "speaker-and-headphones-ext-1",
296 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = "speaker-and-headphones-ext-2",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530297 [SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
298 [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530299 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = "wsa-voice-speaker",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530300 [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
301 [SND_DEVICE_OUT_HDMI] = "hdmi",
302 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
303 [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530304 [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530305 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
306 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
307 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530308 [SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530309 [SND_DEVICE_OUT_AFE_PROXY] = "afe-proxy",
310 [SND_DEVICE_OUT_USB_HEADSET] = "usb-headphones",
311 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = "speaker-and-usb-headphones",
312 [SND_DEVICE_OUT_TRANSMISSION_FM] = "transmission-fm",
313 [SND_DEVICE_OUT_ANC_HEADSET] = "anc-headphones",
314 [SND_DEVICE_OUT_ANC_FB_HEADSET] = "anc-fb-headphones",
315 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = "voice-anc-headphones",
316 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = "voice-anc-fb-headphones",
317 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
318 [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
319 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530320 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = "voice-speaker-protected",
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530321#ifdef RECORD_PLAY_CONCURRENCY
322 [SND_DEVICE_OUT_VOIP_HANDSET] = "voip-handset",
323 [SND_DEVICE_OUT_VOIP_SPEAKER] = "voip-speaker",
324 [SND_DEVICE_OUT_VOIP_HEADPHONES] = "voip-headphones",
325#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530326
327 /* Capture sound devices */
328 [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530329 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = "handset-mic-ext",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530330 [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530331 [SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
332 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
333 [SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
334 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
335 [SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
336 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
337 [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
338 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
339 [SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
340 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
341 [SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
342 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
343 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
344 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
345 [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
346 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = "headset-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530347 [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
348 [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
349 [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
350 [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700351 [SND_DEVICE_IN_BT_SCO_MIC_NREC] = "bt-sco-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530352 [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700353 [SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = "bt-sco-mic-wb",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530354 [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530355 [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
356 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
357 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = "voice-speaker-qmic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530358 [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
359 [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
360 [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
361 [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530362 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
363 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
364 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530365 [SND_DEVICE_IN_VOICE_RX] = "voice-rx",
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530366 [SND_DEVICE_IN_USB_HEADSET_MIC] = "usb-headset-mic",
367 [SND_DEVICE_IN_CAPTURE_FM] = "capture-fm",
368 [SND_DEVICE_IN_AANC_HANDSET_MIC] = "aanc-handset-mic",
369 [SND_DEVICE_IN_QUAD_MIC] = "quad-mic",
370 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = "handset-stereo-dmic-ef",
371 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = "speaker-stereo-dmic-ef",
372 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = "vi-feedback",
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530373 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = "voice-speaker-dmic-broadside",
374 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = "speaker-dmic-broadside",
375 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = "speaker-dmic-broadside",
376 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = "speaker-dmic-broadside",
377 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = "speaker-dmic-broadside",
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530378 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = "aanc-fluence-dmic-handset",
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530379 [SND_DEVICE_IN_HANDSET_QMIC] = "quad-mic",
380 [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = "quad-mic",
381 [SND_DEVICE_IN_SPEAKER_QMIC_NS] = "quad-mic",
382 [SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS] = "quad-mic",
Naresh Tannirue3b18452014-03-04 14:44:27 +0530383};
384
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530385// Platform specific backend bit width table
386static int backend_bit_width_table[SND_DEVICE_MAX] = {0};
387
Naresh Tannirue3b18452014-03-04 14:44:27 +0530388/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530389static int acdb_device_table[SND_DEVICE_MAX] = {
Naresh Tannirue3b18452014-03-04 14:44:27 +0530390 [SND_DEVICE_NONE] = -1,
391 [SND_DEVICE_OUT_HANDSET] = 7,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530392 [SND_DEVICE_OUT_SPEAKER] = 14,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530393 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_1] = 14,
394 [SND_DEVICE_OUT_SPEAKER_EXTERNAL_2] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530395 [SND_DEVICE_OUT_SPEAKER_WSA] = 135,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530396 [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530397 [SND_DEVICE_OUT_HEADPHONES] = 10,
398 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530399 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1] = 10,
400 [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2] = 10,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530401 [SND_DEVICE_OUT_VOICE_HANDSET] = 7,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530402 [SND_DEVICE_OUT_VOICE_SPEAKER] = 14,
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530403 [SND_DEVICE_OUT_VOICE_SPEAKER_WSA] = 135,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530404 [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
405 [SND_DEVICE_OUT_HDMI] = 18,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530406 [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530407 [SND_DEVICE_OUT_BT_SCO] = 22,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530408 [SND_DEVICE_OUT_BT_SCO_WB] = 39,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530409 [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
410 [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
411 [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530412 [SND_DEVICE_OUT_VOICE_TX] = 45,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530413 [SND_DEVICE_OUT_AFE_PROXY] = 0,
414 [SND_DEVICE_OUT_USB_HEADSET] = 45,
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +0530415 [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530416 [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
417 [SND_DEVICE_OUT_ANC_HEADSET] = 26,
418 [SND_DEVICE_OUT_ANC_FB_HEADSET] = 27,
419 [SND_DEVICE_OUT_VOICE_ANC_HEADSET] = 26,
420 [SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET] = 27,
421 [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
422 [SND_DEVICE_OUT_ANC_HANDSET] = 103,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530423 [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 124,
424 [SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED] = 101,
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530425#ifdef RECORD_PLAY_CONCURRENCY
426 [SND_DEVICE_OUT_VOIP_HANDSET] = 133,
427 [SND_DEVICE_OUT_VOIP_SPEAKER] = 132,
428 [SND_DEVICE_OUT_VOIP_HEADPHONES] = 134,
429#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +0530430
431 [SND_DEVICE_IN_HANDSET_MIC] = 4,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530432 [SND_DEVICE_IN_HANDSET_MIC_EXTERNAL] = 4,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530433 [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
434 [SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
435 [SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
436 [SND_DEVICE_IN_HANDSET_DMIC] = 41,
437 [SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
438 [SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
439 [SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
440 [SND_DEVICE_IN_SPEAKER_MIC] = 11,
441 [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
442 [SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
443 [SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
444 [SND_DEVICE_IN_SPEAKER_DMIC] = 43,
445 [SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
446 [SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
447 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530448 [SND_DEVICE_IN_HEADSET_MIC] = 8,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530449 [SND_DEVICE_IN_HEADSET_MIC_FLUENCE] = 47,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530450 [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,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530455 [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,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530457 [SND_DEVICE_IN_CAMCORDER_MIC] = 4,
458 [SND_DEVICE_IN_VOICE_DMIC] = 41,
459 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
460 [SND_DEVICE_IN_VOICE_SPEAKER_QMIC] = 19,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530461 [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,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530464 [SND_DEVICE_IN_VOICE_REC_MIC] = 4,
465 [SND_DEVICE_IN_VOICE_REC_MIC_NS] = 107,
466 [SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 34,
467 [SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 41,
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530468 [SND_DEVICE_IN_VOICE_RX] = 44,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530469 [SND_DEVICE_IN_USB_HEADSET_MIC] = 44,
470 [SND_DEVICE_IN_CAPTURE_FM] = 0,
471 [SND_DEVICE_IN_AANC_HANDSET_MIC] = 104,
472 [SND_DEVICE_IN_QUAD_MIC] = 46,
473 [SND_DEVICE_IN_HANDSET_STEREO_DMIC] = 34,
474 [SND_DEVICE_IN_SPEAKER_STEREO_DMIC] = 35,
475 [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +0530476 [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE] = 12,
477 [SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE] = 12,
478 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
479 [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
480 [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530481 [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 135,
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530482 [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,
Naresh Tannirue3b18452014-03-04 14:44:27 +0530486};
487
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530488struct name_to_index {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530489 char name[100];
490 unsigned int index;
491};
Naresh Tannirue3b18452014-03-04 14:44:27 +0530492
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530493#define TO_NAME_INDEX(X) #X, X
Naresh Tannirue3b18452014-03-04 14:44:27 +0530494
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530495/* Used to get index from parsed sting */
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530496static struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530497 {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
498 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530499 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_1)},
500 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_EXTERNAL_2)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530501 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_WSA)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530502 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
503 {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
504 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530505 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1)},
506 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530507 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
508 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +0530509 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_WSA)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530510 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
511 {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
512 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
513 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
514 {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
515 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
516 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
517 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530518 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530519 {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
520 {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
521 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
522 {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
523 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
524 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
525 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
526 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
527 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
528 {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
529 {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530530 {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED)},
Naresh Tanniruc0517bc2014-10-26 15:30:55 +0530531#ifdef RECORD_PLAY_CONCURRENCY
532 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HANDSET)},
533 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_SPEAKER)},
534 {TO_NAME_INDEX(SND_DEVICE_OUT_VOIP_HEADPHONES)},
535#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530536 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530537 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_EXTERNAL)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530538 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
539 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
540 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
541 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
542 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
543 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
544 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
545 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
546 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
547 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
548 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
549 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
550 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
551 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
552 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
553 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
554 {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
555 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
556 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
557 {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
558 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700559 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530560 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
Vicky Sehrawate240e5d2014-08-12 17:17:04 -0700561 {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB_NREC)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530562 {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
563 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
564 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
565 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
566 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
567 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
568 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
569 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
570 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
571 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
572 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +0530573 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_RX)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530574 {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
575 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
576 {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
577 {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
578 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
579 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
580 {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
Sidipotu Ashok3bcca232014-11-07 14:41:58 +0530581 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC)},
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530582 {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE)},
583 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_BROADSIDE)},
584 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE)},
585 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE)},
586 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE)},
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +0530587 {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_QMIC)},
588 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC)},
589 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_NS)},
590 {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS)},
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530591};
592
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530593static char * backend_table[SND_DEVICE_MAX] = {0};
594
595static struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
596 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
597 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
598 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
599 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
600#ifdef MULTIPLE_OFFLOAD_ENABLED
601 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD2)},
602 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD3)},
603 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD4)},
604 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD5)},
605 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD6)},
606 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD7)},
607 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD8)},
608 {TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD9)},
609#endif
610 {TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
611 {TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
612 {TO_NAME_INDEX(USECASE_VOICE_CALL)},
613 {TO_NAME_INDEX(USECASE_VOICE2_CALL)},
614 {TO_NAME_INDEX(USECASE_VOLTE_CALL)},
615 {TO_NAME_INDEX(USECASE_QCHAT_CALL)},
616 {TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
617 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
618 {TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
619 {TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
620 {TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
621};
622
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700623#define NO_COLS 2
624static int msm_be_id_array_len;
625static int (*msm_device_to_be_id)[];
626
627/* Below table lists output device to BE_ID mapping*/
628/* Update the table based on the board configuration*/
629
630static int msm_device_to_be_id_internal_codec [][NO_COLS] = {
631 {AUDIO_DEVICE_OUT_EARPIECE , 34},
632 {AUDIO_DEVICE_OUT_SPEAKER , 34},
633 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 34},
634 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 34},
635 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
636 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
637 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
638 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
639 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
640 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
641 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
642 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
643 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
644 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
645 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
646 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
647 {AUDIO_DEVICE_OUT_PROXY , 9},
648 {AUDIO_DEVICE_OUT_FM , 7},
649 {AUDIO_DEVICE_OUT_FM_TX , 8},
650 {AUDIO_DEVICE_OUT_ALL , -1},
651 {AUDIO_DEVICE_NONE , -1},
652 {AUDIO_DEVICE_OUT_DEFAULT , -1},
653};
654
655static int msm_device_to_be_id_external_codec [][NO_COLS] = {
656 {AUDIO_DEVICE_OUT_EARPIECE , 2},
657 {AUDIO_DEVICE_OUT_SPEAKER , 2},
658 {AUDIO_DEVICE_OUT_WIRED_HEADSET , 2},
659 {AUDIO_DEVICE_OUT_WIRED_HEADPHONE , 2},
660 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO , 11},
661 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET , 11},
662 {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT , 11},
663 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP , -1},
664 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES , -1},
665 {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER , -1},
666 {AUDIO_DEVICE_OUT_AUX_DIGITAL , 4},
667 {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET , 9},
668 {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET , 9},
669 {AUDIO_DEVICE_OUT_USB_ACCESSORY , -1},
670 {AUDIO_DEVICE_OUT_USB_DEVICE , -1},
671 {AUDIO_DEVICE_OUT_REMOTE_SUBMIX , 9},
672 {AUDIO_DEVICE_OUT_PROXY , 9},
673 {AUDIO_DEVICE_OUT_FM , 7},
674 {AUDIO_DEVICE_OUT_FM_TX , 8},
675 {AUDIO_DEVICE_OUT_ALL , -1},
676 {AUDIO_DEVICE_NONE , -1},
677 {AUDIO_DEVICE_OUT_DEFAULT , -1},
678};
679
680
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530681#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
682#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530683
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530684static bool is_misc_usecase(audio_usecase_t usecase) {
685 bool ret = false;
686 int i;
687
688 for (i = 0; i < AUDIO_USECASE_MAX; i++) {
689 if(usecase == misc_usecase[i]) {
690 ret = true;
691 break;
692 }
693 }
694 return ret;
695}
696
697
698static void update_codec_type(const char *snd_card_name) {
699
700 if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
701 sizeof("msm8939-tapan-snd-card")) ||
702 !strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
703 sizeof("msm8939-tapan9302-snd-card"))||
704 !strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
Karthik Reddy Katta508eca42015-05-11 13:43:18 +0530705 sizeof("msm8939-tomtom9330-snd-card")) ||
706 !strncmp(snd_card_name, "msm8952-tomtom-snd-card",
707 sizeof("msm8952-tomtom-snd-card"))) {
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +0530708 ALOGI("%s: snd_card_name: %s",__func__,snd_card_name);
709 is_external_codec = true;
710 }
711}
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530712static void query_platform(const char *snd_card_name,
713 char *mixer_xml_path)
714{
715 if (!strncmp(snd_card_name, "msm8x16-snd-card-mtp",
716 sizeof("msm8x16-snd-card-mtp"))) {
717 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
718 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700719
720 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
721 msm_be_id_array_len =
722 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
723
Walter Yang7ca90d92014-05-06 17:48:02 +0800724 } else if (!strncmp(snd_card_name, "msm8x16-skuh-snd-card",
725 sizeof("msm8x16-skuh-snd-card"))) {
726 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUH,
727 sizeof(MIXER_XML_PATH_QRD_SKUH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700728
729 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
730 msm_be_id_array_len =
731 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
732
Walter Yang7ca90d92014-05-06 17:48:02 +0800733 } else if (!strncmp(snd_card_name, "msm8x16-skui-snd-card",
734 sizeof("msm8x16-skui-snd-card"))) {
735 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUI,
736 sizeof(MIXER_XML_PATH_QRD_SKUI));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700737
738 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
739 msm_be_id_array_len =
740 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
741
Walter Yang19f244a2014-06-17 13:30:08 +0800742 } else if (!strncmp(snd_card_name, "msm8x16-skuhf-snd-card",
743 sizeof("msm8x16-skuhf-snd-card"))) {
744 strlcpy(mixer_xml_path, MIXER_XML_PATH_QRD_SKUHF,
745 sizeof(MIXER_XML_PATH_QRD_SKUHF));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700746
747 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
748 msm_be_id_array_len =
749 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
750
Walter Yangc899d572014-05-27 21:52:17 +0800751 } else if (!strncmp(snd_card_name, "msm8939-snd-card-mtp",
Yamit Mehtac6003e22014-05-19 10:26:02 +0530752 sizeof("msm8939-snd-card-mtp"))) {
Aravind Kumar71ba22b2014-06-23 15:18:50 +0530753 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
754 sizeof(MIXER_XML_PATH_MTP));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700755
756 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
757 msm_be_id_array_len =
758 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
759
Meng Wangf00485b2014-06-03 19:44:38 +0800760 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skuk",
761 sizeof("msm8939-snd-card-skuk"))) {
762 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUK,
763 sizeof(MIXER_XML_PATH_SKUK));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700764 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
765 msm_be_id_array_len =
766 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
767
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530768 } else if (!strncmp(snd_card_name, "msm8939-tapan-snd-card",
769 sizeof("msm8939-tapan-snd-card"))) {
770 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
771 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700772 msm_device_to_be_id = msm_device_to_be_id_external_codec;
773 msm_be_id_array_len =
774 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
775
Asish Bhattacharyacb8e6d02014-06-19 12:32:25 +0530776 } else if (!strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
777 sizeof("msm8939-tapan9302-snd-card"))) {
778 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9306,
779 sizeof(MIXER_XML_PATH_WCD9306));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700780
781 msm_device_to_be_id = msm_device_to_be_id_external_codec;
782 msm_be_id_array_len =
783 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
784
Aviral Gupta8ed0eec2014-08-25 10:22:11 +0530785 } else if (!strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
786 sizeof("msm8939-tomtom9330-snd-card"))) {
787 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
788 sizeof(MIXER_XML_PATH_WCD9330));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700789 msm_device_to_be_id = msm_device_to_be_id_external_codec;
790 msm_be_id_array_len =
791 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
792
Walter Yang42886c52014-10-23 14:31:48 +0800793 } else if (!strncmp(snd_card_name, "msm8909-skua-snd-card",
794 sizeof("msm8909-skua-snd-card"))) {
795 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUA,
796 sizeof(MIXER_XML_PATH_SKUA));
Walter Yang42886c52014-10-23 14:31:48 +0800797 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
798 msm_be_id_array_len =
799 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530800
Walter Yang42886c52014-10-23 14:31:48 +0800801 } else if (!strncmp(snd_card_name, "msm8909-skuc-snd-card",
802 sizeof("msm8909-skuc-snd-card"))) {
803 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUC,
804 sizeof(MIXER_XML_PATH_SKUC));
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530805 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
806 msm_be_id_array_len =
807 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
808
809 } else if (!strncmp(snd_card_name, "msm8909-pm8916-snd-card",
810 sizeof("msm8909-pm8916-snd-card"))) {
811 strlcpy(mixer_xml_path, MIXER_XML_PATH_MSM8909_PM8916,
812 sizeof(MIXER_XML_PATH_MSM8909_PM8916));
Walter Yang42886c52014-10-23 14:31:48 +0800813
814 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
815 msm_be_id_array_len =
816 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +0530817
818 } else if (!strncmp(snd_card_name, "msm8909-skue-snd-card",
819 sizeof("msm8909-skue-snd-card"))) {
820 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUE,
821 sizeof(MIXER_XML_PATH_SKUE));
822 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
823 msm_be_id_array_len =
824 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
825
Meng Wangcfefb8b2014-12-05 14:35:55 +0800826 } else if (!strncmp(snd_card_name, "msm8939-snd-card-skul",
827 sizeof("msm8939-snd-card-skul"))) {
828 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUL,
829 sizeof(MIXER_XML_PATH_SKUL));
830 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
831 msm_be_id_array_len =
832 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +0530833 } else if (!strncmp(snd_card_name, "msm8952-snd-card-mtp",
834 sizeof("msm8952-snd-card-mtpmsm8952-snd-card-mtp"))) {
835 strlcpy(mixer_xml_path, MIXER_XML_PATH_MTP,
836 sizeof(MIXER_XML_PATH_MTP));
837 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
838 msm_be_id_array_len =
839 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
840 } else if (!strncmp(snd_card_name, "msm8952-tomtom-snd-card",
841 sizeof("msm8952-tomtom-snd-card"))) {
842 strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330,
843 sizeof(MIXER_XML_PATH_WCD9330));
844 msm_device_to_be_id = msm_device_to_be_id_external_codec;
845 msm_be_id_array_len =
846 sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
Walter Yangcd132722015-04-08 16:04:30 +0800847 } else if (!strncmp(snd_card_name, "msm8952-skum-snd-card",
848 sizeof("msm8952-skum-snd-card"))) {
849 strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUM,
850 sizeof(MIXER_XML_PATH_SKUM));
851 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
852 msm_be_id_array_len =
853 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
Naresh Tanniru0d28b4a2015-03-23 00:58:49 +0530854
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530855 } else {
856 strlcpy(mixer_xml_path, MIXER_XML_PATH,
857 sizeof(MIXER_XML_PATH));
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -0700858
859 msm_device_to_be_id = msm_device_to_be_id_internal_codec;
860 msm_be_id_array_len =
861 sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
862
Asish Bhattacharya4ff24802014-04-24 17:46:54 +0530863 }
864}
865
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530866void platform_set_echo_reference(void *platform, bool enable)
Naresh Tannirue3b18452014-03-04 14:44:27 +0530867{
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530868 struct platform_data *my_data = (struct platform_data *)platform;
869 struct audio_device *adev = my_data->adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +0530870
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530871 if (my_data->ec_ref_enabled) {
872 my_data->ec_ref_enabled = false;
873 ALOGV("%s: disabling echo-reference", __func__);
874 audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +0530875 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530876
877 if (enable) {
878 my_data->ec_ref_enabled = true;
879 ALOGD("%s: enabling echo-reference", __func__);
880 audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
881 }
Naresh Tannirue3b18452014-03-04 14:44:27 +0530882}
883
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530884static struct csd_data *open_csd_client()
885{
886 struct csd_data *csd = calloc(1, sizeof(struct csd_data));
Chaithanya Krishna Bacharajudb6236a2015-01-30 10:08:33 +0530887 if (!csd) {
888 ALOGE("failed to allocate csd_data mem");
889 return NULL;
890 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530891
892 csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
893 if (csd->csd_client == NULL) {
894 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
895 goto error;
896 } else {
897 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
898
899 csd->deinit = (deinit_t)dlsym(csd->csd_client,
900 "csd_client_deinit");
901 if (csd->deinit == NULL) {
902 ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
903 dlerror());
904 goto error;
905 }
906 csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
907 "csd_client_disable_device");
908 if (csd->disable_device == NULL) {
909 ALOGE("%s: dlsym error %s for csd_client_disable_device",
910 __func__, dlerror());
911 goto error;
912 }
913 csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
914 "csd_client_enable_device_config");
915 if (csd->enable_device_config == NULL) {
916 ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
917 __func__, dlerror());
918 goto error;
919 }
920 csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
921 "csd_client_enable_device");
922 if (csd->enable_device == NULL) {
923 ALOGE("%s: dlsym error %s for csd_client_enable_device",
924 __func__, dlerror());
925 goto error;
926 }
927 csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
928 "csd_client_start_voice");
929 if (csd->start_voice == NULL) {
930 ALOGE("%s: dlsym error %s for csd_client_start_voice",
931 __func__, dlerror());
932 goto error;
933 }
934 csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
935 "csd_client_stop_voice");
936 if (csd->stop_voice == NULL) {
937 ALOGE("%s: dlsym error %s for csd_client_stop_voice",
938 __func__, dlerror());
939 goto error;
940 }
941 csd->volume = (volume_t)dlsym(csd->csd_client,
942 "csd_client_volume");
943 if (csd->volume == NULL) {
944 ALOGE("%s: dlsym error %s for csd_client_volume",
945 __func__, dlerror());
946 goto error;
947 }
948 csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
949 "csd_client_mic_mute");
950 if (csd->mic_mute == NULL) {
951 ALOGE("%s: dlsym error %s for csd_client_mic_mute",
952 __func__, dlerror());
953 goto error;
954 }
955 csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
956 "csd_client_slow_talk");
957 if (csd->slow_talk == NULL) {
958 ALOGE("%s: dlsym error %s for csd_client_slow_talk",
959 __func__, dlerror());
960 goto error;
961 }
962 csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
963 "csd_client_start_playback");
964 if (csd->start_playback == NULL) {
965 ALOGE("%s: dlsym error %s for csd_client_start_playback",
966 __func__, dlerror());
967 goto error;
968 }
969 csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
970 "csd_client_stop_playback");
971 if (csd->stop_playback == NULL) {
972 ALOGE("%s: dlsym error %s for csd_client_stop_playback",
973 __func__, dlerror());
974 goto error;
975 }
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -0700976 csd->set_lch = (set_lch_t)dlsym(csd->csd_client, "csd_client_set_lch");
977 if (csd->set_lch == NULL) {
978 ALOGE("%s: dlsym error %s for csd_client_set_lch",
979 __func__, dlerror());
980 /* Ignore the error as this is not mandatory function for
981 * basic voice call to work.
982 */
983 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +0530984 csd->start_record = (start_record_t)dlsym(csd->csd_client,
985 "csd_client_start_record");
986 if (csd->start_record == NULL) {
987 ALOGE("%s: dlsym error %s for csd_client_start_record",
988 __func__, dlerror());
989 goto error;
990 }
991 csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
992 "csd_client_stop_record");
993 if (csd->stop_record == NULL) {
994 ALOGE("%s: dlsym error %s for csd_client_stop_record",
995 __func__, dlerror());
996 goto error;
997 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +0530998
999
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301000 csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
1001
1002 if (csd->init == NULL) {
1003 ALOGE("%s: dlsym error %s for csd_client_init",
1004 __func__, dlerror());
1005 goto error;
1006 } else {
1007 csd->init();
1008 }
1009 }
1010 return csd;
1011
1012error:
1013 free(csd);
1014 csd = NULL;
1015 return csd;
1016}
1017
1018void close_csd_client(struct csd_data *csd)
1019{
1020 if (csd != NULL) {
1021 csd->deinit();
1022 dlclose(csd->csd_client);
1023 free(csd);
1024 csd = NULL;
1025 }
1026}
1027
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301028
1029static void set_platform_defaults()
1030{
1031 int32_t dev;
1032 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1033 backend_table[dev] = NULL;
1034 }
1035 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1036 backend_bit_width_table[dev] = 16;
1037 }
1038
1039 // TBD - do these go to the platform-info.xml file.
1040 // will help in avoiding strdups here
1041 backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
1042 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
1043 backend_table[SND_DEVICE_IN_BT_SCO_MIC_NREC] = strdup("bt-sco");
1044 backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB_NREC] = strdup("bt-sco-wb");
1045 backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
1046 backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
1047 backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
1048 backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
1049 backend_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
1050 backend_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
1051 backend_table[SND_DEVICE_OUT_AFE_PROXY] = strdup("afe-proxy");
1052 backend_table[SND_DEVICE_OUT_USB_HEADSET] = strdup("usb-headphones");
1053 backend_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] =
1054 strdup("speaker-and-usb-headphones");
1055 backend_table[SND_DEVICE_IN_USB_HEADSET_MIC] = strdup("usb-headset-mic");
1056 backend_table[SND_DEVICE_IN_CAPTURE_FM] = strdup("capture-fm");
1057 backend_table[SND_DEVICE_OUT_TRANSMISSION_FM] = strdup("transmission-fm");
1058}
1059
Avinash Vaish71c066d2014-08-27 12:32:35 +05301060void get_cvd_version(char *cvd_version, struct audio_device *adev)
1061{
1062 struct mixer_ctl *ctl;
1063 int count;
1064 int ret = 0;
1065
1066 ctl = mixer_get_ctl_by_name(adev->mixer, CVD_VERSION_MIXER_CTL);
1067 if (!ctl) {
1068 ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL);
1069 goto done;
1070 }
1071 mixer_ctl_update(ctl);
1072
1073 count = mixer_ctl_get_num_values(ctl);
1074 if (count > MAX_CVD_VERSION_STRING_SIZE)
1075 count = MAX_CVD_VERSION_STRING_SIZE;
1076
1077 ret = mixer_ctl_get_array(ctl, cvd_version, count);
1078 if (ret != 0) {
1079 ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__);
1080 goto done;
1081 }
1082
1083done:
1084 return;
1085}
1086
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301087static int hw_util_open(int card_no)
1088{
1089 int fd = -1;
1090 char dev_name[256];
1091
1092 snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u",
1093 card_no, WCD9XXX_CODEC_HWDEP_NODE);
1094 ALOGD("%s Opening device %s\n", __func__, dev_name);
1095 fd = open(dev_name, O_WRONLY);
1096 if (fd < 0) {
1097 ALOGE("%s: cannot open device '%s'\n", __func__, dev_name);
1098 return fd;
1099 }
1100 ALOGD("%s success", __func__);
1101 return fd;
1102}
1103
1104struct param_data {
1105 int use_case;
1106 int acdb_id;
1107 int get_size;
1108 int buff_size;
1109 int data_size;
1110 void *buff;
1111};
1112
1113static int send_codec_cal(acdb_loader_get_calibration_t acdb_loader_get_calibration, int fd)
1114{
1115 int ret = 0, type;
1116
1117 for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) {
1118 struct wcdcal_ioctl_buffer codec_buffer;
1119 struct param_data calib;
1120
1121 if (!strcmp(cal_name_info[type], "mad_cal"))
1122 calib.acdb_id = SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID;
1123 calib.get_size = 1;
1124 ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data),
1125 &calib);
1126 if (ret < 0) {
1127 ALOGE("%s get_calibration failed\n", __func__);
1128 return ret;
1129 }
1130 calib.get_size = 0;
1131 calib.buff = malloc(calib.buff_size);
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301132 if(calib.buff == NULL) {
1133 ALOGE("%s mem allocation for %d bytes for %s failed\n"
1134 , __func__, calib.buff_size, cal_name_info[type]);
1135 return -1;
1136 }
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301137 ret = acdb_loader_get_calibration(cal_name_info[type],
1138 sizeof(struct param_data), &calib);
1139 if (ret < 0) {
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301140 ALOGE("%s get_calibration failed type=%s calib.size=%d\n"
1141 , __func__, cal_name_info[type], codec_buffer.size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301142 free(calib.buff);
1143 return ret;
1144 }
1145 codec_buffer.buffer = calib.buff;
1146 codec_buffer.size = calib.data_size;
1147 codec_buffer.cal_type = type;
1148 if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
Sidipotu Ashok04ab3d32014-12-30 10:28:31 +05301149 ALOGE("Failed to call ioctl for %s err=%d calib.size=%d",
1150 cal_name_info[type], errno, codec_buffer.size);
1151 ALOGD("%s cal sent for %s calib.size=%d"
1152 , __func__, cal_name_info[type], codec_buffer.size);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301153 free(calib.buff);
1154 }
1155 return ret;
1156}
1157
1158static void audio_hwdep_send_cal(struct platform_data *plat_data)
1159{
1160 int fd;
1161
1162 fd = hw_util_open(plat_data->adev->snd_card);
1163 if (fd == -1) {
1164 ALOGE("%s error open\n", __func__);
1165 return;
1166 }
1167
1168 acdb_loader_get_calibration = (acdb_loader_get_calibration_t)
1169 dlsym(plat_data->acdb_handle, "acdb_loader_get_calibration");
1170
1171 if (acdb_loader_get_calibration == NULL) {
1172 ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__,
1173 dlerror());
1174 return;
1175 }
1176 if (send_codec_cal(acdb_loader_get_calibration, fd) < 0)
1177 ALOGE("%s: Could not send anc cal", __FUNCTION__);
1178}
1179
Naresh Tannirue3b18452014-03-04 14:44:27 +05301180void *platform_init(struct audio_device *adev)
1181{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301182 char platform[PROPERTY_VALUE_MAX];
1183 char baseband[PROPERTY_VALUE_MAX];
Naresh Tannirue3b18452014-03-04 14:44:27 +05301184 char value[PROPERTY_VALUE_MAX];
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301185 struct platform_data *my_data = NULL;
Dhananjay Kumara3565b32014-07-23 01:12:48 +05301186 int retry_num = 0, snd_card_num = 0, key = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301187 const char *snd_card_name;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301188 char mixer_xml_path[100],ffspEnable[PROPERTY_VALUE_MAX];
Avinash Vaish71c066d2014-08-27 12:32:35 +05301189 char *cvd_version = NULL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301190
1191 my_data = calloc(1, sizeof(struct platform_data));
Chaithanya Krishna Bacharajudb6236a2015-01-30 10:08:33 +05301192 if (!my_data) {
1193 ALOGE("failed to allocate platform data");
1194 return NULL;
1195 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301196
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301197 while (snd_card_num < MAX_SND_CARD) {
1198 adev->mixer = mixer_open(snd_card_num);
1199
1200 while (!adev->mixer && retry_num < RETRY_NUMBER) {
1201 usleep(RETRY_US);
1202 adev->mixer = mixer_open(snd_card_num);
1203 retry_num++;
1204 }
1205
1206 if (!adev->mixer) {
1207 ALOGE("%s: Unable to open the mixer card: %d", __func__,
1208 snd_card_num);
1209 retry_num = 0;
1210 snd_card_num++;
1211 continue;
1212 }
1213
1214 snd_card_name = mixer_get_name(adev->mixer);
1215 ALOGV("%s: snd_card_name: %s", __func__, snd_card_name);
1216
1217 my_data->hw_info = hw_info_init(snd_card_name);
1218 if (!my_data->hw_info) {
1219 ALOGE("%s: Failed to init hardware info", __func__);
1220 } else {
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301221 query_platform(snd_card_name, mixer_xml_path);
1222 ALOGD("%s: mixer path file is %s", __func__,
1223 mixer_xml_path);
1224 if (audio_extn_read_xml(adev, snd_card_num, mixer_xml_path,
1225 MIXER_XML_PATH_AUXPCM) == -ENOSYS) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301226 adev->audio_route = audio_route_init(snd_card_num,
Asish Bhattacharya4ff24802014-04-24 17:46:54 +05301227 mixer_xml_path);
1228 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301229 if (!adev->audio_route) {
1230 ALOGE("%s: Failed to init audio route controls, aborting.",
1231 __func__);
1232 free(my_data);
1233 return NULL;
1234 }
1235 adev->snd_card = snd_card_num;
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301236 update_codec_type(snd_card_name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301237 ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
1238 break;
1239 }
1240 retry_num = 0;
1241 snd_card_num++;
1242 }
1243
1244 if (snd_card_num >= MAX_SND_CARD) {
1245 ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
1246 free(my_data);
1247 return NULL;
1248 }
1249
Naresh Tannirue3b18452014-03-04 14:44:27 +05301250 my_data->adev = adev;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301251 my_data->fluence_in_spkr_mode = false;
1252 my_data->fluence_in_voice_call = false;
1253 my_data->fluence_in_voice_rec = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301254 my_data->fluence_in_audio_rec = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301255 my_data->external_spk_1 = false;
1256 my_data->external_spk_2 = false;
1257 my_data->external_mic = false;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301258 my_data->fluence_type = FLUENCE_NONE;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301259 my_data->fluence_mode = FLUENCE_ENDFIRE;
Avinash Vaishd5fa4572014-09-15 14:41:14 +05301260 my_data->slowtalk = false;
1261 my_data->hd_voice = false;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301262 my_data->edid_info = NULL;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301263 my_data->is_wsa_speaker = false;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301264
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301265 property_get("ro.qc.sdk.audio.fluencetype", my_data->fluence_cap, "");
1266 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301267 my_data->fluence_type = FLUENCE_QUAD_MIC | FLUENCE_DUAL_MIC;
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301268 } else if (!strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301269 my_data->fluence_type = FLUENCE_DUAL_MIC;
1270 } else {
1271 my_data->fluence_type = FLUENCE_NONE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301272 }
1273
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301274 if (my_data->fluence_type != FLUENCE_NONE) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301275 property_get("persist.audio.fluence.voicecall",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301276 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301277 my_data->fluence_in_voice_call = true;
1278 }
1279
1280 property_get("persist.audio.fluence.voicerec",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301281 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301282 my_data->fluence_in_voice_rec = true;
1283 }
1284
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301285 property_get("persist.audio.fluence.audiorec",value,"");
1286 if (!strncmp("true", value, sizeof("true"))) {
1287 my_data->fluence_in_audio_rec = true;
1288 }
1289
Naresh Tannirue3b18452014-03-04 14:44:27 +05301290 property_get("persist.audio.fluence.speaker",value,"");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301291 if (!strncmp("true", value, sizeof("true"))) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05301292 my_data->fluence_in_spkr_mode = true;
1293 }
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05301294
1295 property_get("persist.audio.fluence.mode",value,"");
1296 if (!strncmp("broadside", value, sizeof("broadside"))) {
1297 my_data->fluence_mode = FLUENCE_BROADSIDE;
1298 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301299 }
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301300 property_get("persist.audio.FFSP.enable", ffspEnable, "");
1301 if (!strncmp("true", ffspEnable, sizeof("true"))) {
1302 acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301303 acdb_device_table[SND_DEVICE_OUT_SPEAKER_WSA] = 131;
Srikanth Uyyalaa675cd12014-10-15 14:48:11 +05301304 acdb_device_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = 131;
1305 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 131;
1306 acdb_device_table[SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 131;
1307 }
Dhananjay Kumara3565b32014-07-23 01:12:48 +05301308 property_get("audio.ds1.metainfo.key",value,"0");
1309 key = atoi(value);
1310
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301311 my_data->voice_feature_set = VOICE_FEATURE_SET_DEFAULT;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301312 my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
1313 if (my_data->acdb_handle == NULL) {
1314 ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
1315 } else {
1316 ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
1317 my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
1318 "acdb_loader_deallocate_ACDB");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301319 if (!my_data->acdb_deallocate)
1320 ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
1321 __func__, LIB_ACDB_LOADER);
1322
Naresh Tannirue3b18452014-03-04 14:44:27 +05301323 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 -07001324 "acdb_loader_send_audio_cal_v2");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301325 if (!my_data->acdb_send_audio_cal)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301326 ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301327 __func__, LIB_ACDB_LOADER);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301328
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301329 my_data->acdb_set_audio_cal = (acdb_set_audio_cal_t)dlsym(my_data->acdb_handle,
1330 "acdb_loader_set_audio_cal_v2");
1331 if (!my_data->acdb_set_audio_cal)
1332 ALOGE("%s: Could not find the symbol acdb_set_audio_cal_v2 from %s",
1333 __func__, LIB_ACDB_LOADER);
1334
1335 my_data->acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(my_data->acdb_handle,
1336 "acdb_loader_get_audio_cal_v2");
1337 if (!my_data->acdb_get_audio_cal)
1338 ALOGE("%s: Could not find the symbol acdb_get_audio_cal_v2 from %s",
1339 __func__, LIB_ACDB_LOADER);
1340
Naresh Tannirue3b18452014-03-04 14:44:27 +05301341 my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
1342 "acdb_loader_send_voice_cal");
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301343 if (!my_data->acdb_send_voice_cal)
1344 ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
1345 __func__, LIB_ACDB_LOADER);
1346
1347 my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
1348 "acdb_loader_reload_vocvoltable");
1349 if (!my_data->acdb_reload_vocvoltable)
1350 ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
1351 __func__, LIB_ACDB_LOADER);
1352
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001353 my_data->acdb_get_default_app_type = (acdb_get_default_app_type_t)dlsym(
1354 my_data->acdb_handle,
1355 "acdb_loader_get_default_app_type");
1356 if (!my_data->acdb_get_default_app_type)
1357 ALOGE("%s: Could not find the symbol acdb_get_default_app_type from %s",
1358 __func__, LIB_ACDB_LOADER);
1359
Naresh Tannirue3b18452014-03-04 14:44:27 +05301360 my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301361 "acdb_loader_init_v2");
Avinash Vaish71c066d2014-08-27 12:32:35 +05301362 if (my_data->acdb_init == NULL) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301363 ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
Avinash Vaish71c066d2014-08-27 12:32:35 +05301364 goto acdb_init_fail;
1365 }
1366
1367 cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE);
1368 if (!cvd_version)
1369 ALOGE("Failed to allocate cvd version");
Naresh Tannirue3b18452014-03-04 14:44:27 +05301370 else
Avinash Vaish71c066d2014-08-27 12:32:35 +05301371 get_cvd_version(cvd_version, adev);
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301372 my_data->acdb_init(snd_card_name, cvd_version, key);
Avinash Vaish71c066d2014-08-27 12:32:35 +05301373 if (cvd_version)
1374 free(cvd_version);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301375 }
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301376 audio_extn_pm_vote();
Naresh Tannirue3b18452014-03-04 14:44:27 +05301377
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05301378 // Check if WSA speaker is supported in codec
1379 char CodecPeek[1024] = "/sys/kernel/debug/asoc/";
1380 DIR *dir;
1381 struct dirent *dirent;
1382 char file_name[10] = "wsa";
1383 strcat(CodecPeek, snd_card_name);
1384
1385 dir = opendir(CodecPeek);
1386 if (dir != NULL) {
1387 while (NULL != (dirent = readdir(dir))) {
1388 if (strstr (dirent->d_name,file_name))
1389 {
1390 my_data->is_wsa_speaker = true;
1391 break;
1392 }
1393 }
1394 closedir(dir);
1395 }
1396
Avinash Vaish71c066d2014-08-27 12:32:35 +05301397acdb_init_fail:
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301398
1399 set_platform_defaults();
1400
Dhananjay Kumara68d7af2015-05-25 19:11:30 +05301401 /* Initialize ACDB and PCM ID's */
1402 if (is_external_codec)
1403 platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC);
1404 else
1405 platform_info_init(PLATFORM_INFO_XML_PATH);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301406
1407 /* init usb */
1408 audio_extn_usb_init(adev);
1409 /* update sound cards appropriately */
1410 audio_extn_usb_set_proxy_sound_card(adev->snd_card);
1411
1412 /* Read one time ssr property */
1413 audio_extn_ssr_update_enabled();
1414 audio_extn_spkr_prot_init(adev);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301415
Ashish Jain8ec50472014-10-16 13:56:28 +05301416 /* init dap hal */
1417 audio_extn_dap_hal_init(adev->snd_card);
1418
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301419 audio_extn_dolby_set_license(adev);
Srikanth Uyyalacae4aa32014-10-17 13:44:09 +05301420 audio_hwdep_send_cal(my_data);
Dhananjay Kumar89ea3bd2014-04-29 15:45:57 +05301421
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301422 /* init audio device arbitration */
1423 audio_extn_dev_arbi_init();
1424
1425 my_data->edid_info = NULL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301426 return my_data;
1427}
1428
1429void platform_deinit(void *platform)
1430{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301431 struct platform_data *my_data = (struct platform_data *)platform;
1432
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301433 if (my_data->edid_info) {
1434 free(my_data->edid_info);
1435 my_data->edid_info = NULL;
1436 }
1437
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301438 hw_info_deinit(my_data->hw_info);
1439 close_csd_client(my_data->csd);
1440
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301441 int32_t dev;
1442 for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
1443 if (backend_table[dev]) {
1444 free(backend_table[dev]);
1445 backend_table[dev]= NULL;
1446 }
1447 }
1448
1449 /* deinit audio device arbitration */
1450 audio_extn_dev_arbi_deinit();
1451
1452 if (my_data->edid_info) {
1453 free(my_data->edid_info);
1454 my_data->edid_info = NULL;
1455 }
1456
Naresh Tannirue3b18452014-03-04 14:44:27 +05301457 free(platform);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301458 /* deinit usb */
1459 audio_extn_usb_deinit();
Ashish Jain8ec50472014-10-16 13:56:28 +05301460 audio_extn_dap_hal_deinit();
Naresh Tannirue3b18452014-03-04 14:44:27 +05301461}
1462
1463const char *platform_get_snd_device_name(snd_device_t snd_device)
1464{
1465 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
1466 return device_table[snd_device];
1467 else
1468 return "";
1469}
1470
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301471int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
1472 char *device_name)
1473{
1474 struct platform_data *my_data = (struct platform_data *)platform;
1475
1476 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) {
1477 strlcpy(device_name, device_table[snd_device], DEVICE_NAME_MAX_SIZE);
1478 hw_info_append_hw_type(my_data->hw_info, snd_device, device_name);
1479 } else {
1480 strlcpy(device_name, "", DEVICE_NAME_MAX_SIZE);
1481 return -EINVAL;
1482 }
1483
1484 return 0;
1485}
1486
Naresh Tannirue3b18452014-03-04 14:44:27 +05301487void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
1488{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301489 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1490 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1491 return;
1492 }
1493
1494 const char * suffix = backend_table[snd_device];
1495
1496 if (suffix != NULL) {
1497 strlcat(mixer_path, " ", MIXER_PATH_MAX_LENGTH);
1498 strlcat(mixer_path, suffix, MIXER_PATH_MAX_LENGTH);
1499 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301500}
1501
1502int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
1503{
Venkata Narendra Kumar Guttaed408a12015-03-31 20:24:04 +05301504 int device_id = -1;
1505
1506 if (is_external_codec && is_misc_usecase(usecase)) {
1507 if (device_type == PCM_PLAYBACK)
1508 device_id = pcm_device_table_of_ext_codec[usecase][0];
1509 else
1510 device_id = pcm_device_table_of_ext_codec[usecase][1];
1511 } else {
1512 if (device_type == PCM_PLAYBACK)
1513 device_id = pcm_device_table[usecase][0];
1514 else
1515 device_id = pcm_device_table[usecase][1];
1516 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301517 return device_id;
1518}
1519
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301520static int find_index(struct name_to_index * table, int32_t len, const char * name)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301521{
1522 int ret = 0;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301523 int32_t i;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301524
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301525 if (table == NULL) {
1526 ALOGE("%s: table is NULL", __func__);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301527 ret = -ENODEV;
1528 goto done;
1529 }
1530
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301531 if (name == NULL) {
1532 ALOGE("null key");
1533 ret = -ENODEV;
1534 goto done;
1535 }
1536
1537 for (i=0; i < len; i++) {
1538 const char* tn = table[i].name;
1539 size_t len = strlen(tn);
1540 if (strncmp(tn, name, len) == 0) {
1541 if (strlen(name) != len) {
1542 continue; // substring
1543 }
1544 ret = table[i].index;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301545 goto done;
1546 }
1547 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301548 ALOGE("%s: Could not find index for name = %s",
1549 __func__, name);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301550 ret = -ENODEV;
1551done:
1552 return ret;
1553}
1554
Venkata Narendra Kumar Gutta88fd0bc2014-03-27 19:47:56 +05301555int platform_set_fluence_type(void *platform, char *value)
1556{
1557 int ret = 0;
1558 int fluence_type = FLUENCE_NONE;
1559 int fluence_flag = NONE_FLAG;
1560 struct platform_data *my_data = (struct platform_data *)platform;
1561 struct audio_device *adev = my_data->adev;
1562
1563 ALOGV("%s: fluence type:%d", __func__, my_data->fluence_type);
1564
1565 /* only dual mic turn on and off is supported as of now through setparameters */
1566 if (!strncmp(AUDIO_PARAMETER_VALUE_DUALMIC,value, sizeof(AUDIO_PARAMETER_VALUE_DUALMIC))) {
1567 if (!strncmp("fluencepro", my_data->fluence_cap, sizeof("fluencepro")) ||
1568 !strncmp("fluence", my_data->fluence_cap, sizeof("fluence"))) {
1569 ALOGV("fluence dualmic feature enabled \n");
1570 fluence_type = FLUENCE_DUAL_MIC;
1571 fluence_flag = DMIC_FLAG;
1572 } else {
1573 ALOGE("%s: Failed to set DUALMIC", __func__);
1574 ret = -1;
1575 goto done;
1576 }
1577 } else if (!strncmp(AUDIO_PARAMETER_KEY_NO_FLUENCE, value, sizeof(AUDIO_PARAMETER_KEY_NO_FLUENCE))) {
1578 ALOGV("fluence disabled");
1579 fluence_type = FLUENCE_NONE;
1580 } else {
1581 ALOGE("Invalid fluence value : %s",value);
1582 ret = -1;
1583 goto done;
1584 }
1585
1586 if (fluence_type != my_data->fluence_type) {
1587 ALOGV("%s: Updating fluence_type to :%d", __func__, fluence_type);
1588 my_data->fluence_type = fluence_type;
1589 adev->acdb_settings = (adev->acdb_settings & FLUENCE_MODE_CLEAR) | fluence_flag;
1590 }
1591done:
1592 return ret;
1593}
1594
1595int platform_get_fluence_type(void *platform, char *value, uint32_t len)
1596{
1597 int ret = 0;
1598 struct platform_data *my_data = (struct platform_data *)platform;
1599
1600 if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
1601 strlcpy(value, "quadmic", len);
1602 } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
1603 strlcpy(value, "dualmic", len);
1604 } else if (my_data->fluence_type == FLUENCE_NONE) {
1605 strlcpy(value, "none", len);
1606 } else
1607 ret = -1;
1608
1609 return ret;
1610}
1611
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301612int platform_get_snd_device_index(char *device_name)
1613{
1614 return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
1615}
1616
1617int platform_get_usecase_index(const char *usecase_name)
1618{
1619 return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
1620}
1621
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301622int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
1623{
1624 int ret = 0;
1625
1626 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1627 ALOGE("%s: Invalid snd_device = %d",
1628 __func__, snd_device);
1629 ret = -EINVAL;
1630 goto done;
1631 }
1632
1633 acdb_device_table[snd_device] = acdb_id;
1634done:
1635 return ret;
1636}
1637
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001638int platform_get_default_app_type(void *platform)
1639{
1640 struct platform_data *my_data = (struct platform_data *)platform;
1641
1642 if (my_data->acdb_get_default_app_type)
1643 return my_data->acdb_get_default_app_type();
1644 else
1645 return DEFAULT_APP_TYPE;
1646}
1647
Subhash Chandra Bose Naripeddy19dc03b2014-03-10 14:43:05 -07001648int platform_get_snd_device_acdb_id(snd_device_t snd_device)
1649{
1650 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1651 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1652 return -EINVAL;
1653 }
1654 return acdb_device_table[snd_device];
1655}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301656
1657int platform_set_snd_device_bit_width(snd_device_t snd_device, unsigned int bit_width)
Amit Shekhar5a39c912014-10-14 15:39:30 -07001658{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301659 int ret = 0;
1660
1661 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1662 ALOGE("%s: Invalid snd_device = %d",
1663 __func__, snd_device);
1664 ret = -EINVAL;
1665 goto done;
1666 }
1667
1668 backend_bit_width_table[snd_device] = bit_width;
1669done:
1670 return ret;
Amit Shekhar5a39c912014-10-14 15:39:30 -07001671}
1672
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301673int platform_get_snd_device_bit_width(snd_device_t snd_device)
Amit Shekhar5a39c912014-10-14 15:39:30 -07001674{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301675 if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
1676 ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
1677 return DEFAULT_OUTPUT_SAMPLING_RATE;
1678 }
1679 return backend_bit_width_table[snd_device];
Amit Shekhar5a39c912014-10-14 15:39:30 -07001680}
1681
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08001682int platform_set_native_support(bool codec_support __unused)
1683{
1684 return 0;
1685}
1686
1687int platform_get_backend_index(snd_device_t snd_device __unused)
1688{
1689 return 0;
1690}
1691
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301692int platform_send_audio_calibration(void *platform, struct audio_usecase *usecase,
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001693 int app_type, int sample_rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301694{
1695 struct platform_data *my_data = (struct platform_data *)platform;
1696 int acdb_dev_id, acdb_dev_type;
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05301697 struct audio_device *adev = my_data->adev;
1698 int snd_device = SND_DEVICE_OUT_SPEAKER;
1699
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301700 if (usecase->type == PCM_PLAYBACK)
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05301701 snd_device = usecase->out_snd_device;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301702 else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
Naresh Tannirucc7c4de2015-03-10 16:19:23 +05301703 snd_device = usecase->in_snd_device;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301704 acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
Naresh Tannirue3b18452014-03-04 14:44:27 +05301705
Naresh Tanniru2727f822015-05-11 15:27:08 +05301706 // Do not use Rx path default app type for TX path
1707 if ((usecase->type == PCM_CAPTURE) && (app_type == DEFAULT_APP_TYPE_RX_PATH)) {
1708 ALOGD("Resetting app type for Tx path to default");
1709 app_type = DEFAULT_APP_TYPE_TX_PATH;
1710 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05301711 if (acdb_dev_id < 0) {
1712 ALOGE("%s: Could not find acdb id for device(%d)",
1713 __func__, snd_device);
1714 return -EINVAL;
1715 }
1716 if (my_data->acdb_send_audio_cal) {
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001717 ALOGV("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
Naresh Tannirue3b18452014-03-04 14:44:27 +05301718 __func__, snd_device, acdb_dev_id);
1719 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
1720 snd_device < SND_DEVICE_OUT_END)
1721 acdb_dev_type = ACDB_DEV_TYPE_OUT;
1722 else
1723 acdb_dev_type = ACDB_DEV_TYPE_IN;
Subhash Chandra Bose Naripeddy54274672014-03-10 14:51:02 -07001724 my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type, app_type,
1725 sample_rate);
Naresh Tannirue3b18452014-03-04 14:44:27 +05301726 }
1727 return 0;
1728}
1729
1730int platform_switch_voice_call_device_pre(void *platform)
1731{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301732 struct platform_data *my_data = (struct platform_data *)platform;
1733 int ret = 0;
1734
1735 if (my_data->csd != NULL &&
Ravi Kumar Alamandabe149392014-10-20 17:07:43 -07001736 voice_is_in_call(my_data->adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301737 /* This must be called before disabling mixer controls on APQ side */
1738 ret = my_data->csd->disable_device();
1739 if (ret < 0) {
1740 ALOGE("%s: csd_client_disable_device, failed, error %d",
1741 __func__, ret);
1742 }
1743 }
1744 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301745}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301746
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301747int platform_switch_voice_call_enable_device_config(void *platform,
1748 snd_device_t out_snd_device,
1749 snd_device_t in_snd_device)
1750{
1751 struct platform_data *my_data = (struct platform_data *)platform;
1752 int acdb_rx_id, acdb_tx_id;
1753 int ret = 0;
1754
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301755 if (my_data->csd == NULL)
1756 return ret;
1757
1758 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1759 audio_extn_spkr_prot_is_enabled())
1760 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1761 else
1762 acdb_rx_id = acdb_device_table[out_snd_device];
1763
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301764 acdb_tx_id = acdb_device_table[in_snd_device];
1765
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301766 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1767 ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
1768 if (ret < 0) {
1769 ALOGE("%s: csd_enable_device_config, failed, error %d",
1770 __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301771 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301772 } else {
1773 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1774 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301775 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301776
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301777 return ret;
1778}
1779
Naresh Tannirue3b18452014-03-04 14:44:27 +05301780int platform_switch_voice_call_device_post(void *platform,
1781 snd_device_t out_snd_device,
1782 snd_device_t in_snd_device)
1783{
1784 struct platform_data *my_data = (struct platform_data *)platform;
1785 int acdb_rx_id, acdb_tx_id;
1786
1787 if (my_data->acdb_send_voice_cal == NULL) {
1788 ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
1789 } else {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301790 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1791 audio_extn_spkr_prot_is_enabled())
1792 out_snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
1793
Naresh Tannirue3b18452014-03-04 14:44:27 +05301794 acdb_rx_id = acdb_device_table[out_snd_device];
1795 acdb_tx_id = acdb_device_table[in_snd_device];
1796
1797 if (acdb_rx_id > 0 && acdb_tx_id > 0)
1798 my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
1799 else
1800 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1801 acdb_rx_id, acdb_tx_id);
1802 }
1803
1804 return 0;
1805}
1806
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301807int platform_switch_voice_call_usecase_route_post(void *platform,
1808 snd_device_t out_snd_device,
1809 snd_device_t in_snd_device)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301810{
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301811 struct platform_data *my_data = (struct platform_data *)platform;
1812 int acdb_rx_id, acdb_tx_id;
1813 int ret = 0;
1814
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301815 if (my_data->csd == NULL)
1816 return ret;
1817
1818 if (out_snd_device == SND_DEVICE_OUT_VOICE_SPEAKER &&
1819 audio_extn_spkr_prot_is_enabled())
1820 acdb_rx_id = acdb_device_table[SND_DEVICE_OUT_SPEAKER_PROTECTED];
1821 else
1822 acdb_rx_id = acdb_device_table[out_snd_device];
1823
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301824 acdb_tx_id = acdb_device_table[in_snd_device];
1825
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301826 if (acdb_rx_id > 0 && acdb_tx_id > 0) {
1827 ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
1828 my_data->adev->acdb_settings);
1829 if (ret < 0) {
1830 ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301831 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301832 } else {
1833 ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
1834 acdb_rx_id, acdb_tx_id);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301835 }
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301836
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301837 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301838}
1839
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301840int platform_start_voice_call(void *platform, uint32_t vsid)
1841{
1842 struct platform_data *my_data = (struct platform_data *)platform;
1843 int ret = 0;
1844
1845 if (my_data->csd != NULL) {
1846 ret = my_data->csd->start_voice(vsid);
1847 if (ret < 0) {
1848 ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
1849 }
1850 }
1851 return ret;
1852}
1853
1854int platform_stop_voice_call(void *platform, uint32_t vsid)
1855{
1856 struct platform_data *my_data = (struct platform_data *)platform;
1857 int ret = 0;
1858
1859 if (my_data->csd != NULL) {
1860 ret = my_data->csd->stop_voice(vsid);
1861 if (ret < 0) {
1862 ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
1863 }
1864 }
1865 return ret;
1866}
Ravi Kumar Alamandabdf14162014-09-05 16:14:17 -07001867
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301868int platform_get_sample_rate(void *platform, uint32_t *rate)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301869{
1870 return 0;
1871}
1872
1873int platform_set_voice_volume(void *platform, int volume)
1874{
1875 struct platform_data *my_data = (struct platform_data *)platform;
1876 struct audio_device *adev = my_data->adev;
1877 struct mixer_ctl *ctl;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301878 const char *mixer_ctl_name = "Voice Rx Gain";
1879 int vol_index = 0, ret = 0;
1880 uint32_t set_values[ ] = {0,
1881 ALL_SESSION_VSID,
1882 DEFAULT_VOLUME_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301883
1884 // Voice volume levels are mapped to adsp volume levels as follows.
1885 // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
1886 // But this values don't changed in kernel. So, below change is need.
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301887 vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
1888 set_values[0] = vol_index;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301889
1890 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1891 if (!ctl) {
1892 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1893 __func__, mixer_ctl_name);
1894 return -EINVAL;
1895 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301896 ALOGV("Setting voice volume index: %d", set_values[0]);
1897 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301898
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301899 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301900 ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
1901 DEFAULT_VOLUME_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301902 if (ret < 0) {
1903 ALOGE("%s: csd_volume error %d", __func__, ret);
1904 }
1905 }
1906 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301907}
1908
1909int platform_set_mic_mute(void *platform, bool state)
1910{
1911 struct platform_data *my_data = (struct platform_data *)platform;
1912 struct audio_device *adev = my_data->adev;
1913 struct mixer_ctl *ctl;
1914 const char *mixer_ctl_name = "Voice Tx Mute";
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301915 int ret = 0;
1916 uint32_t set_values[ ] = {0,
1917 ALL_SESSION_VSID,
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301918 DEFAULT_MUTE_RAMP_DURATION_MS};
Naresh Tannirue3b18452014-03-04 14:44:27 +05301919
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301920 set_values[0] = state;
1921 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1922 if (!ctl) {
1923 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1924 __func__, mixer_ctl_name);
1925 return -EINVAL;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301926 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301927 ALOGV("Setting voice mute state: %d", state);
1928 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
Naresh Tannirue3b18452014-03-04 14:44:27 +05301929
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301930 if (my_data->csd != NULL) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05301931 ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
1932 DEFAULT_MUTE_RAMP_DURATION_MS);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301933 if (ret < 0) {
1934 ALOGE("%s: csd_mic_mute error %d", __func__, ret);
1935 }
1936 }
1937 return ret;
Naresh Tannirue3b18452014-03-04 14:44:27 +05301938}
1939
Shiv Maliyappanahallic6fd8ee2014-03-07 15:31:55 -08001940int platform_set_device_mute(void *platform, bool state, char *dir)
1941{
1942 struct platform_data *my_data = (struct platform_data *)platform;
1943 struct audio_device *adev = my_data->adev;
1944 struct mixer_ctl *ctl;
1945 char *mixer_ctl_name = NULL;
1946 int ret = 0;
1947 uint32_t set_values[ ] = {0,
1948 ALL_SESSION_VSID,
1949 0};
1950 if(dir == NULL) {
1951 ALOGE("%s: Invalid direction:%s", __func__, dir);
1952 return -EINVAL;
1953 }
1954
1955 if (!strncmp("rx", dir, sizeof("rx"))) {
1956 mixer_ctl_name = "Voice Rx Device Mute";
1957 } else if (!strncmp("tx", dir, sizeof("tx"))) {
1958 mixer_ctl_name = "Voice Tx Device Mute";
1959 } else {
1960 return -EINVAL;
1961 }
1962
1963 set_values[0] = state;
1964 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
1965 if (!ctl) {
1966 ALOGE("%s: Could not get ctl for mixer cmd - %s",
1967 __func__, mixer_ctl_name);
1968 return -EINVAL;
1969 }
1970
1971 ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
1972 __func__,state, mixer_ctl_name);
1973 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
1974
1975 return ret;
1976}
1977
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08001978snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *out)
Naresh Tannirue3b18452014-03-04 14:44:27 +05301979{
1980 struct platform_data *my_data = (struct platform_data *)platform;
1981 struct audio_device *adev = my_data->adev;
1982 audio_mode_t mode = adev->mode;
1983 snd_device_t snd_device = SND_DEVICE_NONE;
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08001984 audio_devices_t devices = out->devices;
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05301985#ifdef RECORD_PLAY_CONCURRENCY
1986 bool use_voip_out_devices = false;
1987 bool prop_rec_play_enabled = false;
1988 char recConcPropValue[PROPERTY_VALUE_MAX];
1989
1990 if (property_get("rec.playback.conc.disabled", recConcPropValue, NULL)) {
1991 prop_rec_play_enabled = atoi(recConcPropValue) || !strncmp("true", recConcPropValue, 4);
1992 }
1993 use_voip_out_devices = prop_rec_play_enabled &&
1994 (my_data->rec_play_conc_set || adev->mode == AUDIO_MODE_IN_COMMUNICATION);
1995 ALOGV("platform_get_output_snd_device use_voip_out_devices : %d",use_voip_out_devices);
1996#endif
Naresh Tannirue3b18452014-03-04 14:44:27 +05301997
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05301998 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
1999 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2000 int channel_count = popcount(channel_mask);
2001
Naresh Tannirue3b18452014-03-04 14:44:27 +05302002 ALOGV("%s: enter: output devices(%#x)", __func__, devices);
2003 if (devices == AUDIO_DEVICE_NONE ||
2004 devices & AUDIO_DEVICE_BIT_IN) {
2005 ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
2006 goto exit;
2007 }
2008
Venkata Narendra Kumar Guttadb4e1f02015-06-29 13:42:43 +05302009 if (popcount(devices) == 2 && !voice_is_in_call(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302010 if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
2011 AUDIO_DEVICE_OUT_SPEAKER)) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302012 if (my_data->external_spk_1)
2013 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2014 else if (my_data->external_spk_2)
2015 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
2016 else
2017 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302018 } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
2019 AUDIO_DEVICE_OUT_SPEAKER)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302020 if (audio_extn_get_anc_enabled())
2021 snd_device = SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302022 else if (my_data->external_spk_1)
2023 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1;
2024 else if (my_data->external_spk_2)
2025 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302026 else
2027 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302028 } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
2029 AUDIO_DEVICE_OUT_SPEAKER)) {
2030 snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302031 } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
2032 AUDIO_DEVICE_OUT_SPEAKER)) {
2033 snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302034 } else {
2035 ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
2036 goto exit;
2037 }
2038 if (snd_device != SND_DEVICE_NONE) {
2039 goto exit;
2040 }
2041 }
2042
2043 if (popcount(devices) != 1) {
2044 ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
2045 goto exit;
2046 }
2047
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302048 if ((mode == AUDIO_MODE_IN_CALL) ||
2049 voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302050 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2051 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2052 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2053 !voice_extn_compress_voip_is_active(adev)) {
2054 switch (adev->voice.tty_mode) {
2055 case TTY_MODE_FULL:
2056 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
2057 break;
2058 case TTY_MODE_VCO:
2059 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
2060 break;
2061 case TTY_MODE_HCO:
2062 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
2063 break;
2064 default:
2065 ALOGE("%s: Invalid TTY mode (%#x)",
2066 __func__, adev->voice.tty_mode);
2067 }
2068 } else if (audio_extn_get_anc_enabled()) {
2069 if (audio_extn_should_use_fb_anc())
2070 snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
2071 else
2072 snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
2073 } else {
2074 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
2075 }
2076 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002077 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302078 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2079 else
2080 snd_device = SND_DEVICE_OUT_BT_SCO;
2081 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302082 if (my_data->is_wsa_speaker)
2083 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER_WSA;
2084 else
2085 snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302086 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2087 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2088 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2089 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2090 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
2091 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
2092 if (audio_extn_should_use_handset_anc(channel_count))
2093 snd_device = SND_DEVICE_OUT_ANC_HANDSET;
2094 else
2095 snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05302096 } else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2097 snd_device = SND_DEVICE_OUT_VOICE_TX;
2098
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302099 if (snd_device != SND_DEVICE_NONE) {
2100 goto exit;
2101 }
2102 }
2103
Naresh Tannirue3b18452014-03-04 14:44:27 +05302104 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2105 devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302106 if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
2107 && audio_extn_get_anc_enabled()) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302108#ifdef RECORD_PLAY_CONCURRENCY
2109 if (use_voip_out_devices) {
2110 // ANC should be disabled for voip concurrency
2111 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
2112 } else
2113#endif
2114 {
2115 if (audio_extn_should_use_fb_anc())
2116 snd_device = SND_DEVICE_OUT_ANC_FB_HEADSET;
2117 else
2118 snd_device = SND_DEVICE_OUT_ANC_HEADSET;
2119 }
2120 } else {
2121#ifdef RECORD_PLAY_CONCURRENCY
2122 if (use_voip_out_devices)
2123 snd_device = SND_DEVICE_OUT_VOIP_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302124 else
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302125#endif
2126 snd_device = SND_DEVICE_OUT_HEADPHONES;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302127 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302128 } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302129#ifdef RECORD_PLAY_CONCURRENCY
2130 if (use_voip_out_devices) {
2131 snd_device = SND_DEVICE_OUT_VOIP_SPEAKER;
2132 } else
2133#endif
2134 {
2135 if (adev->speaker_lr_swap)
2136 snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
2137 else
Preetam Singh Ranawatc7f7f5c2015-04-02 12:19:58 +05302138 {
2139 if (my_data->is_wsa_speaker)
2140 snd_device = SND_DEVICE_OUT_SPEAKER_WSA;
2141 else
2142 snd_device = SND_DEVICE_OUT_SPEAKER;
2143 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302144 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302145 } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
Mingming Yin514a8bc2014-07-29 15:22:21 -07002146 if (adev->bt_wb_speech_enabled)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302147 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
2148 else
2149 snd_device = SND_DEVICE_OUT_BT_SCO;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302150 } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2151 snd_device = SND_DEVICE_OUT_HDMI ;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302152 } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2153 devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002154 ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
2155 audio_extn_set_afe_proxy_channel_mixer(adev, 2);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302156 snd_device = SND_DEVICE_OUT_USB_HEADSET;
2157 } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
2158 snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302159 } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302160#ifdef RECORD_PLAY_CONCURRENCY
2161 if (use_voip_out_devices)
2162 snd_device = SND_DEVICE_OUT_VOIP_HANDSET;
2163 else
2164#endif
2165 snd_device = SND_DEVICE_OUT_HANDSET;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302166 } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
Mingming Yin5a7c5d62014-03-05 17:45:03 -08002167 channel_count = audio_extn_get_afe_proxy_channel_count();
2168 ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
2169 audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302170 snd_device = SND_DEVICE_OUT_AFE_PROXY;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302171 } else {
2172 ALOGE("%s: Unknown device(s) %#x", __func__, devices);
2173 }
2174exit:
2175 ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
2176 return snd_device;
2177}
2178
2179snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
2180{
2181 struct platform_data *my_data = (struct platform_data *)platform;
2182 struct audio_device *adev = my_data->adev;
2183 audio_source_t source = (adev->active_input == NULL) ?
2184 AUDIO_SOURCE_DEFAULT : adev->active_input->source;
2185
2186 audio_mode_t mode = adev->mode;
2187 audio_devices_t in_device = ((adev->active_input == NULL) ?
2188 AUDIO_DEVICE_NONE : adev->active_input->device)
2189 & ~AUDIO_DEVICE_BIT_IN;
2190 audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
2191 AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
2192 snd_device_t snd_device = SND_DEVICE_NONE;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302193 int channel_count = popcount(channel_mask);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302194
2195 ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
2196 __func__, out_device, in_device);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302197 if (my_data->external_mic) {
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302198 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
2199 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302200 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2201 out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2202 out_device & AUDIO_DEVICE_OUT_SPEAKER )
2203 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2204 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2205 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2206 snd_device = SND_DEVICE_IN_HANDSET_MIC_EXTERNAL;
2207 }
2208 }
2209
2210 if (snd_device != AUDIO_DEVICE_NONE)
2211 goto exit;
2212
Venkata Narendra Kumar Guttabfdfa152015-06-22 14:25:35 +05302213 if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
Satya Krishna Pindiproli2aaa6152014-05-21 15:05:22 +05302214 voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302215 if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
2216 !voice_extn_compress_voip_is_active(adev)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302217 if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
2218 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302219 switch (adev->voice.tty_mode) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302220 case TTY_MODE_FULL:
2221 snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
2222 break;
2223 case TTY_MODE_VCO:
2224 snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
2225 break;
2226 case TTY_MODE_HCO:
2227 snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
2228 break;
2229 default:
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302230 ALOGE("%s: Invalid TTY mode (%#x)",
2231 __func__, adev->voice.tty_mode);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302232 }
2233 goto exit;
2234 }
2235 }
2236 if (out_device & AUDIO_DEVICE_OUT_EARPIECE ||
2237 out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302238 if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Sidipotu Ashok3bcca232014-11-07 14:41:58 +05302239 audio_extn_should_use_handset_anc(channel_count) &&
2240 my_data->fluence_type != FLUENCE_NONE) {
2241 snd_device = SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC;
2242 adev->acdb_settings |= DMIC_FLAG;
2243 ALOGD("Selecting AANC, Fluence combo device");
2244 } else if (out_device & AUDIO_DEVICE_OUT_EARPIECE &&
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302245 audio_extn_should_use_handset_anc(channel_count)) {
2246 snd_device = SND_DEVICE_IN_AANC_HANDSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302247 adev->acdb_settings |= ANC_FLAG;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302248 } else if (my_data->fluence_type == FLUENCE_NONE ||
2249 my_data->fluence_in_voice_call == false) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302250 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302251 if (audio_extn_hfp_is_active(adev))
2252 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302253 } else {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302254 snd_device = SND_DEVICE_IN_VOICE_DMIC;
2255 adev->acdb_settings |= DMIC_FLAG;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302256 }
2257 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2258 snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302259 if (audio_extn_hfp_is_active(adev))
2260 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302261 } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002262 if (adev->bt_wb_speech_enabled) {
2263 if (adev->bluetooth_nrec)
2264 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2265 else
2266 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2267 } else {
2268 if (adev->bluetooth_nrec)
2269 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2270 else
2271 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2272 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302273 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302274 if (my_data->fluence_type != FLUENCE_NONE &&
2275 my_data->fluence_in_voice_call &&
2276 my_data->fluence_in_spkr_mode) {
2277 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
2278 adev->acdb_settings |= QMIC_FLAG;
2279 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_QMIC;
2280 } else {
2281 adev->acdb_settings |= DMIC_FLAG;
Karthik Reddy Kattad9fff862014-07-21 21:07:21 +05302282 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2283 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE;
2284 else
2285 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302286 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302287 } else {
2288 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302289 if (audio_extn_hfp_is_active(adev))
2290 platform_set_echo_reference(adev->platform, true);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302291 }
Preetam Singh Ranawat7112f3b2015-02-26 16:51:58 +05302292 } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
2293 snd_device = SND_DEVICE_IN_VOICE_RX;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302294 } else if (source == AUDIO_SOURCE_CAMCORDER) {
2295 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
2296 in_device & AUDIO_DEVICE_IN_BACK_MIC) {
kunleiz18a33302014-05-30 09:52:25 +08002297 if (my_data->fluence_type & FLUENCE_DUAL_MIC &&
2298 channel_count == 2)
kunleiz8f7e9e22014-06-24 15:12:02 +08002299 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
kunleiz18a33302014-05-30 09:52:25 +08002300 else
2301 snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302302 }
2303 } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
2304 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302305 if (channel_count == 2) {
2306 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
2307 adev->acdb_settings |= DMIC_FLAG;
2308 } else if (adev->active_input->enable_ns)
2309 snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
2310 else if (my_data->fluence_type != FLUENCE_NONE &&
2311 my_data->fluence_in_voice_rec) {
2312 snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
2313 adev->acdb_settings |= DMIC_FLAG;
2314 } else {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302315 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
2316 }
2317 }
Karthik Reddy Kattaf621ec72014-11-21 16:37:38 +05302318 } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
2319 (mode == AUDIO_MODE_IN_COMMUNICATION)) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302320 if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
2321 in_device = AUDIO_DEVICE_IN_BACK_MIC;
2322 if (adev->active_input) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302323 if (adev->active_input->enable_aec &&
2324 adev->active_input->enable_ns) {
Naresh Tannirue3b18452014-03-04 14:44:27 +05302325 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05302326 if (my_data->fluence_in_spkr_mode) {
2327 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2328 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS;
2329 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2330 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2331 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE;
2332 else
2333 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
2334 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302335 adev->acdb_settings |= DMIC_FLAG;
2336 } else
2337 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302338 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302339 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2340 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
2341 adev->acdb_settings |= DMIC_FLAG;
2342 } else
2343 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302344 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302345 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302346 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302347 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302348 } else if (adev->active_input->enable_aec) {
2349 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05302350 if (my_data->fluence_in_spkr_mode) {
2351 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2352 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_AEC;
2353 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2354 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2355 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE;
2356 else
2357 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
2358 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302359 adev->acdb_settings |= DMIC_FLAG;
2360 } else
2361 snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
2362 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2363 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2364 snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
2365 adev->acdb_settings |= DMIC_FLAG;
2366 } else
2367 snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
2368 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2369 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
2370 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302371 platform_set_echo_reference(adev->platform, true);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302372 } else if (adev->active_input->enable_ns) {
2373 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05302374 if (my_data->fluence_in_spkr_mode) {
2375 if (my_data->fluence_type & FLUENCE_QUAD_MIC) {
2376 snd_device = SND_DEVICE_IN_SPEAKER_QMIC_NS;
2377 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2378 if (my_data->fluence_mode == FLUENCE_BROADSIDE)
2379 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE;
2380 else
2381 snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
2382 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302383 adev->acdb_settings |= DMIC_FLAG;
2384 } else
2385 snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
2386 } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
2387 if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2388 snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
2389 adev->acdb_settings |= DMIC_FLAG;
2390 } else
2391 snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
2392 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2393 snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
2394 }
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302395 platform_set_echo_reference(adev->platform,false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302396 } else
Venkata Narendra Kumar Gutta1bbbf542014-09-04 19:11:25 +05302397 platform_set_echo_reference(adev->platform, false);
Naresh Tannirue3b18452014-03-04 14:44:27 +05302398 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302399 } else if (source == AUDIO_SOURCE_MIC) {
2400 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
2401 channel_count == 1 ) {
Karthik Reddy Kattad71b94b2015-01-19 14:06:53 +05302402 if(my_data->fluence_in_audio_rec) {
2403 if(my_data->fluence_type & FLUENCE_QUAD_MIC) {
2404 snd_device = SND_DEVICE_IN_HANDSET_QMIC;
2405 platform_set_echo_reference(adev->platform, true);
2406 } else if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
2407 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
2408 platform_set_echo_reference(adev->platform, true);
2409 }
2410 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302411 }
2412 } else if (source == AUDIO_SOURCE_FM_RX ||
2413 source == AUDIO_SOURCE_FM_RX_A2DP) {
2414 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302415 } else if (source == AUDIO_SOURCE_DEFAULT) {
2416 goto exit;
2417 }
2418
2419
2420 if (snd_device != SND_DEVICE_NONE) {
2421 goto exit;
2422 }
2423
2424 if (in_device != AUDIO_DEVICE_NONE &&
2425 !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
2426 !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
2427 if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302428 if (audio_extn_ssr_get_enabled() && channel_count == 6)
2429 snd_device = SND_DEVICE_IN_QUAD_MIC;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302430 else if (my_data->fluence_type & (FLUENCE_DUAL_MIC | FLUENCE_QUAD_MIC) &&
2431 channel_count == 2)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302432 snd_device = SND_DEVICE_IN_HANDSET_STEREO_DMIC;
2433 else
2434 snd_device = SND_DEVICE_IN_HANDSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302435 } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
2436 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
2437 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
2438 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2439 } else if (in_device & AUDIO_DEVICE_IN_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 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302451 } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
2452 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302453 } else if (in_device & AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET ||
2454 in_device & AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET) {
2455 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
2456 } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
2457 snd_device = SND_DEVICE_IN_CAPTURE_FM;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302458 } else {
2459 ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
2460 ALOGW("%s: Using default handset-mic", __func__);
2461 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2462 }
2463 } else {
2464 if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
2465 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2466 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
2467 snd_device = SND_DEVICE_IN_HEADSET_MIC;
2468 } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302469 if (channel_count > 1)
2470 snd_device = SND_DEVICE_IN_SPEAKER_STEREO_DMIC;
2471 else
2472 snd_device = SND_DEVICE_IN_SPEAKER_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302473 } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
2474 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2475 } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
Vicky Sehrawate240e5d2014-08-12 17:17:04 -07002476 if (adev->bt_wb_speech_enabled) {
2477 if (adev->bluetooth_nrec)
2478 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB_NREC;
2479 else
2480 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
2481 } else {
2482 if (adev->bluetooth_nrec)
2483 snd_device = SND_DEVICE_IN_BT_SCO_MIC_NREC;
2484 else
2485 snd_device = SND_DEVICE_IN_BT_SCO_MIC;
2486 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302487 } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
2488 snd_device = SND_DEVICE_IN_HDMI_MIC;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302489 } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
2490 out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
2491 snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302492 } else {
2493 ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
2494 ALOGW("%s: Using default handset-mic", __func__);
2495 snd_device = SND_DEVICE_IN_HANDSET_MIC;
2496 }
2497 }
2498exit:
2499 ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
2500 return snd_device;
2501}
2502
2503int platform_set_hdmi_channels(void *platform, int channel_count)
2504{
2505 struct platform_data *my_data = (struct platform_data *)platform;
2506 struct audio_device *adev = my_data->adev;
2507 struct mixer_ctl *ctl;
2508 const char *channel_cnt_str = NULL;
2509 const char *mixer_ctl_name = "HDMI_RX Channels";
2510 switch (channel_count) {
2511 case 8:
2512 channel_cnt_str = "Eight"; break;
2513 case 7:
2514 channel_cnt_str = "Seven"; break;
2515 case 6:
2516 channel_cnt_str = "Six"; break;
2517 case 5:
2518 channel_cnt_str = "Five"; break;
2519 case 4:
2520 channel_cnt_str = "Four"; break;
2521 case 3:
2522 channel_cnt_str = "Three"; break;
2523 default:
2524 channel_cnt_str = "Two"; break;
2525 }
2526 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2527 if (!ctl) {
2528 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2529 __func__, mixer_ctl_name);
2530 return -EINVAL;
2531 }
2532 ALOGV("HDMI channel count: %s", channel_cnt_str);
2533 mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
2534 return 0;
2535}
2536
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302537int platform_edid_get_max_channels(void *platform)
Naresh Tannirue3b18452014-03-04 14:44:27 +05302538{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302539 int channel_count;
2540 int max_channels = 2;
2541 int i = 0, ret = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302542 struct platform_data *my_data = (struct platform_data *)platform;
2543 struct audio_device *adev = my_data->adev;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302544 edid_audio_info *info = NULL;
2545 ret = platform_get_edid_info(platform);
2546 info = (edid_audio_info *)my_data->edid_info;
Naresh Tannirue3b18452014-03-04 14:44:27 +05302547
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302548 if(ret == 0 && info != NULL) {
2549 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
2550 ALOGV("%s:format %d channel %d", __func__,
2551 info->audio_blocks_array[i].format_id,
2552 info->audio_blocks_array[i].channels);
2553 if (info->audio_blocks_array[i].format_id == LPCM) {
2554 channel_count = info->audio_blocks_array[i].channels;
2555 if (channel_count > max_channels) {
2556 max_channels = channel_count;
2557 }
2558 }
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302559 }
Naresh Tannirue3b18452014-03-04 14:44:27 +05302560 }
2561
2562 return max_channels;
2563}
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302564
2565static int platform_set_slowtalk(struct platform_data *my_data, bool state)
2566{
2567 int ret = 0;
2568 struct audio_device *adev = my_data->adev;
2569 struct mixer_ctl *ctl;
2570 const char *mixer_ctl_name = "Slowtalk Enable";
2571 uint32_t set_values[ ] = {0,
2572 ALL_SESSION_VSID};
2573
2574 set_values[0] = state;
2575 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2576 if (!ctl) {
2577 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2578 __func__, mixer_ctl_name);
2579 ret = -EINVAL;
2580 } else {
2581 ALOGV("Setting slowtalk state: %d", state);
2582 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2583 my_data->slowtalk = state;
2584 }
2585
2586 if (my_data->csd != NULL) {
2587 ret = my_data->csd->slow_talk(ALL_SESSION_VSID, state);
2588 if (ret < 0) {
2589 ALOGE("%s: csd_client_disable_device, failed, error %d",
2590 __func__, ret);
2591 }
2592 }
2593 return ret;
2594}
2595
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302596static int set_hd_voice(struct platform_data *my_data, bool state)
2597{
2598 struct audio_device *adev = my_data->adev;
2599 struct mixer_ctl *ctl;
2600 const char *mixer_ctl_name = "HD Voice Enable";
2601 int ret = 0;
2602 uint32_t set_values[ ] = {0,
2603 ALL_SESSION_VSID};
2604
2605 set_values[0] = state;
2606 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2607 if (!ctl) {
2608 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2609 __func__, mixer_ctl_name);
2610 ret = -EINVAL;
2611 } else {
2612 ALOGV("Setting HD Voice state: %d", state);
2613 ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
2614 my_data->hd_voice = state;
2615 }
2616
2617 return ret;
2618}
2619
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302620static int update_external_device_status(struct platform_data *my_data,
2621 char* event_name, bool status)
2622{
2623 int ret = 0;
2624 struct audio_usecase *usecase;
2625 struct listnode *node;
2626
2627 ALOGD("Recieved external event switch %s", event_name);
2628
2629 if (!strcmp(event_name, EVENT_EXTERNAL_SPK_1))
2630 my_data->external_spk_1 = status;
2631 else if (!strcmp(event_name, EVENT_EXTERNAL_SPK_2))
2632 my_data->external_spk_2 = status;
2633 else if (!strcmp(event_name, EVENT_EXTERNAL_MIC))
2634 my_data->external_mic = status;
2635 else {
2636 ALOGE("The audio event type is not found");
2637 return -EINVAL;
2638 }
2639
2640 list_for_each(node, &my_data->adev->usecase_list) {
2641 usecase = node_to_item(node, struct audio_usecase, list);
2642 select_devices(my_data->adev, usecase->id);
2643 }
2644
2645 return ret;
2646}
2647
2648static int parse_audiocal_cfg(struct str_parms *parms, acdb_audio_cal_cfg_t *cal)
2649{
2650 int err;
2651 unsigned int val;
2652 char value[64];
2653 int ret = 0;
2654
2655 if(parms == NULL || cal == NULL)
2656 return ret;
2657
2658 err = str_parms_get_str(parms, "cal_persist", value, sizeof(value));
2659 if (err >= 0) {
2660 str_parms_del(parms, "cal_persist");
2661 cal->persist = (uint32_t) strtoul(value, NULL, 0);
2662 ret = ret | 0x1;
2663 }
2664 err = str_parms_get_str(parms, "cal_apptype", value, sizeof(value));
2665 if (err >= 0) {
2666 str_parms_del(parms, "cal_apptype");
2667 cal->app_type = (uint32_t) strtoul(value, NULL, 0);
2668 ret = ret | 0x2;
2669 }
2670 err = str_parms_get_str(parms, "cal_caltype", value, sizeof(value));
2671 if (err >= 0) {
2672 str_parms_del(parms, "cal_caltype");
2673 cal->cal_type = (uint32_t) strtoul(value, NULL, 0);
2674 ret = ret | 0x4;
2675 }
2676 err = str_parms_get_str(parms, "cal_samplerate", value, sizeof(value));
2677 if (err >= 0) {
2678 str_parms_del(parms, "cal_samplerate");
2679 cal->sampling_rate = (uint32_t) strtoul(value, NULL, 0);
2680 ret = ret | 0x8;
2681 }
2682 err = str_parms_get_str(parms, "cal_devid", value, sizeof(value));
2683 if (err >= 0) {
2684 str_parms_del(parms, "cal_devid");
2685 cal->dev_id = (uint32_t) strtoul(value, NULL, 0);
2686 ret = ret | 0x10;
2687 }
2688 err = str_parms_get_str(parms, "cal_snddevid", value, sizeof(value));
2689 if (err >= 0) {
2690 str_parms_del(parms, "cal_snddevid");
2691 cal->snd_dev_id = (uint32_t) strtoul(value, NULL, 0);
2692 ret = ret | 0x20;
2693 }
2694 err = str_parms_get_str(parms, "cal_topoid", value, sizeof(value));
2695 if (err >= 0) {
2696 str_parms_del(parms, "cal_topoid");
2697 cal->topo_id = (uint32_t) strtoul(value, NULL, 0);
2698 ret = ret | 0x40;
2699 }
2700 err = str_parms_get_str(parms, "cal_moduleid", value, sizeof(value));
2701 if (err >= 0) {
2702 str_parms_del(parms, "cal_moduleid");
2703 cal->module_id = (uint32_t) strtoul(value, NULL, 0);
2704 ret = ret | 0x80;
2705 }
2706 err = str_parms_get_str(parms, "cal_paramid", value, sizeof(value));
2707 if (err >= 0) {
2708 str_parms_del(parms, "cal_paramid");
2709 cal->param_id = (uint32_t) strtoul(value, NULL, 0);
2710 ret = ret | 0x100;
2711 }
2712 return ret;
2713}
2714
2715static void set_audiocal(void *platform, struct str_parms *parms, char *value, int len) {
2716 struct platform_data *my_data = (struct platform_data *)platform;
2717 acdb_audio_cal_cfg_t cal={0};
2718 uint8_t *dptr = NULL;
2719 int32_t dlen;
2720 int err, ret;
2721 if(value == NULL || platform == NULL || parms == NULL) {
2722 ALOGE("[%s] received null pointer, failed",__func__);
2723 goto done_key_audcal;
2724 }
2725
2726 /* parse audio calibration keys */
2727 ret = parse_audiocal_cfg(parms, &cal);
2728
2729 /* handle audio calibration data now */
2730 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, len);
2731 if (err >= 0) {
2732 str_parms_del(parms, AUDIO_PARAMETER_KEY_AUD_CALDATA);
2733 dlen = strlen(value);
2734 if(dlen <= 0) {
2735 ALOGE("[%s] null data received",__func__);
2736 goto done_key_audcal;
2737 }
2738 dptr = (uint8_t*) calloc(dlen, sizeof(uint8_t));
2739 if(dptr == NULL) {
2740 ALOGE("[%s] memory allocation failed for %d",__func__, dlen);
2741 goto done_key_audcal;
2742 }
2743 dlen = b64decode(value, strlen(value), dptr);
2744 if(dlen<=0) {
2745 ALOGE("[%s] data decoding failed %d", __func__, dlen);
2746 goto done_key_audcal;
2747 }
2748
2749 if(cal.dev_id) {
2750 if(audio_is_input_device(cal.dev_id)) {
2751 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
2752 } else {
2753 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
2754 }
2755 }
2756 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
2757 ALOGD("Setting audio calibration for snd_device(%d) acdb_id(%d)",
2758 cal.snd_dev_id, cal.acdb_dev_id);
2759 if(cal.acdb_dev_id == -EINVAL) {
2760 ALOGE("[%s] Invalid acdb_device id %d for snd device id %d",
2761 __func__, cal.acdb_dev_id, cal.snd_dev_id);
2762 goto done_key_audcal;
2763 }
2764 if(my_data->acdb_set_audio_cal) {
2765 ret = my_data->acdb_set_audio_cal((void *)&cal, (void*)dptr, dlen);
2766 }
2767 }
2768done_key_audcal:
2769 if(dptr != NULL)
2770 free(dptr);
2771}
2772
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302773int platform_set_parameters(void *platform, struct str_parms *parms)
2774{
2775 struct platform_data *my_data = (struct platform_data *)platform;
2776 char *str;
2777 char value[256] = {0};
2778 int val;
2779 int ret = 0, err;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302780 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302781
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05302782 kv_pairs = str_parms_to_str(parms);
2783 ALOGV("%s: enter: - %s", __func__, kv_pairs);
2784 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302785
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302786 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_SLOWTALK, value, sizeof(value));
2787 if (err >= 0) {
2788 bool state = false;
2789 if (!strncmp("true", value, sizeof("true"))) {
2790 state = true;
2791 }
2792
2793 str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
2794 ret = platform_set_slowtalk(my_data, state);
2795 if (ret)
2796 ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
2797 }
2798
Avinash Vaishd5fa4572014-09-15 14:41:14 +05302799 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HD_VOICE, value, sizeof(value));
2800 if (err >= 0) {
2801 bool state = false;
2802 if (!strncmp("true", value, sizeof("true"))) {
2803 state = true;
2804 }
2805
2806 str_parms_del(parms, AUDIO_PARAMETER_KEY_HD_VOICE);
2807 if (my_data->hd_voice != state) {
2808 ret = set_hd_voice(my_data, state);
2809 if (ret)
2810 ALOGE("%s: Failed to set HD voice err: %d", __func__, ret);
2811 } else {
2812 ALOGV("%s: HD Voice already set to %d", __func__, state);
2813 }
2814 }
2815
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302816 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
2817 value, sizeof(value));
2818 if (err >= 0) {
2819 str_parms_del(parms, AUDIO_PARAMETER_KEY_VOLUME_BOOST);
2820
2821 if (my_data->acdb_reload_vocvoltable == NULL) {
2822 ALOGE("%s: acdb_reload_vocvoltable is NULL", __func__);
2823 } else if (!strcmp(value, "on")) {
2824 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_VOLUME_BOOST)) {
2825 my_data->voice_feature_set = 1;
2826 }
2827 } else {
2828 if (!my_data->acdb_reload_vocvoltable(VOICE_FEATURE_SET_DEFAULT)) {
2829 my_data->voice_feature_set = 0;
2830 }
2831 }
2832 }
2833
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302834#ifdef RECORD_PLAY_CONCURRENCY
2835 err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC, value, sizeof(value));
2836 if (err >= 0) {
2837 if (!strncmp("true", value, sizeof("true"))) {
2838 ALOGD("setting record playback concurrency to true");
2839 my_data->rec_play_conc_set = true;
2840 } else {
2841 ALOGD("setting record playback concurrency to false");
2842 my_data->rec_play_conc_set = false;
2843 }
Naresh Tanniruc0517bc2014-10-26 15:30:55 +05302844 }
2845#endif
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05302846 ALOGV("%s: exit with code(%d)", __func__, ret);
2847 return ret;
2848}
2849
2850int platform_set_incall_recording_session_id(void *platform,
2851 uint32_t session_id, int rec_mode)
2852{
2853 int ret = 0;
2854 struct platform_data *my_data = (struct platform_data *)platform;
2855 struct audio_device *adev = my_data->adev;
2856 struct mixer_ctl *ctl;
2857 const char *mixer_ctl_name = "Voc VSID";
2858 int num_ctl_values;
2859 int i;
2860
2861 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
2862 if (!ctl) {
2863 ALOGE("%s: Could not get ctl for mixer cmd - %s",
2864 __func__, mixer_ctl_name);
2865 ret = -EINVAL;
2866 } else {
2867 num_ctl_values = mixer_ctl_get_num_values(ctl);
2868 for (i = 0; i < num_ctl_values; i++) {
2869 if (mixer_ctl_set_value(ctl, i, session_id)) {
2870 ALOGV("Error: invalid session_id: %x", session_id);
2871 ret = -EINVAL;
2872 break;
2873 }
2874 }
2875 }
2876
2877 if (my_data->csd != NULL) {
2878 ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
2879 if (ret < 0) {
2880 ALOGE("%s: csd_client_start_record failed, error %d",
2881 __func__, ret);
2882 }
2883 }
2884
2885 return ret;
2886}
2887
2888int platform_stop_incall_recording_usecase(void *platform)
2889{
2890 int ret = 0;
2891 struct platform_data *my_data = (struct platform_data *)platform;
2892
2893 if (my_data->csd != NULL) {
2894 ret = my_data->csd->stop_record(ALL_SESSION_VSID);
2895 if (ret < 0) {
2896 ALOGE("%s: csd_client_stop_record failed, error %d",
2897 __func__, ret);
2898 }
2899 }
2900
2901 return ret;
2902}
2903
2904int platform_start_incall_music_usecase(void *platform)
2905{
2906 int ret = 0;
2907 struct platform_data *my_data = (struct platform_data *)platform;
2908
2909 if (my_data->csd != NULL) {
2910 ret = my_data->csd->start_playback(ALL_SESSION_VSID);
2911 if (ret < 0) {
2912 ALOGE("%s: csd_client_start_playback failed, error %d",
2913 __func__, ret);
2914 }
2915 }
2916
2917 return ret;
2918}
2919
2920int platform_stop_incall_music_usecase(void *platform)
2921{
2922 int ret = 0;
2923 struct platform_data *my_data = (struct platform_data *)platform;
2924
2925 if (my_data->csd != NULL) {
2926 ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
2927 if (ret < 0) {
2928 ALOGE("%s: csd_client_stop_playback failed, error %d",
2929 __func__, ret);
2930 }
2931 }
2932
2933 return ret;
2934}
2935
Vidyakumar Athota21b3bb92014-04-25 11:08:08 -07002936int platform_update_lch(void *platform, struct voice_session *session,
2937 enum voice_lch_mode lch_mode)
2938{
2939 int ret = 0;
2940 struct platform_data *my_data = (struct platform_data *)platform;
2941
2942 if ((my_data->csd != NULL) && (my_data->csd->set_lch != NULL))
2943 ret = my_data->csd->set_lch(session->vsid, lch_mode);
2944 else
2945 ret = pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode);
2946
2947 return ret;
2948}
2949
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05302950static void get_audiocal(void *platform, void *keys, void *pReply) {
2951 struct platform_data *my_data = (struct platform_data *)platform;
2952 struct str_parms *query = (struct str_parms *)keys;
2953 struct str_parms *reply=(struct str_parms *)pReply;
2954 acdb_audio_cal_cfg_t cal={0};
2955 uint8_t *dptr = NULL;
2956 char value[512] = {0};
2957 char *rparms=NULL;
2958 int ret=0, err;
2959 uint32_t param_len;
2960
2961 if(query==NULL || platform==NULL || reply==NULL) {
2962 ALOGE("[%s] received null pointer",__func__);
2963 ret=-EINVAL;
2964 goto done;
2965 }
2966 /* parse audiocal configuration keys */
2967 ret = parse_audiocal_cfg(query, &cal);
2968 if(ret == 0) {
2969 /* No calibration keys found */
2970 goto done;
2971 }
2972 err = str_parms_get_str(query, AUDIO_PARAMETER_KEY_AUD_CALDATA, value, sizeof(value));
2973 if (err >= 0) {
2974 str_parms_del(query, AUDIO_PARAMETER_KEY_AUD_CALDATA);
2975 } else {
2976 goto done;
2977 }
2978
2979 if(cal.dev_id & AUDIO_DEVICE_BIT_IN) {
2980 cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
2981 } else if(cal.dev_id) {
2982 cal.snd_dev_id = platform_get_output_snd_device(platform, cal.dev_id);
2983 }
2984 cal.acdb_dev_id = platform_get_snd_device_acdb_id(cal.snd_dev_id);
2985 if (cal.acdb_dev_id < 0) {
2986 ALOGE("%s: Failed. Could not find acdb id for snd device(%d)",
2987 __func__, cal.snd_dev_id);
2988 ret = -EINVAL;
2989 goto done_key_audcal;
2990 }
2991 ALOGD("[%s] Getting audio calibration for snd_device(%d) acdb_id(%d)",
2992 __func__, cal.snd_dev_id, cal.acdb_dev_id);
2993
2994 param_len = MAX_SET_CAL_BYTE_SIZE;
2995 dptr = (uint8_t*)calloc(param_len, sizeof(uint8_t));
2996 if(dptr == NULL) {
2997 ALOGE("[%s] Memory allocation failed for length %d",__func__,param_len);
2998 ret = -ENOMEM;
2999 goto done_key_audcal;
3000 }
3001 if (my_data->acdb_get_audio_cal != NULL) {
3002 ret = my_data->acdb_get_audio_cal((void*)&cal, (void*)dptr, &param_len);
3003 if (ret == 0) {
3004 int dlen;
3005 if(param_len == 0 || param_len == MAX_SET_CAL_BYTE_SIZE) {
3006 ret = -EINVAL;
3007 goto done_key_audcal;
3008 }
3009 /* Allocate memory for encoding */
3010 rparms = (char*)calloc((param_len*2), sizeof(char));
3011 if(rparms == NULL) {
3012 ALOGE("[%s] Memory allocation failed for size %d",
3013 __func__, param_len*2);
3014 ret = -ENOMEM;
3015 goto done_key_audcal;
3016 }
3017 if(cal.persist==0 && cal.module_id && cal.param_id) {
3018 err = b64encode(dptr+12, param_len-12, rparms);
3019 } else {
3020 err = b64encode(dptr, param_len, rparms);
3021 }
3022 if(err < 0) {
3023 ALOGE("[%s] failed to convert data to string", __func__);
3024 ret = -EINVAL;
3025 goto done_key_audcal;
3026 }
3027 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
3028 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, rparms);
3029 }
3030 }
3031done_key_audcal:
3032 if(ret != 0) {
3033 str_parms_add_int(reply, AUDIO_PARAMETER_KEY_AUD_CALRESULT, ret);
3034 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_AUD_CALDATA, "");
3035 }
3036done:
3037 if(dptr != NULL)
3038 free(dptr);
3039 if(rparms != NULL)
3040 free(rparms);
3041}
3042
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303043void platform_get_parameters(void *platform,
3044 struct str_parms *query,
3045 struct str_parms *reply)
3046{
3047 struct platform_data *my_data = (struct platform_data *)platform;
3048 char *str = NULL;
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303049 char value[512] = {0};
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303050 int ret;
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303051 char *kv_pairs = NULL;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303052
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303053 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_SLOWTALK,
3054 value, sizeof(value));
3055 if (ret >= 0) {
3056 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_SLOWTALK,
3057 my_data->slowtalk?"true":"false");
3058 }
3059
Avinash Vaishd5fa4572014-09-15 14:41:14 +05303060 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_HD_VOICE,
3061 value, sizeof(value));
3062 if (ret >= 0) {
3063 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_HD_VOICE,
3064 my_data->hd_voice?"true":"false");
3065 }
3066
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303067 ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_VOLUME_BOOST,
3068 value, sizeof(value));
3069 if (ret >= 0) {
3070 if (my_data->voice_feature_set == VOICE_FEATURE_SET_VOLUME_BOOST) {
3071 strlcpy(value, "on", sizeof(value));
3072 } else {
3073 strlcpy(value, "off", sizeof(value));
3074 }
3075
3076 str_parms_add_str(reply, AUDIO_PARAMETER_KEY_VOLUME_BOOST, value);
3077 }
3078
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303079 /* Handle audio calibration keys */
Karthik Reddy Kattabfe193d2014-08-14 17:58:18 +05303080 kv_pairs = str_parms_to_str(reply);
3081 ALOGV("%s: exit: returns - %s", __func__, kv_pairs);
3082 free(kv_pairs);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303083}
3084
3085/* 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}
3097
3098int platform_update_usecase_from_source(int source, int usecase)
3099{
3100 ALOGV("%s: input source :%d", __func__, source);
3101 if(source == AUDIO_SOURCE_FM_RX_A2DP)
3102 usecase = USECASE_AUDIO_RECORD_FM_VIRTUAL;
3103 return usecase;
3104}
3105
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303106bool platform_listen_device_needs_event(snd_device_t snd_device)
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303107{
Dhananjay Kumar45b71742014-05-29 21:47:27 +05303108 bool needs_event = false;
3109
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303110 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
3119bool platform_listen_usecase_needs_event(audio_usecase_t uc_id)
3120{
3121 bool needs_event = false;
3122
3123 switch(uc_id){
3124 /* concurrent playback usecases needs event */
3125 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3126 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
3127 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3128 needs_event = true;
3129 break;
3130 /* concurrent playback in low latency allowed */
3131 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3132 break;
3133 /* concurrent playback FM needs event */
3134 case USECASE_AUDIO_PLAYBACK_FM:
3135 needs_event = true;
3136 break;
3137
3138 /* concurrent capture usecases, no event, capture handled by device
3139 * USECASE_AUDIO_RECORD:
3140 * USECASE_AUDIO_RECORD_COMPRESS:
3141 * USECASE_AUDIO_RECORD_LOW_LATENCY:
3142
3143 * USECASE_VOICE_CALL:
3144 * USECASE_VOICE2_CALL:
3145 * USECASE_VOLTE_CALL:
3146 * USECASE_QCHAT_CALL:
3147 * USECASE_VOWLAN_CALL:
3148 * USECASE_COMPRESS_VOIP_CALL:
3149 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
3150 * USECASE_INCALL_REC_UPLINK:
3151 * USECASE_INCALL_REC_DOWNLINK:
3152 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
3153 * USECASE_INCALL_REC_UPLINK_COMPRESS:
3154 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
3155 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
3156 * USECASE_INCALL_MUSIC_UPLINK:
3157 * USECASE_INCALL_MUSIC_UPLINK2:
3158 * USECASE_AUDIO_SPKR_CALIB_RX:
3159 * USECASE_AUDIO_SPKR_CALIB_TX:
3160 */
3161 default:
3162 ALOGV("%s:usecase_id[%d} no need to raise event.", __func__, uc_id);
3163 }
3164 return needs_event;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303165}
3166
Ravi Kumar Alamanda8fa6b192014-09-09 16:06:42 -07003167bool platform_sound_trigger_device_needs_event(snd_device_t snd_device)
3168{
3169 bool needs_event = false;
3170
3171 if ((snd_device >= SND_DEVICE_IN_BEGIN) &&
3172 (snd_device < SND_DEVICE_IN_END) &&
3173 (snd_device != SND_DEVICE_IN_CAPTURE_FM) &&
3174 (snd_device != SND_DEVICE_IN_CAPTURE_VI_FEEDBACK))
3175 needs_event = true;
3176
3177 return needs_event;
3178}
3179
3180bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id)
3181{
3182 bool needs_event = false;
3183
3184 switch(uc_id){
3185 /* concurrent playback usecases needs event */
3186 case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
3187 case USECASE_AUDIO_PLAYBACK_MULTI_CH:
3188 case USECASE_AUDIO_PLAYBACK_OFFLOAD:
3189 needs_event = true;
3190 break;
3191 /* concurrent playback in low latency allowed */
3192 case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
3193 break;
3194 /* concurrent playback FM needs event */
3195 case USECASE_AUDIO_PLAYBACK_FM:
3196 needs_event = true;
3197 break;
3198
3199 /* concurrent capture usecases, no event, capture handled by device
3200 * USECASE_AUDIO_RECORD:
3201 * USECASE_AUDIO_RECORD_COMPRESS:
3202 * USECASE_AUDIO_RECORD_LOW_LATENCY:
3203
3204 * USECASE_VOICE_CALL:
3205 * USECASE_VOICE2_CALL:
3206 * USECASE_VOLTE_CALL:
3207 * USECASE_QCHAT_CALL:
3208 * USECASE_VOWLAN_CALL:
3209 * USECASE_COMPRESS_VOIP_CALL:
3210 * USECASE_AUDIO_RECORD_FM_VIRTUAL:
3211 * USECASE_INCALL_REC_UPLINK:
3212 * USECASE_INCALL_REC_DOWNLINK:
3213 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
3214 * USECASE_INCALL_REC_UPLINK_COMPRESS:
3215 * USECASE_INCALL_REC_DOWNLINK_COMPRESS:
3216 * USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
3217 * USECASE_INCALL_MUSIC_UPLINK:
3218 * USECASE_INCALL_MUSIC_UPLINK2:
3219 * USECASE_AUDIO_SPKR_CALIB_RX:
3220 * USECASE_AUDIO_SPKR_CALIB_TX:
3221 */
3222 default:
3223 ALOGV("%s:usecase_id[%d] no need to raise event.", __func__, uc_id);
3224 }
3225 return needs_event;
3226}
3227
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303228/* Read offload buffer size from a property.
3229 * If value is not power of 2 round it to
3230 * power of 2.
3231 */
3232uint32_t platform_get_compress_offload_buffer_size(audio_offload_info_t* info)
3233{
3234 char value[PROPERTY_VALUE_MAX] = {0};
3235 uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3236 if((property_get("audio.offload.buffer.size.kb", value, "")) &&
3237 atoi(value)) {
3238 fragment_size = atoi(value) * 1024;
3239 }
3240
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303241 // For FLAC use max size since it is loss less, and has sampling rates
3242 // upto 192kHZ
3243 if (info != NULL && !info->has_video &&
3244 info->format == AUDIO_FORMAT_FLAC) {
3245 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3246 ALOGV("FLAC fragment size %d", fragment_size);
3247 }
3248
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303249 if (info != NULL && info->has_video && info->is_streaming) {
3250 fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
3251 ALOGV("%s: offload fragment size reduced for AV streaming to %d",
Apoorv Raghuvanshi44bd9172014-05-28 14:50:07 -07003252 __func__, fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303253 }
3254
3255 fragment_size = ALIGN( fragment_size, 1024);
3256
3257 if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3258 fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3259 else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
3260 fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
3261 ALOGV("%s: fragment_size %d", __func__, fragment_size);
3262 return fragment_size;
3263}
3264
3265uint32_t platform_get_pcm_offload_buffer_size(audio_offload_info_t* info)
3266{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303267 uint32_t fragment_size = 0;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303268 uint32_t bits_per_sample = 16;
Alexy Joseph2ce25e22015-06-18 12:02:01 -07003269 uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303270
3271 if (info->format == AUDIO_FORMAT_PCM_24_BIT_OFFLOAD) {
3272 bits_per_sample = 32;
3273 }
3274
Alexy Joseph2ce25e22015-06-18 12:02:01 -07003275 //duration is set to 40 ms worth of stereo data at 48Khz
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303276 //with 16 bit per sample, modify this when the channel
3277 //configuration is different
3278 fragment_size = (pcm_offload_time
3279 * info->sample_rate
3280 * (bits_per_sample >> 3)
3281 * popcount(info->channel_mask))/1000;
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303282 if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
3283 fragment_size = MIN_PCM_OFFLOAD_FRAGMENT_SIZE;
3284 else if(fragment_size > MAX_PCM_OFFLOAD_FRAGMENT_SIZE)
3285 fragment_size = MAX_PCM_OFFLOAD_FRAGMENT_SIZE;
Preetam Singh Ranawat6efde5c2015-04-24 11:04:22 +05303286 // To have same PCM samples for all channels, the buffer size requires to
3287 // be multiple of (number of channels * bytes per sample)
3288 // For writes to succeed, the buffer must be written at address which is multiple of 32
Preetam Singh Ranawat8347e462015-05-27 11:14:03 +05303289 fragment_size = ALIGN(fragment_size, ((bits_per_sample >> 3)* popcount(info->channel_mask) * 32));
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303290
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303291 ALOGI("PCM offload Fragment size to %d bytes", fragment_size);
Naresh Tannirudb72d1e2014-03-05 17:33:47 +05303292 return fragment_size;
3293}
3294
Asish Bhattacharya9e25c492015-07-10 14:23:28 +05303295bool platform_use_small_buffer(audio_offload_info_t* info)
3296{
3297 return OFFLOAD_USE_SMALL_BUFFER;
3298}
3299
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303300int platform_set_codec_backend_cfg(struct audio_device* adev,
3301 unsigned int bit_width, unsigned int sample_rate)
3302{
3303 ALOGV("%s bit width: %d, sample rate: %d", __func__, bit_width, sample_rate);
3304
3305 int ret = 0;
Preetam Singh Ranawate6755952015-04-27 16:31:54 +05303306 const char *snd_card_name = mixer_get_name(adev->mixer);
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303307 if (bit_width != adev->cur_codec_backend_bit_width) {
Preetam Singh Ranawate6755952015-04-27 16:31:54 +05303308 const char * mixer_ctl_name;
3309 if (!strncmp(snd_card_name, "msm8952-tomtom-snd-card",
3310 sizeof("msm8952-tomtom-snd-card"))) {
3311 mixer_ctl_name = "SLIM_0_RX Format";
3312 }
3313 else
3314 mixer_ctl_name = "MI2S_RX Format";
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303315 struct mixer_ctl *ctl;
3316 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3317 if (!ctl) {
3318 ALOGE("%s: Could not get ctl for mixer command - %s",
3319 __func__, mixer_ctl_name);
3320 return -EINVAL;
3321 }
3322
3323 if (bit_width == 24) {
3324 mixer_ctl_set_enum_by_string(ctl, "S24_LE");
3325 } else {
3326 mixer_ctl_set_enum_by_string(ctl, "S16_LE");
3327 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3328 }
3329 adev->cur_codec_backend_bit_width = bit_width;
3330 ALOGE("Backend bit width is set to %d ", bit_width);
3331 }
3332
3333 /*
3334 * Backend sample rate configuration follows:
3335 * 16 bit playback - 48khz for streams at any valid sample rate
3336 * 24 bit playback - 48khz for stream sample rate less than 48khz
3337 * 24 bit playback - 96khz for sample rate range of 48khz to 96khz
3338 * 24 bit playback - 192khz for sample rate range of 96khz to 192 khz
3339 * Upper limit is inclusive in the sample rate range.
3340 */
3341 // TODO: This has to be more dynamic based on policy file
3342 if (sample_rate != adev->cur_codec_backend_samplerate) {
3343 char *rate_str = NULL;
3344 const char * mixer_ctl_name = "SLIM_0_RX SampleRate";
3345 struct mixer_ctl *ctl;
3346
3347 switch (sample_rate) {
3348 case 8000:
3349 case 11025:
3350 case 16000:
3351 case 22050:
3352 case 32000:
3353 case 44100:
3354 case 48000:
3355 rate_str = "KHZ_48";
3356 break;
3357 case 64000:
3358 case 88200:
3359 case 96000:
3360 rate_str = "KHZ_96";
3361 break;
3362 case 176400:
3363 case 192000:
3364 rate_str = "KHZ_192";
3365 break;
3366 default:
3367 rate_str = "KHZ_48";
3368 break;
3369 }
3370
3371 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3372 if(!ctl) {
3373 ALOGE("%s: Could not get ctl for mixer command - %s",
3374 __func__, mixer_ctl_name);
3375 return -EINVAL;
3376 }
3377
3378 ALOGV("Set sample rate as rate_str = %s", rate_str);
3379 mixer_ctl_set_enum_by_string(ctl, rate_str);
3380 adev->cur_codec_backend_samplerate = sample_rate;
3381 }
3382
3383 return ret;
3384}
3385
3386bool platform_check_codec_backend_cfg(struct audio_device* adev,
3387 struct audio_usecase* usecase __unused,
3388 unsigned int* new_bit_width,
3389 unsigned int* new_sample_rate)
3390{
3391 bool backend_change = false;
3392 struct listnode *node;
3393 struct stream_out *out = NULL;
3394 unsigned int bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3395 unsigned int sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3396
3397 // For voice calls use default configuration
3398 // force routing is not required here, caller will do it anyway
3399 if (voice_is_in_call(adev) || adev->mode == AUDIO_MODE_IN_COMMUNICATION) {
3400 ALOGW("%s:Use default bw and sr for voice/voip calls ",__func__);
3401 bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
3402 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3403 } else {
3404 /*
3405 * The backend should be configured at highest bit width and/or
3406 * sample rate amongst all playback usecases.
3407 * If the selected sample rate and/or bit width differ with
3408 * current backend sample rate and/or bit width, then, we set the
3409 * backend re-configuration flag.
3410 *
3411 * Exception: 16 bit playbacks is allowed through 16 bit/48 khz backend only
3412 */
3413 list_for_each(node, &adev->usecase_list) {
3414 struct audio_usecase *curr_usecase;
3415 curr_usecase = node_to_item(node, struct audio_usecase, list);
3416 if (curr_usecase->type == PCM_PLAYBACK) {
3417 struct stream_out *out =
3418 (struct stream_out*) curr_usecase->stream.out;
3419 if (out != NULL ) {
3420 ALOGV("Offload playback running bw %d sr %d",
3421 out->bit_width, out->sample_rate);
3422 if (bit_width < out->bit_width)
3423 bit_width = out->bit_width;
3424 if (sample_rate < out->sample_rate)
3425 sample_rate = out->sample_rate;
3426 }
3427 }
3428 }
3429 }
3430
3431 // 16 bit playback on speakers is allowed through 48 khz backend only
3432 if (16 == bit_width) {
3433 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3434 }
3435 // 24 bit playback on speakers is allowed through 48 khz backend only
3436 // bit width re-configured based on platform info
3437 if ((24 == bit_width) &&
3438 (usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER)) {
3439 bit_width = (uint32_t)platform_get_snd_device_bit_width(SND_DEVICE_OUT_SPEAKER);
3440 sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
3441 }
3442 // Force routing if the expected bitwdith or samplerate
3443 // is not same as current backend comfiguration
3444 if ((bit_width != adev->cur_codec_backend_bit_width) ||
3445 (sample_rate != adev->cur_codec_backend_samplerate)) {
3446 *new_bit_width = bit_width;
3447 *new_sample_rate = sample_rate;
3448 backend_change = true;
3449 ALOGI("%s Codec backend needs to be updated. new bit width: %d new sample rate: %d",
3450 __func__, *new_bit_width, *new_sample_rate);
3451 }
3452
3453 return backend_change;
3454}
3455
Apoorv Raghuvanshi21492162015-02-19 18:19:36 -08003456bool platform_check_and_set_codec_backend_cfg(struct audio_device* adev,
3457 struct audio_usecase *usecase,
3458 snd_device_t snd_device __unused)
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303459{
3460 ALOGV("platform_check_and_set_codec_backend_cfg usecase = %d",usecase->id );
3461
3462 unsigned int new_bit_width, old_bit_width;
3463 unsigned int new_sample_rate, old_sample_rate;
3464
3465 new_bit_width = old_bit_width = adev->cur_codec_backend_bit_width;
3466 new_sample_rate = old_sample_rate = adev->cur_codec_backend_samplerate;
3467
3468 ALOGW("Codec backend bitwidth %d, samplerate %d", old_bit_width, old_sample_rate);
3469 if (platform_check_codec_backend_cfg(adev, usecase,
3470 &new_bit_width, &new_sample_rate)) {
3471 platform_set_codec_backend_cfg(adev, new_bit_width, new_sample_rate);
3472 return true;
3473 }
3474
3475 return false;
3476}
3477
3478int platform_set_snd_device_backend(snd_device_t device, const char *backend)
3479{
3480 int ret = 0;
3481
3482 if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
3483 ALOGE("%s: Invalid snd_device = %d",
3484 __func__, device);
3485 ret = -EINVAL;
3486 goto done;
3487 }
3488
3489 if (backend_table[device]) {
3490 free(backend_table[device]);
3491 }
3492 backend_table[device] = strdup(backend);
3493done:
3494 return ret;
3495}
3496
3497int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
3498{
3499 int ret = 0;
3500 if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
3501 ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
3502 ret = -EINVAL;
3503 goto done;
3504 }
3505
3506 if ((type != 0) && (type != 1)) {
3507 ALOGE("%s: invalid usecase type", __func__);
3508 ret = -EINVAL;
3509 }
3510 pcm_device_table[usecase][type] = pcm_id;
3511done:
3512 return ret;
3513}
3514
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003515void platform_get_device_to_be_id_map(int **device_to_be_id, int *length)
3516{
3517 *device_to_be_id = msm_device_to_be_id;
3518 *length = msm_be_id_array_len;
3519}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303520int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask, int snd_id)
3521{
3522 int ret = 0;
3523 int channels = audio_channel_count_from_out_mask(channel_mask);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003524
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303525 char channel_map[8];
3526 memset(channel_map, 0, sizeof(channel_map));
3527 /* Following are all most common standard WAV channel layouts
3528 overridden by channel mask if its allowed and different */
3529 switch (channels) {
3530 case 1:
3531 /* AUDIO_CHANNEL_OUT_MONO */
3532 channel_map[0] = PCM_CHANNEL_FC;
3533 break;
3534 case 2:
3535 /* AUDIO_CHANNEL_OUT_STEREO */
3536 channel_map[0] = PCM_CHANNEL_FL;
3537 channel_map[1] = PCM_CHANNEL_FR;
3538 break;
3539 case 3:
3540 /* AUDIO_CHANNEL_OUT_2POINT1 */
3541 channel_map[0] = PCM_CHANNEL_FL;
3542 channel_map[1] = PCM_CHANNEL_FR;
3543 channel_map[2] = PCM_CHANNEL_FC;
3544 break;
3545 case 4:
3546 /* AUDIO_CHANNEL_OUT_QUAD_SIDE */
3547 channel_map[0] = PCM_CHANNEL_FL;
3548 channel_map[1] = PCM_CHANNEL_FR;
3549 channel_map[2] = PCM_CHANNEL_LS;
3550 channel_map[3] = PCM_CHANNEL_RS;
3551 if (channel_mask == AUDIO_CHANNEL_OUT_QUAD_BACK)
3552 {
3553 channel_map[2] = PCM_CHANNEL_LB;
3554 channel_map[3] = PCM_CHANNEL_RB;
3555 }
3556 if (channel_mask == AUDIO_CHANNEL_OUT_SURROUND)
3557 {
3558 channel_map[2] = PCM_CHANNEL_FC;
3559 channel_map[3] = PCM_CHANNEL_CS;
3560 }
3561 break;
3562 case 5:
3563 /* AUDIO_CHANNEL_OUT_PENTA */
3564 channel_map[0] = PCM_CHANNEL_FL;
3565 channel_map[1] = PCM_CHANNEL_FR;
3566 channel_map[2] = PCM_CHANNEL_FC;
3567 channel_map[3] = PCM_CHANNEL_LB;
3568 channel_map[4] = PCM_CHANNEL_RB;
3569 break;
3570 case 6:
3571 /* AUDIO_CHANNEL_OUT_5POINT1 */
3572 channel_map[0] = PCM_CHANNEL_FL;
3573 channel_map[1] = PCM_CHANNEL_FR;
3574 channel_map[2] = PCM_CHANNEL_FC;
3575 channel_map[3] = PCM_CHANNEL_LFE;
3576 channel_map[4] = PCM_CHANNEL_LB;
3577 channel_map[5] = PCM_CHANNEL_RB;
3578 if (channel_mask == AUDIO_CHANNEL_OUT_5POINT1_SIDE)
3579 {
3580 channel_map[4] = PCM_CHANNEL_LS;
3581 channel_map[5] = PCM_CHANNEL_RS;
3582 }
3583 break;
3584 case 7:
3585 /* AUDIO_CHANNEL_OUT_6POINT1 */
3586 channel_map[0] = PCM_CHANNEL_FL;
3587 channel_map[1] = PCM_CHANNEL_FR;
3588 channel_map[2] = PCM_CHANNEL_FC;
3589 channel_map[3] = PCM_CHANNEL_LFE;
3590 channel_map[4] = PCM_CHANNEL_LB;
3591 channel_map[5] = PCM_CHANNEL_RB;
3592 channel_map[6] = PCM_CHANNEL_CS;
3593 break;
3594 case 8:
3595 /* AUDIO_CHANNEL_OUT_7POINT1 */
3596 channel_map[0] = PCM_CHANNEL_FL;
3597 channel_map[1] = PCM_CHANNEL_FR;
3598 channel_map[2] = PCM_CHANNEL_FC;
3599 channel_map[3] = PCM_CHANNEL_LFE;
3600 channel_map[4] = PCM_CHANNEL_LB;
3601 channel_map[5] = PCM_CHANNEL_RB;
3602 channel_map[6] = PCM_CHANNEL_LS;
3603 channel_map[7] = PCM_CHANNEL_RS;
3604 break;
3605 default:
3606 ALOGE("unsupported channels %d for setting channel map", channels);
3607 return -1;
3608 }
3609 ret = platform_set_channel_map(platform, channels, channel_map, snd_id);
3610 return ret;
3611}
3612
3613int platform_get_edid_info(void *platform)
3614{
3615 struct platform_data *my_data = (struct platform_data *)platform;
3616 struct audio_device *adev = my_data->adev;
3617 char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
3618 char *sad = block;
3619 int num_audio_blocks;
3620 int channel_count = 2;
3621 int i, ret, count;
3622
3623 struct mixer_ctl *ctl;
3624 char edid_data[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE + 1] = {0};
3625 edid_audio_info *info;
3626
3627 if (my_data->edid_valid) {
3628 /* use cached edid */
3629 return 0;
3630 }
3631
3632 if (my_data->edid_info == NULL) {
3633 my_data->edid_info =
3634 (struct edid_audio_info *)calloc(1, sizeof(struct edid_audio_info));
3635 }
3636
3637 info = my_data->edid_info;
3638
3639 ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
3640 if (!ctl) {
3641 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3642 __func__, AUDIO_DATA_BLOCK_MIXER_CTL);
3643 goto fail;
3644 }
3645
3646 mixer_ctl_update(ctl);
3647
3648 count = mixer_ctl_get_num_values(ctl);
3649
3650 /* Read SAD blocks, clamping the maximum size for safety */
3651 if (count > (int)sizeof(block))
3652 count = (int)sizeof(block);
3653
3654 ret = mixer_ctl_get_array(ctl, block, count);
3655 if (ret != 0) {
3656 ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
3657 goto fail;
3658 }
3659 edid_data[0] = count;
3660 memcpy(&edid_data[1], block, count);
3661
3662#ifdef AUDIO_FEATURE_ENABLED_HDMI_EDID
3663 if (!edid_get_sink_caps(info, edid_data)) {
3664 ALOGE("%s: Failed to get HDMI sink capabilities", __func__);
3665 goto fail;
3666 }
3667 my_data->edid_valid = true;
3668 return 0;
3669#endif
3670fail:
3671 if (my_data->edid_info) {
3672 free(my_data->edid_info);
3673 my_data->edid_info = NULL;
3674 my_data->edid_valid = false;
3675 }
3676 ALOGE("%s: return -EINVAL", __func__);
3677 return -EINVAL;
3678}
3679
3680
3681int platform_set_channel_allocation(void *platform, int channel_alloc)
3682{
3683 struct mixer_ctl *ctl;
3684 const char *mixer_ctl_name = "HDMI RX CA";
3685 int ret;
3686 struct platform_data *my_data = (struct platform_data *)platform;
3687 struct audio_device *adev = my_data->adev;
3688
3689 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3690 if (!ctl) {
3691 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3692 __func__, mixer_ctl_name);
3693 ret = EINVAL;
3694 }
3695 ALOGD(":%s channel allocation = 0x%x", __func__, channel_alloc);
3696 ret = mixer_ctl_set_value(ctl, 0, channel_alloc);
3697
3698 if (ret < 0) {
3699 ALOGE("%s: Could not set ctl, error:%d ", __func__, ret);
3700 }
3701
3702 return ret;
3703}
3704
3705int platform_set_channel_map(void *platform, int ch_count, char *ch_map, int snd_id)
3706{
3707 struct mixer_ctl *ctl;
3708 char mixer_ctl_name[44]; // max length of name is 44 as defined
3709 int ret;
3710 unsigned int i;
3711 int set_values[8] = {0};
3712 char device_num[13]; // device number up to 2 digit
3713 struct platform_data *my_data = (struct platform_data *)platform;
3714 struct audio_device *adev = my_data->adev;
3715 ALOGV("%s channel_count:%d",__func__, ch_count);
3716 if (NULL == ch_map) {
3717 ALOGE("%s: Invalid channel mapping used", __func__);
3718 return -EINVAL;
3719 }
3720 strlcpy(mixer_ctl_name, "Playback Channel Map", sizeof(mixer_ctl_name));
3721 if (snd_id >= 0) {
3722 snprintf(device_num, sizeof(device_num), "%d", snd_id);
3723 strncat(mixer_ctl_name, device_num, 13);
3724 }
3725
3726 ALOGD("%s mixer_ctl_name:%s", __func__, mixer_ctl_name);
3727
3728 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3729 if (!ctl) {
3730 ALOGE("%s: Could not get ctl for mixer cmd - %s",
3731 __func__, mixer_ctl_name);
3732 return -EINVAL;
3733 }
3734 for (i = 0; i< ARRAY_SIZE(set_values); i++) {
3735 set_values[i] = ch_map[i];
3736 }
3737
3738 ALOGD("%s: set mapping(%d %d %d %d %d %d %d %d) for channel:%d", __func__,
3739 set_values[0], set_values[1], set_values[2], set_values[3], set_values[4],
3740 set_values[5], set_values[6], set_values[7], ch_count);
3741
3742 ret = mixer_ctl_set_array(ctl, set_values, ch_count);
3743 if (ret < 0) {
3744 ALOGE("%s: Could not set ctl, error:%d ch_count:%d",
3745 __func__, ret, ch_count);
3746 }
3747 return ret;
3748}
3749
3750unsigned char platform_map_to_edid_format(int audio_format)
3751{
3752 unsigned char format;
3753 switch (audio_format & AUDIO_FORMAT_MAIN_MASK) {
3754 case AUDIO_FORMAT_AC3:
3755 ALOGV("%s: AC3", __func__);
3756 format = AC3;
3757 break;
3758 case AUDIO_FORMAT_AAC:
3759 ALOGV("%s:AAC", __func__);
3760 format = AAC;
3761 break;
3762 case AUDIO_FORMAT_E_AC3:
3763 ALOGV("%s:E_AC3", __func__);
3764 format = DOLBY_DIGITAL_PLUS;
3765 break;
3766 case AUDIO_FORMAT_PCM_16_BIT:
3767 case AUDIO_FORMAT_PCM_16_BIT_OFFLOAD:
3768 case AUDIO_FORMAT_PCM_24_BIT_OFFLOAD:
3769 default:
3770 ALOGV("%s:PCM", __func__);
3771 format = LPCM;
3772 break;
3773 }
3774 return format;
3775}
3776
3777uint32_t platform_get_compress_passthrough_buffer_size(
3778 audio_offload_info_t* info)
3779{
3780 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
3781 if (!info->has_video)
3782 fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
3783
3784 return fragment_size;
3785}
3786
3787void platform_reset_edid_info(void *platform) {
3788
3789 ALOGV("%s:", __func__);
3790 struct platform_data *my_data = (struct platform_data *)platform;
3791 if (my_data->edid_info) {
3792 ALOGV("%s :free edid", __func__);
3793 free(my_data->edid_info);
3794 my_data->edid_info = NULL;
3795 }
3796}
3797
3798bool platform_is_edid_supported_format(void *platform, int format)
3799{
3800 struct platform_data *my_data = (struct platform_data *)platform;
3801 struct audio_device *adev = my_data->adev;
3802 edid_audio_info *info = NULL;
3803 int num_audio_blocks;
3804 int i, ret, count;
3805 unsigned char format_id = platform_map_to_edid_format(format);
3806
3807 ret = platform_get_edid_info(platform);
3808 info = (edid_audio_info *)my_data->edid_info;
3809 if (ret == 0 && info != NULL) {
3810 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
3811 /*
3812 * To check
3813 * is there any special for CONFIG_HDMI_PASSTHROUGH_CONVERT
3814 * & DOLBY_DIGITAL_PLUS
3815 */
3816 if (info->audio_blocks_array[i].format_id == format_id) {
3817 ALOGV("%s:platform_is_edid_supported_format true %x",
3818 __func__, format);
3819 return true;
3820 }
3821 }
3822 }
3823 ALOGV("%s:platform_is_edid_supported_format false %x",
3824 __func__, format);
Pradnya Chaphekar8a9dcd82014-09-09 09:49:10 -07003825 return false;
3826}
3827
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303828int platform_set_edid_channels_configuration(void *platform, int channels) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003829
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303830 struct platform_data *my_data = (struct platform_data *)platform;
3831 struct audio_device *adev = my_data->adev;
3832 edid_audio_info *info = NULL;
3833 int num_audio_blocks;
3834 int channel_count = 2;
3835 int i, ret, count;
3836 char default_channelMap[MAX_CHANNELS_SUPPORTED] = {0};
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003837
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303838 ret = platform_get_edid_info(platform);
3839 info = (edid_audio_info *)my_data->edid_info;
3840 if(ret == 0 && info != NULL) {
3841 if (channels > 2) {
Haynes Mathew Georgef4da6fe2014-06-20 19:14:25 -07003842
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303843 ALOGV("%s:able to get HDMI sink capabilities multi channel playback",
3844 __func__);
3845 for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) {
3846 if (info->audio_blocks_array[i].format_id == LPCM &&
3847 info->audio_blocks_array[i].channels > channel_count &&
3848 info->audio_blocks_array[i].channels <= MAX_HDMI_CHANNEL_CNT) {
3849 channel_count = info->audio_blocks_array[i].channels;
3850 }
3851 }
3852 ALOGV("%s:channel_count:%d", __func__, channel_count);
3853 /*
3854 * Channel map is set for supported hdmi max channel count even
3855 * though the input channel count set on adm is less than or equal to
3856 * max supported channel count
3857 */
3858 platform_set_channel_map(platform, channel_count, info->channel_map, -1);
3859 platform_set_channel_allocation(platform, info->channel_allocation);
3860 } else {
3861 default_channelMap[0] = PCM_CHANNEL_FL;
3862 default_channelMap[1] = PCM_CHANNEL_FR;
3863 platform_set_channel_map(platform,2,default_channelMap,-1);
3864 platform_set_channel_allocation(platform,0);
3865 }
3866 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003867
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003868 return 0;
3869}
3870
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303871void platform_cache_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003872{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303873 platform_get_edid_info(platform);
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003874}
3875
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303876void platform_invalidate_edid(void * platform)
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003877{
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303878 struct platform_data *my_data = (struct platform_data *)platform;
3879 my_data->edid_valid = false;
3880 if (my_data->edid_info) {
3881 memset(my_data->edid_info, 0, sizeof(struct edid_audio_info));
3882 }
Pradnya Chaphekar4403bd72014-09-09 09:50:01 -07003883}
Preetam Singh Ranawat8bde2c52015-03-20 12:00:49 +05303884
3885int platform_set_mixer_control(struct stream_out *out, const char * mixer_ctl_name,
3886 const char *mixer_val)
3887{
3888 struct audio_device *adev = out->dev;
3889 struct mixer_ctl *ctl = NULL;
3890 ALOGD("setting mixer ctl %s with value %s", mixer_ctl_name, mixer_val);
3891 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3892 if (!ctl) {
3893 ALOGE("%s: could not get ctl for mixer cmd - %s",
3894 __func__, mixer_ctl_name);
3895 return -EINVAL;
3896 }
3897
3898 return mixer_ctl_set_enum_by_string(ctl, mixer_val);
3899}
3900
3901int platform_set_hdmi_config(struct stream_out *out)
3902{
3903 struct listnode *node;
3904 struct audio_usecase *usecase;
3905 struct audio_device *adev = out->dev;
3906 const char *hdmi_format_ctrl = "HDMI RX Format";
3907 const char *hdmi_rate_ctrl = "HDMI_RX SampleRate";
3908 int sample_rate = out->sample_rate;
3909 /*TODO: Add rules and check if this needs to be done.*/
3910 if((is_offload_usecase(out->usecase)) &&
3911 (out->compr_config.codec->compr_passthr == PASSTHROUGH ||
3912 out->compr_config.codec->compr_passthr == PASSTHROUGH_CONVERT)) {
3913 /* TODO: can we add mixer control for channels here avoid setting */
3914 if ((out->format == AUDIO_FORMAT_E_AC3 ||
3915 out->format == AUDIO_FORMAT_E_AC3_JOC) &&
3916 (out->compr_config.codec->compr_passthr == PASSTHROUGH))
3917 sample_rate = out->sample_rate * 4;
3918 ALOGD("%s:HDMI compress format and samplerate %d, sample_rate %d",
3919 __func__, out->sample_rate, sample_rate);
3920 platform_set_mixer_control(out, hdmi_format_ctrl, "Compr");
3921 switch (sample_rate) {
3922 case 32000:
3923 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_32");
3924 break;
3925 case 44100:
3926 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_44_1");
3927 break;
3928 case 96000:
3929 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_96");
3930 break;
3931 case 176400:
3932 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_176_4");
3933 break;
3934 case 192000:
3935 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_192");
3936 break;
3937 case 128000:
3938 if (out->format != AUDIO_FORMAT_E_AC3) {
3939 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_128");
3940 break;
3941 } else
3942 ALOGW("Unsupported sample rate for E_AC3 32K");
3943 default:
3944 case 48000:
3945 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_48");
3946 break;
3947 }
3948 } else {
3949 ALOGD("%s: HDMI pcm and samplerate %d", __func__,
3950 out->sample_rate);
3951 platform_set_mixer_control(out, hdmi_format_ctrl, "LPCM");
3952 platform_set_mixer_control(out, hdmi_rate_ctrl, "KHZ_48");
3953 }
3954
3955 /*
3956 * Deroute all the playback streams routed to HDMI so that
3957 * the back end is deactivated. Note that backend will not
3958 * be deactivated if any one stream is connected to it.
3959 */
3960 list_for_each(node, &adev->usecase_list) {
3961 usecase = node_to_item(node, struct audio_usecase, list);
3962 ALOGV("%s:disable: usecase type %d, devices 0x%x", __func__,
3963 usecase->type, usecase->devices);
3964 if (usecase->type == PCM_PLAYBACK &&
3965 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3966 disable_audio_route(adev, usecase);
3967 }
3968 }
3969
3970 /*
3971 * Enable all the streams disabled above. Now the HDMI backend
3972 * will be activated with new channel configuration
3973 */
3974 list_for_each(node, &adev->usecase_list) {
3975 usecase = node_to_item(node, struct audio_usecase, list);
3976 ALOGV("%s:enable: usecase type %d, devices 0x%x", __func__,
3977 usecase->type, usecase->devices);
3978 if (usecase->type == PCM_PLAYBACK &&
3979 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
3980 enable_audio_route(adev, usecase);
3981 }
3982 }
3983
3984 return 0;
3985}
3986
3987int platform_set_device_params(struct stream_out *out, int param, int value)
3988{
3989 struct audio_device *adev = out->dev;
3990 struct mixer_ctl *ctl;
3991 char *mixer_ctl_name = "Device PP Params";
3992 int ret = 0;
3993 uint32_t set_values[] = {0,0};
3994
3995 set_values[0] = param;
3996 set_values[1] = value;
3997
3998 ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
3999 if (!ctl) {
4000 ALOGE("%s: Could not get ctl for mixer cmd - %s",
4001 __func__, mixer_ctl_name);
4002 ret = -EINVAL;
4003 goto end;
4004 }
4005
4006 ALOGV("%s: Setting device pp params param: %d, value %d mixer ctrl:%s",
4007 __func__,param, value, mixer_ctl_name);
4008 mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
4009
4010end:
4011 return ret;
4012}
4013
Preetam Singh Ranawat2d0e4632015-02-02 12:40:59 +05304014int platform_get_subsys_image_name(char *buf)
4015{
4016 strlcpy(buf, PLATFORM_IMAGE_NAME, sizeof(PLATFORM_IMAGE_NAME));
4017 return 0;
4018}
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004019
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304020/*
4021 * This is a lookup table to map android audio input device to audio h/w interface (backend).
4022 * The table can be extended for other input devices by adding appropriate entries.
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304023 * The audio interface for a particular input device need to be added in
4024 * audio_platform_info.xml file.
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304025 */
4026struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304027 {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), ""},
4028 {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), ""},
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304029};
4030
4031int audio_device_to_interface_table_len =
4032 sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
4033
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304034int platform_set_audio_device_interface(const char * device_name,
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304035 const char *intf_name,
4036 const char *codec_type)
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004037{
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304038 int ret = 0;
4039 int i;
4040
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304041 if (device_name == NULL || intf_name == NULL || codec_type == NULL) {
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304042 ALOGE("%s: Invalid input", __func__);
4043
4044 ret = -EINVAL;
4045 goto done;
4046 }
4047
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304048 ALOGD("%s: Enter, device name:%s, intf name:%s, codec_type:%s", __func__,
4049 device_name, intf_name, codec_type);
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304050
4051 size_t device_name_len = strlen(device_name);
4052 for (i = 0; i < audio_device_to_interface_table_len; i++) {
4053 char* name = audio_device_to_interface_table[i].device_name;
4054 size_t name_len = strlen(name);
4055 if ((name_len == device_name_len) &&
4056 (strncmp(device_name, name, name_len) == 0)) {
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304057 if (is_external_codec &&
4058 (strncmp(codec_type, "external", strlen(codec_type)) == 0)) {
4059 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304060 __func__, device_name, intf_name);
4061
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304062 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304063 sizeof(audio_device_to_interface_table[i].interface_name));
Karthik Reddy Katta508eca42015-05-11 13:43:18 +05304064 } else if (!is_external_codec &&
4065 (strncmp(codec_type, "internal", strlen(codec_type)) == 0)) {
4066 ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
4067 __func__, device_name, intf_name);
4068
4069 strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
4070 sizeof(audio_device_to_interface_table[i].interface_name));
4071 } else
4072 ALOGE("Invalid codec_type specified. Ignoring this interface entry.");
Karthik Reddy Kattae4078ed2015-04-21 11:46:15 +05304073 goto done;
4074 }
4075 }
4076 ALOGE("%s: Could not find matching device name %s",
4077 __func__, device_name);
4078
4079 ret = -EINVAL;
4080
4081done:
4082 return ret;
Narsinga Rao Chellaf928a982015-03-06 14:57:35 -08004083}
Laxminath Kasam82252432015-05-29 18:37:11 +05304084
4085/*
4086 * This is a lookup table to map names of speaker device with respective left and right TZ names.
4087 * Also the tz names for a particular left or right speaker can be overriden by adding
4088 * corresponding entry in audio_platform_info.xml file.
4089 */
4090struct speaker_device_to_tz_names speaker_device_tz_names = {
4091 {SND_DEVICE_OUT_SPEAKER, "", ""},
4092};
4093
4094const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
4095{
4096 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
4097 return speaker_device_tz_names.spkr_1_tz_name;
4098 else
4099 return "";
4100}
4101
4102const char *platform_get_spkr_2_tz_name(snd_device_t snd_device)
4103{
4104 if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
4105 return speaker_device_tz_names.spkr_2_tz_name;
4106 else
4107 return "";
4108}
4109
4110int platform_set_spkr_device_tz_names(snd_device_t index,
4111 const char *spkr_1_tz_name, const char *spkr_2_tz_name)
4112{
4113 int ret = 0;
4114
4115 if (spkr_1_tz_name == NULL && spkr_2_tz_name == NULL) {
4116 ALOGE("%s: Invalid input", __func__);
4117 ret = -EINVAL;
4118 goto done;
4119 }
4120 if (index != speaker_device_tz_names.snd_device) {
4121 ALOGE("%s: not matching speaker device\n");
4122 ret = -EINVAL;
4123 goto done;
4124 }
4125 ALOGD("%s: Enter, spkr_1_tz_name :%s, spkr_2_tz_name:%s",
4126 __func__, spkr_1_tz_name, spkr_2_tz_name);
4127
4128 if (spkr_1_tz_name != NULL)
4129 strlcpy(speaker_device_tz_names.spkr_1_tz_name, spkr_1_tz_name,
4130 sizeof(speaker_device_tz_names.spkr_1_tz_name));
4131
4132 if (spkr_2_tz_name != NULL)
4133 strlcpy(speaker_device_tz_names.spkr_2_tz_name, spkr_2_tz_name,
4134 sizeof(speaker_device_tz_names.spkr_2_tz_name));
4135done:
4136 return ret;
4137}
Asish Bhattacharya4a69acd2015-07-12 20:54:14 +05304138
4139bool platform_send_gain_dep_cal(void *platform __unused,
4140 int level __unused)
4141{
4142 return 0;
4143}