audio_hal: Add support for multi voice sessions

Update HAL to add multi SIM voice support. Seperate
out voice features to voice files.

Add getprop/setprop for BT sample rate, Fluence and Slow talk.

Change-Id: Ief61466f78c7b915549981a28fc7ff32731607a5
diff --git a/hal/Android.mk b/hal/Android.mk
index 5f5c7ae..588df7d 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -6,6 +6,12 @@
 
 LOCAL_ARM_MODE := arm
 
+#MULTI_VOICE_SESSION_ENABLED := true
+
+ifdef MULTI_VOICE_SESSION_ENABLED
+LOCAL_CFLAGS += -DMULTI_VOICE_SESSION_ENABLED
+endif
+
 AUDIO_PLATFORM := $(TARGET_BOARD_PLATFORM)
 ifneq ($(filter msm8974 msm8226 msm8610 apq8084,$(TARGET_BOARD_PLATFORM)),)
   # B-family platform uses msm8974 code base
@@ -13,12 +19,20 @@
 ifneq ($(filter msm8610,$(TARGET_BOARD_PLATFORM)),)
   LOCAL_CFLAGS := -DPLATFORM_MSM8610
 endif
+ifneq ($(filter msm8226,$(TARGET_BOARD_PLATFORM)),)
+  LOCAL_CFLAGS := -DPLATFORM_MSM8x26
+endif
 endif
 
 LOCAL_SRC_FILES := \
 	audio_hw.c \
+	voice.c \
 	$(AUDIO_PLATFORM)/platform.c
 
+ifdef MULTI_VOICE_SESSION_ENABLED
+LOCAL_SRC_FILES += voice_extn/voice_extn.c
+endif
+
 LOCAL_SRC_FILES += audio_extn/audio_extn.c
 
 ifneq ($(strip $(AUDIO_FEATURE_DISABLED_ANC_HEADSET)),true)
@@ -49,6 +63,10 @@
 	$(LOCAL_PATH)/$(AUDIO_PLATFORM) \
 	$(LOCAL_PATH)/audio_extn
 
+ifdef MULTI_VOICE_SESSION_ENABLED
+LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
+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 b10a5e9..068ab46 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -161,8 +161,8 @@
     }
 }
 
-char* audio_extn_get_afe_proxy_parameters(struct str_parms *query,
-                                          struct str_parms *reply)
+int audio_extn_get_afe_proxy_parameters(struct str_parms *query,
+                                        struct str_parms *reply)
 {
     int ret, val;
     char value[32]={0};
@@ -174,10 +174,9 @@
         /* Todo: check if proxy is free by maintaining a state flag*/
         val = 1;
         str_parms_add_int(reply, AUDIO_PARAMETER_CAN_OPEN_PROXY, val);
-        str = str_parms_to_str(reply);
     }
 
-    return str;
+    return 0;
 }
 #endif /* AFE_PROXY_ENABLED */
 
@@ -189,27 +188,10 @@
    audio_extn_fm_set_parameters(adev, parms);
 }
 
-char* audio_extn_get_parameters(const struct audio_hw_device *dev,
-                               const char *keys)
+void audio_extn_get_parameters(const struct audio_device *adev,
+                              struct str_parms *query,
+                              struct str_parms *reply)
 {
-    struct str_parms *query = str_parms_create_str(keys);
-    struct str_parms *reply = str_parms_create();
-    char *str = NULL;
-
-    ALOGD("%s: enter: keys - %s", __func__, keys);
-
-    if (NULL != (str = audio_extn_get_afe_proxy_parameters(query, reply)))
-    {
-        ALOGD("%s: handled %s", __func__, str);
-        goto exit;
-    } else {
-        str = strdup(keys);
-    }
-
-exit:
-    str_parms_destroy(query);
-    str_parms_destroy(reply);
-
-    ALOGD("%s: exit: returns %s", __func__, str);
-    return str;
+    audio_extn_get_afe_proxy_parameters(query, reply);
+    ALOGD("%s: exit: returns %s", __func__, str_parms_to_str(reply));
 }
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index c537b77..1cd6c67 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -25,8 +25,9 @@
 void audio_extn_set_parameters(struct audio_device *adev,
                                struct str_parms *parms);
 
-char* audio_extn_get_parameters(const struct audio_hw_device *dev,
-                               const char *keys);
+void audio_extn_get_parameters(const struct audio_device *adev,
+                               struct str_parms *query,
+                               struct str_parms *reply);
 
 #ifndef ANC_HEADSET_ENABLED
 #define audio_extn_get_anc_enabled()                     (0)
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index e80f88f..3155ab6 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -79,22 +79,17 @@
     .format = PCM_FORMAT_S16_LE,
 };
 
