Merge "configs: add USB_HEADSET device in policy conf files"
diff --git a/configs/apq8098_latv/apq8098_latv.mk b/configs/apq8098_latv/apq8098_latv.mk
old mode 100755
new mode 100644
index 493d5ce..088f3ed
--- a/configs/apq8098_latv/apq8098_latv.mk
+++ b/configs/apq8098_latv/apq8098_latv.mk
@@ -69,6 +69,7 @@
 AUDIO_FEATURE_ENABLED_RAS := true
 AUDIO_FEATURE_ENABLED_DYNAMIC_LOG := true
 AUDIO_FEATURE_ENABLED_SND_MONITOR := true
+AUDIO_FEATURE_ENABLED_MS12_ARM := true
 ##AUDIO_FEATURE_FLAGS
 
 #Audio Specific device overlays
diff --git a/configs/sdm670/audio_output_policy.conf b/configs/sdm670/audio_output_policy.conf
index 52ef791..d66782e 100644
--- a/configs/sdm670/audio_output_policy.conf
+++ b/configs/sdm670/audio_output_policy.conf
@@ -82,3 +82,37 @@
     app_type 69940
   }
 }
+
+inputs {
+  primary {
+    flags AUDIO_INPUT_FLAG_NONE
+    formats AUDIO_FORMAT_PCM_16_BIT
+    sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000
+    bit_width 16
+    app_type 69938
+  }
+  record_24bit {
+    profile none
+    flags AUDIO_INPUT_FLAG_NONE
+    formats AUDIO_FORMAT_PCM_24_BIT_PACKED
+    sampling_rates 16000|48000
+    bit_width 24
+    app_type 69945
+  }
+  record_fluence1 {
+    flags AUDIO_INPUT_FLAG_COMPRESS
+    profile record_fluence
+    formats AUDIO_FORMAT_PCM_16_BIT
+    sampling_rates 48000
+    bit_width 16
+    app_type 69944
+  }
+  record_fluence {
+    flags AUDIO_INPUT_FLAG_TIMESTAMP
+    profile record_fluence
+    formats AUDIO_FORMAT_PCM_16_BIT
+    sampling_rates 48000
+    bit_width 16
+    app_type 69944
+  }
+}
diff --git a/configs/sdm670/audio_platform_info_intcodec.xml b/configs/sdm670/audio_platform_info_intcodec.xml
index b249102..87ebeb5 100644
--- a/configs/sdm670/audio_platform_info_intcodec.xml
+++ b/configs/sdm670/audio_platform_info_intcodec.xml
@@ -63,6 +63,11 @@
         <usecase name="USECASE_AUDIO_HFP_SCO_WB" type="in" id="12" />
         <usecase name="USECASE_AUDIO_PLAYBACK_VOIP" type="out" id="16" />
         <usecase name="USECASE_AUDIO_RECORD_VOIP" type="in" id="16" />
+        <usecase name="USECASE_AUDIO_RECORD_COMPRESS2" type="in" id="41"/>
+        <usecase name="USECASE_AUDIO_RECORD_COMPRESS3" type="in" id="42"/>
+        <usecase name="USECASE_AUDIO_RECORD_COMPRESS4" type="in" id="43"/>
+        <usecase name="USECASE_AUDIO_RECORD_COMPRESS5" type="in" id="44"/>
+        <usecase name="USECASE_AUDIO_RECORD_COMPRESS6" type="in" id="45"/>
     </pcm_ids>
     <config_params>
         <!-- In the below value string, the value indicates default mono -->
@@ -97,6 +102,7 @@
         <device name="SND_DEVICE_IN_UNPROCESSED_THREE_MIC" acdb_id="145"/>
         <device name="SND_DEVICE_IN_UNPROCESSED_QUAD_MIC" acdb_id="146"/>
         <device name="SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC" acdb_id="147"/>
+        <device name="SND_DEVICE_IN_HANDSET_GENERIC_QMIC" acdb_id="157"/>
     </acdb_ids>
     <backend_names>
         <device name="SND_DEVICE_OUT_HEADPHONES" backend="headphones" interface="INT0_MI2S_RX"/>
@@ -122,6 +128,7 @@
         <device name="SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_1" interface="INT4_MI2S_RX-and-INT0_MI2S_RX"/>
         <device name="SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES_EXTERNAL_2" interface="INT4_MI2S_RX-and-INT0_MI2S_RX"/>
         <device name="SND_DEVICE_OUT_VOICE_HANDSET" interface="INT4_MI2S_RX"/>
+        <device name="SND_DEVICE_IN_HANDSET_GENERIC_QMIC" interface="INT3_MI2S_TX"/>
         <device name="SND_DEVICE_OUT_VOICE_SPEAKER" interface="INT4_MI2S_RX"/>
         <device name="SND_DEVICE_OUT_VOICE_SPEAKER_VBAT" interface="INT4_MI2S_RX"/>
         <device name="SND_DEVICE_OUT_VOICE_SPEAKER_2" interface="INT4_MI2S_RX"/>
diff --git a/configs/sdm670/mixer_paths_mtp.xml b/configs/sdm670/mixer_paths_mtp.xml
index c5d2cf2..efb37b1 100644
--- a/configs/sdm670/mixer_paths_mtp.xml
+++ b/configs/sdm670/mixer_paths_mtp.xml
@@ -373,6 +373,11 @@
     <ctl name="IIR1 INP3 Volume" value="53" />
     <ctl name="IIR1 INP4 Volume" value="53" />
     <ctl name="IIR1 INP1 MUX" value="ZERO" />
+    <ctl name="MultiMedia17 Mixer INT3_MI2S_TX" value="0" />
+    <ctl name="MultiMedia18 Mixer INT3_MI2S_TX" value="0" />
+    <ctl name="MultiMedia19 Mixer INT3_MI2S_TX" value="0" />
+    <ctl name="MultiMedia28 Mixer INT3_MI2S_TX" value="0" />
+    <ctl name="MultiMedia29 Mixer INT3_MI2S_TX" value="0" />
 
     <!-- anc related -->
 
