Merge tag 'AU_LINUX_ANDROID_LA.BF64.1.05.00.00.021.095' into merge_branch

AU_LINUX_ANDROID_LA.BF64.1.05.00.00.021.095 based on quic/aosp/LA.BF64.1

* tag 'AU_LINUX_ANDROID_LA.BF64.1.05.00.00.021.095': (30 commits)
  audio: Reject incall record request when mode is not IN_CALL
  mm-audio: aenc-aac: fix integer overflow for encoded buffer timestamp calculation
  hal: Add support for parsing hdmi edid information for msm8992
  hal: Fix glitch in audio playback during device switch
  hal: add support to query hpx state using getparameter
  hal: add all compressed formats for app type selection
  hal: Performance mode during recording usecase
  hal: fix null pointer de-reference
  hal : add 8992 for msm8992 audio
  post_proc: Support Headphone:X in offload and non tunnel modes
  post_proc: Add support for non-tunnel DSP audio effects
  audio: Avoid mute during AFE PROXY Usecase
  hal: Fix DTS HPX Get parameters
  hal: bug fixes for PCM offload
  hal: Fix progress bar issue during compress offload playback
  hal: Fix setting stream channel map properly
  hardware/qcom/audio: Integrate Eagle framework for HeadphoneX
  hal: Remove setting DAP bypass /DAP on from HAL
  hal: Avoid resetting device to speaker for HDMI passthrough case
  hal: Audio HAL / APM changes for HDMI passthrough
  ...

Conflicts:
	Android.mk
	hal/Android.mk
	hal/audio_extn/audio_extn.h
	hal/audio_extn/utils.c
	hal/audio_hw.c
	hal/voice.c

Change-Id: Ia92b2002486894e8711a48480324479fe114aeb6
diff --git a/Android.mk b/Android.mk
index 7de3d76..cd6ee3d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,4 +1,4 @@
-ifneq ($(filter mpq8092 msm8960 msm8226 msm8x26 msm8610 msm8974 msm8x74 apq8084 msm8916 msm8994 msm8992 msm8909,$(TARGET_BOARD_PLATFORM)),)
+ifneq ($(filter mpq8092 msm8960 msm8226 msm8x26 msm8610 msm8974 msm8x74 apq8084 msm8916 msm8994 msm8909 msm8909 thulium,$(TARGET_BOARD_PLATFORM)),)
 
 MY_LOCAL_PATH := $(call my-dir)
 
diff --git a/hal/Android.mk b/hal/Android.mk
index 0dcda54..c27ac4b 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -8,7 +8,7 @@
 
 AUDIO_PLATFORM := $(TARGET_BOARD_PLATFORM)
 
-ifneq ($(filter msm8974 msm8226 msm8610 apq8084 msm8994 msm8992,$(TARGET_BOARD_PLATFORM)),)
+ifneq ($(filter msm8974 msm8226 msm8610 apq8084 msm8994 msm8992 thulium,$(TARGET_BOARD_PLATFORM)),)
   # B-family platform uses msm8974 code base
   AUDIO_PLATFORM = msm8974
   MULTIPLE_HW_VARIANTS_ENABLED := true
@@ -27,6 +27,9 @@
 ifneq ($(filter msm8992,$(TARGET_BOARD_PLATFORM)),)
   LOCAL_CFLAGS := -DPLATFORM_MSM8994
 endif
+ifneq ($(filter thulium,$(TARGET_BOARD_PLATFORM)),)
+  LOCAL_CFLAGS := -DPLATFORM_THULIUM
+endif
 endif
 
 ifneq ($(filter msm8916 msm8909,$(TARGET_BOARD_PLATFORM)),)
diff --git a/hal/audio_extn/fm.c b/hal/audio_extn/fm.c
index b6f8689..ed3776c 100644
--- a/hal/audio_extn/fm.c
+++ b/hal/audio_extn/fm.c
@@ -34,6 +34,7 @@
 #ifdef FM_ENABLED
 #define AUDIO_PARAMETER_KEY_HANDLE_FM "handle_fm"
 #define AUDIO_PARAMETER_KEY_FM_VOLUME "fm_volume"
