hal: support wsa combo for jacala

- Extend hw_info module to append wsa tag
  to mixer path for combo usecase

Change-Id: I4e39f50ca6665244bc2ee6177be9b4ca5c01df83
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 10693ea..123752a 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -210,15 +210,19 @@
 #endif
 
 #ifndef HW_VARIANTS_ENABLED
-#define hw_info_init(snd_card_name)                  (0)
-#define hw_info_deinit(hw_info)                      (0)
+#define hw_info_init(snd_card_name)                      (0)
+#define hw_info_deinit(hw_info)                          (0)
 #define hw_info_append_hw_type(hw_info,\
-        snd_device, device_name)                     (0)
+        snd_device, device_name)                         (0)
+#define hw_info_enable_wsa_combo_usecase_support(hw_info)   (0)
+
 #else
 void *hw_info_init(const char *snd_card_name);
 void hw_info_deinit(void *hw_info);
 void hw_info_append_hw_type(void *hw_info, snd_device_t snd_device,
                              char *device_name);
+void hw_info_enable_wsa_combo_usecase_support(void *hw_info);
+
 #endif
 
 #ifndef AUDIO_LISTEN_ENABLED
diff --git a/hal/msm8916/hw_info.c b/hal/msm8916/hw_info.c
index 6140698..fb8d648 100644
--- a/hal/msm8916/hw_info.c
+++ b/hal/msm8916/hw_info.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -47,9 +47,11 @@
     uint32_t num_snd_devices;
     char dev_extn[HW_INFO_ARRAY_MAX_SIZE];
     snd_device_t  *snd_devices;
+    bool is_wsa_combo_suppported;
 };
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+#define WSA_MIXER_PATH_EXTENSION "wsa-"
 
 static const snd_device_t taiko_fluid_variant_devices[] = {
     SND_DEVICE_OUT_SPEAKER,
@@ -123,6 +125,14 @@
     SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET,
 };
 
+static const snd_device_t wsa_combo_devices[] = {
+    SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES,
+    SND_DEVICE_OUT_SPEAKER_AND_LINE,
+    SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1,
+    SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2,
+    SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET
+};
+
 static void update_hardware_info_8x16(struct hardware_info *hw_info, const char *snd_card_name)
 {
     if (!strcmp(snd_card_name, "msm8x16-snd-card")) {
@@ -332,6 +342,8 @@
     } else {
         ALOGW("%s: Not an  8x16/8939/8909/8952 device", __func__);
     }
+
+    hw_info->is_wsa_combo_suppported = false;
 }
 
 void *hw_info_init(const char *snd_card_name)
@@ -363,19 +375,52 @@
 {
     struct hardware_info *my_data = (struct hardware_info*) hw_info;
 
-    if(!my_data)
+    if(my_data != NULL)
         free(my_data);
 }
 
+void hw_info_enable_wsa_combo_usecase_support(void *hw_info)
+{
+    struct hardware_info *my_data = (struct hardware_info*) hw_info;
+    if(!my_data) {
+        ALOGE(" ERROR wsa combo update is called with invalid hw_info");
+        return;
+    }
+    my_data->is_wsa_combo_suppported = true;
+
+}
+
 void hw_info_append_hw_type(void *hw_info, snd_device_t snd_device,
                             char *device_name)
 {
     struct hardware_info *my_data = (struct hardware_info*) hw_info;
     uint32_t i = 0;
 
+    if(!my_data) {
+        ALOGE(" ERROR hw_info_append_hw_type is called with invalid hw_info");
+        return;
+    }
+
     snd_device_t *snd_devices =
             (snd_device_t *) my_data->snd_devices;
 
+
+    if(my_data->is_wsa_combo_suppported) {
+        for (i = 0; i < ARRAY_SIZE(wsa_combo_devices) ; i++) {
+            if (snd_device == (snd_device_t)wsa_combo_devices[i]) {
+                char mixer_device_name[DEVICE_NAME_MAX_SIZE] = {0};
+                ALOGD("appending wsa extension to device %s",
+                        device_name);
+               strlcpy(mixer_device_name, WSA_MIXER_PATH_EXTENSION,
+                        sizeof(WSA_MIXER_PATH_EXTENSION)) ;
+                strlcat(mixer_device_name, device_name, DEVICE_NAME_MAX_SIZE);
+                strlcpy(device_name, mixer_device_name, DEVICE_NAME_MAX_SIZE-1);
+                break;
+            }
+        }
+    }
+
+
     if(snd_devices != NULL) {
         for (i = 0; i <  my_data->num_snd_devices; i++) {
             if (snd_device == (snd_device_t)snd_devices[i]) {
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 378ca83..2f9c2e8 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1564,7 +1564,8 @@
 #define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
 #define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"
 
-static bool is_wsa_found(int *wsaCount)
+static bool check_and_get_wsa_info(char *snd_card_name, int *wsaCount,
+                                   bool *is_wsa_combo_supported)
 {
     DIR *tdir = NULL;
     struct dirent *tdirent = NULL;
@@ -1614,6 +1615,18 @@
          ALOGD("Found %d WSA present on the platform", wsa_count);
          found = true;
          *wsaCount = wsa_count;
+
+        /* update wsa combo supported flag based on sound card name */
+        /* wsa combo flag needs to be set to true only for hardware
+           combinations which has support for both wsa and non-wsa speaker */
+        if (snd_card_name && (!strncmp(snd_card_name, "msm8953-snd-card-mtp",
+                sizeof("msm8953-snd-card-mtp"))) ||
+            !strncmp(snd_card_name, "msm8952-skum-snd-card",
+                sizeof("msm8952-skum-snd-card"))) {
+            *is_wsa_combo_supported = true;
+        } else {
+            *is_wsa_combo_supported = false;
+        }
     }
     closedir(tdir);
     chdir(cwd); /* Restore current working dir */
@@ -1634,6 +1647,7 @@
     struct mixer_ctl *ctl = NULL;
     int idx;
     int wsaCount =0;
+    bool is_wsa_combo_supported = false;
 
     my_data = calloc(1, sizeof(struct platform_data));
 
@@ -1749,14 +1763,19 @@
         }
     }
 
-    if (is_wsa_found(&wsaCount)) {
+    if (check_and_get_wsa_info(snd_card_name, &wsaCount, &is_wsa_combo_supported)) {
         /*Set ACDB ID of Stereo speaker if two WSAs are present*/
         /*Default ACDB ID for wsa speaker is that for mono*/
         if (wsaCount == 2) {
             platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_WSA, 15);
             platform_set_snd_device_acdb_id(SND_DEVICE_OUT_SPEAKER_VBAT, 15);
         }
+
         my_data->is_wsa_speaker = true;
+
+        if (is_wsa_combo_supported)
+            hw_info_enable_wsa_combo_usecase_support(my_data->hw_info);
+
     }
 
     property_get("persist.audio.FFSP.enable", ffspEnable, "");