hal: update platform info parser to read key value pairs

Add support to parse platform specific configuration as
key value pairs from audio_platform_info.xml file.

Change-Id: Id1199f6f5cb3a060476f713a69b5de05f48815ce
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index d15a252..d68591e 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1434,8 +1434,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;
             }
@@ -1449,9 +1448,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);
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index ab9c77b..b837b9f 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1393,9 +1393,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
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) {