audio HAL: Add retry to get mixer in adev_open

If the sound card is not created in kernel before audio hal initialized
by audio flinger, the mixer open would be failed.
This is timing issue. So retry routine is need.

Change-Id: Icff3cd53763bfc483725849874fe27ff4de28890
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 78f38a2..a0b65e0 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -36,8 +36,6 @@
 #include "platform_api.h"
 #include <platform.h>
 
-#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
-
 struct pcm_config pcm_config_deep_buffer = {
     .channels = 2,
     .rate = DEFAULT_OUTPUT_SAMPLING_RATE,
@@ -1715,20 +1713,6 @@
 
     adev = calloc(1, sizeof(struct audio_device));
 
-    adev->mixer = mixer_open(MIXER_CARD);
-    if (!adev->mixer) {
-        ALOGE("Unable to open the mixer, aborting.");
-        return -ENOSYS;
-    }
-
-    adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
-    if (!adev->audio_route) {
-        free(adev);
-        ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
-        *device = NULL;
-        return -EINVAL;
-    }
-
     adev->device.common.tag = HARDWARE_DEVICE_TAG;
     adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
     adev->device.common.module = (struct hw_module_t *)module;
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index 7052d68..0c6871a 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -37,6 +37,7 @@
  * This is the sysfs path for the HDMI audio data block
  */
 #define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block"
+#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
 
 /*
  * This file will have a maximum of 38 bytes:
@@ -248,6 +249,19 @@
     char value[PROPERTY_VALUE_MAX];
     struct platform_data *my_data;
 
+    adev->mixer = mixer_open(MIXER_CARD);
+
+    if (!adev->mixer) {
+        ALOGE("Unable to open the mixer, aborting.");
+        return NULL;
+    }
+
+    adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
+    if (!adev->audio_route) {
+        ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
+        return NULL;
+    }
+
     my_data = calloc(1, sizeof(struct platform_data));
 
     my_data->adev = adev;
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index d563288..0b04e9e 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -36,6 +36,7 @@
  * This is the sysfs path for the HDMI audio data block
  */
 #define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block"
+#define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
 
 /*
  * This file will have a maximum of 38 bytes:
@@ -50,6 +51,10 @@
 /* EDID format ID for LPCM audio */
 #define EDID_FORMAT_LPCM    1
 
+/* Retry for delay in FW loading*/
+#define RETRY_NUMBER 10
+#define RETRY_US 500000
+
 struct audio_block_header
 {
     int reserved;
@@ -224,6 +229,26 @@
 {
     char value[PROPERTY_VALUE_MAX];
     struct platform_data *my_data;
+    int retry_num = 0;
+
+    adev->mixer = mixer_open(MIXER_CARD);
+
+    while (!adev->mixer && retry_num < RETRY_NUMBER) {
+        usleep(RETRY_US);
+        adev->mixer = mixer_open(MIXER_CARD);
+        retry_num++;
+    }
+
+    if (!adev->mixer) {
+        ALOGE("Unable to open the mixer, aborting.");
+        return NULL;
+    }
+
+    adev->audio_route = audio_route_init(MIXER_CARD, MIXER_XML_PATH);
+    if (!adev->audio_route) {
+        ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
+        return NULL;
+    }
 
     my_data = calloc(1, sizeof(struct platform_data));