hal: Add provision to select backend based on codec type

SLIMBUS_0 is the backend on 8952 external codec PLs.
Whereas TERT_MI2S is the backend on 8952 internal codec PLs.
Since both these PLs are supported on same code base,
provision is required to select backend based on codec type.

Change-Id: I9c0dd7d952ab9d6b9bf738074d97597622e09590
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index e9780bc..4ef84b7 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -707,7 +707,9 @@
          !strncmp(snd_card_name, "msm8939-tapan9302-snd-card",
                   sizeof("msm8939-tapan9302-snd-card"))||
          !strncmp(snd_card_name, "msm8939-tomtom9330-snd-card",
-                  sizeof("msm8939-tomtom9330-snd-card"))) {
+                  sizeof("msm8939-tomtom9330-snd-card")) ||
+         !strncmp(snd_card_name, "msm8952-tomtom-snd-card",
+                  sizeof("msm8952-tomtom-snd-card"))) {
          ALOGI("%s: snd_card_name: %s",__func__,snd_card_name);
          is_external_codec = true;
      }
@@ -4009,32 +4011,33 @@
 /*
  * 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.
- * Also the audio interface for a particular input device can be overriden by adding
- * corresponding entry in audio_platform_info.xml file.
+ * The audio interface for a particular input device need to be added in
+ * audio_platform_info.xml file.
  */
 struct audio_device_to_audio_interface audio_device_to_interface_table[] = {
-    {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), "TERT_MI2S"},
-    {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), "TERT_MI2S"},
+    {AUDIO_DEVICE_IN_BUILTIN_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BUILTIN_MIC), ""},
+    {AUDIO_DEVICE_IN_BACK_MIC, ENUM_TO_STRING(AUDIO_DEVICE_IN_BACK_MIC), ""},
 };
 
 int audio_device_to_interface_table_len  =
     sizeof(audio_device_to_interface_table) / sizeof(audio_device_to_interface_table[0]);
 
-
 int platform_set_audio_device_interface(const char * device_name,
-                                        const char *intf_name)
+                                        const char *intf_name,
+                                        const char *codec_type)
 {
     int ret = 0;
     int i;
 
-    if (device_name == NULL || intf_name == NULL) {
+    if (device_name == NULL || intf_name == NULL || codec_type == NULL) {
         ALOGE("%s: Invalid input", __func__);
 
         ret = -EINVAL;
         goto done;
     }
 
-    ALOGD("%s: Enter, device name:%s, intf name:%s", __func__, device_name, intf_name);
+    ALOGD("%s: Enter, device name:%s, intf name:%s, codec_type:%s", __func__,
+                            device_name, intf_name, codec_type);
 
     size_t device_name_len = strlen(device_name);
     for (i = 0; i < audio_device_to_interface_table_len; i++) {
@@ -4042,11 +4045,22 @@
         size_t name_len = strlen(name);
         if ((name_len == device_name_len) &&
             (strncmp(device_name, name, name_len) == 0)) {
-            ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
+            if (is_external_codec &&
+               (strncmp(codec_type, "external", strlen(codec_type)) == 0)) {
+                ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
                   __func__, device_name, intf_name);
 
-            strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
+                strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
                     sizeof(audio_device_to_interface_table[i].interface_name));
+            } else if (!is_external_codec &&
+                       (strncmp(codec_type, "internal", strlen(codec_type)) == 0)) {
+                ALOGD("%s: Matched device name:%s, overwrite intf name with %s",
+                  __func__, device_name, intf_name);
+
+                strlcpy(audio_device_to_interface_table[i].interface_name, intf_name,
+                    sizeof(audio_device_to_interface_table[i].interface_name));
+            } else
+                ALOGE("Invalid codec_type specified. Ignoring this interface entry.");
             goto done;
         }
     }