hal: retry failed MBDRC cal level

- in the start of the playback since usecase list is empty
  or not populated with the current usecase (which will be added
  on the first write) unless volume is changed when playing music
  correct gain level is not selected
- cache gain level on failure and trigger set gain level when a
  new usecase is added

Bug 30503798 29933450

Change-Id: I3d199a2810d34a693a099e3cf4b635d5b156a317
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index a96a509..35b726e 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -233,6 +233,8 @@
 static struct audio_device *adev = NULL;
 static pthread_mutex_t adev_init_lock;
 static unsigned int audio_device_ref_count;
+//cache last MBDRC cal step level
+static int last_known_cal_step = -1 ;
 
 static bool may_use_noirq_mode(struct audio_device *adev, audio_usecase_t uc_id,
                                int flags __unused)
@@ -380,6 +382,13 @@
         pthread_mutex_lock(&adev->lock);
         ret_val = platform_send_gain_dep_cal(adev->platform, level);
         pthread_mutex_unlock(&adev->lock);
+
+        // if cal set fails, cache level info
+        // if cal set succeds, reset known last cal set
+        if (!ret_val)
+            last_known_cal_step = level;
+        else if (last_known_cal_step != -1)
+            last_known_cal_step = -1;
     } else {
         ALOGE("%s: %s is NULL", __func__, adev == NULL ? "adev" : "adev->platform");
     }
@@ -1995,6 +2004,11 @@
             out->standby = true;
             goto exit;
         }
+
+        if (last_known_cal_step != -1) {
+            ALOGD("%s: retry previous failed cal level set", __func__);
+            audio_hw_send_gain_dep_calibration(last_known_cal_step);
+        }
     }
 
     if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 683723f..52e9fd8 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -599,7 +599,7 @@
 
 bool platform_send_gain_dep_cal(void *platform __unused, int level __unused)
 {
-    return 0;
+    return true;
 }
 
 void platform_set_echo_reference(struct audio_device *adev, bool enable,
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index e11db63..d7fc84c 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1072,7 +1072,7 @@
 bool platform_send_gain_dep_cal(void *platform __unused,
                                 int level __unused)
 {
-    return 0;
+    return true;
 }
 
 bool platform_can_split_snd_device(snd_device_t in_snd_device __unused,