From a1805d9a1c74e7b30afa86641b5254ab5b053923 Mon Sep 17 00:00:00 2001
From: Kamal Negi <kamaln@codeaurora.org>
Date: Tue, 14 Feb 2017 12:46:33 +0530
Subject: [PATCH] FM Radio: Wait for disable to complete

Make disable fm to be synchronous. On factory reset, disable fm
and enable fm called back to back. If enable fm command sent before
disable fm completes, fm enable fails. Hence wait for disable fm
to complete.

Change-Id: Ic3630f7bdd39ca812d9ae81b45a9c496049aef84
---
 fm_hci/fm_hci.c | 7 +++++++
 fm_hci/fm_hci.h | 1 +
 2 files changed, 8 insertions(+)

diff --git a/fm_hci/fm_hci.c b/fm_hci/fm_hci.c
index c48edd5..378e0c9 100644
--- a/fm_hci/fm_hci.c
+++ b/fm_hci/fm_hci.c
@@ -677,6 +677,12 @@ void fm_hci_close(void *arg) {
         return;
     }
     event_notification(hci, HC_EVENT_EXIT);
+    pthread_mutex_lock(&hci->event_lock);
+again:
+    pthread_cond_wait(&hci->event_cond, &hci->event_lock);
+    if (!(ready_events & HC_EVENT_EXIT_DONE))
+        goto again;
+    pthread_mutex_unlock(&hci->event_lock);
 }
 
 int fm_hci_init(fm_hci_hal_t *hci_hal)
@@ -785,6 +791,7 @@ static void fm_hci_exit(void *arg)
     vendor_close(hci);
     pthread_cond_broadcast(&hci->event_cond);
     pthread_cond_broadcast(&hci->cmd_credits_cond);
+    event_notification(hci, HC_EVENT_EXIT_DONE);
     stop_rx_thread(hci);
     stop_tx_thread(hci);
     ALOGD("Tx, Rx Threads join done");
diff --git a/fm_hci/fm_hci.h b/fm_hci/fm_hci.h
index 8818068..2cfb30e 100644
--- a/fm_hci/fm_hci.h
+++ b/fm_hci/fm_hci.h
@@ -46,6 +46,7 @@
 #define HC_EVENT_LPM_IDLE_TIMEOUT      0x0100
 #define HC_EVENT_EXIT                  0x0200
 #define HC_EVENT_EPILOG                0x0400
+#define HC_EVENT_EXIT_DONE             0x8000
 
 #define MAX_FM_CMD_CNT                 100
 #define FM_CMD                         0x11
-- 
GitLab