hal: audio_extn: enable speaker protection for tasha

Add speaker protection support for wsa speaker.

Change-Id: I5468b2875d0fd028e5c32f25c15b5de0095e7007
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index c5b15e0..7cbed2d 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -285,16 +285,12 @@
 #define audio_extn_spkr_prot_calib_cancel(adev) (0)
 #define audio_extn_spkr_prot_stop_processing(snd_device)     (0)
 #define audio_extn_spkr_prot_is_enabled() (false)
-#define audio_extn_spkr_prot_get_acdb_id(snd_device)         (-EINVAL)
-#define audio_extn_get_spkr_prot_snd_device(snd_device) (snd_device)
 #define audio_extn_spkr_prot_set_parameters(parms, value, len)   (0)
 #else
 void audio_extn_spkr_prot_init(void *adev);
 int audio_extn_spkr_prot_start_processing(snd_device_t snd_device);
 void audio_extn_spkr_prot_stop_processing(snd_device_t snd_device);
 bool audio_extn_spkr_prot_is_enabled();
-int audio_extn_spkr_prot_get_acdb_id(snd_device_t snd_device);
-int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device);
 void audio_extn_spkr_prot_calib_cancel(void *adev);
 void audio_extn_spkr_prot_set_parameters(struct str_parms *parms,
                                          char *value, int len);
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index efa885e..fee98f5 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -1061,55 +1061,6 @@
     }
 }
 
-int audio_extn_spkr_prot_get_acdb_id(snd_device_t snd_device)
-{
-    int acdb_id;
-
-    switch(snd_device) {
-    case SND_DEVICE_OUT_SPEAKER:
-    case SND_DEVICE_OUT_SPEAKER_WSA:
-        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_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;
-    case SND_DEVICE_OUT_VOICE_SPEAKER:
-
-    case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
-
-        acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED);
-        break;
-    default:
-        acdb_id = -EINVAL;
-        break;
-    }
-    return acdb_id;
-}
-
-int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device)
-{
-    if (!handle.spkr_prot_enable)
-        return snd_device;
-
-    switch(snd_device) {
-    case SND_DEVICE_OUT_SPEAKER:
-    case SND_DEVICE_OUT_SPEAKER_WSA:
-        return SND_DEVICE_OUT_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;
-    case SND_DEVICE_OUT_VOICE_SPEAKER:
-    case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
-        return SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED;
-    default:
-        return snd_device;
-    }
-}
-
 int audio_extn_spkr_prot_start_processing(snd_device_t snd_device)
 {
     struct audio_usecase *uc_info_tx;
@@ -1123,13 +1074,13 @@
        ALOGE("%s: Invalid params", __func__);
        return -EINVAL;
     }
-    snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
+    snd_device = platform_get_spkr_prot_snd_device(snd_device);
     spkr_prot_set_spkrstatus(true);
     uc_info_tx = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
     if (!uc_info_tx) {
         return -ENOMEM;
     }