-struct pcm_config pcm_config_voice_call = {
-    .channels = 1,
-    .rate = 8000,
-    .period_size = 160,
-    .period_count = 2,
-    .format = PCM_FORMAT_S16_LE,
-};
-
 static const char * const use_case_table[AUDIO_USECASE_MAX] = {
     [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
     [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
     [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
     [USECASE_AUDIO_RECORD] = "audio-record",
     [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
-    [USECASE_VOICE_CALL] = "voice-call",
     [USECASE_AUDIO_PLAYBACK_FM] = "play-fm",
+    [USECASE_VOICE_CALL] = "voice-call",
+    [USECASE_VOICE2_CALL] = "voice2-call",
+    [USECASE_VOLTE_CALL] = "volte-call",
+    [USECASE_QCHAT_CALL] = "qchat-call",
 };
 
 
@@ -144,8 +139,8 @@
 }
 
 int disable_audio_route(struct audio_device *adev,
-                               struct audio_usecase *usecase,
-                               bool update_mixer)
+                        struct audio_usecase *usecase,
+                        bool update_mixer)
 {
     snd_device_t snd_device;
     char mixer_path[MIXER_PATH_MAX_LENGTH];
@@ -201,8 +196,8 @@
 }
 
 int disable_snd_device(struct audio_device *adev,
-                              snd_device_t snd_device,
-                              bool update_mixer)
+                       snd_device_t snd_device,
+                       bool update_mixer)
 {
     if (snd_device < SND_DEVICE_MIN ||
         snd_device >= SND_DEVICE_MAX) {
@@ -250,7 +245,7 @@
 
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if (usecase->type != PCM_CAPTURE &&
+        if (usecase->type == PCM_PLAYBACK &&
                 usecase != uc_info &&
                 usecase->out_snd_device != snd_device &&
                 usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
@@ -317,7 +312,7 @@
 
     list_for_each(node, &adev->usecase_list) {
         usecase = node_to_item(node, struct audio_usecase, list);
-        if (usecase->type != PCM_PLAYBACK &&
+        if (usecase->type == PCM_CAPTURE &&
                 usecase != uc_info &&
                 usecase->in_snd_device != snd_device) {
             ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
@@ -359,6 +354,51 @@
     }
 }
 
+static int disable_all_usecases_of_type(struct audio_device *adev,
+                                        usecase_type_t usecase_type,
+                                        bool update_mixer)
+{
+    struct audio_usecase *usecase;
+    struct listnode *node;
+    int ret = 0;
+
+    list_for_each(node, &adev->usecase_list) {
+        usecase = node_to_item(node, struct audio_usecase, list);
+        if (usecase->type == usecase_type) {
+            ALOGV("%s: usecase id %d", __func__, usecase->id);
+            ret = disable_audio_route(adev, usecase, update_mixer);
+            if (ret) {
+                ALOGE("%s: Failed to disable usecase id %d",
+                      __func__, usecase->id);
+            }
+        }
+    }
+
+    return ret;
+}
+
+static int enable_all_usecases_of_type(struct audio_device *adev,
+                                       usecase_type_t usecase_type,
+                                       bool update_mixer)
+{
+    struct audio_usecase *usecase;
+    struct listnode *node;
+    int ret = 0;
+
+    list_for_each(node, &adev->usecase_list) {
+        usecase = node_to_item(node, struct audio_usecase, list);
+        if (usecase->type == usecase_type) {
+            ALOGV("%s: usecase id %d", __func__, usecase->id);
+            ret = enable_audio_route(adev, usecase, update_mixer);
+            if (ret) {
+                ALOGE("%s: Failed to enable usecase id %d",
+                      __func__, usecase->id);
+            }
+        }
+    }
+
+    return ret;
+}
 
 /* must be called with hw device mutex locked */
 static int read_hdmi_channel_masks(struct stream_out *out)
@@ -388,8 +428,23 @@
     return ret;
 }
 
+static audio_usecase_t get_voice_usecase_id_from_list(struct audio_device *adev)
+{
+    struct audio_usecase *usecase;
+    struct listnode *node;
+
+    list_for_each(node, &adev->usecase_list) {
+        usecase = node_to_item(node, struct audio_usecase, list);
+        if (usecase->type == VOICE_CALL) {
+            ALOGV("%s: usecase id %d", __func__, usecase->id);
+            return usecase->id;
+        }
+    }
+    return USECASE_INVALID;
+}
+
 struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
-                                                   audio_usecase_t uc_id)
+                                            audio_usecase_t uc_id)
 {
     struct audio_usecase *usecase;
     struct listnode *node;
@@ -402,8 +457,7 @@
     return NULL;
 }
 
-int select_devices(struct audio_device *adev,
-                          audio_usecase_t uc_id)
+int select_devices(struct audio_device *adev, audio_usecase_t uc_id)
 {
     snd_device_t out_snd_device = SND_DEVICE_NONE;
     snd_device_t in_snd_device = SND_DEVICE_NONE;
@@ -431,8 +485,9 @@
          * usecase. This is to avoid switching devices for voice call when
          * check_usecases_codec_backend() is called below.
          */
-        if (adev->in_call) {
-            vc_usecase = get_usecase_from_list(adev, USECASE_VOICE_CALL);
+        if (voice_is_in_call(adev)) {
+            vc_usecase = get_usecase_from_list(adev,
+                                               get_voice_usecase_id_from_list(adev));
             if (vc_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
                 in_snd_device = vc_usecase->in_snd_device;
                 out_snd_device = vc_usecase->out_snd_device;
@@ -481,6 +536,7 @@
      * device.
      */
     if (usecase->type == VOICE_CALL) {
+        disable_all_usecases_of_type(adev, VOICE_CALL, true);
         status = platform_switch_voice_call_device_pre(adev->platform);
     }
 
@@ -517,7 +573,10 @@
     usecase->in_snd_device = in_snd_device;
     usecase->out_snd_device = out_snd_device;
 
-    enable_audio_route(adev, usecase, true);
+    if (usecase->type == VOICE_CALL)
+        enable_all_usecases_of_type(adev, VOICE_CALL, true);
+    else
+        enable_audio_route(adev, usecase, true);
 
     return status;
 }
@@ -679,117 +738,6 @@
     return ret;
 }
 
-static int stop_voice_call(struct audio_device *adev)
-{
-    int i, ret = 0;
-    struct audio_usecase *uc_info;
-
-    ALOGV("%s: enter", __func__);
-    adev->in_call = false;
-
-    ret = platform_stop_voice_call(adev->platform);
-
-    /* 1. Close the PCM devices */
-    if (adev->voice_call_rx) {
-        pcm_close(adev->voice_call_rx);
-        adev->voice_call_rx = NULL;
-    }
-    if (adev->voice_call_tx) {
-        pcm_close(adev->voice_call_tx);
-        adev->voice_call_tx = NULL;
-    }
-
-    uc_info = get_usecase_from_list(adev, USECASE_VOICE_CALL);
-    if (uc_info == NULL) {
-        ALOGE("%s: Could not find the usecase (%d) in the list",
-              __func__, USECASE_VOICE_CALL);
-        return -EINVAL;
-    }
-
-    /* 2. Get and set stream specific mixer controls */
-    disable_audio_route(adev, uc_info, true);
-
-    /* 3. Disable the rx and tx devices */
-    disable_snd_device(adev, uc_info->out_snd_device, false);
-    disable_snd_device(adev, uc_info->in_snd_device, true);
-
-    list_remove(&uc_info->list);
-    free(uc_info);
-
-    ALOGV("%s: exit: status(%d)", __func__, ret);
-    return ret;
-}
-
-static int start_voice_call(struct audio_device *adev)
-{
-    int i, ret = 0;
-    struct audio_usecase *uc_info;
-    int pcm_dev_rx_id, pcm_dev_tx_id;
-
-    ALOGV("%s: enter", __func__);
-
-    uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
-    uc_info->id = USECASE_VOICE_CALL;
-    uc_info->type = VOICE_CALL;
-    uc_info->stream.out = adev->primary_output;
-    uc_info->devices = adev->primary_output->devices;
-    uc_info->in_snd_device = SND_DEVICE_NONE;
-    uc_info->out_snd_device = SND_DEVICE_NONE;
-
-    list_add_tail(&adev->usecase_list, &uc_info->list);
-
-    select_devices(adev, USECASE_VOICE_CALL);
-
-    pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
-    pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
-
-    if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
-        ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
-              __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
-        ret = -EIO;
-        goto error_start_voice;
-    }
-
-    ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
-          __func__, SOUND_CARD, pcm_dev_rx_id);
-    adev->voice_call_rx = pcm_open(SOUND_CARD,
-                                  pcm_dev_rx_id,
-                                  PCM_OUT, &pcm_config_voice_call);
-    if (adev->voice_call_rx && !pcm_is_ready(adev->voice_call_rx)) {
-        ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_rx));
-        ret = -EIO;
-        goto error_start_voice;
-    }
-
-    ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
-          __func__, SOUND_CARD, pcm_dev_tx_id);
-    adev->voice_call_tx = pcm_open(SOUND_CARD,
-                                   pcm_dev_tx_id,
-                                   PCM_IN, &pcm_config_voice_call);
-    if (adev->voice_call_tx && !pcm_is_ready(adev->voice_call_tx)) {
-        ALOGE("%s: %s", __func__, pcm_get_error(adev->voice_call_tx));
-        ret = -EIO;
-        goto error_start_voice;
-    }
-    pcm_start(adev->voice_call_rx);
-    pcm_start(adev->voice_call_tx);
-
-    ret = platform_start_voice_call(adev->platform);
-    if (ret < 0) {
-        ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
-        goto error_start_voice;
-    }
-
-    adev->in_call = true;
-    return 0;
-
-error_start_voice:
-    stop_voice_call(adev);
-
-    ALOGD("%s: exit: status(%d)", __func__, ret);
-    return ret;
-}
-
 static int check_input_parameters(uint32_t sample_rate,
                                   audio_format_t format,
                                   int channel_count)
@@ -957,18 +905,21 @@
             if (!out->standby)
                 select_devices(adev, out->usecase);
 
-            if ((adev->mode == AUDIO_MODE_IN_CALL) && !adev->in_call &&
+            if ((adev->mode == AUDIO_MODE_IN_CALL) &&
+                    !voice_is_in_call(adev) &&
                     (out == adev->primary_output)) {
-                start_voice_call(adev);
-            } else if ((adev->mode == AUDIO_MODE_IN_CALL) && adev->in_call &&
-                       (out == adev->primary_output)) {
-                select_devices(adev, USECASE_VOICE_CALL);
+                voice_start_call(adev);
+            } else if ((adev->mode == AUDIO_MODE_IN_CALL) &&
+                            voice_is_in_call(adev) &&
+                            (out == adev->primary_output)) {
+                select_devices(adev, get_voice_usecase_id_from_list(adev));
             }
         }
 
