blob: fe937d5f6c0d0980cf462955657cd8f399dbab51 [file] [log] [blame]
/*
* Copyright (C) 2013-2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "msm8974_platform"
/*#define LOG_NDEBUG 0*/
#define LOG_NDDEBUG 0
#include <stdlib.h>
#include <dlfcn.h>
#include <cutils/log.h>
#include <cutils/str_parms.h>
#include <cutils/properties.h>
#include <audio_hw.h>
#include <platform_api.h>
#include "platform.h"
#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
#define LIB_ACDB_LOADER "libacdbloader.so"
#define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
#define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */
#define DUALMIC_CONFIG_ENDFIRE 1
#define DUALMIC_CONFIG_BROADSIDE 2
/*
* This file will have a maximum of 38 bytes:
*
* 4 bytes: number of audio blocks
* 4 bytes: total length of Short Audio Descriptor (SAD) blocks
* Maximum 10 * 3 bytes: SAD blocks
*/
#define MAX_SAD_BLOCKS 10
#define SAD_BLOCK_SIZE 3
/* EDID format ID for LPCM audio */
#define EDID_FORMAT_LPCM 1
/* Retry for delay in FW loading*/
#define RETRY_NUMBER 10
#define RETRY_US 500000
#define MAX_SND_CARD 8
struct audio_block_header
{
int reserved;
int length;
};
/* Audio calibration related functions */
typedef void (*acdb_deallocate_t)();
#ifdef PLATFORM_MSM8084
typedef int (*acdb_init_t)(char *);
#else
typedef int (*acdb_init_t)();
#endif
typedef void (*acdb_send_audio_cal_t)(int, int);
typedef void (*acdb_send_voice_cal_t)(int, int);
typedef int (*acdb_reload_vocvoltable_t)(int);
/* Audio calibration related functions */
struct platform_data {
struct audio_device *adev;
bool fluence_in_spkr_mode;
bool fluence_in_voice_call;
bool fluence_in_voice_comm;
bool fluence_in_voice_rec;
int dualmic_config;
void *acdb_handle;
acdb_init_t acdb_init;
acdb_deallocate_t acdb_deallocate;
acdb_send_audio_cal_t acdb_send_audio_cal;
acdb_send_voice_cal_t acdb_send_voice_cal;
acdb_reload_vocvoltable_t acdb_reload_vocvoltable;
struct csd_data *csd;
bool ext_speaker;
bool ext_earpiece;
};
static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
[USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
DEEP_BUFFER_PCM_DEVICE},
[USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
LOWLATENCY_PCM_DEVICE},
[USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
MULTIMEDIA2_PCM_DEVICE},
[USECASE_AUDIO_PLAYBACK_OFFLOAD] = {PLAYBACK_OFFLOAD_DEVICE,
PLAYBACK_OFFLOAD_DEVICE},
[USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE,
AUDIO_RECORD_PCM_DEVICE},
[USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
LOWLATENCY_PCM_DEVICE},
[USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE,
VOICE_CALL_PCM_DEVICE},
[USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
[USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
[USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
[USECASE_VOWLAN_CALL] = {VOWLAN_CALL_PCM_DEVICE, VOWLAN_CALL_PCM_DEVICE},
[USECASE_INCALL_REC_UPLINK] = {AUDIO_RECORD_PCM_DEVICE,
AUDIO_RECORD_PCM_DEVICE},
[USECASE_INCALL_REC_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
AUDIO_RECORD_PCM_DEVICE},
[USECASE_INCALL_REC_UPLINK_AND_DOWNLINK] = {AUDIO_RECORD_PCM_DEVICE,
AUDIO_RECORD_PCM_DEVICE},
[USECASE_AUDIO_HFP_SCO] = {HFP_PCM_RX, HFP_SCO_RX},
[USECASE_AUDIO_PLAYBACK_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
AFE_PROXY_RECORD_PCM_DEVICE},
[USECASE_AUDIO_RECORD_AFE_PROXY] = {AFE_PROXY_PLAYBACK_PCM_DEVICE,
AFE_PROXY_RECORD_PCM_DEVICE},
};
/* Array to store sound devices */
static const char * const device_table[SND_DEVICE_MAX] = {
[SND_DEVICE_NONE] = "none",
/* Playback sound devices */
[SND_DEVICE_OUT_HANDSET] = "handset",
[SND_DEVICE_OUT_SPEAKER] = "speaker",
[SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse",
[SND_DEVICE_OUT_HEADPHONES] = "headphones",
[SND_DEVICE_OUT_LINE] = "line",
[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones",
[SND_DEVICE_OUT_VOICE_HANDSET] = "voice-handset",
[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = "voice-hac-handset",
[SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker",
[SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones",
[SND_DEVICE_OUT_VOICE_LINE] = "voice-line",
[SND_DEVICE_OUT_HDMI] = "hdmi",
[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
[SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
[SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset",
[SND_DEVICE_OUT_VOICE_TX] = "voice-tx",
/* Capture sound devices */
[SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
[SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic",
[SND_DEVICE_IN_HANDSET_MIC_NS] = "handset-mic",
[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = "handset-mic",
[SND_DEVICE_IN_HANDSET_DMIC] = "dmic-endfire",
[SND_DEVICE_IN_HANDSET_DMIC_AEC] = "dmic-endfire",
[SND_DEVICE_IN_HANDSET_DMIC_NS] = "dmic-endfire",
[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = "dmic-endfire",
[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = "dmic-endfire",
[SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic",
[SND_DEVICE_IN_SPEAKER_MIC_AEC] = "speaker-mic",
[SND_DEVICE_IN_SPEAKER_MIC_NS] = "speaker-mic",
[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = "speaker-mic",
[SND_DEVICE_IN_SPEAKER_DMIC] = "speaker-dmic-endfire",
[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = "speaker-dmic-endfire",
[SND_DEVICE_IN_SPEAKER_DMIC_NS] = "speaker-dmic-endfire",
[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = "speaker-dmic-endfire",
[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = "speaker-dmic-endfire",
[SND_DEVICE_IN_HEADSET_MIC] = "headset-mic",
[SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
[SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
[SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
[SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
[SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
[SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic",
[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = "voice-speaker-dmic-ef",
[SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic",
[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic",
[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic",
[SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic",
[SND_DEVICE_IN_VOICE_REC_MIC_NS] = "voice-rec-mic",
[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = "voice-rec-dmic-ef",
[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = "voice-rec-dmic-ef-fluence",
[SND_DEVICE_IN_VOICE_RX] = "voice-rx",
};
/* ACDB IDs (audio DSP path configuration IDs) for each sound device */
static int acdb_device_table[SND_DEVICE_MAX] = {
[SND_DEVICE_NONE] = -1,
[SND_DEVICE_OUT_HANDSET] = 7,
[SND_DEVICE_OUT_SPEAKER] = 15,
[SND_DEVICE_OUT_SPEAKER_REVERSE] = 15,
[SND_DEVICE_OUT_HEADPHONES] = 10,
[SND_DEVICE_OUT_LINE] = 10,
[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10,
[SND_DEVICE_OUT_VOICE_HANDSET] = ACDB_ID_VOICE_HANDSET,
[SND_DEVICE_OUT_VOICE_SPEAKER] = ACDB_ID_VOICE_SPEAKER,
[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = 53,
[SND_DEVICE_OUT_VOICE_HEADPHONES] = 10,
[SND_DEVICE_OUT_VOICE_LINE] = 10,
[SND_DEVICE_OUT_HDMI] = 18,
[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
[SND_DEVICE_OUT_BT_SCO] = 22,
[SND_DEVICE_OUT_BT_SCO_WB] = 39,
[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = ACDB_ID_VOICE_HANDSET_TMUS,
[SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
[SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
[SND_DEVICE_OUT_VOICE_TX] = 45,
[SND_DEVICE_IN_HANDSET_MIC] = 4,
[SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
[SND_DEVICE_IN_HANDSET_MIC_NS] = 107,
[SND_DEVICE_IN_HANDSET_MIC_AEC_NS] = 108,
[SND_DEVICE_IN_HANDSET_DMIC] = 41,
[SND_DEVICE_IN_HANDSET_DMIC_AEC] = 109,
[SND_DEVICE_IN_HANDSET_DMIC_NS] = 110,
[SND_DEVICE_IN_HANDSET_DMIC_AEC_NS] = 111,
[SND_DEVICE_IN_HANDSET_DMIC_STEREO] = 34,
[SND_DEVICE_IN_SPEAKER_MIC] = 11,
[SND_DEVICE_IN_SPEAKER_MIC_AEC] = 112,
[SND_DEVICE_IN_SPEAKER_MIC_NS] = 113,
[SND_DEVICE_IN_SPEAKER_MIC_AEC_NS] = 114,
[SND_DEVICE_IN_SPEAKER_DMIC] = 43,
[SND_DEVICE_IN_SPEAKER_DMIC_AEC] = 115,
[SND_DEVICE_IN_SPEAKER_DMIC_NS] = 116,
[SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS] = 117,
[SND_DEVICE_IN_SPEAKER_DMIC_STEREO] = 35,
[SND_DEVICE_IN_HEADSET_MIC] = 8,
[SND_DEVICE_IN_HDMI_MIC] = 4,
[SND_DEVICE_IN_BT_SCO_MIC] = 21,
[SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
[SND_DEVICE_IN_CAMCORDER_MIC] = 61,
[SND_DEVICE_IN_VOICE_DMIC] = 41,
[SND_DEVICE_IN_VOICE_DMIC_TMUS] = ACDB_ID_VOICE_DMIC_EF_TMUS,
[SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11,
[SND_DEVICE_IN_VOICE_SPEAKER_DMIC] = 43,
[SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
[SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16,
[SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36,
[SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16,
[SND_DEVICE_IN_VOICE_REC_MIC] = 62,
[SND_DEVICE_IN_VOICE_REC_MIC_NS] = 113,
[SND_DEVICE_IN_VOICE_REC_DMIC_STEREO] = 35,
[SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE] = 43,
[SND_DEVICE_IN_VOICE_RX] = 44,
};
struct name_to_index {
char name[100];
unsigned int index;
};
#define TO_NAME_INDEX(X) #X, X
/* Used to get index from parsed string */
static const struct name_to_index snd_device_name_index[SND_DEVICE_MAX] = {
/* out */
{TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
{TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
{TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
{TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
{TO_NAME_INDEX(SND_DEVICE_OUT_LINE)},
{TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_LINE)},
{TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
{TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
{TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
{TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET_TMUS)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HAC_HANDSET)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
{TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
/* in */
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_STEREO)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_STEREO)},
{TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
{TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC_TMUS)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
{TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
};
static char * backend_table[SND_DEVICE_MAX] = {0};
static const struct name_to_index usecase_name_index[AUDIO_USECASE_MAX] = {
{TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_DEEP_BUFFER)},
{TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_LOW_LATENCY)},
{TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_MULTI_CH)},
{TO_NAME_INDEX(USECASE_AUDIO_PLAYBACK_OFFLOAD)},
{TO_NAME_INDEX(USECASE_AUDIO_RECORD)},
{TO_NAME_INDEX(USECASE_AUDIO_RECORD_LOW_LATENCY)},
{TO_NAME_INDEX(USECASE_VOICE_CALL)},
{TO_NAME_INDEX(USECASE_VOICE2_CALL)},
{TO_NAME_INDEX(USECASE_VOLTE_CALL)},
{TO_NAME_INDEX(USECASE_QCHAT_CALL)},
{TO_NAME_INDEX(USECASE_VOWLAN_CALL)},
{TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK)},
{TO_NAME_INDEX(USECASE_INCALL_REC_DOWNLINK)},
{TO_NAME_INDEX(USECASE_INCALL_REC_UPLINK_AND_DOWNLINK)},
{TO_NAME_INDEX(USECASE_AUDIO_HFP_SCO)},
};
#define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
#define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT;
static bool is_tmus = false;
static void check_operator()
{
char value[PROPERTY_VALUE_MAX];
int mccmnc;
property_get("gsm.sim.operator.numeric",value,"0");
mccmnc = atoi(value);
ALOGD("%s: tmus mccmnc %d", __func__, mccmnc);
switch(mccmnc) {
/* TMUS MCC(310), MNC(490, 260, 026) */
case 310490:
case 310260:
case 310026:
/* Add new TMUS MNC(800, 660, 580, 310, 270, 250, 240, 230, 220, 210, 200, 160) */
case 310800:
case 310660:
case 310580:
case 310310:
case 310270:
case 310250:
case 310240:
case 310230:
case 310220:
case 310210:
case 310200:
case 310160:
is_tmus = true;
break;
}
}
bool is_operator_tmus()
{
pthread_once(&check_op_once_ctl, check_operator);
return is_tmus;
}
static void set_echo_reference(struct audio_device *adev, bool enable)
{
if (enable)
audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
else
audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
ALOGV("Setting EC Reference: %d", enable);
}
static struct csd_data *open_csd_client(bool i2s_ext_modem)
{
struct csd_data *csd = calloc(1, sizeof(struct csd_data));
csd->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW);
if (csd->csd_client == NULL) {
ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT);
goto error;
} else {
ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT);
csd->deinit = (deinit_t)dlsym(csd->csd_client,
"csd_client_deinit");
if (csd->deinit == NULL) {
ALOGE("%s: dlsym error %s for csd_client_deinit", __func__,
dlerror());
goto error;
}
csd->disable_device = (disable_device_t)dlsym(csd->csd_client,
"csd_client_disable_device");
if (csd->disable_device == NULL) {
ALOGE("%s: dlsym error %s for csd_client_disable_device",
__func__, dlerror());
goto error;
}
csd->enable_device_config = (enable_device_config_t)dlsym(csd->csd_client,
"csd_client_enable_device_config");
if (csd->enable_device_config == NULL) {
ALOGE("%s: dlsym error %s for csd_client_enable_device_config",
__func__, dlerror());
goto error;
}
csd->enable_device = (enable_device_t)dlsym(csd->csd_client,
"csd_client_enable_device");
if (csd->enable_device == NULL) {
ALOGE("%s: dlsym error %s for csd_client_enable_device",
__func__, dlerror());
goto error;
}
csd->start_voice = (start_voice_t)dlsym(csd->csd_client,
"csd_client_start_voice");
if (csd->start_voice == NULL) {
ALOGE("%s: dlsym error %s for csd_client_start_voice",
__func__, dlerror());
goto error;
}
csd->stop_voice = (stop_voice_t)dlsym(csd->csd_client,
"csd_client_stop_voice");
if (csd->stop_voice == NULL) {
ALOGE("%s: dlsym error %s for csd_client_stop_voice",
__func__, dlerror());
goto error;
}
csd->volume = (volume_t)dlsym(csd->csd_client,
"csd_client_volume");
if (csd->volume == NULL) {
ALOGE("%s: dlsym error %s for csd_client_volume",
__func__, dlerror());
goto error;
}
csd->mic_mute = (mic_mute_t)dlsym(csd->csd_client,
"csd_client_mic_mute");
if (csd->mic_mute == NULL) {
ALOGE("%s: dlsym error %s for csd_client_mic_mute",
__func__, dlerror());
goto error;
}
csd->slow_talk = (slow_talk_t)dlsym(csd->csd_client,
"csd_client_slow_talk");
if (csd->slow_talk == NULL) {
ALOGE("%s: dlsym error %s for csd_client_slow_talk",
__func__, dlerror());
goto error;
}
csd->start_playback = (start_playback_t)dlsym(csd->csd_client,
"csd_client_start_playback");
if (csd->start_playback == NULL) {
ALOGE("%s: dlsym error %s for csd_client_start_playback",
__func__, dlerror());
goto error;
}
csd->stop_playback = (stop_playback_t)dlsym(csd->csd_client,
"csd_client_stop_playback");
if (csd->stop_playback == NULL) {
ALOGE("%s: dlsym error %s for csd_client_stop_playback",
__func__, dlerror());
goto error;
}
csd->start_record = (start_record_t)dlsym(csd->csd_client,
"csd_client_start_record");
if (csd->start_record == NULL) {
ALOGE("%s: dlsym error %s for csd_client_start_record",
__func__, dlerror());
goto error;
}
csd->stop_record = (stop_record_t)dlsym(csd->csd_client,
"csd_client_stop_record");
if (csd->stop_record == NULL) {
ALOGE("%s: dlsym error %s for csd_client_stop_record",
__func__, dlerror());
goto error;
}
csd->get_sample_rate = (get_sample_rate_t)dlsym(csd->csd_client,
"csd_client_get_sample_rate");
if (csd->get_sample_rate == NULL) {
ALOGE("%s: dlsym error %s for csd_client_get_sample_rate",
__func__, dlerror());
goto error;
}
csd->init = (init_t)dlsym(csd->csd_client, "csd_client_init");
if (csd->init == NULL) {
ALOGE("%s: dlsym error %s for csd_client_init",
__func__, dlerror());
goto error;
} else {
csd->init(i2s_ext_modem);
}
}
return csd;
error:
free(csd);
csd = NULL;
return csd;
}
void close_csd_client(struct csd_data *csd)
{
if (csd != NULL) {
csd->deinit();
dlclose(csd->csd_client);
free(csd);
csd = NULL;
}
}
static void platform_csd_init(struct platform_data *my_data)
{
#ifdef PLATFORM_MSM8084
int32_t modems, (*count_modems)(void);
const char *name = "libdetectmodem.so";
const char *func = "count_modems";
const char *error;
my_data->csd = NULL;
void *lib = dlopen(name, RTLD_NOW);
error = dlerror();
if (!lib) {
ALOGE("%s: could not find %s: %s", __func__, name, error);
return;
}
count_modems = NULL;
*(void **)(&count_modems) = dlsym(lib, func);
error = dlerror();
if (!count_modems) {
ALOGE("%s: could not find symbol %s in %s: %s",
__func__, func, name, error);
goto done;
}
modems = count_modems();
if (modems < 0) {
ALOGE("%s: count_modems failed\n", __func__);
goto done;
}
ALOGD("%s: num_modems %d\n", __func__, modems);
if (modems > 0)
my_data->csd = open_csd_client(false /*is_i2s_ext_modem*/);
done:
dlclose(lib);
#else
my_data->csd = NULL;
#endif
}
static void set_platform_defaults(struct platform_data * my_data)
{
int32_t dev;
for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
backend_table[dev] = NULL;
}
// TBD - do these go to the platform-info.xml file.
// will help in avoiding strdups here
backend_table[SND_DEVICE_IN_BT_SCO_MIC] = strdup("bt-sco");
backend_table[SND_DEVICE_OUT_BT_SCO] = strdup("bt-sco");
backend_table[SND_DEVICE_OUT_HDMI] = strdup("hdmi");
backend_table[SND_DEVICE_OUT_SPEAKER_AND_HDMI] = strdup("speaker-and-hdmi");
backend_table[SND_DEVICE_OUT_BT_SCO_WB] = strdup("bt-sco-wb");
backend_table[SND_DEVICE_IN_BT_SCO_MIC_WB] = strdup("bt-sco-wb");
backend_table[SND_DEVICE_OUT_VOICE_TX] = strdup("afe-proxy");
backend_table[SND_DEVICE_IN_VOICE_RX] = strdup("afe-proxy");
if (my_data->ext_speaker) {
backend_table[SND_DEVICE_OUT_SPEAKER] = strdup("speaker");
backend_table[SND_DEVICE_OUT_VOICE_SPEAKER] = strdup("speaker");
backend_table[SND_DEVICE_OUT_SPEAKER_REVERSE] = strdup("speaker");
backend_table[SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] =
strdup("speaker-and-headphones");
}
if (my_data->ext_earpiece) {
backend_table[SND_DEVICE_OUT_VOICE_HANDSET] = strdup("handset");
backend_table[SND_DEVICE_OUT_VOICE_HAC_HANDSET] = strdup("handset");
backend_table[SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = strdup("handset");
backend_table[SND_DEVICE_OUT_HANDSET] = strdup("handset");
backend_table[SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = strdup("handset");
}
}
void *platform_init(struct audio_device *adev)
{
char value[PROPERTY_VALUE_MAX];
struct platform_data *my_data;
int retry_num = 0, snd_card_num = 0;
const char *snd_card_name;
while (snd_card_num < MAX_SND_CARD) {
adev->mixer = mixer_open(snd_card_num);
while (!adev->mixer && retry_num < RETRY_NUMBER) {
usleep(RETRY_US);
adev->mixer = mixer_open(snd_card_num);
retry_num++;
}
if (!adev->mixer) {
ALOGE("%s: Unable to open the mixer card: %d", __func__,
snd_card_num);
retry_num = 0;
snd_card_num++;
continue;
}
snd_card_name = mixer_get_name(adev->mixer);
ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH);
if (!adev->audio_route) {
ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
return NULL;
}
adev->snd_card = snd_card_num;
ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
break;
}
if (snd_card_num >= MAX_SND_CARD) {
ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
return NULL;
}
my_data = calloc(1, sizeof(struct platform_data));
my_data->adev = adev;
my_data->dualmic_config = DUALMIC_CONFIG_NONE;
my_data->fluence_in_spkr_mode = false;
my_data->fluence_in_voice_call = false;
my_data->fluence_in_voice_comm = false;
my_data->fluence_in_voice_rec = false;
/*
* The default assumption is that earpiece (handset), speaker and headphones
* devices are connected to internal HW codec and communicated through
* slimbus backend. If any platform communicates with speaker or earpiece
* or headphones through non-slimbus backend such as MI2S or AUXPCM etc.,
* the ext_xxxx flags must be set accordingly.
*/
if (strstr(snd_card_name, "tfa9890_stereo")) {
my_data->ext_speaker = true;
my_data->ext_earpiece = true;
} else if (strstr(snd_card_name, "tfa9890")) {
my_data->ext_speaker = true;
}
property_get("persist.audio.dualmic.config",value,"");
if (!strcmp("broadside", value)) {
ALOGE("%s: Unsupported dualmic configuration", __func__);
} else if (!strcmp("endfire", value)) {
my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE;
}
if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
property_get("persist.audio.fluence.voicecall",value,"");
if (!strcmp("true", value)) {
my_data->fluence_in_voice_call = true;
}
property_get("persist.audio.fluence.voicecomm",value,"");
if (!strcmp("true", value)) {
my_data->fluence_in_voice_comm = true;
}
property_get("persist.audio.fluence.voicerec",value,"");
if (!strcmp("true", value)) {
my_data->fluence_in_voice_rec = true;
}
property_get("persist.audio.fluence.speaker",value,"");
if (!strcmp("true", value)) {
my_data->fluence_in_spkr_mode = true;
}
}
my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW);
if (my_data->acdb_handle == NULL) {
ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER);
} else {
ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER);
my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle,
"acdb_loader_deallocate_ACDB");
if (!my_data->acdb_deallocate)
ALOGE("%s: Could not find the symbol acdb_loader_deallocate_ACDB from %s",
__func__, LIB_ACDB_LOADER);
my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle,
"acdb_loader_send_audio_cal");
if (!my_data->acdb_send_audio_cal)
ALOGE("%s: Could not find the symbol acdb_send_audio_cal from %s",
__func__, LIB_ACDB_LOADER);
my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle,
"acdb_loader_send_voice_cal");
if (!my_data->acdb_send_voice_cal)
ALOGE("%s: Could not find the symbol acdb_loader_send_voice_cal from %s",
__func__, LIB_ACDB_LOADER);
my_data->acdb_reload_vocvoltable = (acdb_reload_vocvoltable_t)dlsym(my_data->acdb_handle,
"acdb_loader_reload_vocvoltable");
if (!my_data->acdb_reload_vocvoltable)
ALOGE("%s: Could not find the symbol acdb_loader_reload_vocvoltable from %s",
__func__, LIB_ACDB_LOADER);
#ifdef PLATFORM_MSM8084
my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
"acdb_loader_init_v2");
if (my_data->acdb_init == NULL)
ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
else
my_data->acdb_init((char *)snd_card_name);
#else
my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
"acdb_loader_init_ACDB");
if (my_data->acdb_init == NULL)
ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
else
my_data->acdb_init();
#endif
}
set_platform_defaults(my_data);
/* Initialize platform specific ids and/or backends*/
platform_info_init();
/* load csd client */
platform_csd_init(my_data);
return my_data;
}
void platform_deinit(void *platform)
{
struct platform_data *my_data = (struct platform_data *)platform;
close_csd_client(my_data->csd);
free(platform);
}
const char *platform_get_snd_device_name(snd_device_t snd_device)
{
if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
return device_table[snd_device];
else
return "";
}
void platform_add_backend_name(void *platform, char *mixer_path,
snd_device_t snd_device)
{
struct platform_data *my_data = (struct platform_data *)platform;
if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
return;
}
const char * suffix = backend_table[snd_device];
if (suffix != NULL) {
strcat(mixer_path, " ");
strcat(mixer_path, suffix);
}
}
int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
{
int device_id;
if (device_type == PCM_PLAYBACK)
device_id = pcm_device_table[usecase][0];
else
device_id = pcm_device_table[usecase][1];
return device_id;
}
static int find_index(const struct name_to_index * table, int32_t len,
const char * name)
{
int ret = 0;
int32_t i;
if (table == NULL) {
ALOGE("%s: table is NULL", __func__);
ret = -ENODEV;
goto done;
}
if (name == NULL) {
ALOGE("null key");
ret = -ENODEV;
goto done;
}
for (i=0; i < len; i++) {
if (!strcmp(table[i].name, name)) {
ret = table[i].index;
goto done;
}
}
ALOGE("%s: Could not find index for name = %s",
__func__, name);
ret = -ENODEV;
done:
return ret;
}
int platform_get_snd_device_index(char *device_name)
{
return find_index(snd_device_name_index, SND_DEVICE_MAX, device_name);
}
int platform_get_usecase_index(const char *usecase_name)
{
return find_index(usecase_name_index, AUDIO_USECASE_MAX, usecase_name);
}
int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
{
int ret = 0;
if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
ALOGE("%s: Invalid snd_device = %d",
__func__, snd_device);
ret = -EINVAL;
goto done;
}
acdb_device_table[snd_device] = acdb_id;
done:
return ret;
}
int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
{
struct platform_data *my_data = (struct platform_data *)platform;
int acdb_dev_id, acdb_dev_type;
acdb_dev_id = acdb_device_table[snd_device];
if (acdb_dev_id < 0) {
ALOGE("%s: Could not find acdb id for device(%d)",
__func__, snd_device);
return -EINVAL;
}
if (my_data->acdb_send_audio_cal) {
ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)",
__func__, snd_device, acdb_dev_id);
if (snd_device >= SND_DEVICE_OUT_BEGIN &&
snd_device < SND_DEVICE_OUT_END)
acdb_dev_type = ACDB_DEV_TYPE_OUT;
else
acdb_dev_type = ACDB_DEV_TYPE_IN;
my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type);
}
return 0;
}
int platform_switch_voice_call_device_pre(void *platform)
{
struct platform_data *my_data = (struct platform_data *)platform;
int ret = 0;
if (my_data->csd != NULL &&
my_data->adev->mode == AUDIO_MODE_IN_CALL) {
/* This must be called before disabling mixer controls on APQ side */
ret = my_data->csd->disable_device();
if (ret < 0) {
ALOGE("%s: csd_client_disable_device, failed, error %d",
__func__, ret);
}
}
return ret;
}
int platform_switch_voice_call_enable_device_config(void *platform,
snd_device_t out_snd_device,
snd_device_t in_snd_device)
{
struct platform_data *my_data = (struct platform_data *)platform;
int acdb_rx_id, acdb_tx_id;
int ret = 0;
if (my_data->csd == NULL)
return ret;
acdb_rx_id = acdb_device_table[out_snd_device];
acdb_tx_id = acdb_device_table[in_snd_device];
if (acdb_rx_id > 0 && acdb_tx_id > 0) {
ret = my_data->csd->enable_device_config(acdb_rx_id, acdb_tx_id);
if (ret < 0) {
ALOGE("%s: csd_enable_device_config, failed, error %d",
__func__, ret);
}
} else {
ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
acdb_rx_id, acdb_tx_id);
}
return ret;
}
int platform_switch_voice_call_device_post(void *platform,
snd_device_t out_snd_device,
snd_device_t in_snd_device)
{
struct platform_data *my_data = (struct platform_data *)platform;
int acdb_rx_id, acdb_tx_id;
if (my_data->acdb_send_voice_cal == NULL) {
ALOGE("%s: dlsym error for acdb_send_voice_call", __func__);
} else {
acdb_rx_id = acdb_device_table[out_snd_device];
acdb_tx_id = acdb_device_table[in_snd_device];
if (acdb_rx_id > 0 && acdb_tx_id > 0)
my_data->acdb_send_voice_cal(acdb_rx_id, acdb_tx_id);
else
ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
acdb_rx_id, acdb_tx_id);
}
return 0;
}
int platform_switch_voice_call_usecase_route_post(void *platform,
snd_device_t out_snd_device,
snd_device_t in_snd_device)
{
struct platform_data *my_data = (struct platform_data *)platform;
int acdb_rx_id, acdb_tx_id;
int ret = 0;
if (my_data->csd == NULL)
return ret;
acdb_rx_id = acdb_device_table[out_snd_device];
acdb_tx_id = acdb_device_table[in_snd_device];
if (acdb_rx_id > 0 && acdb_tx_id > 0) {
ret = my_data->csd->enable_device(acdb_rx_id, acdb_tx_id,
my_data->adev->acdb_settings);
if (ret < 0) {
ALOGE("%s: csd_enable_device, failed, error %d", __func__, ret);
}
} else {
ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__,
acdb_rx_id, acdb_tx_id);
}
return ret;
}
int platform_start_voice_call(void *platform, uint32_t vsid)
{
struct platform_data *my_data = (struct platform_data *)platform;
int ret = 0;
if (my_data->csd != NULL) {
ret = my_data->csd->start_voice(vsid);
if (ret < 0) {
ALOGE("%s: csd_start_voice error %d\n", __func__, ret);
}
}
return ret;
}
int platform_stop_voice_call(void *platform, uint32_t vsid)
{
struct platform_data *my_data = (struct platform_data *)platform;
int ret = 0;
if (my_data->csd != NULL) {
ret = my_data->csd->stop_voice(vsid);
if (ret < 0) {
ALOGE("%s: csd_stop_voice error %d\n", __func__, ret);
}
}
return ret;
}
int platform_get_sample_rate(void *platform, uint32_t *rate)
{
struct platform_data *my_data = (struct platform_data *)platform;
int ret = 0;
if (my_data->csd != NULL) {
ret = my_data->csd->get_sample_rate(rate);
if (ret < 0) {
ALOGE("%s: csd_get_sample_rate error %d\n", __func__, ret);
}
}
return ret;
}
int platform_set_voice_volume(void *platform, int volume)
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
struct mixer_ctl *ctl;
const char *mixer_ctl_name = "Voice Rx Gain";
int vol_index = 0, ret = 0;
uint32_t set_values[ ] = {0,
ALL_SESSION_VSID,
DEFAULT_VOLUME_RAMP_DURATION_MS};
// Voice volume levels are mapped to adsp volume levels as follows.
// 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1 0 -> 0
// But this values don't changed in kernel. So, below change is need.
vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
set_values[0] = vol_index;
ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
if (!ctl) {
ALOGE("%s: Could not get ctl for mixer cmd - %s",
__func__, mixer_ctl_name);
return -EINVAL;
}
ALOGV("Setting voice volume index: %d", set_values[0]);
mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
if (my_data->csd != NULL) {
ret = my_data->csd->volume(ALL_SESSION_VSID, volume,
DEFAULT_VOLUME_RAMP_DURATION_MS);
if (ret < 0) {
ALOGE("%s: csd_volume error %d", __func__, ret);
}
}
return ret;
}
int platform_set_mic_mute(void *platform, bool state)
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
struct mixer_ctl *ctl;
const char *mixer_ctl_name = "Voice Tx Mute";
int ret = 0;
uint32_t set_values[ ] = {0,
ALL_SESSION_VSID,
DEFAULT_MUTE_RAMP_DURATION_MS};
if (adev->mode != AUDIO_MODE_IN_CALL)
return 0;
set_values[0] = state;
ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
if (!ctl) {
ALOGE("%s: Could not get ctl for mixer cmd - %s",
__func__, mixer_ctl_name);
return -EINVAL;
}
ALOGV("Setting voice mute state: %d", state);
mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
if (my_data->csd != NULL) {
ret = my_data->csd->mic_mute(ALL_SESSION_VSID, state,
DEFAULT_MUTE_RAMP_DURATION_MS);
if (ret < 0) {
ALOGE("%s: csd_mic_mute error %d", __func__, ret);
}
}
return ret;
}
int platform_set_device_mute(void *platform, bool state, char *dir)
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
struct mixer_ctl *ctl;
char *mixer_ctl_name = NULL;
int ret = 0;
uint32_t set_values[ ] = {0,
ALL_SESSION_VSID,
0};
if(dir == NULL) {
ALOGE("%s: Invalid direction:%s", __func__, dir);
return -EINVAL;
}
if (!strncmp("rx", dir, sizeof("rx"))) {
mixer_ctl_name = "Voice Rx Device Mute";
} else if (!strncmp("tx", dir, sizeof("tx"))) {
mixer_ctl_name = "Voice Tx Device Mute";
} else {
return -EINVAL;
}
set_values[0] = state;
ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
if (!ctl) {
ALOGE("%s: Could not get ctl for mixer cmd - %s",
__func__, mixer_ctl_name);
return -EINVAL;
}
ALOGV("%s: Setting device mute state: %d, mixer ctrl:%s",
__func__,state, mixer_ctl_name);
mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
return ret;
}
snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices)
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
audio_mode_t mode = adev->mode;
snd_device_t snd_device = SND_DEVICE_NONE;
ALOGV("%s: enter: output devices(%#x)", __func__, devices);
if (devices == AUDIO_DEVICE_NONE ||
devices & AUDIO_DEVICE_BIT_IN) {
ALOGV("%s: Invalid output devices (%#x)", __func__, devices);
goto exit;
}
if (mode == AUDIO_MODE_IN_CALL) {
if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
devices & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
devices & AUDIO_DEVICE_OUT_LINE) {
if (adev->voice.tty_mode == TTY_MODE_FULL)
snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
else if (adev->voice.tty_mode == TTY_MODE_VCO)
snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
else if (adev->voice.tty_mode == TTY_MODE_HCO)
snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
else {
if (devices & AUDIO_DEVICE_OUT_LINE)
snd_device = SND_DEVICE_OUT_VOICE_LINE;
else
snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
}
} else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
if (adev->bt_wb_speech_enabled) {
snd_device = SND_DEVICE_OUT_BT_SCO_WB;
} else {
snd_device = SND_DEVICE_OUT_BT_SCO;
}
} else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
} else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
if(adev->voice.hac)
snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
else if (is_operator_tmus())
snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS;
else
snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
} else if (devices & AUDIO_DEVICE_OUT_TELEPHONY_TX)
snd_device = SND_DEVICE_OUT_VOICE_TX;
if (snd_device != SND_DEVICE_NONE) {
goto exit;
}
}
if (popcount(devices) == 2) {
if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
AUDIO_DEVICE_OUT_SPEAKER)) {
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
} else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET |
AUDIO_DEVICE_OUT_SPEAKER)) {
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES;
} else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL |
AUDIO_DEVICE_OUT_SPEAKER)) {
snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI;
} else {
ALOGE("%s: Invalid combo device(%#x)", __func__, devices);
goto exit;
}
if (snd_device != SND_DEVICE_NONE) {
goto exit;
}
}
if (popcount(devices) != 1) {
ALOGE("%s: Invalid output devices(%#x)", __func__, devices);
goto exit;
}
if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
snd_device = SND_DEVICE_OUT_HEADPHONES;
} else if (devices & AUDIO_DEVICE_OUT_LINE) {
snd_device = SND_DEVICE_OUT_LINE;
} else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
if (adev->speaker_lr_swap)
snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
else
snd_device = SND_DEVICE_OUT_SPEAKER;
} else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
if (adev->bt_wb_speech_enabled) {
snd_device = SND_DEVICE_OUT_BT_SCO_WB;
} else {
snd_device = SND_DEVICE_OUT_BT_SCO;
}
} else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
snd_device = SND_DEVICE_OUT_HDMI ;
} else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
/*HAC support for voice-ish audio (eg visual voicemail)*/
if(adev->voice.hac)
snd_device = SND_DEVICE_OUT_VOICE_HAC_HANDSET;
else
snd_device = SND_DEVICE_OUT_HANDSET;
} else {
ALOGE("%s: Unknown device(s) %#x", __func__, devices);
}
exit:
ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]);
return snd_device;
}
snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device)
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
audio_source_t source = (adev->active_input == NULL) ?
AUDIO_SOURCE_DEFAULT : adev->active_input->source;
audio_mode_t mode = adev->mode;
audio_devices_t in_device = ((adev->active_input == NULL) ?
AUDIO_DEVICE_NONE : adev->active_input->device)
& ~AUDIO_DEVICE_BIT_IN;
audio_channel_mask_t channel_mask = (adev->active_input == NULL) ?
AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask;
snd_device_t snd_device = SND_DEVICE_NONE;
int channel_count = popcount(channel_mask);
ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
__func__, out_device, in_device);
if (mode == AUDIO_MODE_IN_CALL) {
if (out_device == AUDIO_DEVICE_NONE) {
ALOGE("%s: No output device set for voice call", __func__);
goto exit;
}
if (adev->voice.tty_mode != TTY_MODE_OFF) {
if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET ||
out_device & AUDIO_DEVICE_OUT_LINE) {
switch (adev->voice.tty_mode) {
case TTY_MODE_FULL:
snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
break;
case TTY_MODE_VCO:
snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC;
break;
case TTY_MODE_HCO:
snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
break;
default:
ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
}
goto exit;
}
}
if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
if (my_data->fluence_in_voice_call == false) {
snd_device = SND_DEVICE_IN_HANDSET_MIC;
set_echo_reference(adev, true);
} else {
if (is_operator_tmus())
snd_device = SND_DEVICE_IN_VOICE_DMIC_TMUS;
else
snd_device = SND_DEVICE_IN_VOICE_DMIC;
}
} else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
} else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
if (adev->bt_wb_speech_enabled) {
snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
} else {
snd_device = SND_DEVICE_IN_BT_SCO_MIC;
}
} else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
out_device & AUDIO_DEVICE_OUT_LINE) {
if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode &&
my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC;
} else {
snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
set_echo_reference(adev, true);
}
} else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX)
snd_device = SND_DEVICE_IN_VOICE_RX;
} else if (source == AUDIO_SOURCE_CAMCORDER) {
if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC ||
in_device & AUDIO_DEVICE_IN_BACK_MIC) {
snd_device = SND_DEVICE_IN_CAMCORDER_MIC;
}
} else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) {
if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK)
snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_STEREO;
else if (my_data->fluence_in_voice_rec &&
adev->active_input->enable_ns)
snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE;
}
if (snd_device == SND_DEVICE_NONE) {
if (adev->active_input->enable_ns)
snd_device = SND_DEVICE_IN_VOICE_REC_MIC_NS;
else
snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
}
}
} else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
in_device = AUDIO_DEVICE_IN_BACK_MIC;
if (adev->active_input) {
if (adev->active_input->enable_aec &&
adev->active_input->enable_ns) {
if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
if (my_data->fluence_in_spkr_mode &&
my_data->fluence_in_voice_comm &&
my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS;
} else
snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC_NS;
} else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
if (my_data->fluence_in_voice_comm &&
my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC_NS;
} else
snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
}
set_echo_reference(adev, true);
} else if (adev->active_input->enable_aec) {
if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
if (my_data->fluence_in_spkr_mode &&
my_data->fluence_in_voice_comm &&
my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
snd_device = SND_DEVICE_IN_SPEAKER_DMIC_AEC;
} else
snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC;
} else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
if (my_data->fluence_in_voice_comm &&
my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
snd_device = SND_DEVICE_IN_HANDSET_DMIC_AEC;
} else
snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
}
set_echo_reference(adev, true);
} else if (adev->active_input->enable_ns) {
if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
if (my_data->fluence_in_spkr_mode &&
my_data->fluence_in_voice_comm &&
my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
snd_device = SND_DEVICE_IN_SPEAKER_DMIC_NS;
} else
snd_device = SND_DEVICE_IN_SPEAKER_MIC_NS;
} else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
if (my_data->fluence_in_voice_comm &&
my_data->dualmic_config != DUALMIC_CONFIG_NONE) {
snd_device = SND_DEVICE_IN_HANDSET_DMIC_NS;
} else
snd_device = SND_DEVICE_IN_HANDSET_MIC_NS;
}
set_echo_reference(adev, false);
} else
set_echo_reference(adev, false);
}
} else if (source == AUDIO_SOURCE_DEFAULT) {
goto exit;
}
if (snd_device != SND_DEVICE_NONE) {
goto exit;
}
if (in_device != AUDIO_DEVICE_NONE &&
!(in_device & AUDIO_DEVICE_IN_VOICE_CALL) &&
!(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) {
if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) {
if (my_data->dualmic_config != DUALMIC_CONFIG_NONE &&
channel_count == 2)
snd_device = SND_DEVICE_IN_HANDSET_DMIC_STEREO;
else
snd_device = SND_DEVICE_IN_HANDSET_MIC;
} else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
if (my_data->dualmic_config != DUALMIC_CONFIG_NONE &&
channel_count == 2)
snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
else
snd_device = SND_DEVICE_IN_SPEAKER_MIC;
} else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
snd_device = SND_DEVICE_IN_HEADSET_MIC;
} else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
if (adev->bt_wb_speech_enabled) {
snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
} else {
snd_device = SND_DEVICE_IN_BT_SCO_MIC;
}
} else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
snd_device = SND_DEVICE_IN_HDMI_MIC;
} else {
ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
ALOGW("%s: Using default handset-mic", __func__);
snd_device = SND_DEVICE_IN_HANDSET_MIC;
}
} else {
if (out_device & AUDIO_DEVICE_OUT_EARPIECE) {
snd_device = SND_DEVICE_IN_HANDSET_MIC;
} else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
snd_device = SND_DEVICE_IN_HEADSET_MIC;
} else if (out_device & AUDIO_DEVICE_OUT_SPEAKER ||
out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
out_device & AUDIO_DEVICE_OUT_LINE) {
if (channel_count == 2)
snd_device = SND_DEVICE_IN_SPEAKER_DMIC_STEREO;
else
snd_device = SND_DEVICE_IN_SPEAKER_MIC;
} else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
if (adev->bt_wb_speech_enabled) {
snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
} else {
snd_device = SND_DEVICE_IN_BT_SCO_MIC;
}
} else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
snd_device = SND_DEVICE_IN_HDMI_MIC;
} else {
ALOGE("%s: Unknown output device(s) %#x", __func__, out_device);
ALOGW("%s: Using default handset-mic", __func__);
snd_device = SND_DEVICE_IN_HANDSET_MIC;
}
}
exit:
ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]);
return snd_device;
}
int platform_set_hdmi_channels(void *platform, int channel_count)
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
struct mixer_ctl *ctl;
const char *channel_cnt_str = NULL;
const char *mixer_ctl_name = "HDMI_RX Channels";
switch (channel_count) {
case 8:
channel_cnt_str = "Eight"; break;
case 7:
channel_cnt_str = "Seven"; break;
case 6:
channel_cnt_str = "Six"; break;
case 5:
channel_cnt_str = "Five"; break;
case 4:
channel_cnt_str = "Four"; break;
case 3:
channel_cnt_str = "Three"; break;
default:
channel_cnt_str = "Two"; break;
}
ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
if (!ctl) {
ALOGE("%s: Could not get ctl for mixer cmd - %s",
__func__, mixer_ctl_name);
return -EINVAL;
}
ALOGV("HDMI channel count: %s", channel_cnt_str);
mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
return 0;
}
int platform_edid_get_max_channels(void *platform)
{
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE];
char *sad = block;
int num_audio_blocks;
int channel_count;
int max_channels = 0;
int i, ret, count;
struct mixer_ctl *ctl;
ctl = mixer_get_ctl_by_name(adev->mixer, AUDIO_DATA_BLOCK_MIXER_CTL);
if (!ctl) {
ALOGE("%s: Could not get ctl for mixer cmd - %s",
__func__, AUDIO_DATA_BLOCK_MIXER_CTL);
return 0;
}
mixer_ctl_update(ctl);
count = mixer_ctl_get_num_values(ctl);
/* Read SAD blocks, clamping the maximum size for safety */
if (count > (int)sizeof(block))
count = (int)sizeof(block);
ret = mixer_ctl_get_array(ctl, block, count);
if (ret != 0) {
ALOGE("%s: mixer_ctl_get_array() failed to get EDID info", __func__);
return 0;
}
/* Calculate the number of SAD blocks */
num_audio_blocks = count / SAD_BLOCK_SIZE;
for (i = 0; i < num_audio_blocks; i++) {
/* Only consider LPCM blocks */
if ((sad[0] >> 3) != EDID_FORMAT_LPCM) {
sad += 3;
continue;
}
channel_count = (sad[0] & 0x7) + 1;
if (channel_count > max_channels)
max_channels = channel_count;
/* Advance to next block */
sad += 3;
}
return max_channels;
}
int platform_set_incall_recording_session_id(void *platform,
uint32_t session_id, int rec_mode)
{
int ret = 0;
struct platform_data *my_data = (struct platform_data *)platform;
struct audio_device *adev = my_data->adev;
struct mixer_ctl *ctl;
const char *mixer_ctl_name = "Voc VSID";
int num_ctl_values;
int i;
ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
if (!ctl) {
ALOGE("%s: Could not get ctl for mixer cmd - %s",
__func__, mixer_ctl_name);
ret = -EINVAL;
} else {
num_ctl_values = mixer_ctl_get_num_values(ctl);
for (i = 0; i < num_ctl_values; i++) {
if (mixer_ctl_set_value(ctl, i, session_id)) {
ALOGV("Error: invalid session_id: %x", session_id);
ret = -EINVAL;
break;
}
}
}
if (my_data->csd != NULL) {
ret = my_data->csd->start_record(ALL_SESSION_VSID, rec_mode);
if (ret < 0) {
ALOGE("%s: csd_client_start_record failed, error %d",
__func__, ret);
}
}
return ret;
}
int platform_stop_incall_recording_usecase(void *platform)
{
int ret = 0;
struct platform_data *my_data = (struct platform_data *)platform;
if (my_data->csd != NULL) {
ret = my_data->csd->stop_record(ALL_SESSION_VSID);
if (ret < 0) {
ALOGE("%s: csd_client_stop_record failed, error %d",
__func__, ret);
}
}
return ret;
}
int platform_start_incall_music_usecase(void *platform)
{
int ret = 0;
struct platform_data *my_data = (struct platform_data *)platform;
if (my_data->csd != NULL) {
ret = my_data->csd->start_playback(ALL_SESSION_VSID);
if (ret < 0) {
ALOGE("%s: csd_client_start_playback failed, error %d",
__func__, ret);
}
}
return ret;
}
int platform_stop_incall_music_usecase(void *platform)
{
int ret = 0;
struct platform_data *my_data = (struct platform_data *)platform;
if (my_data->csd != NULL) {
ret = my_data->csd->stop_playback(ALL_SESSION_VSID);
if (ret < 0) {
ALOGE("%s: csd_client_stop_playback failed, error %d",
__func__, ret);
}
}
return ret;
}
/* Delay in Us */
int64_t platform_render_latency(audio_usecase_t usecase)
{
switch (usecase) {
case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
return DEEP_BUFFER_PLATFORM_DELAY;
case USECASE_AUDIO_PLAYBACK_LOW_LATENCY:
return LOW_LATENCY_PLATFORM_DELAY;
default:
return 0;
}
}
int platform_set_snd_device_backend(snd_device_t device, const char *backend)
{
int ret = 0;
if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) {
ALOGE("%s: Invalid snd_device = %d",
__func__, device);
ret = -EINVAL;
goto done;
}
if (backend_table[device]) {
free(backend_table[device]);
}
backend_table[device] = strdup(backend);
done:
return ret;
}
int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id)
{
int ret = 0;
if ((usecase <= USECASE_INVALID) || (usecase >= AUDIO_USECASE_MAX)) {
ALOGE("%s: invalid usecase case idx %d", __func__, usecase);
ret = -EINVAL;
goto done;
}
if ((type != 0) && (type != 1)) {
ALOGE("%s: invalid usecase type", __func__);
ret = -EINVAL;
}
pcm_device_table[usecase][type] = pcm_id;
done:
return ret;
}