Bluetooth: Turn on UART CLK before SoC init

Turn on uart clocks before soc init and turn off clock once the
soc init is done.

Change-Id: I3da7b9e0f801f88fece4113a50b7785a7d9dc06d
CRs-fixed: 695513
diff --git a/libbt-vendor/include/hci_uart.h b/libbt-vendor/include/hci_uart.h
index 99e1daf..fc23e9d 100644
--- a/libbt-vendor/include/hci_uart.h
+++ b/libbt-vendor/include/hci_uart.h
@@ -89,6 +89,10 @@
 #endif
 #endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
 
+/* UART CLOCK IOCTLS*/
+#define USERIAL_OP_CLK_ON 0x5441
+#define USERIAL_OP_CLK_OFF 0x5442
+#define USERIAL_OP_CLK_STATE 0x5443
 /******************************************************************************
 **  Type definitions
 ******************************************************************************/
diff --git a/libbt-vendor/src/bt_vendor_qcom.c b/libbt-vendor/src/bt_vendor_qcom.c
index 48c92f9..77a1e53 100644
--- a/libbt-vendor/src/bt_vendor_qcom.c
+++ b/libbt-vendor/src/bt_vendor_qcom.c
@@ -693,6 +693,9 @@
                                     ALOGE("userial_vendor_open returns err");
                                     retval = -1;
                                 } else {
+                                    /* Clock on */
+                                    userial_clock_operation(fd, USERIAL_OP_CLK_ON);
+                                    ALOGD("userial clock on");
                                     property_get("ro.bluetooth.wipower", wipower_status, false);
                                     if(strcmp(wipower_status, "true") == 0) {
                                        /* wait for embedded mode startup */
@@ -711,9 +714,11 @@
                                     }
                                     if(rome_soc_init(fd,vnd_local_bd_addr)<0) {
                                         retval = -1;
+                                        userial_clock_operation(fd, USERIAL_OP_CLK_OFF);
                                     } else {
                                         ALOGV("rome_soc_init is completed");
                                         property_set("wc_transport.soc_initialized", "1");
+                                        userial_clock_operation(fd, USERIAL_OP_CLK_OFF);
                                         /*Close the UART port*/
                                         close(fd);
                                     }
@@ -745,6 +750,9 @@
                                  else {
                                      retval = -1;
                                  }
+                             } else {
+                               if (fd >= 0)
+                                  close(fd);
                              }
                         }
                         break;
diff --git a/libbt-vendor/src/hci_uart.c b/libbt-vendor/src/hci_uart.c
index 1077fbf..ef58bee 100644
--- a/libbt-vendor/src/hci_uart.c
+++ b/libbt-vendor/src/hci_uart.c
@@ -500,3 +500,21 @@
     }
     return count;
 }
+
+int userial_clock_operation(int fd, int cmd)
+{
+    int ret = 0;
+
+    switch (cmd)
+    {
+        case USERIAL_OP_CLK_ON:
+        case USERIAL_OP_CLK_OFF:
+             ioctl(fd, cmd);
+             break;
+        case USERIAL_OP_CLK_STATE:
+             ret = ioctl(fd, cmd);
+             break;
+    }
+
+    return ret;
+}