Merge "hal: msm8916: Add single session voice call usecases and devices"
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index 312be97..2c47af8 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -35,6 +35,7 @@
 #include <math.h>
 #include <cutils/log.h>
 #include <fcntl.h>
+#include <dirent.h>
 #include "audio_hw.h"
 #include "platform.h"
 #include "platform_api.h"
@@ -61,6 +62,9 @@
 #define MIN_RESISTANCE_SPKR_Q24 (2 * (1 << 24))
 #define MAX_RESISTANCE_SPKR_Q24 (40 * (1 << 24))
 
+/*Number of Attempts for WSA equilibrium t0 reads*/
+#define NUM_ATTEMPTS 5
+
 /*Path where the calibration file will be stored*/
 #define CALIB_FILE "/data/misc/audio/audio.cal"
 
@@ -86,6 +90,10 @@
 #define SPKR_PROCESSING_IN_PROGRESS 1
 #define SPKR_PROCESSING_IN_IDLE 0
 
+#define MAX_PATH             (256)
+#define THERMAL_SYSFS "/sys/class/thermal"
+#define TZ_TYPE "/sys/class/thermal/thermal_zone%d/type"
+#define TZ_WSA "/sys/class/thermal/thermal_zone%d/temp"
 /*Modes of Speaker Protection*/
 enum speaker_protection_mode {
     SPKR_PROTECTION_DISABLED = -1,
@@ -117,7 +125,12 @@
     int (*thermal_client_request)(char *client_name, int req_data);
     bool spkr_prot_enable;
     bool spkr_in_use;
-   struct timespec spkr_last_time_used;
+    struct timespec spkr_last_time_used;
+    bool wsa_found;
+    char *spkr_1_tz_name;
+    char *spkr_2_tz_name;
+    int spkr_1_tzn;
+    int spkr_2_tzn;
 };
 
 static struct pcm_config pcm_config_skr_prot = {
@@ -134,6 +147,93 @@
 static struct speaker_prot_session handle;
 static int vi_feed_no_channels;
 
+int read_line_from_file(const char *path, char *buf, size_t count)
+{
+    char * fgets_ret;
+    FILE * fd;
+    int rv;
+
+    fd = fopen(path, "r");
+    if (fd == NULL)
+        return -1;
+
+    fgets_ret = fgets(buf, (int)count, fd);
+    if (NULL != fgets_ret) {
+        rv = (int)strlen(buf);
+    } else {
+        rv = ferror(fd);
+    }
+    fclose(fd);
+
+   return rv;
+}
+
+/*===========================================================================
+FUNCTION get_tzn
+
+Utility function to match a sensor name with thermal zone id.
+
+ARGUMENTS
+	sensor_name - name of sensor to match
+
+RETURN VALUE
+	Thermal zone id on success,
+	-1 on failure.
+===========================================================================*/
+int get_tzn(const char *sensor_name)
+{
+    DIR *tdir = NULL;
+    struct dirent *tdirent = NULL;
+    int found = -1;
+    int tzn = 0;
+    char name[MAX_PATH] = {0};
+    char cwd[MAX_PATH] = {0};
+
+    if (!getcwd(cwd, sizeof(cwd)))
+        return found;
+
+    chdir(THERMAL_SYSFS); /* Change dir to read the entries. Doesnt work
+                             otherwise */
+    tdir = opendir(THERMAL_SYSFS);
+    if (!tdir) {
+        ALOGE("Unable to open %s\n", THERMAL_SYSFS);
+        return found;
+    }
+
+    while ((tdirent = readdir(tdir))) {
+        char buf[50];
+        struct dirent *tzdirent;
+        DIR *tzdir = NULL;
+
+        tzdir = opendir(tdirent->d_name);
+        if (!tzdir)
+            continue;
+        while ((tzdirent = readdir(tzdir))) {
+            if (strcmp(tzdirent->d_name, "type"))
+                continue;
+            snprintf(name, MAX_PATH, TZ_TYPE, tzn);
+            ALOGD("Opening %s\n", name);
+            read_line_from_file(name, buf, sizeof(buf));
+            buf[strlen(sensor_name)] = '\0';
+            if (!strcmp(buf, sensor_name)) {
+                found = 1;
+                break;
+            }
+            tzn++;
+        }
+        closedir(tzdir);
+        if (found == 1)
+            break;
+    }
+    closedir(tdir);
+    chdir(cwd); /* Restore current working dir */
+    if (found == 1) {
+        found = tzn;
+        ALOGE("Sensor %s found at tz: %d\n", sensor_name, tzn);
+    }
+    return found;
+}
+
 static void spkr_prot_set_spkrstatus(bool enable)
 {
     struct timespec ts;
@@ -302,7 +402,7 @@
      return -EINVAL;
 }
 
-static int spkr_calibrate(int t0)
+static int spkr_calibrate(int t0_spk_1, int t0_spk_2)
 {
     struct audio_device *adev = handle.adev_handle;
     struct audio_cal_info_spk_prot_cfg protCfg;
@@ -328,9 +428,8 @@
         return -ENODEV;
     } else {
         protCfg.mode = MSM_SPKR_PROT_CALIBRATION_IN_PROGRESS;
-        /* HAL for speaker protection gets only one Temperature */
-        protCfg.t0[SP_V2_SPKR_1] = t0;
-        protCfg.t0[SP_V2_SPKR_2] = t0;
+        protCfg.t0[SP_V2_SPKR_1] = t0_spk_1;
+        protCfg.t0[SP_V2_SPKR_2] = t0_spk_2;
         if (set_spkr_prot_cal(acdb_fd, &protCfg)) {
             ALOGE("%s: spkr_prot_thread set failed AUDIO_SET_SPEAKER_PROT",
             __func__);
@@ -536,13 +635,20 @@
 {
     unsigned long sec = 0;
     int t0;
+    int i = 0;
+    int t0_spk_1 = 0;
+    int t0_spk_2 = 0;
+    int t0_spk_prior = 0;
     bool goahead = false;
     struct audio_cal_info_spk_prot_cfg protCfg;
     FILE *fp;
-    int acdb_fd;
+    int acdb_fd, thermal_fd;
     struct audio_device *adev = handle.adev_handle;
     unsigned long min_idle_time = MIN_SPKR_IDLE_SEC;
     char value[PROPERTY_VALUE_MAX];
+    char wsa_path[MAX_PATH] = {0};
+    int spk_1_tzn, spk_2_tzn;
+    char buf[32] = {0};
 
     /* If the value of this persist.spkr.cal.duration is 0
      * then it means it will take 30min to calibrate
@@ -622,7 +728,95 @@
 
     while (1) {
         ALOGV("%s: start calibration", __func__);
-        if (!handle.thermal_client_request("spkr",1)) {
+        if (handle.wsa_found) {
+            spk_1_tzn = handle.spkr_1_tzn;
+            spk_2_tzn = handle.spkr_2_tzn;
+            goahead = false;
+            pthread_mutex_lock(&adev->lock);
+            if (is_speaker_in_use(&sec)) {
+                ALOGD("%s: WSA Speaker in use retry calibration", __func__);
+                pthread_mutex_unlock(&adev->lock);
+                continue;
+            } else {
+                ALOGD("%s: wsa speaker idle %ld min time %ld", __func__, sec, min_idle_time);
+                if (sec < min_idle_time) {
+                    ALOGD("%s: speaker idle is less retry", __func__);
+                    pthread_mutex_unlock(&adev->lock);
+                    continue;
+               }
+               goahead = true;
+           }
+           if (!list_empty(&adev->usecase_list)) {
+                ALOGD("%s: Usecase active re-try calibration", __func__);
+                goahead = false;
+           }
+           if (goahead) {
+               if (spk_1_tzn > 0) {
+                   snprintf(wsa_path, MAX_PATH, TZ_WSA, spk_1_tzn);
+                   ALOGD("%s: wsa_path: %s\n", __func__, wsa_path);
+                   thermal_fd = -1;
+                   thermal_fd = open(wsa_path, O_RDONLY);
+                   if (thermal_fd > 0) {
+                       for (i = 0; i < NUM_ATTEMPTS; i++) {
+                            if (read(thermal_fd, buf, sizeof(buf))) {
+                                t0_spk_1 = atoi(buf);
+                                if (i > 0 && (t0_spk_1 != t0_spk_prior))
+                                    break;
+                                t0_spk_prior = t0_spk_1;
+                            } else {
+                               ALOGE("%s: read fail for %s\n", __func__, wsa_path);
+                               break;
+                            }
+                        }
+                        close(thermal_fd);
+                   } else {
+                       ALOGE("%s: fd for %s is NULL\n", __func__, wsa_path);
+                   }
+                   if (i == NUM_ATTEMPTS) {
+                       /*Convert temp into q6 format*/
+                       t0_spk_1 = (t0_spk_1 * (1 << 6));
+                       ALOGE("%s: temp T0 for spkr1 %d\n", __func__, t0_spk_1);
+                   } else {
+                       ALOGE("%s: thermal equilibrium failed for spkr1 in %d readings\n",
+                                                __func__, NUM_ATTEMPTS);
+                       t0_spk_1 = SAFE_SPKR_TEMP_Q6;
+                   }
+                   fclose(fp);
+               }
+               if (spk_2_tzn > 0) {
+                   snprintf(wsa_path, MAX_PATH, TZ_WSA, spk_2_tzn);
+                   ALOGE("%s: wsa_path: %s\n", __func__, wsa_path);
+                   thermal_fd = open(wsa_path, O_RDONLY);
+                   if (thermal_fd > 0) {
+                       for (i = 0; i < NUM_ATTEMPTS; i++) {
+                            if (read(thermal_fd, buf, sizeof(buf))) {
+                                t0_spk_2 = atoi(buf);
+                                if (i > 0 && (t0_spk_2 != t0_spk_prior))
+                                    break;
+                                t0_spk_prior = t0_spk_2;
+                            } else {
+                               ALOGE("%s: read fail for %s\n", __func__, wsa_path);
+                               break;
+                            }
+                        }
+                        close(thermal_fd);
+                   } else {
+                       ALOGE("%s: fd for %s is NULL\n", __func__, wsa_path);
+                   }
+                   if (i == NUM_ATTEMPTS) {
+                       /*Convert temp into q6 format*/
+                       t0_spk_2 = (t0_spk_2 * (1 << 6));
+                       ALOGE("%s: temp T0 for spkr2 %d\n", __func__, t0_spk_2);
+                   } else {
+                       ALOGE("%s: thermal equilibrium failed for spkr2 in %d readings\n",
+                                                __func__, NUM_ATTEMPTS);
+                       t0_spk_2 = SAFE_SPKR_TEMP_Q6;
+                   }
+                   fclose(fp);
+               }
+           }
+           pthread_mutex_unlock(&adev->lock);
+        } else if (!handle.thermal_client_request("spkr",1)) {
             ALOGD("%s: wait for callback from thermal daemon", __func__);
             pthread_mutex_lock(&handle.spkr_prot_thermalsync_mutex);
             pthread_cond_wait(&handle.spkr_prot_thermalsync,
@@ -635,12 +829,15 @@
                       handle.spkr_prot_t0);
                 continue;
             }