+#define AUDIO_PARAMETER_KEY_REC_PLAY_CONC "rec_play_conc_on"
 
 static struct pcm_config pcm_config_fm = {
     .channels = 2,
@@ -280,6 +281,21 @@
         fm_set_volume(adev, vol);
     }
 
+#ifdef RECORD_PLAY_CONCURRENCY
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC,
+                               value, sizeof(value));
+    if ((ret >= 0)
+          && (fmmod.is_fm_running == true)) {
+
+        if (!strncmp("true", value, sizeof("true")))
+            ALOGD("Record play concurrency ON Forcing FM device reroute");
+        else
+            ALOGD("Record play concurrency OFF Forcing FM device reroute");
+
+        select_devices(adev, USECASE_AUDIO_PLAYBACK_FM);
+        fm_set_volume(adev,fmmod.fm_volume);
+    }
+#endif
 exit:
     ALOGV("%s: exit", __func__);
 }
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index a350198..a8c2ccc 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 - 2014, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013 - 2015, 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
@@ -141,7 +141,7 @@
        handle.spkr_in_use = true;
     else {
        handle.spkr_in_use = false;
-       clock_gettime(CLOCK_MONOTONIC, &handle.spkr_last_time_used);
+       clock_gettime(CLOCK_BOOTTIME, &handle.spkr_last_time_used);
    }
 }
 
@@ -181,7 +181,7 @@
         *sec = 0;
          return true;
      } else {
-         clock_gettime(CLOCK_MONOTONIC, &temp);
+         clock_gettime(CLOCK_BOOTTIME, &temp);
          *sec = temp.tv_sec - handle.spkr_last_time_used.tv_sec;
          return false;
      }
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 5234624..3750945 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -836,8 +836,10 @@
             out_snd_device = SND_DEVICE_NONE;
             if (in_snd_device == SND_DEVICE_NONE) {
                 audio_devices_t out_device = AUDIO_DEVICE_NONE;
-                if (adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
-                        adev->primary_output && !adev->primary_output->standby) {
+                if ((adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
+                    (adev->mode == AUDIO_MODE_IN_COMMUNICATION &&
+                     adev->active_input->source == AUDIO_SOURCE_MIC)) &&
+                     adev->primary_output && !adev->primary_output->standby) {
                     out_device = adev->primary_output->devices;
                     platform_set_echo_reference(adev->platform, false);
                 } else if (usecase->id == USECASE_AUDIO_RECORD_AFE_PROXY) {
diff --git a/hal/msm8916/hw_info.c b/hal/msm8916/hw_info.c
index ed6f251..624850b 100644
--- a/hal/msm8916/hw_info.c
+++ b/hal/msm8916/hw_info.c
@@ -186,6 +186,18 @@
         hw_info->snd_devices = NULL;
         hw_info->num_snd_devices = 0;
         strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn));
+    } else if (!strcmp(snd_card_name, "msm8909-skua-snd-card")) {
+        strlcpy(hw_info->type, "skua", sizeof(hw_info->type));
+        strlcpy(hw_info->name, "msm8909", sizeof(hw_info->name));
+        hw_info->snd_devices = NULL;
+        hw_info->num_snd_devices = 0;
+        strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn));
+    } else if (!strcmp(snd_card_name, "msm8909-skuc-snd-card")) {
+        strlcpy(hw_info->type, "skuc", sizeof(hw_info->type));
+        strlcpy(hw_info->name, "msm8909", sizeof(hw_info->name));
+        hw_info->snd_devices = NULL;
+        hw_info->num_snd_devices = 0;
+        strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn));
     } else {
         ALOGW("%s: Not an  8x16/8939/8909 device", __func__);
     }
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index a589425..201a170 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -42,6 +42,8 @@
 #define MIXER_XML_PATH_QRD_SKUI "/system/etc/mixer_paths_qrd_skui.xml"
 #define MIXER_XML_PATH_QRD_SKUHF "/system/etc/mixer_paths_qrd_skuhf.xml"
 #define MIXER_XML_PATH_SKUK "/system/etc/mixer_paths_skuk.xml"
