diff --git a/hal/audio_extn/ultrasound.c b/hal/audio_extn/ultrasound.c index 172a0b79..72319b7e 100644 --- a/hal/audio_extn/ultrasound.c +++ b/hal/audio_extn/ultrasound.c @@ -21,6 +21,7 @@ #include #include #include "audio_hw.h" +#include "audio_extn.h" #include "platform_api.h" #include #include "ultrasound.h" @@ -28,6 +29,7 @@ #define ULTRASOUND_CALIBRATION_FILE "/mnt/vendor/persist/audio/us_cal" #define ULTRASOUND_CALIBRATION_MIXER "Ultrasound Calibration Data" #define ULTRASOUND_RAMPDOWN_MIXER "Ultrasound RampDown" +#define ULTRASOUND_SUSPEND_MIXER "Ultrasound Suspend" enum { ULTRASOUND_STATUS_DEFAULT, @@ -109,6 +111,32 @@ exit: ALOGD("%s: exit", __func__); } +void us_suspend(int val) +{ + struct mixer_ctl *ctl; + int rc; + + ALOGD("%s: enter", __func__); + ALOGD("%s: suspend: %d", __func__, val); + + ctl = mixer_get_ctl_by_name(us->adev->mixer, ULTRASOUND_SUSPEND_MIXER); + if (!ctl) { + ALOGD("%s: Could not get ctl for mixer cmd - %s", + __func__, ULTRASOUND_SUSPEND_MIXER); + goto exit; + } + + if (val) + us_ramp_down(); + + rc = mixer_ctl_set_value(ctl, 0, val); + if (rc < 0) + ALOGE("%s: Could not set ctl, error:%d ", __func__, rc); + +exit: + ALOGD("%s: exit", __func__); +} + int us_init(struct audio_device *adev) { int rc = 0; @@ -198,6 +226,33 @@ static int stop_us(void) return rc; } +extern bool is_operator_tmus(void); + +static snd_device_t us_get_output_snd_device(void) +{ + struct stream_in *in = adev_get_active_input(us->adev); + audio_channel_mask_t channel_mask = (in == NULL) ? + AUDIO_CHANNEL_IN_MONO : in->channel_mask; + int channel_count = popcount(channel_mask); + snd_device_t snd_device = SND_DEVICE_OUT_SPEAKER; + + if (compare_device_type(&us->adev->primary_output->device_list, + AUDIO_DEVICE_OUT_EARPIECE)) { + if (us->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 if (audio_extn_should_use_handset_anc(channel_count)) + snd_device = SND_DEVICE_OUT_ANC_HANDSET; + else + snd_device = SND_DEVICE_OUT_VOICE_HANDSET; + } + + ALOGD("%s: %s", __func__, platform_get_snd_device_name(snd_device)); + + return snd_device; +} + int us_start(void) { int rc = 0, rx_device_id, tx_device_id; @@ -228,14 +283,14 @@ int us_start(void) } rx_usecase->type = PCM_PLAYBACK; - rx_usecase->out_snd_device = SND_DEVICE_OUT_VOICE_HANDSET; + rx_usecase->out_snd_device = us_get_output_snd_device(); rx_usecase->id = USECASE_AUDIO_ULTRASOUND_RX; rx_usecase->stream.out = us->adev->primary_output; list_init(&rx_usecase->device_list); assign_devices(&rx_usecase->device_list, &us->adev->primary_output->device_list); list_add_tail(&us->adev->usecase_list, &rx_usecase->list); - enable_snd_device(us->adev, SND_DEVICE_OUT_VOICE_HANDSET); + enable_snd_device(us->adev, rx_usecase->out_snd_device); enable_audio_route(us->adev, rx_usecase); ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)", __func__, us->adev->snd_card, rx_device_id); diff --git a/hal/audio_extn/ultrasound.h b/hal/audio_extn/ultrasound.h index 0bb24cab..a12d7742 100644 --- a/hal/audio_extn/ultrasound.h +++ b/hal/audio_extn/ultrasound.h @@ -23,11 +23,13 @@ #define us_deinit() (0) #define us_start() (0) #define us_stop() (0) +#define us_suspend() (0) #else int us_init(struct audio_device *adev); void us_deinit(void); int us_start(void); int us_stop(void); +void us_suspend(int val); #endif #endif diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 035d65b9..4af9ea16 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -2131,11 +2131,6 @@ static void check_usecases_codec_backend(struct audio_device *adev, platform_get_snd_device_name(usecase->out_snd_device), platform_check_backends_match(snd_device, usecase->out_snd_device)); -#ifdef ELLIPTIC_ULTRASOUND_ENABLED - if (usecase->id == USECASE_AUDIO_ULTRASOUND_RX) - continue; -#endif - if ((usecase->type != PCM_CAPTURE) && (usecase != uc_info) && (usecase->type != PCM_PASSTHROUGH)) { uc_derive_snd_device = derive_playback_snd_device(adev->platform, @@ -2152,11 +2147,33 @@ static void check_usecases_codec_backend(struct audio_device *adev, ALOGD("%s:becf: check_usecases (%s) is active on (%s) - disabling ..", __func__, use_case_table[usecase->id], platform_get_snd_device_name(usecase->out_snd_device)); +#ifdef ELLIPTIC_ULTRASOUND_ENABLED + if (usecase->id == USECASE_AUDIO_ULTRASOUND_RX) + us_suspend(1); +#endif disable_audio_route(adev, usecase); switch_device[usecase->id] = true; /* Enable existing usecase on derived playback device */ derive_snd_device[usecase->id] = uc_derive_snd_device; num_uc_to_switch++; +#ifdef ELLIPTIC_ULTRASOUND_ENABLED + if (usecase->id == USECASE_AUDIO_ULTRASOUND_RX) { + switch (snd_device) { + case SND_DEVICE_OUT_HANDSET: + case SND_DEVICE_OUT_VOICE_HANDSET: + case SND_DEVICE_OUT_VOICE_HANDSET_TMUS: + case SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET: + case SND_DEVICE_OUT_VOICE_HAC_HANDSET: + case SND_DEVICE_OUT_ANC_HANDSET: + case SND_DEVICE_OUT_VOIP_HANDSET: + derive_snd_device[usecase->id] = snd_device; + break; + default: + derive_snd_device[usecase->id] = SND_DEVICE_OUT_SPEAKER; + break; + } + } +#endif } } } @@ -2208,6 +2225,10 @@ static void check_usecases_codec_backend(struct audio_device *adev, } else { enable_snd_device(adev, derive_snd_device[usecase->id]); } +#ifdef ELLIPTIC_ULTRASOUND_ENABLED + if (usecase->id == USECASE_AUDIO_ULTRASOUND_RX) + us_suspend(0); +#endif } }