+            t0_spk_1 = t0;
+            t0_spk_2 = t0;
             ALOGD("%s: Request t0 success value %d", __func__,
             handle.spkr_prot_t0);
         } else {
             ALOGE("%s: Request t0 failed", __func__);
             /*Assume safe value for temparature*/
-            t0 = SAFE_SPKR_TEMP_Q6;
+            t0_spk_1 = SAFE_SPKR_TEMP_Q6;
+            t0_spk_2 = SAFE_SPKR_TEMP_Q6;
         }
         goahead = false;
         pthread_mutex_lock(&adev->lock);
@@ -664,7 +861,7 @@
         }
         if (goahead) {
                 int status;
-                status = spkr_calibrate(t0);
+                status = spkr_calibrate(t0_spk_1, t0_spk_2);
                 pthread_mutex_unlock(&adev->lock);
                 if (status == -EAGAIN) {
                     ALOGE("%s: failed to calibrate try again %s",
@@ -698,6 +895,17 @@
     return 0;
 }
 
+static bool is_wsa_present(void)
+{
+   handle.spkr_1_tz_name = platform_get_spkr_1_tz_name(SND_DEVICE_OUT_SPEAKER);
+   handle.spkr_2_tz_name = platform_get_spkr_2_tz_name(SND_DEVICE_OUT_SPEAKER);
+   handle.spkr_1_tzn = get_tzn(handle.spkr_1_tz_name);
+   handle.spkr_2_tzn = get_tzn(handle.spkr_2_tz_name);
+   if ((handle.spkr_1_tzn >= 0) || (handle.spkr_2_tzn >= 0))
+        handle.wsa_found = true;
+   return handle.wsa_found;
+}
+
 void audio_extn_spkr_prot_init(void *adev)
 {
     char value[PROPERTY_VALUE_MAX];
@@ -719,6 +927,17 @@
     handle.spkr_prot_mode = MSM_SPKR_PROT_DISABLED;
     handle.spkr_processing_state = SPKR_PROCESSING_IN_IDLE;
     handle.spkr_prot_t0 = -1;
+
+    if (is_wsa_present()) {
+        pthread_cond_init(&handle.spkr_calib_cancel, NULL);
+        pthread_cond_init(&handle.spkr_calibcancel_ack, NULL);
+        pthread_mutex_init(&handle.mutex_spkr_prot, NULL);
+        pthread_mutex_init(&handle.spkr_calib_cancelack_mutex, NULL);
+        ALOGD("%s:WSA Create calibration thread", __func__);
+        (void)pthread_create(&handle.spkr_calibration_thread,
+        (const pthread_attr_t *) NULL, spkr_calibration_thread, &handle);
+        return;
+    }
     pthread_cond_init(&handle.spkr_prot_thermalsync, NULL);
     pthread_cond_init(&handle.spkr_calib_cancel, NULL);
     pthread_cond_init(&handle.spkr_calibcancel_ack, NULL);
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 5d3e440..435138d 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3088,20 +3088,21 @@
 static void close_compress_sessions(struct audio_device *adev)
 {
     struct stream_out *out;
-    struct listnode *node;
+    struct listnode *node, *tempnode;
     struct audio_usecase *usecase;
     pthread_mutex_lock(&adev->lock);
-    list_for_each(node, &adev->usecase_list) {
+
+    list_for_each_safe(node, tempnode, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if (usecase && is_offload_usecase(usecase->id)) {
-            if (usecase && usecase->stream.out) {
+        if (is_offload_usecase(usecase->id)) {
+            if (usecase->stream.out) {
                 ALOGI(" %s closing compress session %d on OFFLINE state", __func__, usecase->id);
                 out = usecase->stream.out;
                 pthread_mutex_unlock(&adev->lock);
                 out_standby(&out->stream.common);
                 pthread_mutex_lock(&adev->lock);
             }
-        }
+       }
     }
     pthread_mutex_unlock(&adev->lock);
 }
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index c652331..223f1d8 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -498,7 +498,7 @@
     [SND_DEVICE_IN_SPEAKER_DMIC_AEC_BROADSIDE] = 119,
     [SND_DEVICE_IN_SPEAKER_DMIC_NS_BROADSIDE] = 121,
     [SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS_BROADSIDE] = 120,
-    [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 135,
+    [SND_DEVICE_IN_VOICE_FLUENCE_DMIC_AANC] = 105,
     [SND_DEVICE_IN_HANDSET_QMIC] = 125,
     [SND_DEVICE_IN_SPEAKER_QMIC_AEC] = 126,
     [SND_DEVICE_IN_SPEAKER_QMIC_NS] = 127,
@@ -3139,6 +3139,10 @@
                     }
                 }
             }
+        } else if (SND_CARD_STATE_OFFLINE == get_snd_card_state(my_data->adev)) {
+            //Do not allow DSP session during SSR
+            ALOGI("Rejecting request for DSP only session from HAL due to SSR");
+            isallowed = 0;
         }
         str_parms_add_int(reply, AUDIO_PARAMETER_IS_HW_DECODER_SESSION_ALLOWED, isallowed);
     }
@@ -4178,3 +4182,58 @@
 done:
     return ret;
 }