@@ -1270,6 +1275,26 @@
         <ctl name="MultiMedia8 Mixer INT3_MI2S_TX" value="1" />
     </path>
 
+    <path name="audio-record-compress2">
+        <ctl name="MultiMedia17 Mixer INT3_MI2S_TX" value="1" />
+    </path>
+
+    <path name="audio-record-compress3">
+        <ctl name="MultiMedia18 Mixer INT3_MI2S_TX" value="1" />
+    </path>
+
+    <path name="audio-record-compress4">
+        <ctl name="MultiMedia19 Mixer INT3_MI2S_TX" value="1" />
+    </path>
+
+    <path name="audio-record-compress5">
+        <ctl name="MultiMedia28 Mixer INT3_MI2S_TX" value="1" />
+    </path>
+
+    <path name="audio-record-compress6">
+        <ctl name="MultiMedia29 Mixer INT3_MI2S_TX" value="1" />
+    </path>
+
     <path name="audio-record-compress bt-sco">
         <ctl name="MultiMedia8 Mixer SLIM_7_TX" value="1" />
     </path>
diff --git a/configs/sdm670/mixer_paths_skuw.xml b/configs/sdm670/mixer_paths_skuw.xml
index 2b3c8bb..bced57c 100644
--- a/configs/sdm670/mixer_paths_skuw.xml
+++ b/configs/sdm670/mixer_paths_skuw.xml
@@ -2624,4 +2624,25 @@
     <path name="mmap-record usb-headset-mic">
        <ctl name="MultiMedia16 Mixer USB_AUDIO_TX" value="1" />
     </path>
+
+    <path name="hifi-playback display-port">
+        <ctl name="DISPLAY_PORT Mixer MultiMedia2" value="1" />
+    </path>
+
+    <path name="hifi-playback afe-proxy">
+        <ctl name="AFE_PCM_RX Audio Mixer MultiMedia2" value="1" />
+    </path>
+
+    <path name="hifi-playback usb-headset">
+        <ctl name="USB_AUDIO_RX Audio Mixer MultiMedia2" value="1" />
+    </path>
+
+    <path name="hifi-playback usb-headphones">
+        <ctl name="USB_AUDIO_RX Audio Mixer MultiMedia2" value="1" />
+    </path>
+
+    <path name="hifi-record usb-headset-mic">
+        <ctl name="MultiMedia2 Mixer USB_AUDIO_TX" value="1" />
+    </path>
+
 </mixer>
diff --git a/configs/sdm670/sdm670.mk b/configs/sdm670/sdm670.mk
index d34ff01..b939b09 100644
--- a/configs/sdm670/sdm670.mk
+++ b/configs/sdm670/sdm670.mk
@@ -6,6 +6,7 @@
 ifneq ($(TARGET_USES_AOSP_FOR_AUDIO), true)
 USE_CUSTOM_AUDIO_POLICY := 1
 AUDIO_FEATURE_ENABLED_COMPRESS_CAPTURE := false
+AUDIO_FEATURE_ENABLED_COMPRESS_INPUT := true
 AUDIO_FEATURE_ENABLED_COMPRESS_VOIP := false
 AUDIO_FEATURE_ENABLED_DYNAMIC_ECNS := false
 AUDIO_FEATURE_ENABLED_EXTN_FORMATS := true
@@ -140,8 +141,14 @@
 persist.vendor.audio.fluence.voicecall=true\
 persist.vendor.audio.fluence.voicerec=false\
 persist.vendor.audio.fluence.speaker=true\
+persist.vendor.audio.fluence.audiorec=false\
 persist.vendor.audio.fluence.tmic.enabled=false
 
+# Mutlirec Apptype
+PRODUCT_PROPERTY_OVERRIDES += \
+    vendor.audio.apptype.multirec.enabled=false \
+    vendor.audio.record.multiple.enabled=false
+
 ##speaker protection v3 switch and ADSP AFE API version
 PRODUCT_PROPERTY_OVERRIDES += \
 persist.vendor.audio.spv3.enable=true\
diff --git a/configs/sdm670/sound_trigger_platform_info.xml b/configs/sdm670/sound_trigger_platform_info.xml
index b9e36f5..1b8f45a 100644
--- a/configs/sdm670/sound_trigger_platform_info.xml
+++ b/configs/sdm670/sound_trigger_platform_info.xml
@@ -38,8 +38,10 @@
         <!-- Below backend params must match with port used in mixer path file -->
         <!-- param used to configure backend sample rate, format and channels -->
         <param backend_port_name="SLIM_0_TX" />
+        <param backend_port_name="INT3_MI2S_TX" />
         <!-- Param used to match and obtain device backend index -->
         <param backend_dai_name="SLIMBUS_0_TX" />
+        <param backend_dai_name="INT3_MI2S_TX" />
     </common_config>
     <acdb_ids>
         <param DEVICE_HANDSET_MIC_APE="100" />
diff --git a/configs/sdm845/mixer_paths_i2s.xml b/configs/sdm845/mixer_paths_i2s.xml
index 10d5ec5..75d984f 100644
--- a/configs/sdm845/mixer_paths_i2s.xml
+++ b/configs/sdm845/mixer_paths_i2s.xml
@@ -144,11 +144,11 @@
     </path>
 
     <path name="adc2">
+        <ctl name="AIF1_CAP Mixer SLIM TX6" value="1"/>
         <ctl name="MI2S_TX Channels" value="One" />