+#define MIXER_XML_PATH_SKUA "/system/etc/mixer_paths_skua.xml"
+#define MIXER_XML_PATH_SKUC "/system/etc/mixer_paths_skuc.xml"
 #define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
 #define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
 #define MIXER_XML_PATH_WCD9306 "/system/etc/mixer_paths_wcd9306.xml"
@@ -602,6 +604,22 @@
         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, "msm8909-skua-snd-card",
+                 sizeof("msm8909-skua-snd-card"))) {
+        strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUA,
+                sizeof(MIXER_XML_PATH_SKUA));
+
+        msm_device_to_be_id = msm_device_to_be_id_internal_codec;
+        msm_be_id_array_len  =
+            sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
+    } else if (!strncmp(snd_card_name, "msm8909-skuc-snd-card",
+                 sizeof("msm8909-skuc-snd-card"))) {
+        strlcpy(mixer_xml_path, MIXER_XML_PATH_SKUC,
+                sizeof(MIXER_XML_PATH_SKUC));
+
+        msm_device_to_be_id = msm_device_to_be_id_internal_codec;
+        msm_be_id_array_len  =
+            sizeof(msm_device_to_be_id_internal_codec) / sizeof(msm_device_to_be_id_internal_codec[0]);
     } else {
         strlcpy(mixer_xml_path, MIXER_XML_PATH,
                 sizeof(MIXER_XML_PATH));
@@ -843,10 +861,16 @@
         }
         calib.get_size = 0;
         calib.buff = malloc(calib.buff_size);
+        if(calib.buff == NULL) {
+            ALOGE("%s mem allocation for %d bytes for %s failed\n"
+                , __func__, calib.buff_size, cal_name_info[type]);
+            return -1;
+        }
         ret = acdb_loader_get_calibration(cal_name_info[type],
                               sizeof(struct param_data), &calib);
         if (ret < 0) {
-            ALOGE("%s get_calibration failed\n", __func__);
+            ALOGE("%s get_calibration failed type=%s calib.size=%d\n"
+                , __func__, cal_name_info[type], codec_buffer.size);
             free(calib.buff);
             return ret;
         }
@@ -854,9 +878,10 @@
         codec_buffer.size = calib.data_size;
         codec_buffer.cal_type = type;
         if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0)
-            ALOGE("Failed to call ioctl  for %s err=%d",
-                                  cal_name_info[type], errno);
-        ALOGD("%s cal sent for %s", __func__, cal_name_info[type]);
+            ALOGE("Failed to call ioctl  for %s err=%d calib.size=%d",
+                cal_name_info[type], errno, codec_buffer.size);
+        ALOGD("%s cal sent for %s calib.size=%d"
+            , __func__, cal_name_info[type], codec_buffer.size);
         free(calib.buff);
     }
     return ret;
@@ -1844,7 +1869,8 @@
                 snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
             }
         }
-    } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
+    } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
+              (mode == AUDIO_MODE_IN_COMMUNICATION)) {
         if (out_device & AUDIO_DEVICE_OUT_SPEAKER)
             in_device = AUDIO_DEVICE_IN_BACK_MIC;
         if (adev->active_input) {
@@ -2227,7 +2253,6 @@
             ALOGD("setting record playback concurrency to false");
             my_data->rec_play_conc_set = false;
         }
-        str_parms_del(parms, AUDIO_PARAMETER_KEY_REC_PLAY_CONC);
     }
 #endif
     ALOGV("%s: exit with code(%d)", __func__, ret);
diff --git a/hal/msm8974/hw_info.c b/hal/msm8974/hw_info.c
index 57dcc22..e5ab181 100644
--- a/hal/msm8974/hw_info.c
+++ b/hal/msm8974/hw_info.c
@@ -87,6 +87,9 @@
     SND_DEVICE_IN_HANDSET_MIC,
 };
 
+static const snd_device_t tomtom_thulium_CDP_variant_devices[] = {
+};
+
 static const snd_device_t tomtom_liquid_variant_devices[] = {
     SND_DEVICE_OUT_SPEAKER,
     SND_DEVICE_OUT_SPEAKER_EXTERNAL_1,
@@ -249,6 +252,37 @@
     }
 }
 