+
+/*
+ * This is a lookup table to map names of speaker device with respective left and right TZ names.
+ * Also the tz names for a particular left or right speaker can be overriden by adding
+ * corresponding entry in audio_platform_info.xml file.
+ */
+struct speaker_device_to_tz_names speaker_device_tz_names = {
+    {SND_DEVICE_OUT_SPEAKER, "", ""},
+};
+
+const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
+{
+    if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
+        return speaker_device_tz_names.spkr_1_tz_name;
+    else
+        return "";
+}
+
+const char *platform_get_spkr_2_tz_name(snd_device_t snd_device)
+{
+    if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
+        return speaker_device_tz_names.spkr_2_tz_name;
+    else
+        return "";
+}
+
+int platform_set_spkr_device_tz_names(snd_device_t index,
+                                      const char *spkr_1_tz_name, const char *spkr_2_tz_name)
+{
+    int ret = 0;
+    int i;
+
+    if (spkr_1_tz_name == NULL && spkr_2_tz_name == NULL) {
+        ALOGE("%s: Invalid input", __func__);
+        ret = -EINVAL;
+        goto done;
+    }
+    if (index != speaker_device_tz_names.snd_device) {
+        ALOGE("%s: not matching speaker device\n");
+        ret = -EINVAL;
+        goto done;
+    }
+    ALOGD("%s: Enter, spkr_1_tz_name :%s, spkr_2_tz_name:%s",
+            __func__, spkr_1_tz_name, spkr_2_tz_name);
+
+    if (spkr_1_tz_name != NULL)
+        strlcpy(speaker_device_tz_names.spkr_1_tz_name, spkr_1_tz_name,
+                sizeof(speaker_device_tz_names.spkr_1_tz_name));
+
+    if (spkr_2_tz_name != NULL)
+        strlcpy(speaker_device_tz_names.spkr_2_tz_name, spkr_2_tz_name,
+                sizeof(speaker_device_tz_names.spkr_2_tz_name));
+done:
+    return ret;
+}
diff --git a/hal/msm8916/platform.h b/hal/msm8916/platform.h
index 78c9ff8..d564839 100644
--- a/hal/msm8916/platform.h
+++ b/hal/msm8916/platform.h
@@ -298,4 +298,10 @@
     char device_name[100];
     char interface_name[100];
 };