-        <ctl name="AIF1_CAP Mixer SLIM TX8" value="1"/>
-        <ctl name="SLIM TX8 MUX" value="DEC8" />
-        <ctl name="ADC MUX8" value="AMIC" />
-        <ctl name="AMIC MUX8" value="ADC2" />
+        <ctl name="SLIM TX6 MUX" value="DEC6" />
+        <ctl name="ADC MUX6" value="AMIC" />
+        <ctl name="AMIC MUX6" value="ADC2" />
     </path>
 
     <path name="dmic1">
@@ -159,14 +159,15 @@
     </path>
 
     <path name="speaker">
-        <ctl name="SLIM RX3 MUX" value="AIF1_PB" />
-        <ctl name="SLIM RX4 MUX" value="AIF1_PB" />
-        <ctl name="QUAT_MI2S_RX Channels" value="Two" />
-        <ctl name="RX1 MIX1 INP1" value="RX3" />
-        <ctl name="RX2 MIX1 INP1" value="RX4" />
-        <ctl name="CLASS_H_DSM MUX" value="DSM_HPHL_RX1" />
-        <ctl name="HPHL DAC Switch" value="1" />
-        <ctl name="COMP1 Switch" value="1" />
+        <ctl name="I2S RX0 MUX" value="AIF1_PB" />
+        <ctl name="MI2S_RX Channels" value="One" />
+        <ctl name="CDC_IF RX0 MUX" value="I2S RX0" />
+        <ctl name="RX INT8_1 MIX1 INP0" value="RX0" />
+        <ctl name="COMP8 Switch" value="1" />
+        <ctl name="SpkrRight COMP Switch" value="1" />
+        <ctl name="SpkrRight BOOST Switch" value="1" />
+        <ctl name="SpkrRight VISENSE Switch" value="1" />
+        <ctl name="SpkrRight SWR DAC_Port Switch" value="1" />
     </path>
 
    <path name="sidetone-iir">
@@ -210,11 +211,13 @@
     </path>
 
     <path name="headphones">
-        <ctl name="SLIM RX2 MUX" value="AIF1_PB" />
-        <ctl name="SLIM RX3 MUX" value="AIF1_PB" />
+        <ctl name="I2S RX0 MUX" value="AIF1_PB" />
+        <ctl name="I2S RX1 MUX" value="AIF1_PB" />
+        <ctl name="CDC_IF RX0 MUX" value="I2S RX0" />
+        <ctl name="CDC_IF RX1 MUX" value="I2S RX1" />
         <ctl name="MI2S_RX Channels" value="Two" />
-        <ctl name="RX INT1_1 MIX1 INP0" value="RX2" />
-        <ctl name="RX INT2_1 MIX1 INP0" value="RX3" />
+        <ctl name="RX INT1_2 MUX" value="RX0" />
+        <ctl name="RX INT2_2 MUX" value="RX1" />
         <ctl name="RX INT1 DEM MUX" value="CLSH_DSM_OUT" />
         <ctl name="RX INT2 DEM MUX" value="CLSH_DSM_OUT" />
         <ctl name="COMP1 Switch" value="1" />
diff --git a/configs/sdm845/sound_trigger_mixer_paths_wcd9340.xml b/configs/sdm845/sound_trigger_mixer_paths_wcd9340.xml
index 676ae95..55dd42f 100644
--- a/configs/sdm845/sound_trigger_mixer_paths_wcd9340.xml
+++ b/configs/sdm845/sound_trigger_mixer_paths_wcd9340.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<!--- Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.       -->
+<!--- Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.       -->
 <!---                                                                           -->
 <!--- Redistribution and use in source and binary forms, with or without        -->
 <!--- modification, are permitted provided that the following conditions are    -->
@@ -193,6 +193,21 @@
         <ctl name="MAD_CPE1 Switch" value="1" />
     </path>
 
+    <path name="listen-cpe-handset-dmic">
+        <ctl name="CLK MODE" value="INTERNAL" />
+        <ctl name= "ADC MUX0" value="DMIC" />
+        <ctl name= "DMIC MUX0" value="DMIC2" />
+        <ctl name= "DEC0 Volume" value="84" />
+        <ctl name= "ADC MUX1" value="DMIC" />
+        <ctl name= "DMIC MUX1" value="DMIC0" />
+        <ctl name= "DEC1 Volume" value="84" />
+        <ctl name= "WDMA3 PORT0 MUX" value="DEC0" />
+        <ctl name= "WDMA3 PORT1 MUX" value="DEC1" />
+        <ctl name= "WDMA3 CH0 MUX" value="PORT_0" />
+        <ctl name= "WDMA3 CH1 MUX" value="PORT_1" />
+        <ctl name= "WDMA3_ON_OFF Switch" value="1" />
+    </path>
+
     <path name="listen-cpe-handset-tmic">
         <ctl name="CLK MODE" value="INTERNAL" />
         <ctl name= "ADC MUX0" value="DMIC" />
diff --git a/configs/sdm845/sound_trigger_platform_info.xml b/configs/sdm845/sound_trigger_platform_info.xml
index e1f21a7..b017cc4 100644
--- a/configs/sdm845/sound_trigger_platform_info.xml
+++ b/configs/sdm845/sound_trigger_platform_info.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<!--- Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.       -->
+<!--- Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.       -->
 <!---                                                                           -->
 <!--- Redistribution and use in source and binary forms, with or without        -->
 <!--- modification, are permitted provided that the following conditions are    -->
@@ -26,7 +26,11 @@
 <!--- OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN    -->
 <!--- IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                             -->
 <sound_trigger_platform_info>
-    <param version="0x0101" /> <!-- this must be the first param -->
+    <param version="0x0102" /> <!-- this must be the first param -->
+<!--- Version History:                                                          -->
+<!--- 0x0101: Legacy version.                                                   -->
+<!--- 0x0102: Includes acdb_ids param with the gcs_usecase tag. This matches    -->
+<!--- the gcs_usecase with the acdb device that uses it.                        -->
     <common_config>
         <param max_cpe_sessions="1" />
         <param max_wdsp_sessions="2" />
