From 7b05e8f445c0604f9ce39f148648531eb080ae49 Mon Sep 17 00:00:00 2001 From: Alexander Winkowski Date: Mon, 28 Oct 2024 05:45:27 +0000 Subject: [PATCH] hal: Select speaker when it's active If handset and speaker use different interfaces, then they can't be enabled simultaneously. On veux, this causes top speaker to be disabled during ultrasound emitting. This matches stock audio HAL from veux. Change-Id: Id5afafbce56f2192bde9729e4c5c1349b37c390e --- hal/audio_extn/ultrasound.c | 35 +++++++++++++++++++++++++++++++++-- hal/audio_extn/ultrasound.h | 2 ++ hal/audio_hw.c | 32 +++++++++++++++++++++++++++----- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/hal/audio_extn/ultrasound.c b/hal/audio_extn/ultrasound.c index 172a0b79..4a1a4780 100644 --- a/hal/audio_extn/ultrasound.c +++ b/hal/audio_extn/ultrasound.c @@ -28,6 +28,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 +110,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; @@ -228,14 +255,18 @@ int us_start(void) } rx_usecase->type = PCM_PLAYBACK; - rx_usecase->out_snd_device = SND_DEVICE_OUT_VOICE_HANDSET; + if (compare_device_type(&us->adev->primary_output->device_list, + AUDIO_DEVICE_OUT_SPEAKER)) + rx_usecase->out_snd_device = SND_DEVICE_OUT_SPEAKER; + else + rx_usecase->out_snd_device = SND_DEVICE_OUT_VOICE_HANDSET; 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..ebdfa9b3 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,34 @@ 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) { + derive_snd_device[usecase->id] = uc_derive_snd_device; + 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 +2226,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 } }