+
+struct speaker_device_to_tz_names {
+    snd_device_t snd_device;
+    char spkr_1_tz_name[100];
+    char spkr_2_tz_name[100];
+};
 #endif // QCOM_AUDIO_PLATFORM_H
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index e5ecda1..2065b54 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1169,3 +1169,9 @@
 {
     return -ENOSYS;
 }
+
+int platform_set_spkr_device_tz_names(snd_device_t index,
+                                      const char *spkr_1_tz_name, const char *spkr_2_tz_name)
+{
+    return -ENOSYS;
+}
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index dbfc8ff..4f90850 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1346,6 +1346,22 @@
         return "";
 }
 
+const char *platform_get_spkr_1_tz_name(snd_device_t snd_device)
+{
+    if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
+        return speaker_device_tz_names.spkr_1_tz_name;
+    else
+        return "";
+}
+
+const char *platform_get_spkr_2_tz_name(snd_device_t snd_device)
+{
+    if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX)
+        return speaker_device_tz_names.spkr_2_tz_name;
+    else
+        return "";
+}
+
 int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device,
                                       char *device_name)
 {
@@ -3773,6 +3789,15 @@
 }
 
 /*
+ * This is a lookup table to map names of speaker device with respective left and right TZ names.
+ * Also the tz names for a particular left or right speaker can be overriden by adding
+ * corresponding entry in audio_platform_info.xml file.
+ */
+struct speaker_device_to_tz_names speaker_device_tz_names = {
+    {SND_DEVICE_OUT_SPEAKER, "", ""},
+};
+
+/*
  * 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
@@ -3823,3 +3848,33 @@
 done:
     return ret;
 }
+
+int platform_set_spkr_device_tz_names(snd_device_t index,
+                                      const char *spkr_1_tz_name, const char *spkr_2_tz_name)
+{
+    int ret = 0;
+    int i;
+
+    if (spkr_1_tz_name == NULL && spkr_2_tz_name == NULL) {
+        ALOGE("%s: Invalid input", __func__);
+        ret = -EINVAL;
+        goto done;
+    }
+    if (index != speaker_device_tz_names.snd_device) {
+        ALOGE("%s: not matching speaker device\n");
+        ret = -EINVAL;
+        goto done;
+    }
+    ALOGD("%s: Enter, spkr_1_tz_name :%s, spkr_2_tz_name:%s",
+           __func__, spkr_1_tz_name, spkr_2_tz_name);
+
+    if (spkr_1_tz_name != NULL)
+        strlcpy(speaker_device_tz_names.spkr_1_tz_name, spkr_1_tz_name,
+                sizeof(speaker_device_tz_names.spkr_1_tz_name));
+
+    if (spkr_2_tz_name != NULL)
+        strlcpy(speaker_device_tz_names.spkr_2_tz_name, spkr_2_tz_name,
+                sizeof(speaker_device_tz_names.spkr_2_tz_name));
+done:
+    return ret;
+}
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index 83922d5..41e2c55 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -382,4 +382,10 @@
     char device_name[100];
     char interface_name[100];
 };
+
+struct speaker_device_to_tz_names {
+    snd_device_t snd_device;
+    char spkr_1_tz_name[100];
+    char spkr_2_tz_name[100];
+};
 #endif // QCOM_AUDIO_PLATFORM_H
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 4ecdd36..2f9af6c 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -111,4 +111,8 @@
 int platform_set_device_params(struct stream_out *out, int param, int value);
 int platform_set_audio_device_interface(const char * device_name, const char *intf_name,
                                         const char * codec_type);
+int platform_set_spkr_device_tz_names(snd_device_t index,
+                                       const char *spkr_1_tz_name, const char *spkr_2_tz_name);
+const char *platform_get_spkr_1_tz_name(snd_device_t snd_device);
+const char *platform_get_spkr_2_tz_name(snd_device_t snd_device);
 #endif // AUDIO_PLATFORM_API_H
diff --git a/hal/platform_info.c b/hal/platform_info.c
index b65411f..6a35be5 100644
--- a/hal/platform_info.c
+++ b/hal/platform_info.c
@@ -47,6 +47,7 @@
     PCM_ID,
     BACKEND_NAME,
     INTERFACE_NAME,
+    TZ_NAME,
 } section_t;
 
 typedef void (* section_process_fn)(const XML_Char **attr);
@@ -56,6 +57,7 @@
 static void process_pcm_id(const XML_Char **attr);
 static void process_backend_name(const XML_Char **attr);
 static void process_interface_name(const XML_Char **attr);
+static void process_tz_name(const XML_Char **attr);
 static void process_root(const XML_Char **attr);
 
 static section_process_fn section_table[] = {
@@ -65,6 +67,7 @@
     [PCM_ID] = process_pcm_id,
     [BACKEND_NAME] = process_backend_name,
     [INTERFACE_NAME] = process_interface_name,
+    [TZ_NAME] = process_tz_name,
 };
 
 static section_t section;
@@ -91,6 +94,11 @@
  * ...
  * ...
  * </interface_names>
+ * <tz_names>
+ * <device name="???" spkr_1_tz_name="???" spkr_2_tz_name="???"/>
+ * ...
+ * ...
+ * </tz_names>
  * </audio_platform_info>
  */
 