@@ -50,6 +54,7 @@
         <param DEVICE_HANDSET_QMIC_APE="137" />
         <param DEVICE_HEADSET_MIC_CPE="139" />
         <param DEVICE_HANDSET_DMIC_APE="149" />
+        <param DEVICE_HANDSET_DMIC_CPE="153" />
     </acdb_ids>
     <!-- Multiple sound_model_config tags can be listed, each with unique   -->
     <!-- vendor_uuid. The below tag represents QTI SVA engine sound model   -->
@@ -72,12 +77,13 @@
         <param adm_cfg_profile="NONE" />
         <!-- fluence_type: "FLUENCE", "FLUENCE_DMIC", "FLUENCE_TMIC", -->
         <!-- "FLUENCE_QMIC". param value is valid when adm_cfg_profile="FLUENCE"-->
-        <param fluence_type="FLUENCE_QMIC" />
+        <param fluence_type="FLUENCE_DMIC" />
         <!-- wdsp_fluence_type: fluence disabled: "NONE" -->
         <!-- fluence enabled: "FLUENCE_DMIC", "FLUENCE_TMIC", "FLUENCE_QMIC" -->
         <param wdsp_fluence_type="NONE" />
         <gcs_usecase>
             <param uid="0x1" />
+            <param acdb_devices="DEVICE_HANDSET_MIC_CPE, DEVICE_HANDSET_TMIC_CPE, DEVICE_HEADSET_MIC_CPE" />
             <!-- module_id, instance_id, param_id -->
             <param load_sound_model_ids="0x00012C0D, 0x2, 0x00012C14" />
             <param confidence_levels_ids="0x00012C0D, 0x2, 0x00012C28" />
@@ -88,6 +94,7 @@
         </gcs_usecase>
         <gcs_usecase>
             <param uid="0x2" />
+            <param acdb_devices="DEVICE_HANDSET_MIC_CPE, DEVICE_HANDSET_TMIC_CPE, DEVICE_HEADSET_MIC_CPE" />
             <param load_sound_model_ids="0x00012C0D, 0x3, 0x00012C14" />
             <param confidence_levels_ids="0x00012C0D, 0x3, 0x00012C28" />
             <param detection_event_ids="0x00012C0D, 0x3, 0x00012C29" />
@@ -145,12 +152,13 @@
         <param adm_cfg_profile="NONE" />
         <!-- fluence_type: "FLUENCE", "FLUENCE_DMIC", "FLUENCE_TMIC", -->
         <!-- "FLUENCE_QMIC". param value is valid when adm_cfg_profile="FLUENCE"-->
-        <param fluence_type="FLUENCE_QMIC" />
+        <param fluence_type="FLUENCE_DMIC" />
         <!-- wdsp_fluence_type: fluence disabled: "NONE" -->
         <!-- fluence enabled: "FLUENCE_DMIC", "FLUENCE_TMIC", "FLUENCE_QMIC" -->
         <param wdsp_fluence_type="NONE" />
         <gcs_usecase>
             <param uid="0x3" />
+            <param acdb_devices="DEVICE_HANDSET_MIC_CPE, DEVICE_HANDSET_TMIC_CPE" />
             <param load_sound_model_ids="0x18000001, 0x4, 0x00012C14" />
             <param confidence_levels_ids="0x18000001, 0x4, 0x00012C28" />
             <param detection_event_ids="0x18000001, 0x4, 0x00012C29" />
@@ -158,6 +166,16 @@
             <param read_rsp_ids="0x00020013, 0x4, 0x00020016" />
             <param custom_config_ids="0x18000001, 0x4, 0x00012C20" />
         </gcs_usecase>
+        <gcs_usecase>
+            <param uid="0x4" />
+            <param acdb_devices="DEVICE_HANDSET_DMIC_CPE" />
+            <param load_sound_model_ids="0x18000001, 0x5, 0x00012C14" />
+            <param confidence_levels_ids="0x18000001, 0x5, 0x00012C28" />
+            <param detection_event_ids="0x18000001, 0x5, 0x00012C29" />
+            <param read_cmd_ids="0x00020013, 0x5, 0x00020015" />
+            <param read_rsp_ids="0x00020013, 0x5, 0x00020016" />
+            <param custom_config_ids="0x18000001, 0x5, 0x00012C20" />
+        </gcs_usecase>
         <!-- Module and param ids with which the algorithm is integrated
             in non-graphite firmware (note these must come after gcs params)
             Extends flexibility to have different ids based on execution type.
@@ -205,6 +223,13 @@
         <param bit_width="16" />
     </adm_config>
 
+    <adm_config>
+        <param adm_cfg_profile="FLUENCE_STEREO" />
+        <param app_type="69948" />
+        <param sample_rate="16000" />
+        <param bit_width="16" />
+    </adm_config>
+
     <!-- backend_type tag defines backend type for each device -->
     <!-- Default value is assumed for devices that are not listed here -->
     <backend_type>
diff --git a/configure.ac b/configure.ac
index 805d00c..c3c0e34 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,6 +73,10 @@
          AC_SUBST([TARGET_PLATFORM], ["msm8974"])
          TARGET_CFLAGS="-DPLATFORM_MSM8998"
 fi
+if (test x$TARGET_SUPPORT = xsdxpoorwills); then
+         AC_SUBST([TARGET_PLATFORM], ["msm8974"])
+         TARGET_CFLAGS="-DPLATFORM_SDX24"
+fi
 AC_SUBST([TARGET_CFLAGS])
 
 AM_CONDITIONAL([QTI_AUDIO_SERVER_ENABLED],[test x$BOARD_SUPPORTS_QTI_AUDIO_SERVER = xtrue])
