Merge "configs: SDM660: Add microphone characteristics and snd device mapping"
diff --git a/configs/sdm660/sdm660.mk b/configs/sdm660/sdm660.mk
index 047adb0..555340a 100644
--- a/configs/sdm660/sdm660.mk
+++ b/configs/sdm660/sdm660.mk
@@ -245,4 +245,10 @@
     android.hardware.audio@2.0-service \
     android.hardware.audio@2.0-impl \
     android.hardware.audio.effect@2.0-impl \
-    android.hardware.soundtrigger@2.0-impl
+    android.hardware.soundtrigger@2.0-impl \
+    android.hardware.audio@4.0 \
+    android.hardware.audio.common@4.0 \
+    android.hardware.audio.common@4.0-util \
+    android.hardware.audio@4.0-impl \
+    android.hardware.audio.effect@4.0 \
+    android.hardware.audio.effect@4.0-impl
diff --git a/configs/sdm710/mixer_paths_tavil.xml b/configs/sdm710/mixer_paths_tavil.xml
index 0409cc1..1810efa 100644
--- a/configs/sdm710/mixer_paths_tavil.xml
+++ b/configs/sdm710/mixer_paths_tavil.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-<!-- Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.    -->
+<!-- Copyright (c) 2016-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 -->
@@ -1863,6 +1863,10 @@
         <path name="speaker-mono-2" />
     </path>
 
+    <path name="speaker-hdk">
+        <path name="speaker-mono" />
+    </path>
+
     <path name="speaker-fluid">
         <path name="speaker-mono" />
     </path>
@@ -1954,6 +1958,14 @@
         <ctl name="EAR SPKR PA Gain" value="G_6_DB" />
     </path>
 
+    <path name="handset-hdk">
+        <ctl name="SLIM RX0 MUX" value="AIF1_PB" />
+        <ctl name="CDC_IF RX0 MUX" value="SLIM RX0" />
+        <ctl name="SLIM_0_RX Channels" value="One" />
+        <ctl name="RX INT0_1 MIX1 INP0" value="RX0" />
+        <ctl name="EAR PA Gain" value="G_6_DB" />
+    </path>
+
     <path name="handset-mic">
         <path name="dmic3" />
     </path>
@@ -2069,10 +2081,22 @@
         <path name="handset" />
     </path>
 
+    <path name="voice-handset-hdk">
+        <path name="handset-hdk" />
+    </path>
+
+    <path name="voice-handset-tmus-hdk">
+        <path name="handset-hdk" />
+    </path>
+
     <path name="voice-speaker">
         <path name="speaker-mono" />
     </path>
 
+    <path name="voice-speaker-hdk">
+        <path name="speaker-mono" />
+    </path>
+
     <path name="voice-speaker-2">
         <path name="speaker-mono-2" />
     </path>
@@ -2412,6 +2436,11 @@
         <path name="handset" />
     </path>
 
+    <path name="voice-tty-hco-handset-hdk">
+        <ctl name="TTY Mode" value="HCO" />
+        <path name="handset-hdk" />
+    </path>
+
     <path name="voice-tty-full-headset-mic">
         <path name="amic2" />
         <ctl name="ADC2 Volume" value="0" />
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index 28aa23a..5b388a8 100755
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -80,6 +80,7 @@
 
 static struct audio_extn_module aextnmod;
 
+#define AUDIO_PARAMETER_KEY_AANC_NOISE_LEVEL "aanc_noise_level"
 #define AUDIO_PARAMETER_KEY_ANC        "anc_enabled"
 #define AUDIO_PARAMETER_KEY_WFD        "wfd_channel_cap"
 #define AUDIO_PARAMETER_CAN_OPEN_PROXY "can_open_proxy"
@@ -467,6 +468,26 @@
   return false;
 }
 
