Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20cdd21a authored by Banajit Goswami's avatar Banajit Goswami
Browse files

hal: Add support to enable VBat feature

Add support to enable VBat feature. This includes required changes
to select VBat speaker devices for audio and voice usecases and
sending the VBat calibration data to codec driver.

Change-Id: I2234bee3cc4d6f16934a4b27ef9da21cde74bb48
parent 39d9d7d9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -69,6 +69,10 @@ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_ANC_HEADSET)),true)
    LOCAL_CFLAGS += -DANC_HEADSET_ENABLED
endif

ifeq ($(strip $(AUDIO_FEATURE_ENABLED_VBAT_MONITOR)),true)
    LOCAL_CFLAGS += -DVBAT_MONITOR_ENABLED
endif

ifeq ($(strip $(AUDIO_FEATURE_ENABLED_FLUENCE)),true)
    LOCAL_CFLAGS += -DFLUENCE_ENABLED
endif
+23 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ struct audio_extn_module {
    bool custom_stereo_enabled;
    uint32_t proxy_channel_num;
    bool hpx_enabled;
    bool vbat_enabled;
};

static struct audio_extn_module aextnmod = {
@@ -70,6 +71,7 @@ static struct audio_extn_module aextnmod = {
    .custom_stereo_enabled = 0,
    .proxy_channel_num = 2,
    .hpx_enabled = 0,
    .vbat_enabled = 0,
};

#define AUDIO_PARAMETER_KEY_ANC        "anc_enabled"
@@ -216,6 +218,27 @@ void audio_extn_check_and_set_dts_hpx_state(const struct audio_device *adev)
}
#endif

#ifdef VBAT_MONITOR_ENABLED
bool audio_extn_is_vbat_enabled(void)
{
    ALOGD("%s: status: %d", __func__, aextnmod.vbat_enabled);
    return (aextnmod.vbat_enabled ? true: false);
}

bool audio_extn_can_use_vbat(void)
{
    char prop_vbat_enabled[PROPERTY_VALUE_MAX] = "false";

    property_get("persist.audio.vbat.enabled", prop_vbat_enabled, "0");
    if (!strncmp("true", prop_vbat_enabled, 4)) {
        aextnmod.vbat_enabled = 1;
    }

    ALOGD("%s: vbat.enabled property is set to %s", __func__, prop_vbat_enabled);
    return (aextnmod.vbat_enabled ? true: false);
}
#endif

#ifndef ANC_HEADSET_ENABLED
#define audio_extn_set_anc_parameters(adev, parms)       (0)
#else
+8 −0
Original line number Diff line number Diff line
@@ -127,6 +127,14 @@ bool audio_extn_should_use_fb_anc(void);
bool audio_extn_should_use_handset_anc(int in_channels);
#endif

#ifndef VBAT_MONITOR_ENABLED
#define audio_extn_is_vbat_enabled()                     (0)
#define audio_extn_can_use_vbat()                        (0)
#else
bool audio_extn_is_vbat_enabled(void);
bool audio_extn_can_use_vbat(void);
#endif

#ifndef FLUENCE_ENABLED
#define audio_extn_set_fluence_parameters(adev, parms) (0)
#define audio_extn_get_fluence_parameters(adev, query, reply) (0)
+22 −3
Original line number Diff line number Diff line
@@ -467,9 +467,15 @@ static int spkr_calibrate(int t0_spk_1, int t0_spk_2)
    uc_info_rx->type = PCM_PLAYBACK;
    uc_info_rx->in_snd_device = SND_DEVICE_NONE;
    uc_info_rx->stream.out = adev->primary_output;
    if (audio_extn_is_vbat_enabled())
        uc_info_rx->out_snd_device = SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT;
    else
        uc_info_rx->out_snd_device = SND_DEVICE_OUT_SPEAKER_PROTECTED;
    disable_rx = true;
    list_add_tail(&adev->usecase_list, &uc_info_rx->list);
    if (audio_extn_is_vbat_enabled())
         enable_snd_device(adev, SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT);
    else
         enable_snd_device(adev, SND_DEVICE_OUT_SPEAKER_PROTECTED);
    enable_audio_route(adev, uc_info_rx);