-        if ((adev->mode == AUDIO_MODE_NORMAL) && adev->in_call &&
+        if ((adev->mode == AUDIO_MODE_NORMAL) &&
+                voice_is_in_call(adev) &&
                 (out == adev->primary_output)) {
-            stop_voice_call(adev);
+            voice_stop_call(adev);
         }
 
         pthread_mutex_unlock(&adev->lock);
@@ -1249,7 +1200,7 @@
      * Instead of writing zeroes here, we could trust the hardware
      * to always provide zeroes when muted.
      */
-    if (ret == 0 && adev->mic_mute)
+    if (ret == 0 && voice_get_mic_mute(adev))
         memset(buffer, 0, bytes);
 
 exit:
@@ -1443,32 +1394,10 @@
     int ret;
 
     ALOGV("%s: enter: %s", __func__, kvpairs);
-
     parms = str_parms_create_str(kvpairs);
-    ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
-    if (ret >= 0) {
-        int tty_mode;
 
-        if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
-            tty_mode = TTY_MODE_OFF;
-        else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
-            tty_mode = TTY_MODE_VCO;
-        else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
-            tty_mode = TTY_MODE_HCO;
-        else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
-            tty_mode = TTY_MODE_FULL;
-        else
-            return -EINVAL;
-
-        pthread_mutex_lock(&adev->lock);
-        if (tty_mode != adev->tty_mode) {
-            adev->tty_mode = tty_mode;
-            adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
-            if (adev->in_call)
-                select_devices(adev, USECASE_VOICE_CALL);
-        }
-        pthread_mutex_unlock(&adev->lock);
-    }
+    voice_set_parameters(adev, parms);
+    platform_set_parameters(adev->platform, parms);
 
     ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value));
     if (ret >= 0) {
@@ -1532,7 +1461,19 @@
 static char* adev_get_parameters(const struct audio_hw_device *dev,
                                  const char *keys)
 {
-    return audio_extn_get_parameters(dev, keys);
+    struct audio_device *adev = (struct audio_device *)dev;
+    struct str_parms *reply = str_parms_create();
+    struct str_parms *query = str_parms_create_str(keys);
+    char *str;
+
+    audio_extn_get_parameters(adev, query, reply);
+    platform_get_parameters(adev->platform, query, reply);
+    str = str_parms_to_str(reply);
+    str_parms_destroy(query);
+    str_parms_destroy(reply);
+
+    ALOGV("%s: exit: returns - %s", __func__, str);
+    return str;
 }
 
 static int adev_init_check(const struct audio_hw_device *dev)
@@ -1542,29 +1483,7 @@
 
 static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
 {
-    struct audio_device *adev = (struct audio_device *)dev;
-    int vol, err = 0;
-
-    pthread_mutex_lock(&adev->lock);
-    adev->voice_volume = volume;
-    if (adev->mode == AUDIO_MODE_IN_CALL) {
-        if (volume < 0.0) {
-            volume = 0.0;
-        } else if (volume > 1.0) {
-            volume = 1.0;
-        }
-
-        vol = lrint(volume * 100.0);
-
-        // Voice volume levels from android are mapped to driver volume levels as follows.
-        // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
-        // So adjust the volume to get the correct volume index in driver
-        vol = 100 - vol;
-
-        err = platform_set_voice_volume(adev->platform, vol);
-    }
-    pthread_mutex_unlock(&adev->lock);
-    return err;
+    return voice_set_volume((struct audio_device *)dev, volume);
 }
 
 static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
@@ -1591,7 +1510,6 @@
 static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
 {
     struct audio_device *adev = (struct audio_device *)dev;
-
     pthread_mutex_lock(&adev->lock);
     if (adev->mode != mode) {
         adev->mode = mode;
@@ -1602,23 +1520,12 @@
 
 static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
 {
-    struct audio_device *adev = (struct audio_device *)dev;
-    int err = 0;
-
-    pthread_mutex_lock(&adev->lock);
-    adev->mic_mute = state;
-
-    err = platform_set_mic_mute(adev->platform, state);
-    pthread_mutex_unlock(&adev->lock);
-    return err;
+    return voice_set_mic_mute((struct audio_device *)dev, state);
 }
 
 static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
 {
-    struct audio_device *adev = (struct audio_device *)dev;
-
-    *state = adev->mic_mute;
-
+    *state = voice_get_mic_mute((struct audio_device *)dev);
     return 0;
 }
 
@@ -1765,14 +1672,10 @@
     adev->active_input = NULL;
     adev->primary_output = NULL;
     adev->out_device = AUDIO_DEVICE_NONE;
-    adev->voice_call_rx = NULL;
-    adev->voice_call_tx = NULL;
-    adev->voice_volume = 1.0f;
-    adev->tty_mode = TTY_MODE_OFF;
     adev->bluetooth_nrec = true;
-    adev->in_call = false;
     adev->acdb_settings = TTY_MODE_OFF;
     adev->snd_dev_ref_cnt = calloc(SND_DEVICE_MAX, sizeof(int));
+    voice_init(adev);
     list_init(&adev->usecase_list);
 
     /* Loads platform specific libraries dynamically */
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 59f82d2..2eb1616 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -1,4 +1,7 @@
 /*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a contribution.
+ *
  * Copyright (C) 2013 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,10 +22,10 @@
 
 #include <cutils/list.h>
 #include <hardware/audio.h>
-
 #include <tinyalsa/asoundlib.h>
 
 #include <audio_route/audio_route.h>
+#include "voice.h"
 
 /* Flags used to initialize acdb_settings variable that goes to ACDB library */
 #define DMIC_FLAG       0x00000002
@@ -57,8 +60,14 @@
     USECASE_AUDIO_RECORD,
     USECASE_AUDIO_RECORD_LOW_LATENCY,
 
+    /* Voice usecase */
     USECASE_VOICE_CALL,
 
+    /* Voice extension usecases */
+    USECASE_VOICE2_CALL,
+    USECASE_VOLTE_CALL,
+    USECASE_QCHAT_CALL,
+
     AUDIO_USECASE_MAX
 } audio_usecase_t;
 
@@ -136,20 +145,14 @@
     audio_devices_t out_device;
     struct stream_in *active_input;
     struct stream_out *primary_output;
-    int in_call;
-    float voice_volume;
-    bool mic_mute;
-    int tty_mode;
     bool bluetooth_nrec;
     bool screen_off;
-    struct pcm *voice_call_rx;
-    struct pcm *voice_call_tx;
     int *snd_dev_ref_cnt;
     struct listnode usecase_list;
     struct audio_route *audio_route;
     int acdb_settings;
     bool speaker_lr_swap;
-
+    struct voice voice;
     void *platform;
 };
 
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index a24ca83..a2eefdd 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1,4 +1,7 @@
 /*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a contribution.
+ *
  * Copyright (C) 2013 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -364,13 +367,17 @@
 void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
 {
     if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
-        strcat(mixer_path, " bt-sco");
+        strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
+    else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
+        strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
     else if(snd_device == SND_DEVICE_OUT_BT_SCO)
-        strcat(mixer_path, " bt-sco");
+        strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
+    else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
+        strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
     else if (snd_device == SND_DEVICE_OUT_HDMI)
-        strcat(mixer_path, " hdmi");
+        strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
     else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
-        strcat(mixer_path, " speaker-and-hdmi");
+        strlcat(mixer_path, " speaker-and-hdmi", MIXER_PATH_MAX_LENGTH);
 }
 
 int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
@@ -864,3 +871,15 @@
 
     return max_channels;
 }
+
+void platform_get_parameters(void *platform, struct str_parms *query,
+                             struct str_parms *reply)
+{
+    LOGE("%s: Not implemented", __func__);
+}
+
+int platform_set_parameters(void *platform, struct str_parms *parms)
+{
+    LOGE("%s: Not implemented", __func__);
+    return -ENOSYS;
+}
diff --git a/hal/msm8960/platform.h b/hal/msm8960/platform.h
index f09b9b1..d583560 100644
--- a/hal/msm8960/platform.h
+++ b/hal/msm8960/platform.h
@@ -1,4 +1,7 @@
 /*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a contribution.
+ *
  * Copyright (C) 2013 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -95,7 +98,7 @@
 #define SOUND_CARD 0
 
 #define DEFAULT_OUTPUT_SAMPLING_RATE 48000
-
+#define MIXER_PATH_MAX_LENGTH 100
 /*
  * tinyAlsa library interprets period size as number of frames
  * one frame = channel_count * sizeof (pcm sample)
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 02940b4..ee069d7 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -25,6 +25,7 @@
 #include <dlfcn.h>
 #include <cutils/log.h>
 #include <cutils/properties.h>
+#include <cutils/str_parms.h>
 #include <audio_hw.h>
 #include <platform_api.h>
 #include "platform.h"
@@ -51,10 +52,17 @@
 #define RETRY_NUMBER 10
 #define RETRY_US 500000
 
+#define SAMPLE_RATE_8KHZ  8000
+#define SAMPLE_RATE_16KHZ 16000
+
 #define MAX_VOL_INDEX 5
 #define MIN_VOL_INDEX 0
 #define percent_to_index(val, min, max) \
-                ((val) * ((max) - (min)) * 0.01 + (min) + .5)
+            ((val) * ((max) - (min)) * 0.01 + (min) + .5)
+
+#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE  "fluence"
+#define AUDIO_PARAMETER_KEY_BTSCO         "bt_samplerate"
+#define AUDIO_PARAMETER_KEY_SLOWTALK      "st_enable"
 
 struct audio_block_header
 {
@@ -74,6 +82,8 @@
     bool fluence_in_voice_call;
     bool fluence_in_voice_rec;
     int  fluence_type;
+    int  btsco_sample_rate;
+    bool slowtalk;
 
     void *acdb_handle;
     acdb_init_t acdb_init;
@@ -92,8 +102,11 @@
     [USECASE_AUDIO_RECORD] = {DEEP_BUFFER_PCM_DEVICE, DEEP_BUFFER_PCM_DEVICE},
     [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
                                           LOWLATENCY_PCM_DEVICE},
-    [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
     [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
+    [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
+    [USECASE_VOICE2_CALL] = {VOICE2_CALL_PCM_DEVICE, VOICE2_CALL_PCM_DEVICE},
+    [USECASE_VOLTE_CALL] = {VOLTE_CALL_PCM_DEVICE, VOLTE_CALL_PCM_DEVICE},
+    [USECASE_QCHAT_CALL] = {QCHAT_CALL_PCM_DEVICE, QCHAT_CALL_PCM_DEVICE},
 };
 
 /* Array to store sound devices */
@@ -111,6 +124,7 @@
     [SND_DEVICE_OUT_HDMI] = "hdmi",
     [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi",
     [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset",
+    [SND_DEVICE_OUT_BT_SCO_WB] = "bt-sco-headset-wb",
     [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus",
     [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones",
     [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones",
@@ -134,6 +148,7 @@
     [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic",
     [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic",
     [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic",
+    [SND_DEVICE_IN_BT_SCO_MIC_WB] = "bt-sco-mic-wb",
     [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic",
     [SND_DEVICE_IN_VOICE_DMIC] = "voice-dmic-ef",
     [SND_DEVICE_IN_VOICE_DMIC_TMUS] = "voice-dmic-ef-tmus",
@@ -162,6 +177,7 @@
     [SND_DEVICE_OUT_HDMI] = 18,
     [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 15,
     [SND_DEVICE_OUT_BT_SCO] = 22,
+    [SND_DEVICE_OUT_BT_SCO_WB] = 39,
     [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 88,
     [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17,
     [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
@@ -184,6 +200,7 @@
     [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8,
     [SND_DEVICE_IN_HDMI_MIC] = 4,
     [SND_DEVICE_IN_BT_SCO_MIC] = 21,
+    [SND_DEVICE_IN_BT_SCO_MIC_WB] = 38,
     [SND_DEVICE_IN_CAMCORDER_MIC] = 61,
     [SND_DEVICE_IN_VOICE_DMIC] = 41,
     [SND_DEVICE_IN_VOICE_DMIC_TMUS] = 89,
@@ -225,24 +242,6 @@
     return is_tmus;
 }
 
-static int set_volume_values(int type, int volume, int* values)
-{
-    values[0] = volume;
-    values[1] = ALL_SESSION_VSID;
-
-    switch(type) {
-    case VOLUME_SET:
-        values[2] = DEFAULT_VOLUME_RAMP_DURATION_MS;
-        break;
-    case MUTE_SET:
-        values[2] = DEFAULT_MUTE_RAMP_DURATION;
-        break;
-    default:
-        return -EINVAL;
-    }
-    return 0;
-}
-
 static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
 {
     struct mixer_ctl *ctl;
@@ -287,6 +286,7 @@
     my_data = calloc(1, sizeof(struct platform_data));
 
     my_data->adev = adev;
+    my_data->btsco_sample_rate = SAMPLE_RATE_8KHZ;
     my_data->fluence_in_spkr_mode = false;
     my_data->fluence_in_voice_call = false;
     my_data->fluence_in_voice_rec = false;
@@ -359,11 +359,15 @@
 void platform_add_backend_name(char *mixer_path, snd_device_t snd_device)
 {
     if (snd_device == SND_DEVICE_IN_BT_SCO_MIC)
-        strcat(mixer_path, " bt-sco");
+        strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
+    else if (snd_device == SND_DEVICE_IN_BT_SCO_MIC_WB)
+        strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
     else if(snd_device == SND_DEVICE_OUT_BT_SCO)
-        strcat(mixer_path, " bt-sco");
+        strlcat(mixer_path, " bt-sco", MIXER_PATH_MAX_LENGTH);
+    else if(snd_device == SND_DEVICE_OUT_BT_SCO_WB)
+        strlcat(mixer_path, " bt-sco-wb", MIXER_PATH_MAX_LENGTH);
     else if (snd_device == SND_DEVICE_OUT_HDMI)
-        strcat(mixer_path, " hdmi");
+        strlcat(mixer_path, " hdmi", MIXER_PATH_MAX_LENGTH);
     else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI)
         strcat(mixer_path, " speaker-and-hdmi");
     else if (snd_device == SND_DEVICE_IN_CAPTURE_FM)
@@ -450,13 +454,16 @@
     struct audio_device *adev = my_data->adev;
     struct mixer_ctl *ctl;
     const char *mixer_ctl_name = "Voice Rx Gain";
-    int values[VOLUME_CTL_PARAM_NUM];
-    int ret = 0;
+    int vol_index = 0;
+    uint32_t set_values[ ] = {0,
+                              ALL_SESSION_VSID,
+                              DEFAULT_VOLUME_RAMP_DURATION_MS};
 
     // Voice volume levels are mapped to adsp volume levels as follows.
     // 100 -> 5, 80 -> 4, 60 -> 3, 40 -> 2, 20 -> 1  0 -> 0
     // But this values don't changed in kernel. So, below change is need.
-    volume = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
+    vol_index = (int)percent_to_index(volume, MIN_VOL_INDEX, MAX_VOL_INDEX);
+    set_values[0] = vol_index;
 
     ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
     if (!ctl) {
@@ -464,16 +471,8 @@
               __func__, mixer_ctl_name);
         return -EINVAL;
     }
-    ret = set_volume_values(VOLUME_SET, volume, values);
-    if (ret < 0) {
-        ALOGV("%s: failed setting volume by incorrect type", __func__);
-        return -EINVAL;
-    }
-    ret = mixer_ctl_set_array(ctl, values, sizeof(values)/sizeof(int));
-    if (ret < 0) {
-        ALOGV("%s: failed set mixer ctl by %d", __func__, ret);
-        return -EINVAL;
-    }
+    ALOGV("Setting voice volume index: %d", set_values[0]);
+    mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
 
     return 0;
 }
@@ -484,27 +483,20 @@
     struct audio_device *adev = my_data->adev;
     struct mixer_ctl *ctl;
     const char *mixer_ctl_name = "Voice Tx Mute";
-    int values[VOLUME_CTL_PARAM_NUM];
-    int ret = 0;
+    uint32_t set_values[ ] = {0,
+                              ALL_SESSION_VSID,
+                              DEFAULT_VOLUME_RAMP_DURATION_MS};
 
     if (adev->mode == AUDIO_MODE_IN_CALL) {
+        set_values[0] = state;
         ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
         if (!ctl) {
             ALOGE("%s: Could not get ctl for mixer cmd - %s",
                   __func__, mixer_ctl_name);
             return -EINVAL;
         }
-        ALOGV("Setting mic mute: %d", state);
-        ret = set_volume_values(MUTE_SET, state, values);
-        if (ret < 0) {
-            ALOGV("%s: failed setting mute by incorrect type", __func__);
-            return -EINVAL;
-        }
-        ret = mixer_ctl_set_array(ctl, values, sizeof(values)/sizeof(int));
-        if (ret < 0) {
-            ALOGV("%s: failed set mixer ctl by %d", __func__, ret);
-            return -EINVAL;
-        }
+        ALOGV("Setting voice mute state: %d", state);
+        mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
     }
 
     return 0;
@@ -536,22 +528,25 @@
     if (mode == AUDIO_MODE_IN_CALL) {
         if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
             devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
-            if (adev->tty_mode == TTY_MODE_FULL)
+            if (adev->voice.tty_mode == TTY_MODE_FULL) {
                 snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES;
-            else if (adev->tty_mode == TTY_MODE_VCO)
+            } else if (adev->voice.tty_mode == TTY_MODE_VCO) {
                 snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES;
-            else if (adev->tty_mode == TTY_MODE_HCO)
+            } else if (adev->voice.tty_mode == TTY_MODE_HCO) {
                 snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET;
-            else if (audio_extn_get_anc_enabled()) {
+            } else if (audio_extn_get_anc_enabled()) {
                 if (audio_extn_should_use_fb_anc())
                     snd_device = SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET;
                 else
                     snd_device = SND_DEVICE_OUT_VOICE_ANC_HEADSET;
-           }
-            else
+            } else {
                 snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
+            }
         } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
-            snd_device = SND_DEVICE_OUT_BT_SCO;
+            if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
+                snd_device = SND_DEVICE_OUT_BT_SCO_WB;
+            else
+                snd_device = SND_DEVICE_OUT_BT_SCO;
         } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
             snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
         } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
@@ -613,7 +608,10 @@
         else
             snd_device = SND_DEVICE_OUT_SPEAKER;
     } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) {
-        snd_device = SND_DEVICE_OUT_BT_SCO;
+        if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
+            snd_device = SND_DEVICE_OUT_BT_SCO_WB;
+        else
+            snd_device = SND_DEVICE_OUT_BT_SCO;
     } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
         snd_device = SND_DEVICE_OUT_HDMI ;
     } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
@@ -651,10 +649,10 @@
             ALOGE("%s: No output device set for voice call", __func__);
             goto exit;
         }
-        if (adev->tty_mode != TTY_MODE_OFF) {
+        if (adev->voice.tty_mode != TTY_MODE_OFF) {
             if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
                 out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
-                switch (adev->tty_mode) {
+                switch (adev->voice.tty_mode) {
                 case TTY_MODE_FULL:
                     snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC;
                     break;
@@ -665,7 +663,8 @@
                     snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC;
                     break;
                 default:
-                    ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode);
+                    ALOGE("%s: Invalid TTY mode (%#x)",
+                          __func__, adev->voice.tty_mode);
                 }
                 goto exit;
             }
@@ -688,7 +687,10 @@
         } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
             snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
         } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
-            snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
+            if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
+                snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
+            else
+                snd_device = SND_DEVICE_IN_BT_SCO_MIC;
         } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) {
             if (my_data->fluence_type != FLUENCE_NONE &&
                 my_data->fluence_in_voice_call &&
@@ -760,7 +762,10 @@
         } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
             snd_device = SND_DEVICE_IN_HEADSET_MIC;
         } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) {
-            snd_device = SND_DEVICE_IN_BT_SCO_MIC ;
+            if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
+                snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
+            else
+                snd_device = SND_DEVICE_IN_BT_SCO_MIC;
         } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
             snd_device = SND_DEVICE_IN_HDMI_MIC;
         } else if (in_device & AUDIO_DEVICE_IN_FM_RX) {
@@ -780,7 +785,10 @@
         } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) {
             snd_device = SND_DEVICE_IN_HANDSET_MIC;
         } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) {
-            snd_device = SND_DEVICE_IN_BT_SCO_MIC;
+            if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
+                snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
+            else
+                snd_device = SND_DEVICE_IN_BT_SCO_MIC;
         } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
             snd_device = SND_DEVICE_IN_HDMI_MIC;
         } else {
@@ -882,3 +890,89 @@
 
     return max_channels;
 }
