hal: Update ACDB ID for stereo WSA speaker

-Mono speaker ACDB ID is set even for devices supporting stereo
WSA speaker.
-Set ACDB ID based on number of WSA present on the device.

Change-Id: I0a1a3acbd41bd948a272eb5f4384f820be3ea4c9
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 1ce6fd1..2563287 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1376,7 +1376,7 @@
 #define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
 #define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"
 
-bool is_wsa_found(void)
+static bool is_wsa_found(int *wsaCount)
 {
     DIR *tdir = NULL;
     struct dirent *tdirent = NULL;
@@ -1385,6 +1385,7 @@
     char cwd[MAX_PATH] = {0};
     char file[10] = "wsa";
     bool found = false;
+    int wsa_count = 0;
 
     if (!getcwd(cwd, sizeof(cwd)))
         return false;
@@ -1412,14 +1413,19 @@
             ALOGD("Opening %s\n", name);
             read_line_from_file(name, buf, sizeof(buf));
             if (strstr(buf, file)) {
-                found = true;
-                break;
+                wsa_count++;
+                /*We support max only two WSA speakers*/
+                if (wsa_count == 2)
+                    break;
             }
             tzn++;
         }
         closedir(tzdir);
-        if (found == true)
-            break;
+    }
+    if (wsa_count > 0){
+         ALOGD("Found %d WSA present on the platform", wsa_count);
+         found = true;
+         *wsaCount = wsa_count;
     }
     closedir(tdir);
     chdir(cwd); /* Restore current working dir */
@@ -1439,6 +1445,7 @@
     const char *mixer_ctl_name = "Set HPX ActiveBe";
     struct mixer_ctl *ctl = NULL;
     int idx;
+    int wsaCount =0;
 
     my_data = calloc(1, sizeof(struct platform_data));
     if (!my_data) {
@@ -1549,6 +1556,17 @@
             my_data->fluence_mode = FLUENCE_BROADSIDE;
         }
     }
+
+    if (is_wsa_found(&wsaCount)) {
+        /*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;
+    }
+
     property_get("persist.audio.FFSP.enable", ffspEnable, "");
     if (!strncmp("true", ffspEnable, sizeof("true"))) {
         acdb_device_table[SND_DEVICE_OUT_SPEAKER] = 131;
@@ -1631,9 +1649,6 @@
     }
     audio_extn_pm_vote();
 
-    if (is_wsa_found())
-        my_data->is_wsa_speaker = true;
-
     /* Configure active back end for HPX*/
     ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
     if (ctl) {