@@ -629,6 +635,9 @@ exit:
        }
        if (disable_rx) {
            list_remove(&uc_info_rx->list);
            if (audio_extn_is_vbat_enabled())
                disable_snd_device(adev, SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT);
            else
                disable_snd_device(adev, SND_DEVICE_OUT_SPEAKER_PROTECTED);
            disable_audio_route(adev, uc_info_rx);
        }
@@ -1075,6 +1084,12 @@ int audio_extn_spkr_prot_get_acdb_id(snd_device_t snd_device)
    case SND_DEVICE_OUT_VOICE_SPEAKER:
        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
        break;
    case SND_DEVICE_OUT_SPEAKER_VBAT:
        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT);
        break;
    case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT);
        break;
    default:
        acdb_id = -EINVAL;
        break;
@@ -1092,6 +1107,10 @@ int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device)
        return SND_DEVICE_OUT_SPEAKER_PROTECTED;
    case SND_DEVICE_OUT_VOICE_SPEAKER:
        return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
    case SND_DEVICE_OUT_SPEAKER_VBAT:
        return SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT;
    case SND_DEVICE_OUT_VOICE_SPEAKER_VBAT:
        return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED_VBAT;
    default:
        return snd_device;
    }
+11 −6
Original line number Diff line number Diff line
@@ -455,7 +455,7 @@ int enable_audio_route(struct audio_device *adev,
    audio_extn_utils_send_audio_calibration(adev, usecase);
    audio_extn_utils_send_app_type_cfg(usecase);
    strcpy(mixer_path, use_case_table[usecase->id]);
    platform_add_backend_name(mixer_path, snd_device);
    platform_add_backend_name(mixer_path, snd_device, usecase);
    ALOGV("%s: apply mixer and update path: %s", __func__, mixer_path);
    audio_route_apply_and_update_path(adev->audio_route, mixer_path);
    ALOGV("%s: exit", __func__);
@@ -477,7 +477,7 @@ int disable_audio_route(struct audio_device *adev,
    else
        snd_device = usecase->out_snd_device;
    strcpy(mixer_path, use_case_table[usecase->id]);
    platform_add_backend_name(mixer_path, snd_device);
    platform_add_backend_name(mixer_path, snd_device, usecase);
    ALOGV("%s: reset and update mixer path: %s", __func__, mixer_path);
    audio_route_reset_and_update_path(adev->audio_route, mixer_path);
    audio_extn_sound_trigger_update_stream_status(usecase, ST_EVENT_STREAM_FREE);
@@ -521,6 +521,8 @@ int enable_snd_device(struct audio_device *adev,
       audio_extn_usb_start_capture(adev);

    if ((snd_device == SND_DEVICE_OUT_SPEAKER ||
         snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
         snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
         snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) &&
         audio_extn_spkr_prot_is_enabled()) {
       if (audio_extn_spkr_prot_get_acdb_id(snd_device) < 0) {
@@ -591,6 +593,8 @@ int disable_snd_device(struct audio_device *adev,
            audio_extn_usb_stop_capture();

        if ((snd_device == SND_DEVICE_OUT_SPEAKER ||
             snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
             snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
             snd_device == SND_DEVICE_OUT_VOICE_SPEAKER) &&
             audio_extn_spkr_prot_is_enabled()) {
            audio_extn_spkr_prot_stop_processing(snd_device);
@@ -3390,6 +3394,7 @@ static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
        if ((mode == AUDIO_MODE_NORMAL || mode == AUDIO_MODE_IN_COMMUNICATION) &&
                voice_is_in_call(adev)) {
            voice_stop_call(adev);
            platform_set_gsm_mode(adev->platform, false);
            adev->current_call_output = NULL;
        }
    }
Loading