blob: 3019eabd4c38f0b2815d0f8fd38afa564ea9796c [file] [log] [blame]
/*
* All Rights Reserved
*
* MARVELL CONFIDENTIAL
* Copyright 2012 Marvell International Ltd All Rights Reserved.
* The source code contained or described herein and all documents related to
* the source code ("Material") are owned by Marvell International Ltd or its
* suppliers or licensors. Title to the Material remains with Marvell International Ltd
* or its suppliers and licensors. The Material contains trade secrets and
* proprietary and confidential information of Marvell or its suppliers and
* licensors. The Material is protected by worldwide copyright and trade secret
* laws and treaty provisions. No part of the Material may be used, copied,
* reproduced, modified, published, uploaded, posted, transmitted, distributed,
* or disclosed in any way without Marvell's prior express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Marvell in writing.
*
*/
#define LOG_TAG "acm_api"
#define LOG_NDEBUG 0
#include <cutils/log.h>
#include "acm_api.h"
#include "acm_aph.h"
#include "acm_param.h"
#ifdef WITH_AUDIO_CALIBRATION
#include "ac_thread.h"
#endif
#ifdef TARGET_mmp_asr1901_KSTR901
#include "audio_dsp.h"
extern void ACM_SendVEtoADSP(void);
#endif
static unsigned int msa_gain_mode = MSA_GAIN_NORMAL_MODE;
void ACMInit(void) {
ACM_APHInit();
ACM_Init_Property(); // property depends on modem_is_master inited ACM_APHInit()
#ifdef WITH_AUDIO_CALIBRATION
ACM_Init_Calibration_IPC();
#endif
#if defined(CODEC_ALC5616)
ACM_enable_headset_detection_ALC5616();
#endif
audio_pa_init();
#ifdef TARGET_mmp_asr1901_KSTR901
audio_dsp_init();
ACM_SendVEtoADSP();
#endif
}
void ACMDeInit(void) {
#ifdef WITH_AUDIO_CALIBRATION
ACM_Cancel_Calibration_IPC();
#endif
}
extern APH_PathStatus path_status_table[APH_PATH_ID_CNT];
audio_mode_t ACMGetAudioMode(void)
{
if (((path_status_table[APH_PATH_ID_HIFIPLAYTOEARPHONE].enabled) ||(path_status_table[APH_PATH_ID_HIFIPLAYTOSPKR].enabled))
&& (path_status_table[APH_PATH_ID_HIFIRECORDFROMMIC1].enabled))
{
return AUDIO_MODE_NORMAL;
}
else if ((path_status_table[APH_PATH_ID_HIFIPLAYTOHP].enabled) && (path_status_table[APH_PATH_ID_HIFIRECORDFROMHSMIC].enabled))
{
return AUDIO_MODE_NORMAL;
}
else if (((path_status_table[APH_PATH_ID_VOICEPLAYTOEARPHONE].enabled) ||(path_status_table[APH_PATH_ID_VOICEPLAYTOSPKR].enabled)
|| (path_status_table[APH_PATH_ID_VOICEPLAYTOHP].enabled ))
&& (path_status_table[APH_PATH_ID_VOICERECORDFROMMIC1].enabled))
{
return AUDIO_MODE_IN_CALL;
}
else if ((path_status_table[APH_PATH_ID_VOICEPLAYTOHP].enabled ) && (path_status_table[APH_PATH_ID_VOICERECORDFROMHSMIC].enabled))
{
return AUDIO_MODE_IN_CALL;
}
else
{
return AUDIO_MODE_INVALID;
}
}
ACM_ReturnCode ACMAudioPathEnable(const char * path, unsigned int value) {
ACM_ReturnCode rc = ACM_RC_INVALID_PATH;
rc = APHAudioPathEnable(path,value);
if( rc == ACM_RC_OK )
APHAudioPathVolumeSet(path, value);
return rc;
}
ACM_ReturnCode ACMAudioPathDisable(const char * path) {
return APHAudioPathDisable(path);
}
ACM_ReturnCode ACMAudioPathSwitch (const char * path_Rx, const char * path_Tx, unsigned int value) {
return APHAudioPathSwitch (path_Rx, path_Tx, value);
}
ACM_ReturnCode ACMAudioPathMute(const char * path, unsigned int value) {
return APHAudioPathMute(path, value > 0 ? 1: 0);
}
ACM_ReturnCode ACMAudioPathVolumeSet(const char * path, unsigned int value) {
return APHAudioPathVolumeSet(path, value);
}
ACM_ReturnCode ACMGetPathStatus(char * buff, unsigned int MaxSize) {
return ACM_GetPathStatus(buff, MaxSize);
}
ACM_ReturnCode ACMGetParameter(unsigned int param_id, void *param, unsigned int *size) {
UNUSEDPARAM(size);
ACM_ReturnCode acmReturnCode = ACM_RC_INVALID_PARAMETER;
signed short gain;
signed short sidetone_gain = 0;
ACM_MsaGain *msa_gain = (ACM_MsaGain *)param;
unsigned char volume = 0;
LOGI(ACMGetParameter, "%s/L%d: param_id=%d, volume=0x%x", __FUNCTION__, __LINE__, param_id, msa_gain->volume);
switch(param_id) {
case ACM_MSA_GAIN:
//volume range: 0,10,20,...,100
volume = (msa_gain->volume + 5) /10;
volume = volume *10;
if(volume > 100)
volume = 100;
if(APHGetMSAGain(msa_gain->out_path_name, msa_gain->path_name, &volume, APH_GAIN_ID_NB, &gain, &sidetone_gain)==ACM_RC_OK) {
msa_gain->gain = gain & 0xff;
msa_gain->wbGain = (gain >> 8) & 0xff;
msa_gain->sidetone_gain = sidetone_gain & 0xff;
msa_gain->sidetone_wbGain = (sidetone_gain >> 8) & 0xff;
msa_gain->volume = volume;
acmReturnCode = ACM_GetPathDirection(msa_gain->path_name, &(msa_gain->path_direction));
}
return acmReturnCode;
default:
return ACM_RC_INVALID_PARAMETER;
}
return ACM_RC_OK;
}
ACM_ReturnCode ACMSetParameter(unsigned int param_id, void *param, unsigned int value) {
UNUSEDPARAM(param);
switch(param_id) {
case ACM_MSA_GAIN_MODE:
msa_gain_mode = value;
break;
default:
return ACM_RC_INVALID_PARAMETER;
}
return ACM_RC_OK;
}