-    ALOGV("%s: snd_device(%d: %s)", __func__, snd_device,
+    ALOGD("%s: snd_device(%d: %s)", __func__, snd_device,
            platform_get_snd_device_name(snd_device));
     audio_route_apply_and_update_path(adev->audio_route,
            platform_get_snd_device_name(snd_device));
@@ -1201,7 +1152,7 @@
     struct audio_device *adev = handle.adev_handle;
 
     ALOGV("%s: Entry", __func__);
-    snd_device = audio_extn_get_spkr_prot_snd_device(snd_device);
+    snd_device = platform_get_spkr_prot_snd_device(snd_device);
     spkr_prot_set_spkrstatus(false);
     pthread_mutex_lock(&handle.mutex_spkr_prot);
     if (adev && handle.spkr_processing_state == SPKR_PROCESSING_IN_PROGRESS) {
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 75e42d4..bb88916 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -588,7 +588,7 @@
         goto exit_send_app_type_cfg;
     }
     snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
-                 audio_extn_get_spkr_prot_snd_device(snd_device) : snd_device;
+                 platform_get_spkr_prot_snd_device(snd_device) : snd_device;
     acdb_dev_id = platform_get_snd_device_acdb_id(snd_device);
     if (acdb_dev_id < 0) {
         ALOGE("%s: Couldn't get the acdb dev id", __func__);
@@ -657,7 +657,7 @@
         struct stream_out *out = usecase->stream.out;
         int snd_device = usecase->out_snd_device;
         snd_device = (snd_device == SND_DEVICE_OUT_SPEAKER) ?
-                     audio_extn_get_spkr_prot_snd_device(snd_device) : snd_device;
+                     platform_get_spkr_prot_snd_device(snd_device) : snd_device;
         platform_send_audio_calibration(adev->platform, usecase,
                                         out->app_type_cfg.app_type,
                                         usecase->stream.out->app_type_cfg.sample_rate);
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index cd5437f..e248f56 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -516,11 +516,9 @@
     if(SND_DEVICE_IN_USB_HEADSET_MIC == snd_device)
        audio_extn_usb_start_capture(adev);
 
-	   if ((snd_device == SND_DEVICE_OUT_SPEAKER || snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
-        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) {
+    if (platform_can_enable_spkr_prot_on_device(snd_device) &&
+         audio_extn_spkr_prot_is_enabled()) {
+       if (platform_get_spkr_prot_acdb_id(snd_device) < 0) {
            adev->snd_dev_ref_cnt[snd_device]--;
            return -EINVAL;
        }
@@ -584,10 +582,9 @@
         /* exit usb capture thread */
         if(SND_DEVICE_IN_USB_HEADSET_MIC == snd_device)
             audio_extn_usb_stop_capture();
-        if ((snd_device == SND_DEVICE_OUT_SPEAKER || snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
-            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 (platform_can_enable_spkr_prot_on_device(snd_device) &&
+             audio_extn_spkr_prot_is_enabled()) {
             audio_extn_spkr_prot_stop_processing(snd_device);
         } else {
             audio_route_reset_and_update_path(adev->audio_route, device_name);
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index c349e79..e069918 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -2240,7 +2240,7 @@
         snd_device = voice_get_incall_rec_snd_device(usecase->in_snd_device);
     else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
         snd_device = usecase->in_snd_device;
-    acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
+    acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
 
     // Do not use Rx path default app type for TX path
     if ((usecase->type == PCM_CAPTURE) && (app_type == DEFAULT_APP_TYPE_RX_PATH)) {
@@ -4898,3 +4898,66 @@
 {
     return 0;
 }
+
+bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device)
+{
+    bool ret = false;
+
+    if (snd_device == SND_DEVICE_OUT_SPEAKER ||
+        snd_device == SND_DEVICE_OUT_SPEAKER_WSA ||
+        snd_device == SND_DEVICE_OUT_SPEAKER_VBAT ||
+        snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_VBAT ||
+        snd_device == SND_DEVICE_OUT_VOICE_SPEAKER ||
+        snd_device == SND_DEVICE_OUT_VOICE_SPEAKER_WSA) {
+        ret = true;
+    }
+
+    return ret;
+}
+
+int platform_get_spkr_prot_acdb_id(snd_device_t snd_device)
+{
+    int acdb_id;
+
+    switch(snd_device) {
+        case SND_DEVICE_OUT_SPEAKER:
+        case SND_DEVICE_OUT_SPEAKER_WSA:
+             acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
+             break;
+        case SND_DEVICE_OUT_VOICE_SPEAKER:
+        case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
+             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;
+    }
+    return acdb_id;
+}
+
+int platform_get_spkr_prot_snd_device(snd_device_t snd_device)
+{
+    if (!audio_extn_spkr_prot_is_enabled())
+        return snd_device;
+
+    switch(snd_device) {
+        case SND_DEVICE_OUT_SPEAKER:
+        case SND_DEVICE_OUT_SPEAKER_WSA:
+             return SND_DEVICE_OUT_SPEAKER_PROTECTED;
+        case SND_DEVICE_OUT_VOICE_SPEAKER:
+        case SND_DEVICE_OUT_VOICE_SPEAKER_WSA:
+             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;
+    }
+}
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index 23e3095..e7d6920 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1189,3 +1189,19 @@
 {
     ALOGE("%s: Not implemented", __func__);
 }
+
+bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device __unused)
+{
+    /* speaker protection not implemented for this platform*/
+    return false;
+}
+
+int platform_get_spkr_prot_acdb_id(snd_device_t snd_device __unused)
+{
+    return -ENOSYS;
+}
+
+int platform_get_spkr_prot_snd_device(snd_device_t snd_device __unused)
+{
+    return -ENOSYS;
+}
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 2fb50c1..8c17895 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -784,7 +784,7 @@
                 app_type = usecase->stream.out->app_type_cfg.app_type;
 
                 if (audio_extn_spkr_prot_is_enabled()) {
-                    acdb_dev_id = audio_extn_spkr_prot_get_acdb_id(usecase->out_snd_device);
+                    acdb_dev_id = platform_get_spkr_prot_acdb_id(usecase->out_snd_device);
                 } else {
                     acdb_dev_id = acdb_device_table[usecase->out_snd_device];
                 }
@@ -1998,7 +1998,7 @@
     else if ((usecase->type == PCM_HFP_CALL) || (usecase->type == PCM_CAPTURE))
         snd_device = usecase->in_snd_device;
 
-    acdb_dev_id = acdb_device_table[audio_extn_get_spkr_prot_snd_device(snd_device)];
+    acdb_dev_id = acdb_device_table[platform_get_spkr_prot_snd_device(snd_device)];
     if (acdb_dev_id < 0) {
         ALOGE("%s: Could not find acdb id for device(%d)",
               __func__, snd_device);
@@ -4351,6 +4351,63 @@
     return ret;
 }
 
+bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device)
+{
+    bool ret = false;
+
+    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) {
+        ret = true;
+    }
+
+    return ret;
+}
+
+int platform_get_spkr_prot_acdb_id(snd_device_t snd_device)
+{
+    int acdb_id;
+
+    switch(snd_device) {
+        case SND_DEVICE_OUT_SPEAKER:
+             acdb_id = platform_get_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_PROTECTED);
+             break;
+        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;
+    }
+    return acdb_id;
+}
+
+int platform_get_spkr_prot_snd_device(snd_device_t snd_device)
+{
+    if (!audio_extn_spkr_prot_is_enabled())
+        return snd_device;
+
+    switch(snd_device) {
+        case SND_DEVICE_OUT_SPEAKER:
+             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;
+    }
+}
+
 /*
  * This is a lookup table to map android audio input device to audio h/w interface (backend).
  * The table can be extended for other input devices by adding appropriate entries.
diff --git a/hal/platform_api.h b/hal/platform_api.h
index a89c267..e5ec2d6 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -122,4 +122,7 @@
 int platform_set_audio_device_interface(const char * device_name, const char *intf_name,
                                         const char * codec_type);
 void platform_set_gsm_mode(void *platform, bool enable);
+bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device);
+int platform_get_spkr_prot_acdb_id(snd_device_t snd_device);
+int platform_get_spkr_prot_snd_device(snd_device_t snd_device);
 #endif // AUDIO_PLATFORM_API_H