+
+static int platform_set_slowtalk(struct platform_data *my_data, bool state)
+{
+    int ret = 0;
+    struct audio_device *adev = my_data->adev;
+    struct mixer_ctl *ctl;
+    const char *mixer_ctl_name = "Slowtalk Enable";
+    uint32_t set_values[ ] = {0,
+                              ALL_SESSION_VSID};
+
+    set_values[0] = state;
+    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+    if (!ctl) {
+        ALOGE("%s: Could not get ctl for mixer cmd - %s",
+              __func__, mixer_ctl_name);
+        ret = -EINVAL;
+    } else {
+        ALOGV("Setting slowtalk state: %d", state);
+        ret = mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
+        my_data->slowtalk = state;
+    }
+
+    return ret;
+}
+
+int platform_set_parameters(void *platform, struct str_parms *parms)
+{
+    struct platform_data *my_data = (struct platform_data *)platform;
+    char *str;
+    char value[32];
+    int val;
+    int ret = 0;
+
+    ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
+
+    ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_BTSCO, &val);
+    if (ret >= 0) {
+        str_parms_del(parms, AUDIO_PARAMETER_KEY_BTSCO);
+        pthread_mutex_lock(&my_data->adev->lock);
+        my_data->btsco_sample_rate = val;
+        pthread_mutex_unlock(&my_data->adev->lock);
+    }
+
+    ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_SLOWTALK, &val);
+    if (ret >= 0) {
+        str_parms_del(parms, AUDIO_PARAMETER_KEY_SLOWTALK);
+        pthread_mutex_lock(&my_data->adev->lock);
+        ret = platform_set_slowtalk(my_data, val);
+        if (ret)
+            ALOGE("%s: Failed to set slow talk err: %d", __func__, ret);
+        pthread_mutex_unlock(&my_data->adev->lock);
+    }
+
+    ALOGV("%s: exit with code(%d)", __func__, ret);
+    return ret;
+}
+
+void platform_get_parameters(void *platform,
+                            struct str_parms *query,
+                            struct str_parms *reply)
+{
+    struct platform_data *my_data = (struct platform_data *)platform;
+    char *str = NULL;
+    char value[256] = {0};
+    int ret;
+    int fluence_type;
+
+    ret = str_parms_get_str(query, AUDIO_PARAMETER_KEY_FLUENCE_TYPE,
+                            value, sizeof(value));
+    if (ret >= 0) {
+        pthread_mutex_lock(&my_data->adev->lock);
+        if (my_data->fluence_type == FLUENCE_QUAD_MIC) {
+            strlcpy(value, "fluencepro", sizeof(value));
+        } else if (my_data->fluence_type == FLUENCE_DUAL_MIC) {
+            strlcpy(value, "fluence", sizeof(value));
+        } else {
+            strlcpy(value, "none", sizeof(value));
+        }
+        pthread_mutex_unlock(&my_data->adev->lock);
+
+        str_parms_add_str(reply, AUDIO_PARAMETER_KEY_FLUENCE_TYPE, value);
+    }
+
+    ALOGV("%s: exit: returns - %s", __func__, str_parms_to_str(reply));
+}
+
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index 1bc4fc4..dd8dfda 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -56,6 +56,7 @@
     SND_DEVICE_OUT_HDMI,
     SND_DEVICE_OUT_SPEAKER_AND_HDMI,
     SND_DEVICE_OUT_BT_SCO,
