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
This commit is contained in:
Alexander Winkowski 2024-10-28 05:45:27 +00:00
parent 2b36e2e9c3
commit 21e630f04b
No known key found for this signature in database
GPG Key ID: 72762A66704CDE44
3 changed files with 62 additions and 7 deletions

View File

@ -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,
@ -106,6 +107,32 @@ static void us_ramp_down(void)
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)
{
ALOGD("%s: enter", __func__);
@ -220,6 +247,10 @@ int us_start(void)
}
rx_usecase->type = PCM_PLAYBACK;
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;
@ -227,7 +258,7 @@ int us_start(void)
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);

View File

@ -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

View File

@ -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
}
}