summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshi Kikuchi <toshik@google.com>2012-11-19 18:44:55 -0800
committerToshi Kikuchi <toshik@google.com>2012-11-27 18:24:44 -0800
commitdca653a64a09a0b94b28fc6034b6330ebf06a76c (patch)
tree4fcd20448190e78a1bf057f9fac7e760e4088194
parent93f649f15719524e6d6616442c67a09b7aaef13f (diff)
downloadbt-dca653a64a09a0b94b28fc6034b6330ebf06a76c.tar.gz
Add libbt-vendor for Marvell BT USB char driver
Change-Id: Idee328cd4aa010dbb69d2e2d8d600c0f6b67149b Signed-off-by: Toshi Kikuchi <toshik@google.com>
-rw-r--r--Android.mk1
-rw-r--r--libbt-vendor/Android.mk22
-rw-r--r--libbt-vendor/bt_vendor_mrvl.c138
3 files changed, 161 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..d34dc85
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1 @@
+include $(call all-named-subdir-makefiles,libbt-vendor)
diff --git a/libbt-vendor/Android.mk b/libbt-vendor/Android.mk
new file mode 100644
index 0000000..86f17bb
--- /dev/null
+++ b/libbt-vendor/Android.mk
@@ -0,0 +1,22 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+BDROID_DIR := $(TOP_DIR)external/bluetooth/bluedroid
+
+LOCAL_SRC_FILES := \
+ bt_vendor_mrvl.c
+
+LOCAL_C_INCLUDES += \
+ $(BDROID_DIR)/hci/include
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils
+
+LOCAL_MODULE := libbt-vendor
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE_OWNER := marvell
+LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/libbt-vendor/bt_vendor_mrvl.c b/libbt-vendor/bt_vendor_mrvl.c
new file mode 100644
index 0000000..93664cc
--- /dev/null
+++ b/libbt-vendor/bt_vendor_mrvl.c
@@ -0,0 +1,138 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2012 Marvell International Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#include <time.h>
+#include <errno.h>
+#include <sched.h>
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <sys/mman.h>
+#include <pthread.h>
+#include "bt_vendor_lib.h"
+
+/* ioctl command to release the read thread before driver close */
+#define MBTCHAR_IOCTL_RELEASE _IO ('M',1)
+
+#define VERSION "M001"
+
+static bt_vendor_callbacks_t *vnd_cb = NULL;
+
+static unsigned char bdaddr[6];
+
+static char mchar_port[] = "/dev/mbtchar0";
+
+static int mchar_fd = -1;
+
+int bt_vnd_mrvl_if_init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr)
+{
+ vnd_cb = p_cb;
+ memcpy(bdaddr, local_bdaddr, sizeof(bdaddr));
+ return 0;
+}
+
+int bt_vnd_mrvl_if_op(bt_vendor_opcode_t opcode, void *param)
+{
+ int ret = 0;
+ int power_state;
+ int local_st = 0;
+
+ switch (opcode) {
+ case BT_VND_OP_POWER_CTRL:
+ power_state = (int *)param;
+ if (BT_VND_PWR_OFF == power_state) {
+ } else if (BT_VND_PWR_ON == power_state) {
+ } else {
+ ret = -1;
+ }
+ break;
+ case BT_VND_OP_FW_CFG:
+ // TODO: Perform any vendor specific initialization or configuration on the BT Controller
+ // ret = xxx
+ if (vnd_cb) {
+ vnd_cb->fwcfg_cb(ret);
+ }
+ break;
+ case BT_VND_OP_SCO_CFG:
+ // TODO: Perform any vendor specific SCO/PCM configuration on the BT Controller.
+ // ret = xxx
+ if (vnd_cb) {
+ vnd_cb->scocfg_cb(ret);
+ }
+ break;
+ case BT_VND_OP_USERIAL_OPEN:
+ mchar_fd = open(mchar_port, O_RDWR|O_NOCTTY);
+ if (mchar_fd < 0) {
+ ret = -1;
+ } else {
+ ret = 1;
+ }
+ ((int *)param)[0] = mchar_fd;
+ break;
+ case BT_VND_OP_USERIAL_CLOSE:
+ if (mchar_fd < 0) {
+ ret = -1;
+ } else {
+ /* mbtchar port is blocked on read. Release the port before we close it */
+ ioctl(mchar_fd,MBTCHAR_IOCTL_RELEASE,&local_st);
+ /* Give it sometime before we close the mbtchar */
+ usleep(1000);
+ if (close(mchar_fd) < 0) {
+ ret = -1;
+ } else {
+ mchar_fd = -1; /* closed successfully */
+ }
+ }
+ break;
+ case BT_VND_OP_GET_LPM_IDLE_TIMEOUT:
+ break;
+ case BT_VND_OP_LPM_SET_MODE:
+ // TODO: Enable or disable LPM mode on BT Controller.
+ // ret = xx;
+ if (vnd_cb) {
+ vnd_cb->lpm_cb(ret);
+ }
+ break;
+ case BT_VND_OP_LPM_WAKE_SET_STATE:
+ break;
+ default:
+ ret = -1;
+ break;
+ }
+ return ret;
+}
+
+void bt_vnd_mrvl_if_cleanup(void)
+{
+ return;
+}
+
+const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
+ sizeof(bt_vendor_interface_t),
+ bt_vnd_mrvl_if_init,
+ bt_vnd_mrvl_if_op,
+ bt_vnd_mrvl_if_cleanup,
+};
+