+static void  update_hardware_info_thulium(struct hardware_info *hw_info, const char *snd_card_name)
+{
+    if (!strcmp(snd_card_name, "thulium-tomtom-mtp-snd-card")) {
+        strlcpy(hw_info->type, " mtp", sizeof(hw_info->type));
+        strlcpy(hw_info->name, "thulium", sizeof(hw_info->name));
+        hw_info->snd_devices = NULL;
+        hw_info->num_snd_devices = 0;
+        strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn));
+    } else if (!strcmp(snd_card_name, "thulium-tomtom-cdp-snd-card")) {
+        strlcpy(hw_info->type, " cdp", sizeof(hw_info->type));
+        strlcpy(hw_info->name, "thulium", sizeof(hw_info->name));
+        hw_info->snd_devices = (snd_device_t *)tomtom_thulium_CDP_variant_devices;
+        hw_info->num_snd_devices = ARRAY_SIZE(tomtom_thulium_CDP_variant_devices);
+        strlcpy(hw_info->dev_extn, "-cdp", sizeof(hw_info->dev_extn));
+    } else if (!strcmp(snd_card_name, "thulium-tomtom-stp-snd-card")) {
+        strlcpy(hw_info->type, " stp", sizeof(hw_info->type));
+        strlcpy(hw_info->name, "thulium", sizeof(hw_info->name));
+        hw_info->snd_devices = (snd_device_t *)tomtom_stp_variant_devices;
+        hw_info->num_snd_devices = ARRAY_SIZE(tomtom_stp_variant_devices);
+        strlcpy(hw_info->dev_extn, "-stp", sizeof(hw_info->dev_extn));
+    } else if (!strcmp(snd_card_name, "thulium-tomtom-liquid-snd-card")) {
+        strlcpy(hw_info->type, " liquid", sizeof(hw_info->type));
+        strlcpy(hw_info->name, "thulium", sizeof(hw_info->name));
+        hw_info->snd_devices = (snd_device_t *)tomtom_liquid_variant_devices;
+        hw_info->num_snd_devices = ARRAY_SIZE(tomtom_liquid_variant_devices);
+        strlcpy(hw_info->dev_extn, "-liquid", sizeof(hw_info->dev_extn));
+    } else {
+        ALOGW("%s: Not a thulium device", __func__);
+    }
+}
+
 static void  update_hardware_info_8974(struct hardware_info *hw_info, const char *snd_card_name)
 {
     if (!strcmp(snd_card_name, "msm8974-taiko-mtp-snd-card")) {
@@ -374,6 +408,9 @@
     } else if(strstr(snd_card_name, "msm8994")) {
         ALOGV("8994 - variant soundcard");
         update_hardware_info_8994(hw_info, snd_card_name);
+    } else if(strstr(snd_card_name, "thulium")) {
+        ALOGV("thulium - variant soundcard");
+        update_hardware_info_thulium(hw_info, snd_card_name);
     } else {
         ALOGE("%s: Unsupported target %s:",__func__, snd_card_name);
         free(hw_info);
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index 8d49424..c7d7f0e 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -229,7 +229,7 @@
 #define PLAYBACK_OFFLOAD_DEVICE8 38
 #define PLAYBACK_OFFLOAD_DEVICE9 39
 #endif
-#ifdef PLATFORM_MSM8994
+#if defined (PLATFORM_MSM8994) || defined (PLATFORM_THULIUM)
 #define PLAYBACK_OFFLOAD_DEVICE2 17
 #define PLAYBACK_OFFLOAD_DEVICE3 18
 #define PLAYBACK_OFFLOAD_DEVICE4 37
@@ -303,6 +303,8 @@
 #define FM_RX_VOLUME "Quat MI2S FM RX Volume"
 #elif PLATFORM_MSM8994
 #define FM_RX_VOLUME "PRI MI2S LOOPBACK Volume"
+#elif PLATFORM_THULIUM
+#define FM_RX_VOLUME "Tert MI2S LOOPBACK Volume"
 #else
 #define FM_RX_VOLUME "Internal FM RX Volume"
 #endif