@@ -117,6 +121,7 @@
 AM_CONDITIONAL([DTSHD_PARSER], [test x$AUDIO_FEATURE_ENABLED_DTSHD_PARSER = xtrue])
 AM_CONDITIONAL([QAP], [test x$AUDIO_FEATURE_ENABLED_QAP = xtrue])
 AM_CONDITIONAL([AUDIO_HW_FFV], [test x$AUDIO_FEATURE_ENABLED_FFV = xtrue])
+AM_CONDITIONAL([CUSTOM_STEREO], [test x$AUDIO_FEATURE_ENABLED_CUSTOM_STEREO = xtrue])
 
 AC_CONFIG_FILES([ \
         Makefile \
diff --git a/hal/Makefile.am b/hal/Makefile.am
index 8ab3e7c..4f01efc 100644
--- a/hal/Makefile.am
+++ b/hal/Makefile.am
@@ -195,6 +195,10 @@
 c_sources += audio_extn/ffv.c
 endif
 
+if CUSTOM_STEREO
+AM_CFLAGS += -DCUSTOM_STEREO_ENABLED
+endif
+
 h_sources = audio_extn/audio_defs.h \
             audio_extn/audio_extn.h \
             audio_hw.h \
diff --git a/hal/acdb.c b/hal/acdb.c
index 182e513..ad67d61 100644
--- a/hal/acdb.c
+++ b/hal/acdb.c
@@ -34,7 +34,7 @@
     int result = -1;
     char *cvd_version = NULL;
 
-    char *snd_card_name = NULL;
+    const char *snd_card_name = NULL;
     struct mixer *mixer = NULL;
     struct acdb_platform_data *my_data = NULL;
 
@@ -115,13 +115,14 @@
     }
 
     /* Get Sound card name */
-    snd_card_name = strdup(mixer_get_name(mixer));
+    snd_card_name = mixer_get_name(mixer);
     if (!snd_card_name) {
         ALOGE("failed to allocate memory for snd_card_name");
         result = -1;
         goto cleanup;
     }
 
+    snd_card_name = platform_get_snd_card_name_for_acdb_loader(snd_card_name);
     int key = 0;
     struct listnode *node = NULL;
     struct meta_key_list *key_info = NULL;
@@ -160,9 +161,6 @@
     if (cvd_version)
         free(cvd_version);
 
-    if (snd_card_name)
-        free(snd_card_name);
-
     return result;
 }
 
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9422704..704f3f3 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2316,6 +2316,12 @@
 {
     int ret = 0;
     struct audio_usecase *uc_info;
+
+    if (in == NULL) {
+        ALOGE("%s: stream_in ptr is NULL", __func__);
+        return -EINVAL;
+    }
+
     struct audio_device *adev = in->dev;
 
     ALOGV("%s: enter: usecase(%d: %s)", __func__,
@@ -3207,7 +3213,9 @@
     case 32000:
     case 44100:
     case 48000:
+    case 88200:
     case 96000:
+    case 176400:
     case 192000:
         break;
     default:
@@ -3273,7 +3281,7 @@
     return (size/(channel_count * bytes_per_sample));
 }
 
-static uint64_t get_actual_pcm_frames_rendered(struct stream_out *out)
+static uint64_t get_actual_pcm_frames_rendered(struct stream_out *out, struct timespec *timestamp)
 {
     uint64_t actual_frames_rendered = 0;
     size_t kernel_buffer_size = out->compr_config.fragment_size * out->compr_config.fragments;
@@ -3284,6 +3292,7 @@
     int64_t platform_latency =  platform_render_latency(out->usecase) *
                                 out->sample_rate / 1000000LL;
 
+    pthread_mutex_lock(&out->position_query_lock);
     /* not querying actual state of buffering in kernel as it would involve an ioctl call
      * which then needs protection, this causes delay in TS query for pcm_offload usecase
      * hence only estimate.
@@ -3292,8 +3301,14 @@
 
     signed_frames = signed_frames / (audio_bytes_per_sample(out->format) * popcount(out->channel_mask)) - platform_latency;
 
-    if (signed_frames > 0)
+    if (signed_frames > 0) {
         actual_frames_rendered = signed_frames;
+        if (timestamp != NULL )
+            *timestamp = out->writeAt;
+    } else if (timestamp != NULL) {
+        clock_gettime(CLOCK_MONOTONIC, timestamp);
+    }
+    pthread_mutex_unlock(&out->position_query_lock);
 
     ALOGVV("%s signed frames %lld out_written %lld kernel_buffer_size %d"
             "bytes/sample %zu channel count %d", __func__,(long long int)signed_frames,
@@ -3421,7 +3436,6 @@
     struct stream_out *out = (struct stream_out *)stream;
 
     lock_output_stream(out);
-
     // always send CMD_ERROR for offload streams, this
     // is needed e.g. when SSR happens within compress_open
     // since the stream is active, offload_callback_thread is also active.
@@ -3429,18 +3443,9 @@
         stop_compressed_output_l(out);
         send_offload_cmd_l(out, OFFLOAD_CMD_ERROR);
     }
-
-    // for compress streams , if the stream is not in standby
-    // it will be triggered eventually from AF.
-    bool do_standby = !out->standby &&
-                      !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
-
     pthread_mutex_unlock(&out->lock);
 
-    if (do_standby)
-        return out_standby(&out->stream.common);
-
-    return 0;
+    return out_standby(&out->stream.common);
 }
 
 /*
@@ -4166,8 +4171,13 @@
     else if (!is_offload_usecase(out->usecase))
         bpf = audio_bytes_per_sample(out->format) *
              audio_channel_count_from_out_mask(out->channel_mask);
-    if (bpf != 0)
+
+    pthread_mutex_lock(&out->position_query_lock);
+    if (bpf != 0) {
         out->written += bytes / bpf;
+        clock_gettime(CLOCK_MONOTONIC, &out->writeAt);
+    }
+    pthread_mutex_unlock(&out->position_query_lock);
 }
 
 static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
@@ -4492,7 +4502,7 @@
          * this operation and adev_close_output_stream(where out gets reset).
          */
         if (!out->non_blocking && !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
-            *dsp_frames = get_actual_pcm_frames_rendered(out);
+            *dsp_frames = get_actual_pcm_frames_rendered(out, NULL);
              ALOGVV("dsp_frames %d sampleRate %d",(int)*dsp_frames,out->sample_rate);
              adjust_frames_for_device_delay(out, dsp_frames);
              return 0;
@@ -4565,9 +4575,7 @@
      */
     if (is_offload_usecase(out->usecase) && !out->non_blocking &&
         !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
-        *frames = get_actual_pcm_frames_rendered(out);
-        /* this is the best we can do */
-        clock_gettime(CLOCK_MONOTONIC, timestamp);
+        *frames = get_actual_pcm_frames_rendered(out, timestamp);
         ALOGVV("frames %lld playedat %lld",(long long int)*frames,
              timestamp->tv_sec * 1000000LL + timestamp->tv_nsec / 1000);
         return 0;
@@ -5197,6 +5205,12 @@
                        size_t bytes)
 {
     struct stream_in *in = (struct stream_in *)stream;
+
+    if (in == NULL) {
+        ALOGE("%s: stream_in ptr is NULL", __func__);
+        return -EINVAL;
+    }
+
     struct audio_device *adev = in->dev;
     int ret = -1;
     size_t bytes_read = 0;
@@ -5544,6 +5558,7 @@
     pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL);
     pthread_mutex_init(&out->pre_lock, (const pthread_mutexattr_t *) NULL);
     pthread_mutex_init(&out->compr_mute_lock, (const pthread_mutexattr_t *) NULL);
+    pthread_mutex_init(&out->position_query_lock, (const pthread_mutexattr_t *) NULL);
     pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL);
 
     if (devices == AUDIO_DEVICE_NONE)
@@ -5851,6 +5866,8 @@
         out->is_compr_metadata_avail = false;
         out->offload_state = OFFLOAD_STATE_IDLE;
         out->playback_started = 0;
+        out->writeAt.tv_sec = 0;
+        out->writeAt.tv_nsec = 0;
 
         audio_extn_dts_create_state_notifier_node(out->usecase);
 
@@ -6901,6 +6918,11 @@
     /* Disable echo reference while closing input stream */
     platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE);
 
+    if (in == NULL) {
+        ALOGE("%s: audio_stream_in ptr is NULL", __func__);
+        return;
+    }
+
     if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
         pthread_mutex_lock(&adev->lock);
         ret = voice_extn_compress_voip_close_input_stream(&stream->common);
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 7885b97..7d1888f 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -274,6 +274,7 @@
     pthread_mutex_t lock; /* see note below on mutex acquisition order */
     pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by playback thread */
     pthread_mutex_t compr_mute_lock; /* acquire before setting compress volume */
+    pthread_mutex_t position_query_lock; /* acquire before updating/getting position of track offload*/
     pthread_cond_t  cond;
     struct pcm_config config;
     struct compr_config compr_config;
@@ -304,6 +305,7 @@
     pthread_t offload_thread;
     struct listnode offload_cmd_list;
     bool offload_thread_blocked;
+    struct timespec writeAt;
 
     void *adsp_hdlr_stream_handle;
     void *ip_hdlr_handle;
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index ef23b15..745bcbe 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -85,6 +85,7 @@
 #define PLATFORM_INFO_XML_PATH_SKUSH  "/etc/audio_platform_info_skush.xml"
 #define PLATFORM_INFO_XML_PATH      "/etc/audio_platform_info.xml"
 #define MIXER_XML_PATH_WCD9326_I2S "/etc/mixer_paths_wcd9326_i2s.xml"
+#define MIXER_XML_PATH_WCD9326_I2S_TDM "/etc/mixer_paths_wcd9326_i2s_tdm.xml"
 #define MIXER_XML_PATH_WCD9330_I2S "/etc/mixer_paths_wcd9330_i2s.xml"
 #define MIXER_XML_PATH_WCD9335_I2S "/etc/mixer_paths_wcd9335_i2s.xml"
 #define MIXER_XML_PATH_SBC "/etc/mixer_paths_sbc.xml"
@@ -100,6 +101,7 @@
 #define MIXER_XML_PATH_SKUN "/vendor/etc/mixer_paths_qrd_skun.xml"
 #define PLATFORM_INFO_XML_PATH      "/vendor/etc/audio_platform_info.xml"
 #define MIXER_XML_PATH_WCD9326_I2S "/vendor/etc/mixer_paths_wcd9326_i2s.xml"
+#define MIXER_XML_PATH_WCD9326_I2S_TDM "/vendor/etc/mixer_paths_wcd9326_i2s_tdm.xml"
 #define MIXER_XML_PATH_WCD9330_I2S "/vendor/etc/mixer_paths_wcd9330_i2s.xml"
 #define MIXER_XML_PATH_WCD9335_I2S "/vendor/etc/mixer_paths_wcd9335_i2s.xml"
 #define MIXER_XML_PATH_SBC "/vendor/etc/mixer_paths_sbc.xml"
@@ -1026,6 +1028,8 @@
                   sizeof("sdm660-tasha-snd-card")) ||
          !strncmp(snd_card_name, "apq8009-tashalite-snd-card",
                   sizeof("apq8009-tashalite-snd-card")) ||