+    SND_DEVICE_OUT_BT_SCO_WB,
     SND_DEVICE_OUT_VOICE_HANDSET_TMUS,
     SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES,
     SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES,
@@ -85,6 +86,7 @@
     SND_DEVICE_IN_VOICE_HEADSET_MIC,
     SND_DEVICE_IN_HDMI_MIC,
     SND_DEVICE_IN_BT_SCO_MIC,
+    SND_DEVICE_IN_BT_SCO_MIC_WB,
     SND_DEVICE_IN_CAMCORDER_MIC,
     SND_DEVICE_IN_VOICE_DMIC,
     SND_DEVICE_IN_VOICE_DMIC_TMUS,
@@ -109,12 +111,9 @@
 
 #define DEFAULT_OUTPUT_SAMPLING_RATE 48000
 
-#define ALL_SESSION_VSID    0xFFFFFFFF
+#define ALL_SESSION_VSID                0xFFFFFFFF
 #define DEFAULT_MUTE_RAMP_DURATION      500
 #define DEFAULT_VOLUME_RAMP_DURATION_MS 20
-#define VOLUME_SET 0
-#define MUTE_SET 1
-#define VOLUME_CTL_PARAM_NUM 3
 #define MIXER_PATH_MAX_LENGTH 100
 
 /*
@@ -144,6 +143,16 @@
 #define FM_PLAYBACK_PCM_DEVICE 5
 #define FM_CAPTURE_PCM_DEVICE  6
 
+#ifdef PLATFORM_MSM8x26
+#define VOICE2_CALL_PCM_DEVICE 14
+#define VOLTE_CALL_PCM_DEVICE 17
+#define QCHAT_CALL_PCM_DEVICE 18
+#else
+#define VOICE2_CALL_PCM_DEVICE 13
+#define VOLTE_CALL_PCM_DEVICE 14
+#define QCHAT_CALL_PCM_DEVICE 20
+#endif
+
 #ifdef PLATFORM_MSM8610
 #define LOWLATENCY_PCM_DEVICE 12
 #else
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 2362a5b..b1d0420 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -1,4 +1,7 @@
 /*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a contribution.
+ *
  * Copyright (C) 2013 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,5 +38,9 @@
 snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device);
 int platform_set_hdmi_channels(void *platform, int channel_count);
 int platform_edid_get_max_channels(void *platform);
+void platform_get_parameters(void *platform, struct str_parms *query,
+                             struct str_parms *reply);
+int platform_set_parameters(void *platform, struct str_parms *parms);
+
 
 #endif // QCOM_AUDIO_PLATFORM_API_H
diff --git a/hal/voice.c b/hal/voice.c
new file mode 100644
index 0000000..2b1ac87
--- /dev/null
+++ b/hal/voice.c
@@ -0,0 +1,337 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a contribution.
+ *
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "voice"
+/*#define LOG_NDEBUG 0*/
+#define LOG_NDDEBUG 0
+
+#include <errno.h>
+#include <math.h>
+#include <cutils/log.h>
+#include <cutils/str_parms.h>
+
+#include "audio_hw.h"
+#include "voice.h"
+#include "voice_extn/voice_extn.h"
+#include "platform.h"
+#include "platform_api.h"
+
+struct pcm_config pcm_config_voice_call = {
+    .channels = 1,
+    .rate = 8000,
+    .period_size = 160,
+    .period_count = 2,
+    .format = PCM_FORMAT_S16_LE,
+};
+
+extern struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
+                                                   audio_usecase_t uc_id);
+extern int disable_snd_device(struct audio_device *adev,
+                              snd_device_t snd_device,
+                              bool update_mixer);
+extern int disable_audio_route(struct audio_device *adev,
+                               struct audio_usecase *usecase,
+                               bool update_mixer);
+
+extern int disable_snd_device(struct audio_device *adev,
+                              snd_device_t snd_device,
+                              bool update_mixer);
+extern int select_devices(struct audio_device *adev,
+                          audio_usecase_t uc_id);
+
+static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev,
+                              audio_usecase_t usecase_id)
+{
+    struct voice_session *session = NULL;
+    int ret = 0;
+
+    ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session);
+    if (ret == -ENOSYS) {
+        session = &adev->voice.session[VOICE_SESS_IDX];
+    }
+
+    return session;
+}
+
+int stop_call(struct audio_device *adev, audio_usecase_t usecase_id)
+{
+    int i, ret = 0;
+    struct audio_usecase *uc_info;
+    struct voice_session *session = NULL;
+
+    ALOGD("%s: enter", __func__);
+
+    session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
+    session->state.current = CALL_INACTIVE;
+
+    ret = platform_stop_voice_call(adev->platform);
+
+    /* 1. Close the PCM devices */
+    if (session->pcm_rx) {
+        pcm_close(session->pcm_rx);
+        session->pcm_rx = NULL;
+    }
+    if (session->pcm_tx) {
+        pcm_close(session->pcm_tx);
+        session->pcm_tx = NULL;
+    }
+
+    uc_info = get_usecase_from_list(adev, usecase_id);
+    if (uc_info == NULL) {
+        ALOGE("%s: Could not find the usecase (%d) in the list",
+              __func__, usecase_id);
+        return -EINVAL;
+    }
+
+    /* 2. Get and set stream specific mixer controls */
+    disable_audio_route(adev, uc_info, true);
+
+    /* 3. Disable the rx and tx devices */
+    disable_snd_device(adev, uc_info->out_snd_device, false);
+    disable_snd_device(adev, uc_info->in_snd_device, true);
+
+    list_remove(&uc_info->list);
+    free(uc_info);
+
+    ALOGD("%s: exit: status(%d)", __func__, ret);
+    return ret;
+}
+
+int start_call(struct audio_device *adev, audio_usecase_t usecase_id)
+{
+    int i, ret = 0;
+    struct audio_usecase *uc_info;
+    int pcm_dev_rx_id, pcm_dev_tx_id;
+    struct voice_session *session = NULL;
+
+    ALOGD("%s: enter", __func__);
+
+    session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id);
+
+    uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
+    uc_info->id = usecase_id;
+    uc_info->type = VOICE_CALL;
+    uc_info->stream.out = adev->primary_output;
+    uc_info->devices = adev->primary_output->devices;
+    uc_info->in_snd_device = SND_DEVICE_NONE;
+    uc_info->out_snd_device = SND_DEVICE_NONE;
+
+    list_add_tail(&adev->usecase_list, &uc_info->list);
+
+    select_devices(adev, usecase_id);
+
+    pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK);
+    pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE);
+
+    if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) {
+        ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)",
+              __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id);
+        ret = -EIO;
+        goto error_start_voice;
+    }
+
+    ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
+          __func__, SOUND_CARD, pcm_dev_rx_id);
+    session->pcm_rx = pcm_open(SOUND_CARD,
+                               pcm_dev_rx_id,
+                               PCM_OUT, &pcm_config_voice_call);
+    if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) {
+        ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx));
+        ret = -EIO;
+        goto error_start_voice;
+    }
+
+    ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)",
+          __func__, SOUND_CARD, pcm_dev_tx_id);
+    session->pcm_tx = pcm_open(SOUND_CARD,
+                               pcm_dev_tx_id,
+                               PCM_IN, &pcm_config_voice_call);
+    if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) {
+        ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx));
+        ret = -EIO;
+        goto error_start_voice;
+    }
+    pcm_start(session->pcm_rx);
+    pcm_start(session->pcm_tx);
+
+    ret = platform_start_voice_call(adev->platform);
+    if (ret < 0) {
+        ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
+        goto error_start_voice;
+    }
+
+    session->state.current = CALL_ACTIVE;
+    return 0;
+
+error_start_voice:
+    stop_call(adev, usecase_id);
+
+    ALOGD("%s: exit: status(%d)", __func__, ret);
+    return ret;
+}
+
+bool voice_is_in_call(struct audio_device *adev)
+{
+    bool in_call = false;
+    int ret = 0;
+
+    ret = voice_extn_is_in_call(adev, &in_call);
+    if (ret == -ENOSYS) {
+        in_call = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false;
+    }
+
+    return in_call;
+}
+
+int voice_set_mic_mute(struct audio_device *adev, bool state)
+{
+    int err = 0;
+
+    pthread_mutex_lock(&adev->lock);
+
+    err = platform_set_mic_mute(adev->platform, state);
+    if (!err) {
+        adev->voice.mic_mute = state;
+    }
+
+    pthread_mutex_unlock(&adev->lock);
+    return err;
+}
+
+bool voice_get_mic_mute(struct audio_device *adev)
+{
+    return adev->voice.mic_mute;
+}
+
+int voice_set_volume(struct audio_device *adev, float volume)
+{
+    int vol, err = 0;
+
+    pthread_mutex_lock(&adev->lock);
+    if (adev->mode == AUDIO_MODE_IN_CALL) {
+        if (volume < 0.0) {
+            volume = 0.0;
+        } else if (volume > 1.0) {
+            volume = 1.0;
+        }
+
+        vol = lrint(volume * 100.0);
+
+        // Voice volume levels from android are mapped to driver volume levels as follows.
+        // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0
+        // So adjust the volume to get the correct volume index in driver
+        vol = 100 - vol;
+
+        err = platform_set_voice_volume(adev->platform, vol);
+        if (!err) {
+            adev->voice.volume = volume;
+        }
+    }
+    pthread_mutex_unlock(&adev->lock);
+    return err;
+}
+
+int voice_start_call(struct audio_device *adev)
+{
+    int ret = 0;
+
+    ret = voice_extn_update_calls(adev);
+    if (ret == -ENOSYS) {
+        ret = start_call(adev, USECASE_VOICE_CALL);
+    }
+
+    return ret;
+}
+
+int voice_stop_call(struct audio_device *adev)
+{
+    int ret = 0;
+
+    ret = voice_extn_update_calls(adev);
+    if (ret == -ENOSYS) {
+        ret = stop_call(adev, USECASE_VOICE_CALL);
+    }
+
+    return ret;
+}
+
+int voice_set_parameters(struct audio_device *adev, struct str_parms *parms)
+{
+    char *str;
+    char value[32];
+    int val;
+    int ret = 0;
+
+    ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
+
+    voice_extn_set_parameters(adev, parms);
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value));
+    if (ret >= 0) {
+        int tty_mode;
+        str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE);
+        if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0)
+            tty_mode = TTY_MODE_OFF;
+        else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0)
+            tty_mode = TTY_MODE_VCO;
+        else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0)
+            tty_mode = TTY_MODE_HCO;
+        else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0)
+            tty_mode = TTY_MODE_FULL;
+        else {
+            ret = -EINVAL;
+            goto done;
+        }
+
+        pthread_mutex_lock(&adev->lock);
+        if (tty_mode != adev->voice.tty_mode) {
+            adev->voice.tty_mode = tty_mode;
+            adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode;
+            if (voice_is_in_call(adev))
+                //todo: what about voice2, volte and qchat usecases?
+                select_devices(adev, USECASE_VOICE_CALL);
+        }
+        pthread_mutex_unlock(&adev->lock);
+    }
+
+done:
+    ALOGV("%s: exit with code(%d)", __func__, ret);
+    return ret;
+}
+
+void voice_init(struct audio_device *adev)
+{
+    int i = 0;
+
+    memset(&adev->voice, 0, sizeof(adev->voice));
+    adev->voice.tty_mode = TTY_MODE_OFF;
+    adev->voice.volume = 1.0f;
+    adev->voice.mic_mute = false;
+    for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
+        adev->voice.session[i].pcm_rx = NULL;
+        adev->voice.session[i].pcm_tx = NULL;
+        adev->voice.session[i].state.current = CALL_INACTIVE;
+        adev->voice.session[i].state.new = CALL_INACTIVE;
+        adev->voice.session[i].vsid = 0;
+    }
+
+    voice_extn_init(adev);
+}
+
+
diff --git a/hal/voice.h b/hal/voice.h
new file mode 100644
index 0000000..22c359d
--- /dev/null
+++ b/hal/voice.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a contribution.
+ *
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef VOICE_H
+#define VOICE_H
+
+#define BASE_SESS_IDX       0
+#define VOICE_SESS_IDX     (BASE_SESS_IDX)
+
+#ifdef MULTI_VOICE_SESSION_ENABLED
+#define MAX_VOICE_SESSIONS 4
+#else
+#define MAX_VOICE_SESSIONS 1
+#endif
+
+#define BASE_CALL_STATE     1
+#define CALL_INACTIVE       (BASE_CALL_STATE)
+#define CALL_ACTIVE         (BASE_CALL_STATE + 1)
+
+#define VOICE_VSID  0x10C01000
+
+struct audio_device;
+struct str_parms;
+
+struct call_state {
+    int current;
+    int new;
+};
+
+struct voice_session {
+    struct pcm *pcm_rx;
+    struct pcm *pcm_tx;
+    struct call_state state;
+    uint32_t vsid;
+};
+
+struct voice {
+    struct voice_session session[MAX_VOICE_SESSIONS];
+    int tty_mode;
+    bool mic_mute;
+    float volume;
+};
+
+int voice_start_call(struct audio_device *adev);
+int voice_stop_call(struct audio_device *adev);
+int voice_set_parameters(struct audio_device *adev, struct str_parms *parms);
+void voice_init(struct audio_device *adev);
+bool voice_is_in_call(struct audio_device *adev);
+int voice_set_mic_mute(struct audio_device *dev, bool state);
+bool voice_get_mic_mute(struct audio_device *dev);
+int voice_set_volume(struct audio_device *adev, float volume);
+#endif //VOICE_H
diff --git a/hal/voice_extn/voice_extn.c b/hal/voice_extn/voice_extn.c
new file mode 100644
index 0000000..ac3d9f2
--- /dev/null
+++ b/hal/voice_extn/voice_extn.c
@@ -0,0 +1,367 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a contribution.
+ *
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef MULTI_VOICE_SESSION_ENABLED
+
+#define LOG_TAG "voice_extn"
+/*#define LOG_NDEBUG 0*/
+#define LOG_NDDEBUG 0
+
+#include <errno.h>
+#include <math.h>
+#include <cutils/log.h>
+#include <cutils/str_parms.h>
+#include <sys/ioctl.h>
+#include <sound/voice_params.h>
+
+#include "audio_hw.h"
+#include "voice.h"
+#include "platform.h"
+#include "platform_api.h"
+
+#define AUDIO_PARAMETER_KEY_VSID        "vsid"
+#define AUDIO_PARAMETER_KEY_CALL_STATE  "call_state"
+
+#define VOICE2_VSID 0x10DC1000
+#define VOLTE_VSID  0x10C02000
+#define QCHAT_VSID  0x10803000
+#define ALL_VSID    0xFFFFFFFF
+
+/* Voice Session Indices */
+#define VOICE2_SESS_IDX    (VOICE_SESS_IDX + 1)
+#define VOLTE_SESS_IDX     (VOICE_SESS_IDX + 2)
+#define QCHAT_SESS_IDX     (VOICE_SESS_IDX + 3)
+
+/* Call States */
+#define CALL_HOLD           (BASE_CALL_STATE + 2)
+#define CALL_LOCAL_HOLD     (BASE_CALL_STATE + 3)
+
+extern int start_call(struct audio_device *adev, audio_usecase_t usecase_id);
+extern int stop_call(struct audio_device *adev, audio_usecase_t usecase_id);
+int voice_extn_update_calls(struct audio_device *adev);
+
+static bool is_valid_call_state(int call_state)
+{
+    if (call_state < CALL_INACTIVE || call_state > CALL_LOCAL_HOLD)
+        return false;
+    else
+        return true;
+}
+
+static bool is_valid_vsid(uint32_t vsid)
+{
+    if (vsid == VOICE_VSID ||
+        vsid == VOICE2_VSID ||
+        vsid == VOLTE_VSID ||
+        vsid == QCHAT_VSID)
+        return true;
+    else
+        return false;
+}
+
+static audio_usecase_t voice_extn_get_usecase_for_session_idx(const int index)
+{
+    audio_usecase_t usecase_id = -1;
+
+    switch(index) {
+    case VOICE_SESS_IDX:
+        usecase_id = USECASE_VOICE_CALL;
+        break;
+
+    case VOICE2_SESS_IDX:
+        usecase_id = USECASE_VOICE2_CALL;
+        break;
+
+    case VOLTE_SESS_IDX:
+        usecase_id = USECASE_VOLTE_CALL;
+        break;
+
+    case QCHAT_SESS_IDX:
+        usecase_id = USECASE_QCHAT_CALL;
+        break;
+
+    default:
+        ALOGE("%s: Invalid voice session index\n", __func__);
+    }
+
+    return usecase_id;
+}
+
+int voice_extn_is_in_call(struct audio_device *adev, bool *in_call)
+{
+    struct voice_session *session = NULL;
+    int i = 0;
+    *in_call = false;
+
+    for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
+        session = &adev->voice.session[i];
+        if(session->state.current != CALL_INACTIVE){
+            *in_call = true;
+            break;
+        }
+    }
+
+    return 0;
+}
+
+static int voice_extn_update_call_states(struct audio_device *adev,
+                                    const uint32_t vsid, const int call_state)
+{
+    struct voice_session *session = NULL;
+    int i = 0;
+    bool is_in_call;
+
+    for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
+        if (vsid == adev->voice.session[i].vsid) {
+            session = &adev->voice.session[i];
+            break;
+        }
+    }
+
+    if (session) {
+        session->state.new = call_state;
+        voice_extn_is_in_call(adev, &is_in_call);
+        if (is_in_call || adev->mode == AUDIO_MODE_IN_CALL) {
+            /* Device routing is not triggered for voice calls on the subsequent
+             * subs, Hence update the call states if voice call is already
+             * active on other sub.
+             */
+            voice_extn_update_calls(adev);
+        }
+    } else {
+        return -EINVAL;
+    }
+
+    return 0;
+
+}
+
+void voice_extn_init(struct audio_device *adev)
+{
+    adev->voice.session[VOICE_SESS_IDX].vsid =  VOICE_VSID;
+    adev->voice.session[VOICE2_SESS_IDX].vsid = VOICE2_VSID;
+    adev->voice.session[VOLTE_SESS_IDX].vsid =  VOLTE_VSID;
+    adev->voice.session[QCHAT_SESS_IDX].vsid =  QCHAT_VSID;
+}
+
+int voice_extn_get_session_from_use_case(struct audio_device *adev,
+                                               const audio_usecase_t usecase_id,
+                                               struct voice_session **session)
+{
+
+    switch(usecase_id)
+    {
+    case USECASE_VOICE_CALL:
+        *session = &adev->voice.session[VOICE_SESS_IDX];
+        break;
+
+    case USECASE_VOICE2_CALL:
+        *session = &adev->voice.session[VOICE2_SESS_IDX];
+        break;
+
+    case USECASE_VOLTE_CALL:
+        *session = &adev->voice.session[VOLTE_SESS_IDX];
+        break;
+
+    case USECASE_QCHAT_CALL:
+        *session = &adev->voice.session[QCHAT_SESS_IDX];
+        break;
+
+    default:
+        ALOGE("%s: Invalid usecase_id:%d\n", __func__, usecase_id);
+        *session = NULL;
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+int voice_extn_update_calls(struct audio_device *adev)
+{
+    int i = 0;
+    audio_usecase_t usecase_id = 0;
+    enum voice_lch_mode lch_mode;
+    struct voice_session *session = NULL;
+    int fd = 0;
+    int ret = 0;
+
+    ALOGD("%s: enter:", __func__);
+
+    for (i = 0; i < MAX_VOICE_SESSIONS; i++) {
+        usecase_id = voice_extn_get_usecase_for_session_idx(i);
+        session = &adev->voice.session[i];
+        ALOGV("%s: cur_state=%d new_state=%d vsid=%x",
+              __func__, session->state.current, session->state.new, session->vsid);
+
+        switch(session->state.new)
+        {
+        case CALL_ACTIVE:
+            switch(session->state.current)
+            {
+            case CALL_INACTIVE:
+                ALOGD("%s: INACTIVE ->ACTIVE vsid:%x", __func__, session->vsid);
+                ret = start_call(adev, usecase_id);
+                if(ret < 0) {
+                    ALOGE("%s: voice_start_call() failed for usecase: %d\n",
+                          __func__, usecase_id);
+                }
+                session->state.current = session->state.new;
+                break;
+
+            case CALL_HOLD:
+                ALOGD("%s: HOLD ->ACTIVE vsid:%x", __func__, session->vsid);
+                session->state.current = session->state.new;
+                break;
+
+            case CALL_LOCAL_HOLD:
+                ALOGD("%s: LOCAL_HOLD ->ACTIVE vsid:%x", __func__, session->vsid);
+                lch_mode = VOICE_LCH_STOP;
+                if (pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode) < 0) {
+                    ALOGE("LOCAL_HOLD ->ACTIVE failed");
+                } else {
+                    session->state.current = session->state.new;
+                }
+                break;
+
+            default:
+                ALOGV("%s: CALL_ACTIVE cannot be handled in state=%d vsid:%x",
+                      __func__, session->state.current, session->vsid);
+                break;
+            }
+            break;
+
+        case CALL_INACTIVE:
+            switch(session->state.current)
+            {
+            case CALL_ACTIVE:
+            case CALL_HOLD:
+            case CALL_LOCAL_HOLD:
+                ALOGD("%s: ACTIVE/HOLD/LOCAL_HOLD ->INACTIVE vsid:%x", __func__, session->vsid);
+                ret = stop_call(adev, usecase_id);
+                if(ret < 0) {
+                    ALOGE("%s: voice_end_call() failed for usecase: %d\n",
+                          __func__, usecase_id);
+                }
+                session->state.current = session->state.new;
+                break;
+
+            default:
+                ALOGV("%s: CALL_INACTIVE cannot be handled in state=%d vsid:%x",
+                      __func__, session->state.current, session->vsid);
+                break;
+            }
+            break;
+
+        case CALL_HOLD:
+            switch(session->state.current)
+            {
+            case CALL_ACTIVE:
+                ALOGD("%s: CALL_ACTIVE ->HOLD vsid:%x", __func__, session->vsid);
+                session->state.current = session->state.new;
+                break;
+
+            case CALL_LOCAL_HOLD:
+                ALOGD("%s: CALL_LOCAL_HOLD ->HOLD vsid:%x", __func__, session->vsid);
+                lch_mode = VOICE_LCH_STOP;
+                if (pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode) < 0) {
+                    ALOGE("LOCAL_HOLD ->HOLD failed");
+                } else {
+                    session->state.current = session->state.new;
+                }
+                break;
+
+            default:
+                ALOGV("%s: CALL_HOLD cannot be handled in state=%d vsid:%x",
+                      __func__, session->state.current, session->vsid);
+                break;
+            }
+            break;
+
+        case CALL_LOCAL_HOLD:
+            switch(session->state.current)
+            {
+            case CALL_ACTIVE:
+            case CALL_HOLD:
+                ALOGD("%s: ACTIVE/CALL_HOLD ->LOCAL_HOLD vsid:%x", __func__, session->vsid);
+                lch_mode = VOICE_LCH_START;
+                if (pcm_ioctl(session->pcm_tx, SNDRV_VOICE_IOCTL_LCH, &lch_mode) < 0) {
+                    ALOGE("LOCAL_HOLD ->HOLD failed");
+                } else {
+                    session->state.current = session->state.new;
+                }
+                break;
+
+            default:
+                ALOGV("%s: CALL_LOCAL_HOLD cannot be handled in state=%d vsid:%x",
+                      __func__, session->state.current, session->vsid);
+                break;
+            }
+            break;
+
+        default:
+            break;
+        } //end out switch loop
+    } //end for loop
+
+    return ret;
+}
+
+int voice_extn_set_parameters(struct audio_device *adev,
+                              struct str_parms *parms)
+{
+    char *str;
+    int value;
+    int ret = 0;
+
+    ALOGV("%s: enter: %s", __func__, str_parms_to_str(parms));
+
+    ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_VSID, &value);
+    if (ret >= 0) {
+        str_parms_del(parms, AUDIO_PARAMETER_KEY_VSID);
+        int vsid = value;
+        int call_state = -1;
+        ret = str_parms_get_int(parms, AUDIO_PARAMETER_KEY_CALL_STATE, &value);
+        if (ret >= 0) {
+            call_state = value;
+            //validate callstate
+        } else {
+            ALOGE("%s: call_state key not found", __func__);
+            ret = -EINVAL;
+            goto done;
+        }
+
+        if (is_valid_vsid(vsid) && is_valid_call_state(call_state)) {
+            pthread_mutex_lock(&adev->lock);
+            voice_extn_update_call_states(adev, vsid, call_state);
+            pthread_mutex_unlock(&adev->lock);
+        } else {
+            ALOGE("%s: invalid vsid or call_state", __func__);
+            ret = -EINVAL;
+            goto done;
+        }
+    } else {
+        ALOGD("%s: Not handled here", __func__);
+    }
+
+done:
+    ALOGV("%s: exit with code(%d)", __func__, ret);
+    return ret;
+}
+
+#endif
diff --git a/hal/voice_extn/voice_extn.h b/hal/voice_extn/voice_extn.h
new file mode 100644
index 0000000..ae983e1
--- /dev/null
+++ b/hal/voice_extn/voice_extn.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Not a contribution.
+ *
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef VOICE_EXTN_H
+#define VOICE_EXTN_H
+
+int voice_extn_update_calls(struct audio_device *adev);
+int voice_extn_get_session_from_use_case(struct audio_device *adev,
+                                         const audio_usecase_t usecase_id,
+                                         struct voice_session **session);
+int voice_extn_init(struct audio_device *adev);
+int voice_extn_set_parameters(struct audio_device *adev,
+                              struct str_parms *parms);
+int voice_extn_is_in_call(struct audio_device *adev, bool *in_call);
+
+#ifndef MULTI_VOICE_SESSION_ENABLED
+int voice_extn_update_calls(struct audio_device *adev)
+{
+    return -ENOSYS;
+}
+
+int voice_extn_get_session_from_use_case(struct audio_device *adev,
+                                       const audio_usecase_t usecase_id,
+                                       struct voice_session **session)
+{
+    return -ENOSYS;
+}
+
+int voice_extn_init(struct audio_device *adev)
+{
+    return -ENOSYS;
+}
+
+int  voice_extn_set_parameters(struct audio_device *adev,
+                               struct str_parms *parms)
+{
+    return -ENOSYS;
+}
+
+int voice_extn_is_in_call(struct audio_device *adev, bool *in_call)
+{
+    return -ENOSYS;
+}
+#endif
+
+#endif //VOICE_EXTN_H