hal: Add support for AUXPCM BT

Atheros BT chip uses AUXPCM instead of slimbus. Audio HAL has
to use different mixer paths file depending on whether it's
internal or external BT chip

Change-Id: I78ae70462fed42d4260ae37070ba23e81779c866
diff --git a/hal/Android.mk b/hal/Android.mk
index 44e6862..f20105c 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -90,6 +90,10 @@
     LOCAL_SRC_FILES += audio_extn/listen.c
 endif
 
+ifeq ($(strip $(AUDIO_FEATURE_ENABLED_AUXPCM_BT)),true)
+    LOCAL_CFLAGS += -DAUXPCM_BT_ENABLED
+endif
+
 LOCAL_MODULE := audio.primary.$(TARGET_BOARD_PLATFORM)
 
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index 98765c4..47d7c33 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -29,6 +29,9 @@
 #include "audio_hw.h"
 #include "audio_extn.h"
 
+#define MAX_SLEEP_RETRY 100
+#define WIFI_INIT_WAIT_SLEEP 50
+
 struct audio_extn_module {
     bool anc_enabled;
     bool aanc_enabled;
@@ -208,3 +211,31 @@
 
     ALOGD("%s: returns %s", __func__, str_parms_to_str(reply));
 }
+
+#ifdef AUXPCM_BT_ENABLED
+int32_t audio_extn_read_xml(struct audio_device *adev, uint32_t mixer_card,
+                            const char* mixer_xml_path,
+                            const char* mixer_xml_path_auxpcm)
+{
+    char bt_soc[128];
+    bool wifi_init_complete = false;
+    int sleep_retry = 0;
+
+    while (!wifi_init_complete && sleep_retry < MAX_SLEEP_RETRY) {
+        property_get("qcom.bluetooth.soc", bt_soc, NULL);
+        if (strncmp(bt_soc, "unknown", sizeof("unknown"))) {
+            wifi_init_complete = true;
+        } else {
+            usleep(WIFI_INIT_WAIT_SLEEP*1000);
+            sleep_retry++;
+        }
+    }
+
+    if (!strncmp(bt_soc, "ath3k", sizeof("ath3k")))
+        adev->audio_route = audio_route_init(mixer_card, mixer_xml_path_auxpcm);
+    else
+        adev->audio_route = audio_route_init(mixer_card, mixer_xml_path);
+
+    return 0;
+}
+#endif /* AUXPCM_BT_ENABLED */
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 71b4863..62fbd8d 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -117,4 +117,12 @@
 
 #endif /* AUDIO_LISTEN_ENABLED */
 
+#ifndef AUXPCM_BT_ENABLED
+#define audio_extn_read_xml(adev, MIXER_CARD, MIXER_XML_PATH, \
+                            MIXER_XML_PATH_AUXPCM)               (-ENOSYS)
+#else
+int32_t audio_extn_read_xml(struct audio_device *adev, uint32_t mixer_card,
+                            const char* mixer_xml_path,
+                            const char* mixer_xml_path_auxpcm);
+#endif /* AUXPCM_BT_ENABLED */
 #endif /* AUDIO_EXTN_H */
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 691a833..359e56c 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -32,6 +32,7 @@
 #include "audio_extn.h"
 
 #define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
+#define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
 #define LIB_ACDB_LOADER "libacdbloader.so"
 #define AUDIO_DATA_BLOCK_MIXER_CTL "HDMI EDID"
 
@@ -324,7 +325,10 @@
         return NULL;
     }
 
-    adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
+    if (audio_extn_read_xml(adev, MIXER_CARD, MIXER_XML_PATH,
+                            MIXER_XML_PATH_AUXPCM) == -ENOSYS)
+        adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
+
     if (!adev->audio_route) {
         ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
         return NULL;