+         !strncmp(snd_card_name, "apq8009-tashalite-snd-card-tdm",
+                  sizeof("apq8009-tashalite-snd-card-tdm")) ||
          !strncmp(snd_card_name, "mdm9607-tomtom-i2s-snd-card",
                   sizeof("mdm9607-tomtom-i2s-snd-card")) ||
          !strncmp(snd_card_name, "mdm-tasha-i2s-snd-card",
@@ -1401,6 +1405,13 @@
         msm_device_to_be_id = msm_device_to_be_id_external_codec;
         msm_be_id_array_len  =
             sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
+   } else if (!strncmp(snd_card_name, "apq8009-tashalite-snd-card-tdm",
+                 sizeof("apq8009-tashalite-snd-card-tdm"))) {
+        strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9326_I2S_TDM,
+               MAX_MIXER_XML_PATH);
+        msm_device_to_be_id = msm_device_to_be_id_external_codec;
+        msm_be_id_array_len  =
+            sizeof(msm_device_to_be_id_external_codec) / sizeof(msm_device_to_be_id_external_codec[0]);
     } else if (!strncmp(snd_card_name, "mdm9607-tomtom-i2s-snd-card",
                  sizeof("mdm9607-tomtom-i2s-snd-card"))) {
         strlcpy(mixer_xml_path, MIXER_XML_PATH_WCD9330_I2S,
@@ -1851,7 +1862,7 @@
     plat_data->hw_dep_fd = fd;
 }
 
-const char * get_snd_card_name_for_acdb_loader(const char *snd_card_name) {
+const char * platform_get_snd_card_name_for_acdb_loader(const char *snd_card_name) {
 
     if(snd_card_name == NULL)
         return NULL;
@@ -1905,7 +1916,7 @@
 {
     struct platform_data *my_data = (struct platform_data *)platform;
     char *cvd_version = NULL;
-    const char *snd_card_name, *acdb_snd_card_name;
+    const char *snd_card_name;
     int result = -1;
     struct listnode *node;
     struct meta_key_list *key_info;
@@ -1920,21 +1931,21 @@
     }
 
     snd_card_name = mixer_get_name(my_data->adev->mixer);
-    acdb_snd_card_name = get_snd_card_name_for_acdb_loader(snd_card_name);
+    snd_card_name = platform_get_snd_card_name_for_acdb_loader(snd_card_name);
 
     if (my_data->acdb_init_v3) {
-        result = my_data->acdb_init_v3(acdb_snd_card_name, cvd_version,
+        result = my_data->acdb_init_v3(snd_card_name, cvd_version,
                                            &my_data->acdb_meta_key_list);
     } else if (my_data->acdb_init) {
         node = list_head(&my_data->acdb_meta_key_list);
         key_info = node_to_item(node, struct meta_key_list, list);
         key = key_info->cal_info.nKey;
-        result = my_data->acdb_init(acdb_snd_card_name, cvd_version, key);
+        result = my_data->acdb_init(snd_card_name, cvd_version, key);
     }
     /* Save these variables in platform_data. These will be used
        while reloading ACDB files during run time. */
     strlcpy(my_data->cvd_version, cvd_version, MAX_CVD_VERSION_STRING_SIZE);
-    strlcpy(my_data->snd_card_name, acdb_snd_card_name,
+    strlcpy(my_data->snd_card_name, snd_card_name,
                                                MAX_SND_CARD_STRING_SIZE);
 
     if (cvd_version)
diff --git a/hal/msm8974/hw_info.c b/hal/msm8974/hw_info.c
index bddaf97..bdc41a5 100644
--- a/hal/msm8974/hw_info.c
+++ b/hal/msm8974/hw_info.c
@@ -558,7 +558,7 @@
     } else if (strstr(snd_card_name, "sdm660") || strstr(snd_card_name, "sdm670")) {
         ALOGV("Bear - variant soundcard");
         update_hardware_info_bear(hw_info, snd_card_name);
-    } else if (strncmp(snd_card_name, "sdx", sizeof("sdx"))) {
+    } else if (strstr(snd_card_name, "sdx")) {
         ALOGV("SDX - variant soundcard");
         update_hardware_info_sdx(hw_info, snd_card_name);
     } else {
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index a86c200..7bea5f1 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -63,7 +63,7 @@
 #define PLATFORM_INFO_XML_PATH "/etc/audio_platform_info.xml"
 #define MIXER_XML_PATH_AUXPCM "/etc/mixer_paths_auxpcm.xml"
 #define MIXER_XML_PATH_I2S "/etc/mixer_paths_i2s.xml"
-#define PLATFORM_INFO_XML_PATH_I2S "/etc/audio_platform_info_i2s.xml"
+#define PLATFORM_INFO_XML_PATH_I2S "/etc/audio_platform_info_extcodec.xml"
 #else
 #define MIXER_XML_BASE_STRING "/vendor/etc/mixer_paths"
 #define MIXER_XML_DEFAULT_PATH "/vendor/etc/mixer_paths.xml"
@@ -1730,7 +1730,7 @@
     plat_data->hw_dep_fd = fd;
 }
 
-const char * get_snd_card_name_for_acdb_loader(const char *snd_card_name) {
+const char * platform_get_snd_card_name_for_acdb_loader(const char *snd_card_name) {
 
     if(snd_card_name == NULL)
         return NULL;
@@ -1767,7 +1767,7 @@
     }
 
     snd_card_name = mixer_get_name(my_data->adev->mixer);
-    snd_card_name = get_snd_card_name_for_acdb_loader(snd_card_name);
+    snd_card_name = platform_get_snd_card_name_for_acdb_loader(snd_card_name);
 
     if (my_data->acdb_init_v3) {
         result = my_data->acdb_init_v3(snd_card_name, cvd_version,
@@ -2061,6 +2061,7 @@
     my_data->ext_disp_type = EXT_DISPLAY_TYPE_NONE;
     my_data->hw_dep_fd = -1;
     my_data->mono_speaker = SPKR_1;
+    my_data->speaker_lr_swap = false;
 
     be_dai_name_table = NULL;
 
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index c2fb810..6efeebe 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -368,11 +368,11 @@
 #define PLAYBACK_OFFLOAD_DEVICE 9
 
 // Direct_PCM
-#if defined (PLATFORM_MSM8994) || defined (PLATFORM_MSM8996) || defined (PLATFORM_APQ8084) || defined (PLATFORM_MSM8998) || defined (PLATFORM_SDM845) || defined (PLATFORM_SDM670) ||defined (PLATFORM_QCS605)
+#if defined (PLATFORM_MSM8994) || defined (PLATFORM_MSM8996) || defined (PLATFORM_APQ8084) || defined (PLATFORM_MSM8998) || defined (PLATFORM_SDM845) || defined (PLATFORM_SDM670) ||defined (PLATFORM_QCS605) ||defined (PLATFORM_SDX24)
 #define PLAYBACK_OFFLOAD_DEVICE2 17
 #endif
 
-#if defined (PLATFORM_APQ8084) || defined (PLATFORM_MSM8996) || defined (PLATFORM_MSM8998) || defined (PLATFORM_SDM845) || defined (PLATFORM_SDM670) || defined(PLATFORM_QCS605)
+#if defined (PLATFORM_APQ8084) || defined (PLATFORM_MSM8996) || defined (PLATFORM_MSM8998) || defined (PLATFORM_SDM845) || defined (PLATFORM_SDM670) || defined(PLATFORM_QCS605) || defined (PLATFORM_SDX24)
 #define PLAYBACK_OFFLOAD_DEVICE3 18
 #define PLAYBACK_OFFLOAD_DEVICE4 34
 #define PLAYBACK_OFFLOAD_DEVICE5 35
diff --git a/hal/platform_api.h b/hal/platform_api.h
index e72c6e9..0fec452 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -260,4 +260,5 @@
 int platform_get_mmap_data_fd(void *platform, int dev, int dir,
                                int *fd, uint32_t *size);
 int platform_get_ec_ref_loopback_snd_device(int channel_count);
+const char * platform_get_snd_card_name_for_acdb_loader(const char *snd_card_name);
 #endif // AUDIO_PLATFORM_API_H
diff --git a/mm-audio/aenc-aac/qdsp6/Android.mk b/mm-audio/aenc-aac/qdsp6/Android.mk
index b427233..00d7106 100644
--- a/mm-audio/aenc-aac/qdsp6/Android.mk
+++ b/mm-audio/aenc-aac/qdsp6/Android.mk
@@ -63,6 +63,7 @@
 LOCAL_PRELINK_MODULE    := false
 LOCAL_SHARED_LIBRARIES  := libmm-omxcore
 LOCAL_SHARED_LIBRARIES  += libOmxAacEnc
+LOCAL_VENDOR_MODULE     := true
 LOCAL_SRC_FILES         := test/omx_aac_enc_test.c
 
 include $(BUILD_EXECUTABLE)
diff --git a/mm-audio/aenc-amrnb/qdsp6/Android.mk b/mm-audio/aenc-amrnb/qdsp6/Android.mk
index 3fa619e..ee6b439 100644
--- a/mm-audio/aenc-amrnb/qdsp6/Android.mk
+++ b/mm-audio/aenc-amrnb/qdsp6/Android.mk
@@ -63,6 +63,7 @@
 LOCAL_PRELINK_MODULE    := false
 LOCAL_SHARED_LIBRARIES  := libmm-omxcore
 LOCAL_SHARED_LIBRARIES  += libOmxAmrEnc
+LOCAL_VENDOR_MODULE     := true
 LOCAL_SRC_FILES         := test/omx_amr_enc_test.c
 
 include $(BUILD_EXECUTABLE)
diff --git a/mm-audio/aenc-evrc/qdsp6/Android.mk b/mm-audio/aenc-evrc/qdsp6/Android.mk
index 03965cb..14a2b70 100644
--- a/mm-audio/aenc-evrc/qdsp6/Android.mk
+++ b/mm-audio/aenc-evrc/qdsp6/Android.mk
@@ -62,6 +62,7 @@
 LOCAL_PRELINK_MODULE    := false
 LOCAL_SHARED_LIBRARIES  := libmm-omxcore
 LOCAL_SHARED_LIBRARIES  += libOmxEvrcEnc
+LOCAL_VENDOR_MODULE     := true
 LOCAL_SRC_FILES         := test/omx_evrc_enc_test.c
 
 include $(BUILD_EXECUTABLE)
diff --git a/mm-audio/aenc-g711/qdsp6/Android.mk b/mm-audio/aenc-g711/qdsp6/Android.mk
index 6b2b453..d2dc9d1 100644
--- a/mm-audio/aenc-g711/qdsp6/Android.mk
+++ b/mm-audio/aenc-g711/qdsp6/Android.mk
@@ -66,6 +66,7 @@
 LOCAL_PRELINK_MODULE    := false
 LOCAL_SHARED_LIBRARIES  := libmm-omxcore
 LOCAL_SHARED_LIBRARIES  += libOmxG711Enc
+LOCAL_VENDOR_MODULE     := true
 LOCAL_SRC_FILES         := test/omx_g711_enc_test.c
 
 include $(BUILD_EXECUTABLE)
diff --git a/mm-audio/aenc-qcelp13/qdsp6/Android.mk b/mm-audio/aenc-qcelp13/qdsp6/Android.mk
index f4b904a..b88c348 100644
--- a/mm-audio/aenc-qcelp13/qdsp6/Android.mk
+++ b/mm-audio/aenc-qcelp13/qdsp6/Android.mk
@@ -65,6 +65,7 @@
 LOCAL_PRELINK_MODULE    := false
 LOCAL_SHARED_LIBRARIES  := libmm-omxcore
 LOCAL_SHARED_LIBRARIES  += libOmxQcelp13Enc
+LOCAL_VENDOR_MODULE     := true
 LOCAL_SRC_FILES         := test/omx_qcelp13_enc_test.c
 
 include $(BUILD_EXECUTABLE)