hal: spk_prot: Update lock for v-validation and timestamp calculation

Ensure take adev lock before v-validation thread calls spkr_calibrate,
since spkr_calibrate() caller expected to take it. Update
timestamp calculation for nsec for v-validation based on
added value.

Change-Id: I1b4004eb1e809219e36b9c3f733a9b484cf1e8a4
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index 7a6e1c1..1e394a4 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -935,6 +935,10 @@
         total_time = (handle.v_vali_wait_time + handle.v_vali_vali_time);
         ts.tv_sec += (total_time/1000);
         ts.tv_nsec += ((total_time%1000) * 1000000);
+        if (ts.tv_nsec >= 1000000000) {
+            ts.tv_nsec -= 1000000000;
+            ts.tv_sec += 1;
+        }
     }
     pthread_mutex_lock(&handle.mutex_spkr_prot);
     pthread_mutex_unlock(&adev->lock);
@@ -1748,12 +1752,14 @@
     if (!handle.v_vali_vali_time)
         handle.v_vali_vali_time = SPKR_V_VALI_DEFAULT_VALI_TIME;/*set default if not setparam */
     set_spkr_prot_v_vali_cfg(handle.v_vali_wait_time, handle.v_vali_vali_time);
+    pthread_mutex_lock(&adev->lock);
     ret = spkr_calibrate(SPKR_V_VALI_TEMP_MASK,
                          SPKR_V_VALI_TEMP_MASK);/*use 0xfffe as temp to initiate v_vali*/
+    pthread_mutex_unlock(&adev->lock);
     if (ret)
         ALOGE("%s: failed, retry again\n", __func__);
-    pthread_exit(0);
     handle.trigger_v_vali = false;
+    pthread_exit(0);
     return NULL;
 }