+void audio_extn_set_aanc_noise_level(struct audio_device *adev,
+                                     struct str_parms *parms)
+{
+    int ret;
+    char value[32] = {0};
+    struct mixer_ctl *ctl = NULL;
+    const char *mixer_ctl_name = "AANC Noise Level";
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_AANC_NOISE_LEVEL, value,
+                            sizeof(value));
+    if (ret >= 0) {
+        ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+        if (ctl)
+            mixer_ctl_set_value(ctl, 0, atoi(value));
+        else
+            ALOGW("%s: Not able to get mixer ctl: %s",
+                  __func__, mixer_ctl_name);
+    }
+}
+
 void audio_extn_set_anc_parameters(struct audio_device *adev,
                                    struct str_parms *parms)
 {
@@ -816,6 +837,7 @@
 void audio_extn_set_parameters(struct audio_device *adev,
                                struct str_parms *parms)
 {
+   audio_extn_set_aanc_noise_level(adev, parms);
    audio_extn_set_anc_parameters(adev, parms);
    audio_extn_set_fluence_parameters(adev, parms);
    audio_extn_set_afe_proxy_parameters(adev, parms);
diff --git a/hal/audio_extn/usb.c b/hal/audio_extn/usb.c
index b7bf22a..9338bc9 100644
--- a/hal/audio_extn/usb.c
+++ b/hal/audio_extn/usb.c
@@ -1436,7 +1436,7 @@
     struct usb_card_config *usb_card_info = NULL;
     bool usb_connected = false;
 
-    if (str_parms_get_int(parms, "card", &card) >= 0) {
+    if ((parms != NULL) && str_parms_get_int(parms, "card", &card) >= 0) {
         usb_connected = audio_extn_usb_alive(card);
     } else {
         list_for_each(node_i, &usbmod->usb_card_conf_list) {
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 3152669..34a9937 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2275,7 +2275,8 @@
 
     /* If input stream is already running then effect needs to be
        applied on the new input device that's being enabled here.  */
-    if ((in_snd_device != SND_DEVICE_NONE) && (!adev->active_input->standby))
+    if ((in_snd_device != SND_DEVICE_NONE) && (adev->active_input != NULL) &&
+        (!adev->active_input->standby))
         check_and_enable_effect(adev);
 
     if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL) {
@@ -5770,6 +5771,14 @@
            ALOGV("AUDIO_DEVICE_OUT_AUX_DIGITAL and DIRECT|OFFLOAD, check hdmi caps");
            ret = read_hdmi_sink_caps(out);
        } else if (is_usb_dev) {
+            /* Check against usb headset connection state */
+            if (!audio_extn_usb_connected(NULL)) {
+                ALOGD("%s: usb headset unplugged", __func__);
+                ret = -EINVAL;
+                pthread_mutex_unlock(&adev->lock);
+                goto error_open;
+            }
+
             ret = read_usb_sup_params_and_compare(true /*is_playback*/,
                                                   &config->format,
                                                   &out->supported_formats[0],
@@ -6904,6 +6913,16 @@
     }
 
     if (is_usb_dev && may_use_hifi_record) {
+        /* Check against usb headset connection state */
+        pthread_mutex_lock(&adev->lock);
+        if (!audio_extn_usb_connected(NULL)) {
+            ALOGD("%s: usb headset unplugged", __func__);
+            ret = -EINVAL;
+            pthread_mutex_unlock(&adev->lock);
+            goto err_open;
+        }
+        pthread_mutex_unlock(&adev->lock);
+
         /* HiFi record selects an appropriate format, channel, rate combo
            depending on sink capabilities*/
         ret = read_usb_sup_params_and_compare(false /*is_playback*/,
diff --git a/hal/msm8974/hw_info.c b/hal/msm8974/hw_info.c
index ea6b7bf..b6b11ad 100644
--- a/hal/msm8974/hw_info.c
+++ b/hal/msm8974/hw_info.c
@@ -573,16 +573,25 @@
 static void update_hardware_info_bear(struct hardware_info *hw_info, const char *snd_card_name)
 {
     if (!strncmp(snd_card_name, "sdm660-snd-card",
-                 sizeof("sdm660-snd-card")))
+                 sizeof("sdm660-snd-card"))) {
         strlcpy(hw_info->name, "sdm660", sizeof(hw_info->name));
-    else if (!strncmp(snd_card_name, "sdm660-tavil-snd-card",
-                      sizeof("sdm660-tavil-snd-card")))
+    } else if (!strncmp(snd_card_name, "sdm660-tavil-snd-card",
+                      sizeof("sdm660-tavil-snd-card"))) {
         strlcpy(hw_info->name, "sdm660", sizeof(hw_info->name));
-    else if (!strncmp(snd_card_name, "sdm670-skuw-snd-card",
-                      sizeof("sdm670-skuw-snd-card")))
+    } else if (!strncmp(snd_card_name, "sdm670-skuw-snd-card",
+                      sizeof("sdm670-skuw-snd-card"))) {
         hw_info->is_stereo_spkr = false;
-    else
+    } else if ( !strncmp(snd_card_name, "sdm670-tavil-hdk-snd-card",
+                      sizeof("sdm670-tavil-hdk-snd-card"))) {
+        strlcpy(hw_info->type, " hdk", sizeof(hw_info->type));
+        strlcpy(hw_info->name, "sdm670", sizeof(hw_info->name));
+        hw_info->snd_devices = (snd_device_t *)tavil_qrd_variant_devices;
+        hw_info->num_snd_devices = ARRAY_SIZE(tavil_qrd_variant_devices);
+        hw_info->is_stereo_spkr = false;
+        strlcpy(hw_info->dev_extn, "-hdk", sizeof(hw_info->dev_extn));
+    } else {
         ALOGW("%s: Not an SDM device", __func__);
+    }
 }
 
 void *hw_info_init(const char *snd_card_name)
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 42dfd95..92f92aa 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -5535,7 +5535,6 @@
     case USECASE_VOICEMMODE1_CALL:
     case USECASE_VOICEMMODE2_CALL:
     case USECASE_COMPRESS_VOIP_CALL:
-    case USECASE_AUDIO_RECORD_FM_VIRTUAL:
     case USECASE_INCALL_REC_UPLINK:
     case USECASE_INCALL_REC_DOWNLINK:
     case USECASE_INCALL_REC_UPLINK_AND_DOWNLINK:
@@ -5544,8 +5543,6 @@
     case USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS:
     case USECASE_INCALL_MUSIC_UPLINK:
     case USECASE_INCALL_MUSIC_UPLINK2:
-    case USECASE_AUDIO_SPKR_CALIB_RX:
-    case USECASE_AUDIO_SPKR_CALIB_TX:
     case USECASE_AUDIO_RECORD_VOIP:
         needs_event = true;
         break;