hal: Add support for Mic break detection

Send request to driver, to enable mic break detection algorithm in ADSP
based on system feature flag during the start of a voice call.

CRs-Fixed: 2314972
Change-Id: I78b0c0ad839dfe513d05c4e8fdc8db7277549124
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index d83002a..2e45807 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -7650,6 +7650,8 @@
         }
     }
 
+    adev->mic_break_enabled = property_get_bool("vendor.audio.mic_break", false);
+
     if (property_get("vendor.audio_hal.period_multiplier", value, NULL) > 0) {
         af_period_multiplier = atoi(value);
         if (af_period_multiplier < 0)
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index c29f7b8..202e09a 100755
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -487,6 +487,7 @@
     bool bt_wb_speech_enabled;
     bool allow_afe_proxy_usage;
     bool is_charging; // from battery listener
+    bool mic_break_enabled;
 
     int snd_card;
     card_status_t card_status;
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index e5cb9b4..c6d1a74 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -3647,6 +3647,11 @@
     return ret;
 }
 
+int platform_set_mic_break_det(void *platform __unused, bool enable __unused)
+{
+    return 0;
+}
+
 int platform_stop_voice_call(void *platform, uint32_t vsid)
 {
     struct platform_data *my_data = (struct platform_data *)platform;
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index fab7034..444f321 100755
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -3510,6 +3510,26 @@
     return ret;
 }
 
+int platform_set_mic_break_det(void *platform, bool enable)
+{
+    int ret = 0;
+    struct platform_data *my_data = (struct platform_data *)platform;
+    struct audio_device *adev = my_data->adev;
+    const char *mixer_ctl_name = "Voice Mic Break Enable";
+    struct mixer_ctl *ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+    if (!ctl) {
+        ALOGE("%s: Could not get ctl for mixer cmd - %s",
+              __func__, mixer_ctl_name);
+        return -EINVAL;
+    }
+
+    ret = mixer_ctl_set_value(ctl, 0, enable);
+    if(ret)
+        ALOGE("%s: Failed to set mixer ctl: %s", __func__, mixer_ctl_name);
+
+    return ret;
+}
+
 int platform_get_sample_rate(void *platform, uint32_t *rate)
 {
     struct platform_data *my_data = (struct platform_data *)platform;
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 226275e..6ba962d 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -150,6 +150,7 @@
                                                   snd_device_t in_snd_device);
 int platform_start_voice_call(void *platform, uint32_t vsid);
 int platform_stop_voice_call(void *platform, uint32_t vsid);
+int platform_set_mic_break_det(void *platform, bool enable);
 int platform_set_voice_volume(void *platform, int volume);
 int platform_set_mic_mute(void *platform, bool state);
 int platform_get_sample_rate(void *platform, uint32_t *rate);
diff --git a/hal/voice.c b/hal/voice.c
index f9e3562..2c698bd 100644
--- a/hal/voice.c
+++ b/hal/voice.c
@@ -281,6 +281,9 @@
         goto error_start_voice;
     }
 
+    if(adev->mic_break_enabled)
+        platform_set_mic_break_det(adev->platform, true);
+
     pcm_start(session->pcm_tx);
     pcm_start(session->pcm_rx);