Merge "hal: fix querying MAD calibration"
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index bdfddbc..72a76b6 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1438,8 +1438,7 @@
     dir = opendir(CodecPeek);
     if (dir != NULL) {
         while (NULL != (dirent = readdir(dir))) {
-            if (strstr (dirent->d_name,file_name))
-            {
+            if (strstr (dirent->d_name,file_name)) {
                 my_data->is_wsa_speaker = true;
                 break;
             }
@@ -1453,9 +1452,9 @@
 
     /* Initialize ACDB and PCM ID's */
     if (is_external_codec)
-        platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC);
+        platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC, my_data);
     else
-        platform_info_init(PLATFORM_INFO_XML_PATH);
+        platform_info_init(PLATFORM_INFO_XML_PATH, my_data);
 
     /* init usb */
     audio_extn_usb_init(adev);
@@ -2298,7 +2297,8 @@
     if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
         devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
         if (OUTPUT_SAMPLING_RATE_44100 == sample_rate &&
-            platform_get_native_support()) {
+            platform_get_native_support() &&
+            !audio_extn_get_anc_enabled()) {
             snd_device = SND_DEVICE_OUT_HEADPHONES_44_1;
         }else if (devices & AUDIO_DEVICE_OUT_WIRED_HEADSET
             && audio_extn_get_anc_enabled()) {
diff --git a/hal/msm8974/hw_info.c b/hal/msm8974/hw_info.c
index 73bc779..5bf6ae4 100644
--- a/hal/msm8974/hw_info.c
+++ b/hal/msm8974/hw_info.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 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
@@ -87,9 +87,6 @@
     SND_DEVICE_IN_HANDSET_MIC,
 };
 
-static const snd_device_t tomtom_8996_CDP_variant_devices[] = {
-};
-
 static const snd_device_t tomtom_liquid_variant_devices[] = {
     SND_DEVICE_OUT_SPEAKER,
     SND_DEVICE_OUT_SPEAKER_EXTERNAL_1,
@@ -286,25 +283,7 @@
 
 static void  update_hardware_info_8996(struct hardware_info *hw_info, const char *snd_card_name)
 {
-    if (!strcmp(snd_card_name, "msm8996-tomtom-mtp-snd-card")) {
-        strlcpy(hw_info->type, " mtp", sizeof(hw_info->type));
-        strlcpy(hw_info->name, "msm8996", 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, "msm8996-tomtom-cdp-snd-card")) {
-        strlcpy(hw_info->type, " cdp", sizeof(hw_info->type));
-        strlcpy(hw_info->name, "msm8996", sizeof(hw_info->name));
-        hw_info->snd_devices = (snd_device_t *)tomtom_8996_CDP_variant_devices;
-        hw_info->num_snd_devices = ARRAY_SIZE(tomtom_8996_CDP_variant_devices);
-        strlcpy(hw_info->dev_extn, "-cdp", sizeof(hw_info->dev_extn));
-    } else if (!strcmp(snd_card_name, "msm8996-tomtom-liquid-snd-card")) {
-        strlcpy(hw_info->type, " liquid", sizeof(hw_info->type));
-        strlcpy(hw_info->name, "msm8996", 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 if (!strcmp(snd_card_name, "msm8996-tasha-fluid-snd-card")) {
+    if (!strcmp(snd_card_name, "msm8996-tasha-fluid-snd-card")) {
         strlcpy(hw_info->type, " fluid", sizeof(hw_info->type));
         strlcpy(hw_info->name, "msm8996", sizeof(hw_info->name));
         hw_info->snd_devices = (snd_device_t *)tasha_fluid_variant_devices;
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 7aed184..d4533f5 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1397,9 +1397,9 @@
 
     /* Initialize ACDB ID's */
     if (my_data->is_i2s_ext_modem)
-        platform_info_init(PLATFORM_INFO_XML_PATH_I2S);
+        platform_info_init(PLATFORM_INFO_XML_PATH_I2S, my_data);
     else
-        platform_info_init(PLATFORM_INFO_XML_PATH);
+        platform_info_init(PLATFORM_INFO_XML_PATH, my_data);
 
     /* If platform is apq8084 and baseband is MDM, load CSD Client specific
      * symbols. Voice call is handled by MDM and apps processor talks to
@@ -4164,7 +4164,7 @@
         goto done;
     }
     if (index != speaker_device_tz_names.snd_device) {
-        ALOGE("%s: not matching speaker device\n");
+        ALOGE("%s: not matching speaker device\n", __func__);
         ret = -EINVAL;
         goto done;
     }
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 921ff0b..5e2ce45 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -87,8 +87,8 @@
 
 int platform_set_snd_device_backend(snd_device_t snd_device, const char * backend);
 
-/* From platform_info_parser.c */
-int platform_info_init(const char *filename);
+/* From platform_info.c */
+int platform_info_init(const char *filename, void *);
 
 void platform_snd_card_update(void *platform, int snd_scard_state);
 
diff --git a/hal/platform_info.c b/hal/platform_info.c
index e6cc15d..b57c90a 100644
--- a/hal/platform_info.c
+++ b/hal/platform_info.c
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <expat.h>
 #include <cutils/log.h>
+#include <cutils/str_parms.h>
 #include <audio_hw.h>
 #include "platform_api.h"
 #include <platform.h>
@@ -49,6 +50,7 @@
     BACKEND_NAME,
     INTERFACE_NAME,
     TZ_NAME,
+    CONFIG_PARAMS,
 } section_t;
 
 typedef void (* section_process_fn)(const XML_Char **attr);
@@ -60,6 +62,7 @@
 static void process_backend_name(const XML_Char **attr);
 static void process_interface_name(const XML_Char **attr);
 static void process_tz_name(const XML_Char **attr);
+static void process_config_params(const XML_Char **attr);
 static void process_root(const XML_Char **attr);
 
 static section_process_fn section_table[] = {
@@ -71,10 +74,18 @@
     [BACKEND_NAME] = process_backend_name,
     [INTERFACE_NAME] = process_interface_name,
     [TZ_NAME] = process_tz_name,
+    [CONFIG_PARAMS] = process_config_params,
 };
 
 static section_t section;
 
+struct platform_info {
+    void             *platform;
+    struct str_parms *kvpairs;
+};
+
+static struct platform_info my_data;
+
 /*
  * <audio_platform_info>
  * <acdb_ids>
@@ -102,6 +113,12 @@
  * ...
  * ...
  * </tz_names>
+ * <config_params>
+ *      <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
+ *      ...
+ *      ...
+ * </config_params>
+ *
  * </audio_platform_info>
  */
 
@@ -115,7 +132,7 @@
     int index;
 
     if (strcmp(attr[0], "name") != 0) {
-        ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
+        ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
         goto done;
     }
 
@@ -352,6 +369,24 @@
     return;
 }
 
+static void process_config_params(const XML_Char **attr)
+{
+    if (strcmp(attr[0], "key") != 0) {
+        ALOGE("%s: 'key' not found", __func__);
+        goto done;
+    }
+
+    if (strcmp(attr[2], "value") != 0) {
+        ALOGE("%s: 'value' not found", __func__);
+        goto done;
+    }
+
+    str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
+done:
+    return;
+}
+
+
 static void start_tag(void *userdata __unused, const XML_Char *tag_name,
                       const XML_Char **attr)
 {
@@ -367,6 +402,8 @@
         section = PCM_ID;
     } else if (strcmp(tag_name, "backend_names") == 0) {
         section = BACKEND_NAME;
+    } else if (strcmp(tag_name, "config_params") == 0) {
+        section = CONFIG_PARAMS;
     } else if (strcmp(tag_name, "interface_names") == 0) {
         section = INTERFACE_NAME;
     } else if (strcmp(tag_name, "native_configs") == 0) {
@@ -399,6 +436,14 @@
 
         section_process_fn fn = section_table[NATIVESUPPORT];
         fn(attr);
+    } else if (strcmp(tag_name, "param") == 0) {
+        if (section != CONFIG_PARAMS) {
+            ALOGE("param tag only supported with CONFIG_PARAMS section");
+            return;
+        }
+
+        section_process_fn fn = section_table[section];
+        fn(attr);
     }
 
     return;
@@ -414,6 +459,9 @@
         section = ROOT;
     } else if (strcmp(tag_name, "backend_names") == 0) {
         section = ROOT;
+    } else if (strcmp(tag_name, "config_params") == 0) {
+        section = ROOT;
+        platform_set_parameters(my_data.platform, my_data.kvpairs);
     } else if (strcmp(tag_name, "interface_names") == 0) {
         section = ROOT;
     } else if (strcmp(tag_name, "native_configs") == 0) {
@@ -421,7 +469,7 @@
     }
 }
 
-int platform_info_init(const char *filename)
+int platform_info_init(const char *filename, void *platform)
 {
     XML_Parser      parser;
     FILE            *file;
@@ -446,6 +494,9 @@
         goto err_close_file;
     }
 
+    my_data.platform = platform;
+    my_data.kvpairs = str_parms_create();
+
     XML_SetElementHandler(parser, start_tag, end_tag);
 
     while (1) {