@@ -281,6 +289,42 @@
     return;
 }
 
+static void process_tz_name(const XML_Char **attr)
+{
+    int ret, index;
+
+    if (strcmp(attr[0], "name") != 0) {
+        ALOGE("%s: 'name' not found, no Audio Interface set!", __func__);
+        goto done;
+    }
+
+    index = platform_get_snd_device_index((char *)attr[1]);
+    if (index < 0) {
+        ALOGE("%s: Device %s not found, no snd device set!",
+              __func__, attr[1]);
+        goto done;
+    }
+
+    if (strcmp(attr[2], "spkr_1_tz_name") != 0) {
+        ALOGE("%s: Device %s has no spkr_1_tz_name set!",
+              __func__, attr[1]);
+    }
+
+    if (strcmp(attr[4], "spkr_2_tz_name") != 0) {
+        ALOGE("%s: Device %s has no spkr_2_tz_name set!",
+              __func__, attr[1]);
+    }
+
+    ret = platform_set_spkr_device_tz_names(index, (char *)attr[3], (char *)attr[5]);
+    if (ret < 0) {
+        ALOGE("%s: Audio Interface not set!", __func__);
+        goto done;
+    }
+
+done:
+    return;
+}
+
 static void start_tag(void *userdata __unused, const XML_Char *tag_name,
                       const XML_Char **attr)
 {
@@ -298,10 +342,12 @@
         section = BACKEND_NAME;
     } else if (strcmp(tag_name, "interface_names") == 0) {
         section = INTERFACE_NAME;
+    } else if (strcmp(tag_name, "tz_names") == 0) {
+        section = TZ_NAME;
     } else if (strcmp(tag_name, "device") == 0) {
         if ((section != ACDB) && (section != BACKEND_NAME) && (section != BITWIDTH) &&
-            (section != INTERFACE_NAME)) {
-            ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
+            (section != INTERFACE_NAME) && (section != TZ_NAME)) {
+            ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface/tz names");
             return;
         }