Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-broadcom-libbt: Commit

hardware/broadcom/libbt


Commit MetaInfo

Revisionb68b1abeef4248a2c96f6f05bcf8f778aea52b82 (tree)
Time2013-04-12 02:09:48
AuthorGeoff Mendal <mendal@goog...>
CommiterGeoff Mendal

Log Message

Merge libbt/ from device/common to /

Change Summary

Incremental Difference

--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,47 @@
1+LOCAL_PATH := $(call my-dir)
2+
3+ifneq ($(BOARD_HAVE_BLUETOOTH_BCM),)
4+
5+include $(CLEAR_VARS)
6+
7+BDROID_DIR := $(TOP_DIR)external/bluetooth/bluedroid
8+
9+LOCAL_SRC_FILES := \
10+ src/bt_vendor_brcm.c \
11+ src/hardware.c \
12+ src/userial_vendor.c \
13+ src/upio.c \
14+ src/conf.c
15+
16+LOCAL_C_INCLUDES += \
17+ $(LOCAL_PATH)/include \
18+ $(BDROID_DIR)/hci/include
19+
20+LOCAL_SHARED_LIBRARIES := \
21+ libcutils \
22+ liblog
23+
24+LOCAL_MODULE := libbt-vendor
25+LOCAL_MODULE_TAGS := optional
26+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
27+LOCAL_MODULE_OWNER := broadcom
28+LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)
29+
30+include $(LOCAL_PATH)/vnd_buildcfg.mk
31+
32+include $(BUILD_SHARED_LIBRARY)
33+
34+ifeq ($(TARGET_PRODUCT), full_maguro)
35+ include $(LOCAL_PATH)/conf/samsung/maguro/Android.mk
36+endif
37+ifeq ($(TARGET_PRODUCT), full_crespo)
38+ include $(LOCAL_PATH)/conf/samsung/crespo/Android.mk
39+endif
40+ifeq ($(TARGET_PRODUCT), full_crespo4g)
41+ include $(LOCAL_PATH)/conf/samsung/crespo4g/Android.mk
42+endif
43+ifeq ($(TARGET_PRODUCT), full_wingray)
44+ include $(LOCAL_PATH)/conf/moto/wingray/Android.mk
45+endif
46+
47+endif # BOARD_HAVE_BLUETOOTH_BCM
--- /dev/null
+++ b/conf/asus/grouper/Android.mk
@@ -0,0 +1,14 @@
1+LOCAL_PATH := $(call my-dir)
2+
3+include $(CLEAR_VARS)
4+
5+LOCAL_MODULE := bt_vendor.conf
6+LOCAL_MODULE_CLASS := ETC
7+LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/bluetooth
8+
9+LOCAL_MODULE_TAGS := eng
10+
11+LOCAL_SRC_FILES := $(LOCAL_MODULE)
12+
13+include $(BUILD_PREBUILT)
14+
--- /dev/null
+++ b/conf/asus/grouper/bt_vendor.conf
@@ -0,0 +1,5 @@
1+# UART device port where Bluetooth controller is attached
2+UartPort = /dev/ttyHS2
3+
4+# Firmware patch file location
5+FwPatchFilePath = /etc/firmware/
--- /dev/null
+++ b/conf/moto/wingray/Android.mk
@@ -0,0 +1,14 @@
1+LOCAL_PATH := $(call my-dir)
2+
3+include $(CLEAR_VARS)
4+
5+LOCAL_MODULE := bt_vendor.conf
6+LOCAL_MODULE_CLASS := ETC
7+LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/bluetooth
8+
9+LOCAL_MODULE_TAGS := eng
10+
11+LOCAL_SRC_FILES := $(LOCAL_MODULE)
12+
13+include $(BUILD_PREBUILT)
14+
--- /dev/null
+++ b/conf/moto/wingray/bt_vendor.conf
@@ -0,0 +1,5 @@
1+# UART device port where Bluetooth controller is attached
2+UartPort = /dev/ttyHS2
3+
4+# Firmware patch file location
5+FwPatchFilePath = /etc/firmware/
--- /dev/null
+++ b/conf/samsung/crespo/Android.mk
@@ -0,0 +1,14 @@
1+LOCAL_PATH := $(call my-dir)
2+
3+include $(CLEAR_VARS)
4+
5+LOCAL_MODULE := bt_vendor.conf
6+LOCAL_MODULE_CLASS := ETC
7+LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/bluetooth
8+
9+LOCAL_MODULE_TAGS := eng
10+
11+LOCAL_SRC_FILES := $(LOCAL_MODULE)
12+
13+include $(BUILD_PREBUILT)
14+
--- /dev/null
+++ b/conf/samsung/crespo/bt_vendor.conf
@@ -0,0 +1,5 @@
1+# UART device port where Bluetooth controller is attached
2+UartPort = /dev/s3c2410_serial0
3+
4+# Firmware patch file location
5+FwPatchFilePath = /vendor/firmware/
--- /dev/null
+++ b/conf/samsung/crespo4g/Android.mk
@@ -0,0 +1,14 @@
1+LOCAL_PATH := $(call my-dir)
2+
3+include $(CLEAR_VARS)
4+
5+LOCAL_MODULE := bt_vendor.conf
6+LOCAL_MODULE_CLASS := ETC
7+LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/bluetooth
8+
9+LOCAL_MODULE_TAGS := eng
10+
11+LOCAL_SRC_FILES := $(LOCAL_MODULE)
12+
13+include $(BUILD_PREBUILT)
14+
--- /dev/null
+++ b/conf/samsung/crespo4g/bt_vendor.conf
@@ -0,0 +1,5 @@
1+# UART device port where Bluetooth controller is attached
2+UartPort = /dev/s3c2410_serial0
3+
4+# Firmware patch file location
5+FwPatchFilePath = /vendor/firmware/
--- /dev/null
+++ b/conf/samsung/maguro/Android.mk
@@ -0,0 +1,14 @@
1+LOCAL_PATH := $(call my-dir)
2+
3+include $(CLEAR_VARS)
4+
5+LOCAL_MODULE := bt_vendor.conf
6+LOCAL_MODULE_CLASS := ETC
7+LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/bluetooth
8+
9+LOCAL_MODULE_TAGS := eng
10+
11+LOCAL_SRC_FILES := $(LOCAL_MODULE)
12+
13+include $(BUILD_PREBUILT)
14+
--- /dev/null
+++ b/conf/samsung/maguro/bt_vendor.conf
@@ -0,0 +1,5 @@
1+# UART device port where Bluetooth controller is attached
2+UartPort = /dev/ttyO1
3+
4+# Firmware patch file location
5+FwPatchFilePath = /vendor/firmware/
--- /dev/null
+++ b/include/bt_vendor_brcm.h
@@ -0,0 +1,359 @@
1+/******************************************************************************
2+ *
3+ * Copyright (C) 2009-2012 Broadcom Corporation
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ ******************************************************************************/
18+
19+/******************************************************************************
20+ *
21+ * Filename: bt_vendor_brcm.h
22+ *
23+ * Description: A wrapper header file of bt_vendor_lib.h
24+ *
25+ * Contains definitions specific for interfacing with Broadcom
26+ * Bluetooth chipsets
27+ *
28+ ******************************************************************************/
29+
30+#ifndef BT_VENDOR_BRCM_H
31+#define BT_VENDOR_BRCM_H
32+
33+#include "bt_vendor_lib.h"
34+#include "vnd_buildcfg.h"
35+
36+/******************************************************************************
37+** Constants & Macros
38+******************************************************************************/
39+
40+#ifndef FALSE
41+#define FALSE 0
42+#endif
43+
44+#ifndef TRUE
45+#define TRUE (!FALSE)
46+#endif
47+
48+#ifndef VENDOR_LIB_RUNTIME_TUNING_ENABLED
49+#define VENDOR_LIB_RUNTIME_TUNING_ENABLED FALSE
50+#endif
51+
52+/* Run-time configuration file */
53+#ifndef VENDOR_LIB_CONF_FILE
54+#define VENDOR_LIB_CONF_FILE "/etc/bluetooth/bt_vendor.conf"
55+#endif
56+
57+/* Device port name where Bluetooth controller attached */
58+#ifndef BLUETOOTH_UART_DEVICE_PORT
59+#define BLUETOOTH_UART_DEVICE_PORT "/dev/ttyO1" /* maguro */
60+#endif
61+
62+/* Location of firmware patch files */
63+#ifndef FW_PATCHFILE_LOCATION
64+#define FW_PATCHFILE_LOCATION "/vendor/firmware/" /* maguro */
65+#endif
66+
67+#ifndef UART_TARGET_BAUD_RATE
68+#define UART_TARGET_BAUD_RATE 3000000
69+#endif
70+
71+/* The millisecond delay pauses on HCI transport after firmware patches
72+ * were downloaded. This gives some time for firmware to restart with
73+ * patches before host attempts to send down any HCI commands.
74+ *
75+ * Note: It has been discovered that BCM43241B0 needs at least 200ms
76+ * settlement delay in here. Without the delay, a Hardware Error event
77+ * from BCM43241B0 had been seen in HCI upstream path right after the
78+ * host sent the HCI_VSC_SET_BDADDR commad to the controller at higher
79+ * baud.
80+ */
81+#ifndef FW_PATCH_SETTLEMENT_DELAY_MS
82+#define FW_PATCH_SETTLEMENT_DELAY_MS 0
83+#endif
84+
85+/* The Bluetooth Device Aaddress source switch:
86+ *
87+ * -FALSE- (default value)
88+ * Get the factory BDADDR from device's file system. Normally the BDADDR is
89+ * stored in the location pointed by the PROPERTY_BT_BDADDR_PATH (defined in
90+ * btif_common.h file) property.
91+ *
92+ * -TRUE-
93+ * If the Bluetooth Controller has equipped with a non-volatile memory (such
94+ * as BCM4330's OTP memory), the factory BDADDR can be stored in there and
95+ * retrieved by the stack while enabling BT.
96+ * !!! WARNING !!! Make sure that the OTP feature has been enabled in the
97+ * firmware patchram (.hcd) file.
98+ */
99+#ifndef USE_CONTROLLER_BDADDR
100+#define USE_CONTROLLER_BDADDR FALSE
101+#endif
102+
103+/* sleep mode
104+
105+ 0: disable
106+ 1: UART with Host wake/BT wake out of band signals
107+*/
108+#ifndef LPM_SLEEP_MODE
109+#define LPM_SLEEP_MODE 1
110+#endif
111+
112+/* Host Stack Idle Threshold in 300ms or 25ms
113+
114+ In sleep mode 1, this is the number of firmware loops executed with no
115+ activity before the Host wake line is deasserted. Activity includes HCI
116+ traffic excluding certain sleep mode commands and the presence of SCO
117+ connections if the "Allow Host Sleep During SCO" flag is not set to 1.
118+ Each count of this parameter is roughly equivalent to 300ms or 25ms.
119+*/
120+#ifndef LPM_IDLE_THRESHOLD
121+#define LPM_IDLE_THRESHOLD 1
122+#endif
123+
124+/* Host Controller Idle Threshold in 300ms or 25ms
125+
126+ This is the number of firmware loops executed with no activity before the
127+ HC is considered idle. Depending on the mode, HC may then attempt to sleep.
128+ Activity includes HCI traffic excluding certain sleep mode commands and
129+ the presence of ACL/SCO connections.
130+*/
131+#ifndef LPM_HC_IDLE_THRESHOLD
132+#define LPM_HC_IDLE_THRESHOLD 1
133+#endif
134+
135+/* BT_WAKE Polarity - 0=Active Low, 1= Active High */
136+#ifndef LPM_BT_WAKE_POLARITY
137+#define LPM_BT_WAKE_POLARITY 1 /* maguro */
138+#endif
139+
140+/* HOST_WAKE Polarity - 0=Active Low, 1= Active High */
141+#ifndef LPM_HOST_WAKE_POLARITY
142+#define LPM_HOST_WAKE_POLARITY 1 /* maguro */
143+#endif
144+
145+/* LPM_ALLOW_HOST_SLEEP_DURING_SCO
146+
147+ When this flag is set to 0, the host is not allowed to sleep while
148+ an SCO is active. In sleep mode 1, the device will keep the host
149+ wake line asserted while an SCO is active.
150+ When this flag is set to 1, the host can sleep while an SCO is active.
151+ This flag should only be set to 1 if SCO traffic is directed to the PCM
152+ interface.
153+*/
154+#ifndef LPM_ALLOW_HOST_SLEEP_DURING_SCO
155+#define LPM_ALLOW_HOST_SLEEP_DURING_SCO 1
156+#endif
157+
158+/* LPM_COMBINE_SLEEP_MODE_AND_LPM
159+
160+ In Mode 0, always set byte 7 to 0. In sleep mode 1, device always
161+ requires permission to sleep between scans / periodic inquiries regardless
162+ of the setting of this byte. In sleep mode 1, if byte is set, device must
163+ have "permission" to sleep during the low power modes of sniff, hold, and
164+ park. If byte is not set, device can sleep without permission during these
165+ modes. Permission to sleep in Mode 1 is obtained if the BT_WAKE signal is
166+ not asserted.
167+*/
168+#ifndef LPM_COMBINE_SLEEP_MODE_AND_LPM
169+#define LPM_COMBINE_SLEEP_MODE_AND_LPM 1
170+#endif
171+
172+/* LPM_ENABLE_UART_TXD_TRI_STATE
173+
174+ When set to 0, the device will not tristate its UART TX line before going
175+ to sleep.
176+ When set to 1, the device will tristate its UART TX line before going to
177+ sleep.
178+*/
179+#ifndef LPM_ENABLE_UART_TXD_TRI_STATE
180+#define LPM_ENABLE_UART_TXD_TRI_STATE 0
181+#endif
182+
183+/* LPM_PULSED_HOST_WAKE
184+*/
185+#ifndef LPM_PULSED_HOST_WAKE
186+#define LPM_PULSED_HOST_WAKE 0
187+#endif
188+
189+/* LPM_IDLE_TIMEOUT_MULTIPLE
190+
191+ The multiple factor of host stack idle threshold in 300ms/25ms
192+*/
193+#ifndef LPM_IDLE_TIMEOUT_MULTIPLE
194+#define LPM_IDLE_TIMEOUT_MULTIPLE 10
195+#endif
196+
197+/* BT_WAKE_VIA_USERIAL_IOCTL
198+
199+ Use userial ioctl function to control BT_WAKE signal
200+*/
201+#ifndef BT_WAKE_VIA_USERIAL_IOCTL
202+#define BT_WAKE_VIA_USERIAL_IOCTL FALSE
203+#endif
204+
205+/* BT_WAKE_VIA_PROC
206+
207+ LPM & BT_WAKE control through PROC nodes
208+*/
209+#ifndef BT_WAKE_VIA_PROC
210+#define BT_WAKE_VIA_PROC FALSE
211+#endif
212+
213+/* SCO_CFG_INCLUDED
214+
215+ Do SCO configuration by default. If the firmware patch had been embedded
216+ with desired SCO configuration, set this FALSE to bypass configuration
217+ from host software.
218+*/
219+#ifndef SCO_CFG_INCLUDED
220+#define SCO_CFG_INCLUDED TRUE
221+#endif
222+
223+#ifndef SCO_USE_I2S_INTERFACE
224+#define SCO_USE_I2S_INTERFACE FALSE
225+#endif
226+
227+#if (SCO_USE_I2S_INTERFACE == TRUE)
228+#define SCO_I2SPCM_PARAM_SIZE 4
229+
230+/* SCO_I2SPCM_IF_MODE - 0=Disable, 1=Enable */
231+#ifndef SCO_I2SPCM_IF_MODE
232+#define SCO_I2SPCM_IF_MODE 1
233+#endif
234+
235+/* SCO_I2SPCM_IF_ROLE - 0=Slave, 1=Master */
236+#ifndef SCO_I2SPCM_IF_ROLE
237+#define SCO_I2SPCM_IF_ROLE 1
238+#endif
239+
240+/* SCO_I2SPCM_IF_SAMPLE_RATE
241+
242+ 0 : 8K
243+ 1 : 16K
244+ 2 : 4K
245+*/
246+#ifndef SCO_I2SPCM_IF_SAMPLE_RATE
247+#define SCO_I2SPCM_IF_SAMPLE_RATE 0
248+#endif
249+
250+/* SCO_I2SPCM_IF_CLOCK_RATE
251+
252+ 0 : 128K
253+ 1 : 256K
254+ 2 : 512K
255+ 3 : 1024K
256+ 4 : 2048K
257+*/
258+#ifndef SCO_I2SPCM_IF_CLOCK_RATE
259+#define SCO_I2SPCM_IF_CLOCK_RATE 1
260+#endif
261+#endif // SCO_USE_I2S_INTERFACE
262+
263+
264+#define SCO_PCM_PARAM_SIZE 5
265+
266+/* SCO_PCM_ROUTING
267+
268+ 0 : PCM
269+ 1 : Transport
270+ 2 : Codec
271+ 3 : I2S
272+*/
273+#ifndef SCO_PCM_ROUTING
274+#define SCO_PCM_ROUTING 0
275+#endif
276+
277+/* SCO_PCM_IF_CLOCK_RATE
278+
279+ 0 : 128K
280+ 1 : 256K
281+ 2 : 512K
282+ 3 : 1024K
283+ 4 : 2048K
284+*/
285+#ifndef SCO_PCM_IF_CLOCK_RATE
286+#define SCO_PCM_IF_CLOCK_RATE 4
287+#endif
288+
289+/* SCO_PCM_IF_FRAME_TYPE - 0=Short, 1=Long */
290+#ifndef SCO_PCM_IF_FRAME_TYPE
291+#define SCO_PCM_IF_FRAME_TYPE 0
292+#endif
293+
294+/* SCO_PCM_IF_SYNC_MODE - 0=Slave, 1=Master */
295+#ifndef SCO_PCM_IF_SYNC_MODE
296+#define SCO_PCM_IF_SYNC_MODE 0
297+#endif
298+
299+/* SCO_PCM_IF_CLOCK_MODE - 0=Slave, 1=Master */
300+#ifndef SCO_PCM_IF_CLOCK_MODE
301+#define SCO_PCM_IF_CLOCK_MODE 0
302+#endif
303+
304+#define PCM_DATA_FORMAT_PARAM_SIZE 5
305+
306+/* PCM_DATA_FMT_SHIFT_MODE
307+
308+ 0 : MSB first
309+ 1 : LSB first
310+*/
311+#ifndef PCM_DATA_FMT_SHIFT_MODE
312+#define PCM_DATA_FMT_SHIFT_MODE 0
313+#endif
314+
315+/* PCM_DATA_FMT_FILL_BITS
316+
317+ Specifies the value with which to fill unused bits
318+ if Fill_Method is set to programmable
319+*/
320+#ifndef PCM_DATA_FMT_FILL_BITS
321+#define PCM_DATA_FMT_FILL_BITS 0
322+#endif
323+
324+/* PCM_DATA_FMT_FILL_METHOD
325+
326+ 0 : 0's
327+ 1 : 1's
328+ 2 : Signed
329+ 3 : Programmable
330+*/
331+#ifndef PCM_DATA_FMT_FILL_METHOD
332+#define PCM_DATA_FMT_FILL_METHOD 3
333+#endif
334+
335+/* PCM_DATA_FMT_FILL_NUM
336+
337+ Specifies the number of bits to be filled
338+*/
339+#ifndef PCM_DATA_FMT_FILL_NUM
340+#define PCM_DATA_FMT_FILL_NUM 3
341+#endif
342+
343+/* PCM_DATA_FMT_JUSTIFY_MODE
344+
345+ 0 : Left justify (fill data shifted out last)
346+ 1 : Right justify (fill data shifted out first)
347+*/
348+#ifndef PCM_DATA_FMT_JUSTIFY_MODE
349+#define PCM_DATA_FMT_JUSTIFY_MODE 0
350+#endif
351+
352+/******************************************************************************
353+** Extern variables and functions
354+******************************************************************************/
355+
356+extern bt_vendor_callbacks_t *bt_vendor_cbacks;
357+
358+#endif /* BT_VENDOR_BRCM_H */
359+
--- /dev/null
+++ b/include/upio.h
@@ -0,0 +1,107 @@
1+/******************************************************************************
2+ *
3+ * Copyright (C) 2009-2012 Broadcom Corporation
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ ******************************************************************************/
18+
19+/******************************************************************************
20+ *
21+ * Filename: upio.h
22+ *
23+ * Description: Contains definitions used for I/O controls
24+ *
25+ ******************************************************************************/
26+
27+#ifndef UPIO_H
28+#define UPIO_H
29+
30+/******************************************************************************
31+** Constants & Macros
32+******************************************************************************/
33+
34+#define UPIO_BT_POWER_OFF 0
35+#define UPIO_BT_POWER_ON 1
36+
37+/* UPIO signals */
38+enum {
39+ UPIO_BT_WAKE = 0,
40+ UPIO_HOST_WAKE,
41+ UPIO_LPM_MODE,
42+ UPIO_MAX_COUNT
43+};
44+
45+/* UPIO assertion/deassertion */
46+enum {
47+ UPIO_UNKNOWN = 0,
48+ UPIO_DEASSERT,
49+ UPIO_ASSERT
50+};
51+
52+/******************************************************************************
53+** Extern variables and functions
54+******************************************************************************/
55+
56+/******************************************************************************
57+** Functions
58+******************************************************************************/
59+
60+/*******************************************************************************
61+**
62+** Function upio_init
63+**
64+** Description Initialization
65+**
66+** Returns None
67+**
68+*******************************************************************************/
69+void upio_init(void);
70+
71+/*******************************************************************************
72+**
73+** Function upio_cleanup
74+**
75+** Description Clean up
76+**
77+** Returns None
78+**
79+*******************************************************************************/
80+void upio_cleanup(void);
81+
82+/*******************************************************************************
83+**
84+** Function upio_set_bluetooth_power
85+**
86+** Description Interact with low layer driver to set Bluetooth power
87+** on/off.
88+**
89+** Returns 0 : SUCCESS or Not-Applicable
90+** <0 : ERROR
91+**
92+*******************************************************************************/
93+int upio_set_bluetooth_power(int on);
94+
95+/*******************************************************************************
96+**
97+** Function upio_set
98+**
99+** Description Set i/o based on polarity
100+**
101+** Returns None
102+**
103+*******************************************************************************/
104+void upio_set(uint8_t pio, uint8_t action, uint8_t polarity);
105+
106+#endif /* UPIO_H */
107+
--- /dev/null
+++ b/include/userial_vendor.h
@@ -0,0 +1,175 @@
1+/******************************************************************************
2+ *
3+ * Copyright (C) 2009-2012 Broadcom Corporation
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ ******************************************************************************/
18+
19+/******************************************************************************
20+ *
21+ * Filename: userial_vendor.h
22+ *
23+ * Description: Contains vendor-specific definitions used in serial port
24+ * controls
25+ *
26+ ******************************************************************************/
27+
28+#ifndef USERIAL_VENDOR_H
29+#define USERIAL_VENDOR_H
30+
31+#include "bt_vendor_brcm.h"
32+#include "userial.h"
33+
34+/******************************************************************************
35+** Constants & Macros
36+******************************************************************************/
37+
38+/**** baud rates ****/
39+#define USERIAL_BAUD_300 0
40+#define USERIAL_BAUD_600 1
41+#define USERIAL_BAUD_1200 2
42+#define USERIAL_BAUD_2400 3
43+#define USERIAL_BAUD_9600 4
44+#define USERIAL_BAUD_19200 5
45+#define USERIAL_BAUD_57600 6
46+#define USERIAL_BAUD_115200 7
47+#define USERIAL_BAUD_230400 8
48+#define USERIAL_BAUD_460800 9
49+#define USERIAL_BAUD_921600 10
50+#define USERIAL_BAUD_1M 11
51+#define USERIAL_BAUD_1_5M 12
52+#define USERIAL_BAUD_2M 13
53+#define USERIAL_BAUD_3M 14
54+#define USERIAL_BAUD_4M 15
55+#define USERIAL_BAUD_AUTO 16
56+
57+/**** Data Format ****/
58+/* Stop Bits */
59+#define USERIAL_STOPBITS_1 1
60+#define USERIAL_STOPBITS_1_5 (1<<1)
61+#define USERIAL_STOPBITS_2 (1<<2)
62+
63+/* Parity Bits */
64+#define USERIAL_PARITY_NONE (1<<3)
65+#define USERIAL_PARITY_EVEN (1<<4)
66+#define USERIAL_PARITY_ODD (1<<5)
67+
68+/* Data Bits */
69+#define USERIAL_DATABITS_5 (1<<6)
70+#define USERIAL_DATABITS_6 (1<<7)
71+#define USERIAL_DATABITS_7 (1<<8)
72+#define USERIAL_DATABITS_8 (1<<9)
73+
74+
75+#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
76+/* These are the ioctl values used for bt_wake ioctl via UART driver. you may
77+ * need to redefine them on you platform!
78+ * Logically they need to be unique and not colide with existing uart ioctl's.
79+ */
80+#ifndef USERIAL_IOCTL_BT_WAKE_ASSERT
81+#define USERIAL_IOCTL_BT_WAKE_ASSERT 0x8003
82+#endif
83+#ifndef USERIAL_IOCTL_BT_WAKE_DEASSERT
84+#define USERIAL_IOCTL_BT_WAKE_DEASSERT 0x8004
85+#endif
86+#ifndef USERIAL_IOCTL_BT_WAKE_GET_ST
87+#define USERIAL_IOCTL_BT_WAKE_GET_ST 0x8005
88+#endif
89+#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
90+
91+/******************************************************************************
92+** Type definitions
93+******************************************************************************/
94+
95+/* Structure used to configure serial port during open */
96+typedef struct
97+{
98+ uint16_t fmt; /* Data format */
99+ uint8_t baud; /* Baud rate */
100+} tUSERIAL_CFG;
101+
102+typedef enum {
103+#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
104+ USERIAL_OP_ASSERT_BT_WAKE,
105+ USERIAL_OP_DEASSERT_BT_WAKE,
106+ USERIAL_OP_GET_BT_WAKE_STATE,
107+#endif
108+ USERIAL_OP_NOP,
109+} userial_vendor_ioctl_op_t;
110+
111+/******************************************************************************
112+** Extern variables and functions
113+******************************************************************************/
114+
115+/******************************************************************************
116+** Functions
117+******************************************************************************/
118+
119+/*******************************************************************************
120+**
121+** Function userial_vendor_init
122+**
123+** Description Initialize userial vendor-specific control block
124+**
125+** Returns None
126+**
127+*******************************************************************************/
128+void userial_vendor_init(void);
129+
130+/*******************************************************************************
131+**
132+** Function userial_vendor_open
133+**
134+** Description Open the serial port with the given configuration
135+**
136+** Returns device fd
137+**
138+*******************************************************************************/
139+int userial_vendor_open(tUSERIAL_CFG *p_cfg);
140+
141+/*******************************************************************************
142+**
143+** Function userial_vendor_close
144+**
145+** Description Conduct vendor-specific close work
146+**
147+** Returns None
148+**
149+*******************************************************************************/
150+void userial_vendor_close(void);
151+
152+/*******************************************************************************
153+**
154+** Function userial_vendor_set_baud
155+**
156+** Description Set new baud rate
157+**
158+** Returns None
159+**
160+*******************************************************************************/
161+void userial_vendor_set_baud(uint8_t userial_baud);
162+
163+/*******************************************************************************
164+**
165+** Function userial_vendor_ioctl
166+**
167+** Description ioctl inteface
168+**
169+** Returns None
170+**
171+*******************************************************************************/
172+void userial_vendor_ioctl(userial_vendor_ioctl_op_t op, void *p_data);
173+
174+#endif /* USERIAL_VENDOR_H */
175+
--- /dev/null
+++ b/include/vnd_crespo.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/s3c2410_serial0"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+SCO_PCM_IF_CLOCK_RATE = 0
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_crespo4g.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/s3c2410_serial0"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+SCO_PCM_IF_CLOCK_RATE = 0
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_generic.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyO1"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+SCO_USE_I2S_INTERFACE = TRUE
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_generic_x86.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyO1"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+SCO_USE_I2S_INTERFACE = TRUE
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_grouper.txt
@@ -0,0 +1,10 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyHS2"
2+FW_PATCHFILE_LOCATION = "/etc/firmware/"
3+BT_WAKE_VIA_PROC = TRUE
4+LPM_IDLE_TIMEOUT_MULTIPLE = 5
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
9+SCO_PCM_IF_CLOCK_RATE = 2
10+USE_CONTROLLER_BDADDR = TRUE
--- /dev/null
+++ b/include/vnd_maguro.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyO1"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+SCO_USE_I2S_INTERFACE = TRUE
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_mako.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyO1"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+SCO_USE_I2S_INTERFACE = TRUE
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_manta.txt
@@ -0,0 +1,10 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttySAC0"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+UART_TARGET_BAUD_RATE = 921600
4+LPM_IDLE_TIMEOUT_MULTIPLE = 5
5+SCO_USE_I2S_INTERFACE = TRUE
6+SCO_I2SPCM_IF_ROLE = 0
7+BTVND_DBG = FALSE
8+BTHW_DBG = TRUE
9+VNDUSERIAL_DBG = FALSE
10+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_phantasm.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyO1"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+SCO_USE_I2S_INTERFACE = TRUE
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_stingray.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyHS2"
2+FW_PATCHFILE_LOCATION = "/etc/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+BTVND_DBG = FALSE
5+BTHW_DBG = TRUE
6+VNDUSERIAL_DBG = FALSE
7+UPIO_DBG = FALSE
8+SCO_PCM_IF_CLOCK_RATE = 2
--- /dev/null
+++ b/include/vnd_tilapia.txt
@@ -0,0 +1,10 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyHS2"
2+FW_PATCHFILE_LOCATION = "/etc/firmware/"
3+BT_WAKE_VIA_PROC = TRUE
4+LPM_IDLE_TIMEOUT_MULTIPLE = 5
5+BTVND_DBG = FALSE
6+BTHW_DBG = TRUE
7+VNDUSERIAL_DBG = FALSE
8+UPIO_DBG = FALSE
9+SCO_PCM_IF_CLOCK_RATE = 2
10+USE_CONTROLLER_BDADDR = TRUE
--- /dev/null
+++ b/include/vnd_toro.txt
@@ -0,0 +1,9 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyO1"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+BT_WAKE_VIA_USERIAL_IOCTL = TRUE
4+LPM_IDLE_TIMEOUT_MULTIPLE = 5
5+SCO_USE_I2S_INTERFACE = TRUE
6+BTVND_DBG = FALSE
7+BTHW_DBG = TRUE
8+VNDUSERIAL_DBG = FALSE
9+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_tuna.txt
@@ -0,0 +1,9 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyO1"
2+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
3+BT_WAKE_VIA_USERIAL_IOCTL = TRUE
4+LPM_IDLE_TIMEOUT_MULTIPLE = 5
5+SCO_USE_I2S_INTERFACE = TRUE
6+BTVND_DBG = FALSE
7+BTHW_DBG = TRUE
8+VNDUSERIAL_DBG = FALSE
9+UPIO_DBG = FALSE
--- /dev/null
+++ b/include/vnd_wingray.txt
@@ -0,0 +1,8 @@
1+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyHS2"
2+FW_PATCHFILE_LOCATION = "/etc/firmware/"
3+LPM_IDLE_TIMEOUT_MULTIPLE = 5
4+BTVND_DBG = FALSE
5+BTHW_DBG = TRUE
6+VNDUSERIAL_DBG = FALSE
7+UPIO_DBG = FALSE
8+SCO_PCM_IF_CLOCK_RATE = 2
--- /dev/null
+++ b/src/bt_vendor_brcm.c
@@ -0,0 +1,227 @@
1+/******************************************************************************
2+ *
3+ * Copyright (C) 2009-2012 Broadcom Corporation
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ ******************************************************************************/
18+
19+/******************************************************************************
20+ *
21+ * Filename: bt_vendor_brcm.c
22+ *
23+ * Description: Broadcom vendor specific library implementation
24+ *
25+ ******************************************************************************/
26+
27+#define LOG_TAG "bt_vendor"
28+
29+#include <utils/Log.h>
30+#include "bt_vendor_brcm.h"
31+#include "upio.h"
32+#include "userial_vendor.h"
33+
34+#ifndef BTVND_DBG
35+#define BTVND_DBG FALSE
36+#endif
37+
38+#if (BTVND_DBG == TRUE)
39+#define BTVNDDBG(param, ...) {ALOGD(param, ## __VA_ARGS__);}
40+#else
41+#define BTVNDDBG(param, ...) {}
42+#endif
43+
44+/******************************************************************************
45+** Externs
46+******************************************************************************/
47+
48+void hw_config_start(void);
49+uint8_t hw_lpm_enable(uint8_t turn_on);
50+uint32_t hw_lpm_get_idle_timeout(void);
51+void hw_lpm_set_wake_state(uint8_t wake_assert);
52+#if (SCO_CFG_INCLUDED == TRUE)
53+void hw_sco_config(void);
54+#endif
55+void vnd_load_conf(const char *p_path);
56+
57+/******************************************************************************
58+** Variables
59+******************************************************************************/
60+
61+bt_vendor_callbacks_t *bt_vendor_cbacks = NULL;
62+uint8_t vnd_local_bd_addr[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
63+
64+/******************************************************************************
65+** Local type definitions
66+******************************************************************************/
67+
68+/******************************************************************************
69+** Static Variables
70+******************************************************************************/
71+
72+static const tUSERIAL_CFG userial_init_cfg =
73+{
74+ (USERIAL_DATABITS_8 | USERIAL_PARITY_NONE | USERIAL_STOPBITS_1),
75+ USERIAL_BAUD_115200
76+};
77+
78+/******************************************************************************
79+** Functions
80+******************************************************************************/
81+
82+/*****************************************************************************
83+**
84+** BLUETOOTH VENDOR INTERFACE LIBRARY FUNCTIONS
85+**
86+*****************************************************************************/
87+
88+static int init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr)
89+{
90+ ALOGI("init");
91+
92+ if (p_cb == NULL)
93+ {
94+ ALOGE("init failed with no user callbacks!");
95+ return -1;
96+ }
97+
98+#if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE)
99+ ALOGW("*****************************************************************");
100+ ALOGW("*****************************************************************");
101+ ALOGW("** Warning - BT Vendor Lib is loaded in debug tuning mode!");
102+ ALOGW("**");
103+ ALOGW("** If this is not intentional, rebuild libbt-vendor.so ");
104+ ALOGW("** with VENDOR_LIB_RUNTIME_TUNING_ENABLED=FALSE and ");
105+ ALOGW("** check if any run-time tuning parameters needed to be");
106+ ALOGW("** carried to the build-time configuration accordingly.");
107+ ALOGW("*****************************************************************");
108+ ALOGW("*****************************************************************");
109+#endif
110+
111+ userial_vendor_init();
112+ upio_init();
113+
114+ vnd_load_conf(VENDOR_LIB_CONF_FILE);
115+
116+ /* store reference to user callbacks */
117+ bt_vendor_cbacks = (bt_vendor_callbacks_t *) p_cb;
118+
119+ /* This is handed over from the stack */
120+ memcpy(vnd_local_bd_addr, local_bdaddr, 6);
121+
122+ return 0;
123+}
124+
125+
126+/** Requested operations */
127+static int op(bt_vendor_opcode_t opcode, void *param)
128+{
129+ int retval = 0;
130+
131+ BTVNDDBG("op for %d", opcode);
132+
133+ switch(opcode)
134+ {
135+ case BT_VND_OP_POWER_CTRL:
136+ {
137+ int *state = (int *) param;
138+ if (*state == BT_VND_PWR_OFF)
139+ upio_set_bluetooth_power(UPIO_BT_POWER_OFF);
140+ else if (*state == BT_VND_PWR_ON)
141+ upio_set_bluetooth_power(UPIO_BT_POWER_ON);
142+ }
143+ break;
144+
145+ case BT_VND_OP_FW_CFG:
146+ {
147+ hw_config_start();
148+ }
149+ break;
150+
151+ case BT_VND_OP_SCO_CFG:
152+ {
153+#if (SCO_CFG_INCLUDED == TRUE)
154+ hw_sco_config();
155+#else
156+ retval = -1;
157+#endif
158+ }
159+ break;
160+
161+ case BT_VND_OP_USERIAL_OPEN:
162+ {
163+ int (*fd_array)[] = (int (*)[]) param;
164+ int fd, idx;
165+ fd = userial_vendor_open((tUSERIAL_CFG *) &userial_init_cfg);
166+ if (fd != -1)
167+ {
168+ for (idx=0; idx < CH_MAX; idx++)
169+ (*fd_array)[idx] = fd;
170+
171+ retval = 1;
172+ }
173+ /* retval contains numbers of open fd of HCI channels */
174+ }
175+ break;
176+
177+ case BT_VND_OP_USERIAL_CLOSE:
178+ {
179+ userial_vendor_close();
180+ }
181+ break;
182+
183+ case BT_VND_OP_GET_LPM_IDLE_TIMEOUT:
184+ {
185+ uint32_t *timeout_ms = (uint32_t *) param;
186+ *timeout_ms = hw_lpm_get_idle_timeout();
187+ }
188+ break;
189+
190+ case BT_VND_OP_LPM_SET_MODE:
191+ {
192+ uint8_t *mode = (uint8_t *) param;
193+ retval = hw_lpm_enable(*mode);
194+ }
195+ break;
196+
197+ case BT_VND_OP_LPM_WAKE_SET_STATE:
198+ {
199+ uint8_t *state = (uint8_t *) param;
200+ uint8_t wake_assert = (*state == BT_VND_LPM_WAKE_ASSERT) ? \
201+ TRUE : FALSE;
202+
203+ hw_lpm_set_wake_state(wake_assert);
204+ }
205+ break;
206+ }
207+
208+ return retval;
209+}
210+
211+/** Closes the interface */
212+static void cleanup( void )
213+{
214+ BTVNDDBG("cleanup");
215+
216+ upio_cleanup();
217+
218+ bt_vendor_cbacks = NULL;
219+}
220+
221+// Entry point of DLib
222+const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
223+ sizeof(bt_vendor_interface_t),
224+ init,
225+ op,
226+ cleanup
227+};
--- /dev/null
+++ b/src/conf.c
@@ -0,0 +1,147 @@
1+/******************************************************************************
2+ *
3+ * Copyright (C) 2009-2012 Broadcom Corporation
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ ******************************************************************************/
18+
19+/******************************************************************************
20+ *
21+ * Filename: conf.c
22+ *
23+ * Description: Contains functions to conduct run-time module configuration
24+ * based on entries present in the .conf file
25+ *
26+ ******************************************************************************/
27+
28+#define LOG_TAG "bt_vnd_conf"
29+
30+#include <utils/Log.h>
31+#include <string.h>
32+#include "bt_vendor_brcm.h"
33+
34+/******************************************************************************
35+** Externs
36+******************************************************************************/
37+int userial_set_port(char *p_conf_name, char *p_conf_value, int param);
38+int hw_set_patch_file_path(char *p_conf_name, char *p_conf_value, int param);
39+int hw_set_patch_file_name(char *p_conf_name, char *p_conf_value, int param);
40+#if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE)
41+int hw_set_patch_settlement_delay(char *p_conf_name, char *p_conf_value, int param);
42+#endif
43+
44+
45+/******************************************************************************
46+** Local type definitions
47+******************************************************************************/
48+
49+#define CONF_COMMENT '#'
50+#define CONF_DELIMITERS " =\n\r\t"
51+#define CONF_VALUES_DELIMITERS "=\n\r\t"
52+#define CONF_MAX_LINE_LEN 255
53+
54+typedef int (conf_action_t)(char *p_conf_name, char *p_conf_value, int param);
55+
56+typedef struct {
57+ const char *conf_entry;
58+ conf_action_t *p_action;
59+ int param;
60+} conf_entry_t;
61+
62+/******************************************************************************
63+** Static variables
64+******************************************************************************/
65+
66+/*
67+ * Current supported entries and corresponding action functions
68+ */
69+static const conf_entry_t conf_table[] = {
70+ {"UartPort", userial_set_port, 0},
71+ {"FwPatchFilePath", hw_set_patch_file_path, 0},
72+ {"FwPatchFileName", hw_set_patch_file_name, 0},
73+#if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE)
74+ {"FwPatchSettlementDelay", hw_set_patch_settlement_delay, 0},
75+#endif
76+ {(const char *) NULL, NULL, 0}
77+};
78+
79+/*****************************************************************************
80+** CONF INTERFACE FUNCTIONS
81+*****************************************************************************/
82+
83+/*******************************************************************************
84+**
85+** Function vnd_load_conf
86+**
87+** Description Read conf entry from p_path file one by one and call
88+** the corresponding config function
89+**
90+** Returns None
91+**
92+*******************************************************************************/
93+void vnd_load_conf(const char *p_path)
94+{
95+ FILE *p_file;
96+ char *p_name;
97+ char *p_value;
98+ conf_entry_t *p_entry;
99+ char line[CONF_MAX_LINE_LEN+1]; /* add 1 for \0 char */
100+
101+ ALOGI("Attempt to load conf from %s", p_path);
102+
103+ if ((p_file = fopen(p_path, "r")) != NULL)
104+ {
105+ /* read line by line */
106+ while (fgets(line, CONF_MAX_LINE_LEN+1, p_file) != NULL)
107+ {
108+ if (line[0] == CONF_COMMENT)
109+ continue;
110+
111+ p_name = strtok(line, CONF_DELIMITERS);
112+
113+ if (NULL == p_name)
114+ {
115+ continue;
116+ }
117+
118+ p_value = strtok(NULL, CONF_DELIMITERS);
119+
120+ if (NULL == p_value)
121+ {
122+ ALOGW("vnd_load_conf: missing value for name: %s", p_name);
123+ continue;
124+ }
125+
126+ p_entry = (conf_entry_t *)conf_table;
127+
128+ while (p_entry->conf_entry != NULL)
129+ {
130+ if (strcmp(p_entry->conf_entry, (const char *)p_name) == 0)
131+ {
132+ p_entry->p_action(p_name, p_value, p_entry->param);
133+ break;
134+ }
135+
136+ p_entry++;
137+ }
138+ }
139+
140+ fclose(p_file);
141+ }
142+ else
143+ {
144+ ALOGI( "vnd_load_conf file >%s< not found", p_path);
145+ }
146+}
147+
--- /dev/null
+++ b/src/hardware.c
@@ -0,0 +1,1233 @@
1+/******************************************************************************
2+ *
3+ * Copyright (C) 2009-2012 Broadcom Corporation
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ ******************************************************************************/
18+
19+/******************************************************************************
20+ *
21+ * Filename: hardware.c
22+ *
23+ * Description: Contains controller-specific functions, like
24+ * firmware patch download
25+ * low power mode operations
26+ *
27+ ******************************************************************************/
28+
29+#define LOG_TAG "bt_hwcfg"
30+
31+#include <utils/Log.h>
32+#include <sys/types.h>
33+#include <sys/stat.h>
34+#include <signal.h>
35+#include <time.h>
36+#include <errno.h>
37+#include <fcntl.h>
38+#include <dirent.h>
39+#include <ctype.h>
40+#include <cutils/properties.h>
41+#include <stdlib.h>
42+#include "bt_hci_bdroid.h"
43+#include "bt_vendor_brcm.h"
44+#include "userial.h"
45+#include "userial_vendor.h"
46+#include "upio.h"
47+
48+/******************************************************************************
49+** Constants & Macros
50+******************************************************************************/
51+
52+#ifndef BTHW_DBG
53+#define BTHW_DBG FALSE
54+#endif
55+
56+#if (BTHW_DBG == TRUE)
57+#define BTHWDBG(param, ...) {ALOGD(param, ## __VA_ARGS__);}
58+#else
59+#define BTHWDBG(param, ...) {}
60+#endif
61+
62+#define FW_PATCHFILE_EXTENSION ".hcd"
63+#define FW_PATCHFILE_EXTENSION_LEN 4
64+#define FW_PATCHFILE_PATH_MAXLEN 248 /* Local_Name length of return of
65+ HCI_Read_Local_Name */
66+
67+#define HCI_CMD_MAX_LEN 258
68+
69+#define HCI_RESET 0x0C03
70+#define HCI_VSC_WRITE_UART_CLOCK_SETTING 0xFC45
71+#define HCI_VSC_UPDATE_BAUDRATE 0xFC18
72+#define HCI_READ_LOCAL_NAME 0x0C14
73+#define HCI_VSC_DOWNLOAD_MINIDRV 0xFC2E
74+#define HCI_VSC_WRITE_BD_ADDR 0xFC01
75+#define HCI_VSC_WRITE_SLEEP_MODE 0xFC27
76+#define HCI_VSC_WRITE_SCO_PCM_INT_PARAM 0xFC1C
77+#define HCI_VSC_WRITE_PCM_DATA_FORMAT_PARAM 0xFC1E
78+#define HCI_VSC_WRITE_I2SPCM_INTERFACE_PARAM 0xFC6D
79+#define HCI_VSC_LAUNCH_RAM 0xFC4E
80+#define HCI_READ_LOCAL_BDADDR 0x1009
81+
82+#define HCI_EVT_CMD_CMPL_STATUS_RET_BYTE 5
83+#define HCI_EVT_CMD_CMPL_LOCAL_NAME_STRING 6
84+#define HCI_EVT_CMD_CMPL_LOCAL_BDADDR_ARRAY 6
85+#define HCI_EVT_CMD_CMPL_OPCODE 3
86+#define LPM_CMD_PARAM_SIZE 12
87+#define UPDATE_BAUDRATE_CMD_PARAM_SIZE 6
88+#define HCI_CMD_PREAMBLE_SIZE 3
89+#define HCD_REC_PAYLOAD_LEN_BYTE 2
90+#define BD_ADDR_LEN 6
91+#define LOCAL_NAME_BUFFER_LEN 32
92+#define LOCAL_BDADDR_PATH_BUFFER_LEN 256
93+
94+#define STREAM_TO_UINT16(u16, p) {u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); (p) += 2;}
95+#define UINT16_TO_STREAM(p, u16) {*(p)++ = (uint8_t)(u16); *(p)++ = (uint8_t)((u16) >> 8);}
96+#define UINT32_TO_STREAM(p, u32) {*(p)++ = (uint8_t)(u32); *(p)++ = (uint8_t)((u32) >> 8); *(p)++ = (uint8_t)((u32) >> 16); *(p)++ = (uint8_t)((u32) >> 24);}
97+
98+/******************************************************************************
99+** Local type definitions
100+******************************************************************************/
101+
102+/* Hardware Configuration State */
103+enum {
104+ HW_CFG_START = 1,
105+ HW_CFG_SET_UART_CLOCK,
106+ HW_CFG_SET_UART_BAUD_1,
107+ HW_CFG_READ_LOCAL_NAME,
108+ HW_CFG_DL_MINIDRIVER,
109+ HW_CFG_DL_FW_PATCH,
110+ HW_CFG_SET_UART_BAUD_2,
111+ HW_CFG_SET_BD_ADDR
112+#if (USE_CONTROLLER_BDADDR == TRUE)
113+ , HW_CFG_READ_BD_ADDR
114+#endif
115+};
116+
117+/* h/w config control block */
118+typedef struct
119+{
120+ uint8_t state; /* Hardware configuration state */
121+ int fw_fd; /* FW patch file fd */
122+ uint8_t f_set_baud_2; /* Baud rate switch state */
123+ char local_chip_name[LOCAL_NAME_BUFFER_LEN];
124+} bt_hw_cfg_cb_t;
125+
126+/* low power mode parameters */
127+typedef struct
128+{
129+ uint8_t sleep_mode; /* 0(disable),1(UART),9(H5) */
130+ uint8_t host_stack_idle_threshold; /* Unit scale 300ms/25ms */
131+ uint8_t host_controller_idle_threshold; /* Unit scale 300ms/25ms */
132+ uint8_t bt_wake_polarity; /* 0=Active Low, 1= Active High */
133+ uint8_t host_wake_polarity; /* 0=Active Low, 1= Active High */
134+ uint8_t allow_host_sleep_during_sco;
135+ uint8_t combine_sleep_mode_and_lpm;
136+ uint8_t enable_uart_txd_tri_state; /* UART_TXD Tri-State */
137+ uint8_t sleep_guard_time; /* sleep guard time in 12.5ms */
138+ uint8_t wakeup_guard_time; /* wakeup guard time in 12.5ms */
139+ uint8_t txd_config; /* TXD is high in sleep state */
140+ uint8_t pulsed_host_wake; /* pulsed host wake if mode = 1 */
141+} bt_lpm_param_t;
142+
143+/* Firmware re-launch settlement time */
144+typedef struct {
145+ const char *chipset_name;
146+ const uint32_t delay_time;
147+} fw_settlement_entry_t;
148+
149+
150+/******************************************************************************
151+** Externs
152+******************************************************************************/
153+
154+void hw_config_cback(void *p_evt_buf);
155+extern uint8_t vnd_local_bd_addr[BD_ADDR_LEN];
156+
157+
158+/******************************************************************************
159+** Static variables
160+******************************************************************************/
161+
162+static char fw_patchfile_path[256] = FW_PATCHFILE_LOCATION;
163+static char fw_patchfile_name[128] = { 0 };
164+#if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE)
165+static int fw_patch_settlement_delay = -1;
166+#endif
167+
168+static bt_hw_cfg_cb_t hw_cfg_cb;
169+
170+static bt_lpm_param_t lpm_param =
171+{
172+ LPM_SLEEP_MODE,
173+ LPM_IDLE_THRESHOLD,
174+ LPM_HC_IDLE_THRESHOLD,
175+ LPM_BT_WAKE_POLARITY,
176+ LPM_HOST_WAKE_POLARITY,
177+ LPM_ALLOW_HOST_SLEEP_DURING_SCO,
178+ LPM_COMBINE_SLEEP_MODE_AND_LPM,
179+ LPM_ENABLE_UART_TXD_TRI_STATE,
180+ 0, /* not applicable */
181+ 0, /* not applicable */
182+ 0, /* not applicable */
183+ LPM_PULSED_HOST_WAKE
184+};
185+
186+#if (!defined(SCO_USE_I2S_INTERFACE) || (SCO_USE_I2S_INTERFACE == FALSE))
187+static uint8_t bt_sco_param[SCO_PCM_PARAM_SIZE] =
188+{
189+ SCO_PCM_ROUTING,
190+ SCO_PCM_IF_CLOCK_RATE,
191+ SCO_PCM_IF_FRAME_TYPE,
192+ SCO_PCM_IF_SYNC_MODE,
193+ SCO_PCM_IF_CLOCK_MODE
194+};
195+
196+static uint8_t bt_pcm_data_fmt_param[PCM_DATA_FORMAT_PARAM_SIZE] =
197+{
198+ PCM_DATA_FMT_SHIFT_MODE,
199+ PCM_DATA_FMT_FILL_BITS,
200+ PCM_DATA_FMT_FILL_METHOD,
201+ PCM_DATA_FMT_FILL_NUM,
202+ PCM_DATA_FMT_JUSTIFY_MODE
203+};
204+#else
205+static uint8_t bt_sco_param[SCO_I2SPCM_PARAM_SIZE] =
206+{
207+ SCO_I2SPCM_IF_MODE,
208+ SCO_I2SPCM_IF_ROLE,
209+ SCO_I2SPCM_IF_SAMPLE_RATE,
210+ SCO_I2SPCM_IF_CLOCK_RATE
211+};
212+#endif
213+
214+/*
215+ * The look-up table of recommended firmware settlement delay (milliseconds) on
216+ * known chipsets.
217+ */
218+static const fw_settlement_entry_t fw_settlement_table[] = {
219+ {"BCM43241", 200},
220+ {(const char *) NULL, 100} // Giving the generic fw settlement delay setting.
221+};
222+
223+/******************************************************************************
224+** Static functions
225+******************************************************************************/
226+
227+/******************************************************************************
228+** Controller Initialization Static Functions
229+******************************************************************************/
230+
231+/*******************************************************************************
232+**
233+** Function look_up_fw_settlement_delay
234+**
235+** Description If FW_PATCH_SETTLEMENT_DELAY_MS has not been explicitly
236+** re-defined in the platform specific build-time configuration
237+** file, we will search into the look-up table for a
238+** recommended firmware settlement delay value.
239+**
240+** Although the settlement time might be also related to board
241+** configurations such as the crystal clocking speed.
242+**
243+** Returns Firmware settlement delay
244+**
245+*******************************************************************************/
246+uint32_t look_up_fw_settlement_delay (void)
247+{
248+ uint32_t ret_value;
249+ fw_settlement_entry_t *p_entry;
250+
251+ if (FW_PATCH_SETTLEMENT_DELAY_MS > 0)
252+ {
253+ ret_value = FW_PATCH_SETTLEMENT_DELAY_MS;
254+ }
255+#if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE)
256+ else if (fw_patch_settlement_delay >= 0)
257+ {
258+ ret_value = fw_patch_settlement_delay;
259+ }
260+#endif
261+ else
262+ {
263+ p_entry = (fw_settlement_entry_t *)fw_settlement_table;
264+
265+ while (p_entry->chipset_name != NULL)
266+ {
267+ if (strstr(hw_cfg_cb.local_chip_name, p_entry->chipset_name)!=NULL)
268+ {
269+ break;
270+ }
271+
272+ p_entry++;
273+ }
274+
275+ ret_value = p_entry->delay_time;
276+ }
277+
278+ BTHWDBG( "Settlement delay -- %d ms", ret_value);
279+
280+ return (ret_value);
281+}
282+
283+/*******************************************************************************
284+**
285+** Function ms_delay
286+**
287+** Description sleep unconditionally for timeout milliseconds
288+**
289+** Returns None
290+**
291+*******************************************************************************/
292+void ms_delay (uint32_t timeout)
293+{
294+ struct timespec delay;
295+ int err;
296+
297+ if (timeout == 0)
298+ return;
299+
300+ delay.tv_sec = timeout / 1000;
301+ delay.tv_nsec = 1000 * 1000 * (timeout%1000);
302+
303+ /* [u]sleep can't be used because it uses SIGALRM */
304+ do {
305+ err = nanosleep(&delay, &delay);
306+ } while (err < 0 && errno ==EINTR);
307+}
308+
309+/*******************************************************************************
310+**
311+** Function line_speed_to_userial_baud
312+**
313+** Description helper function converts line speed number into USERIAL baud
314+** rate symbol
315+**
316+** Returns unit8_t (USERIAL baud symbol)
317+**
318+*******************************************************************************/
319+uint8_t line_speed_to_userial_baud(uint32_t line_speed)
320+{
321+ uint8_t baud;
322+
323+ if (line_speed == 4000000)
324+ baud = USERIAL_BAUD_4M;
325+ else if (line_speed == 3000000)
326+ baud = USERIAL_BAUD_3M;
327+ else if (line_speed == 2000000)
328+ baud = USERIAL_BAUD_2M;
329+ else if (line_speed == 1000000)
330+ baud = USERIAL_BAUD_1M;
331+ else if (line_speed == 921600)
332+ baud = USERIAL_BAUD_921600;
333+ else if (line_speed == 460800)
334+ baud = USERIAL_BAUD_460800;
335+ else if (line_speed == 230400)
336+ baud = USERIAL_BAUD_230400;
337+ else if (line_speed == 115200)
338+ baud = USERIAL_BAUD_115200;
339+ else if (line_speed == 57600)
340+ baud = USERIAL_BAUD_57600;
341+ else if (line_speed == 19200)
342+ baud = USERIAL_BAUD_19200;
343+ else if (line_speed == 9600)
344+ baud = USERIAL_BAUD_9600;
345+ else if (line_speed == 1200)
346+ baud = USERIAL_BAUD_1200;
347+ else if (line_speed == 600)
348+ baud = USERIAL_BAUD_600;
349+ else
350+ {
351+ ALOGE( "userial vendor: unsupported baud speed %d", line_speed);
352+ baud = USERIAL_BAUD_115200;
353+ }
354+
355+ return baud;
356+}
357+
358+
359+/*******************************************************************************
360+**
361+** Function hw_strncmp
362+**
363+** Description Used to compare two strings in caseless
364+**
365+** Returns 0: match, otherwise: not match
366+**
367+*******************************************************************************/
368+static int hw_strncmp (const char *p_str1, const char *p_str2, const int len)
369+{
370+ int i;
371+
372+ if (!p_str1 || !p_str2)
373+ return (1);
374+
375+ for (i = 0; i < len; i++)
376+ {
377+ if (toupper(p_str1[i]) != toupper(p_str2[i]))
378+ return (i+1);
379+ }
380+
381+ return 0;
382+}
383+
384+/*******************************************************************************
385+**
386+** Function hw_config_findpatch
387+**
388+** Description Search for a proper firmware patch file
389+** The selected firmware patch file name with full path
390+** will be stored in the input string parameter, i.e.
391+** p_chip_id_str, when returns.
392+**
393+** Returns TRUE when found the target patch file, otherwise FALSE
394+**
395+*******************************************************************************/
396+static uint8_t hw_config_findpatch(char *p_chip_id_str)
397+{
398+ DIR *dirp;
399+ struct dirent *dp;
400+ int filenamelen;
401+ uint8_t retval = FALSE;
402+
403+ BTHWDBG("Target name = [%s]", p_chip_id_str);
404+
405+ if (strlen(fw_patchfile_name)> 0)
406+ {
407+ /* If specific filepath and filename have been given in run-time
408+ * configuration /etc/bluetooth/bt_vendor.conf file, we will use them
409+ * to concatenate the filename to open rather than searching a file
410+ * matching to chipset name in the fw_patchfile_path folder.
411+ */
412+ sprintf(p_chip_id_str, "%s", fw_patchfile_path);
413+ if (fw_patchfile_path[strlen(fw_patchfile_path)- 1] != '/')
414+ {
415+ strcat(p_chip_id_str, "/");
416+ }
417+ strcat(p_chip_id_str, fw_patchfile_name);
418+
419+ ALOGI("FW patchfile: %s", p_chip_id_str);
420+ return TRUE;
421+ }
422+
423+ if ((dirp = opendir(fw_patchfile_path)) != NULL)
424+ {
425+ /* Fetch next filename in patchfile directory */
426+ while ((dp = readdir(dirp)) != NULL)
427+ {
428+ /* Check if filename starts with chip-id name */
429+ if ((hw_strncmp(dp->d_name, p_chip_id_str, strlen(p_chip_id_str)) \
430+ ) == 0)
431+ {
432+ /* Check if it has .hcd extenstion */
433+ filenamelen = strlen(dp->d_name);
434+ if ((filenamelen >= FW_PATCHFILE_EXTENSION_LEN) &&
435+ ((hw_strncmp(
436+ &dp->d_name[filenamelen-FW_PATCHFILE_EXTENSION_LEN], \
437+ FW_PATCHFILE_EXTENSION, \
438+ FW_PATCHFILE_EXTENSION_LEN) \
439+ ) == 0))
440+ {
441+ ALOGI("Found patchfile: %s/%s", \
442+ fw_patchfile_path, dp->d_name);
443+
444+ /* Make sure length does not exceed maximum */
445+ if ((filenamelen + strlen(fw_patchfile_path)) > \
446+ FW_PATCHFILE_PATH_MAXLEN)
447+ {
448+ ALOGE("Invalid patchfile name (too long)");
449+ }
450+ else
451+ {
452+ memset(p_chip_id_str, 0, FW_PATCHFILE_PATH_MAXLEN);
453+ /* Found patchfile. Store location and name */
454+ strcpy(p_chip_id_str, fw_patchfile_path);
455+ if (fw_patchfile_path[ \
456+ strlen(fw_patchfile_path)- 1 \
457+ ] != '/')
458+ {
459+ strcat(p_chip_id_str, "/");
460+ }
461+ strcat(p_chip_id_str, dp->d_name);
462+ retval = TRUE;
463+ }
464+ break;
465+ }
466+ }
467+ }
468+
469+ closedir(dirp);
470+
471+ if (retval == FALSE)
472+ {
473+ /* Try again chip name without revision info */
474+
475+ int len = strlen(p_chip_id_str);
476+ char *p = p_chip_id_str + len - 1;
477+
478+ /* Scan backward and look for the first alphabet
479+ which is not M or m
480+ */
481+ while (len > 3) // BCM****
482+ {
483+ if ((isdigit(*p)==0) && (*p != 'M') && (*p != 'm'))
484+ break;
485+
486+ p--;
487+ len--;
488+ }
489+
490+ if (len > 3)
491+ {
492+ *p = 0;
493+ retval = hw_config_findpatch(p_chip_id_str);
494+ }
495+ }
496+ }
497+ else
498+ {
499+ ALOGE("Could not open %s", fw_patchfile_path);
500+ }
501+
502+ return (retval);
503+}
504+
505+/*******************************************************************************
506+**
507+** Function hw_config_set_bdaddr
508+**
509+** Description Program controller's Bluetooth Device Address
510+**
511+** Returns TRUE, if valid address is sent
512+** FALSE, otherwise
513+**
514+*******************************************************************************/
515+static uint8_t hw_config_set_bdaddr(HC_BT_HDR *p_buf)
516+{
517+ uint8_t retval = FALSE;
518+ uint8_t *p = (uint8_t *) (p_buf + 1);
519+
520+ ALOGI("Setting local bd addr to %02X:%02X:%02X:%02X:%02X:%02X",
521+ vnd_local_bd_addr[0], vnd_local_bd_addr[1], vnd_local_bd_addr[2],
522+ vnd_local_bd_addr[3], vnd_local_bd_addr[4], vnd_local_bd_addr[5]);
523+
524+ UINT16_TO_STREAM(p, HCI_VSC_WRITE_BD_ADDR);
525+ *p++ = BD_ADDR_LEN; /* parameter length */
526+ *p++ = vnd_local_bd_addr[5];
527+ *p++ = vnd_local_bd_addr[4];
528+ *p++ = vnd_local_bd_addr[3];
529+ *p++ = vnd_local_bd_addr[2];
530+ *p++ = vnd_local_bd_addr[1];
531+ *p = vnd_local_bd_addr[0];
532+
533+ p_buf->len = HCI_CMD_PREAMBLE_SIZE + BD_ADDR_LEN;
534+ hw_cfg_cb.state = HW_CFG_SET_BD_ADDR;
535+
536+ retval = bt_vendor_cbacks->xmit_cb(HCI_VSC_WRITE_BD_ADDR, p_buf, \
537+ hw_config_cback);
538+
539+ return (retval);
540+}
541+
542+#if (USE_CONTROLLER_BDADDR == TRUE)
543+/*******************************************************************************
544+**
545+** Function hw_config_read_bdaddr
546+**
547+** Description Read controller's Bluetooth Device Address
548+**
549+** Returns TRUE, if valid address is sent
550+** FALSE, otherwise
551+**
552+*******************************************************************************/
553+static uint8_t hw_config_read_bdaddr(HC_BT_HDR *p_buf)
554+{
555+ uint8_t retval = FALSE;
556+ uint8_t *p = (uint8_t *) (p_buf + 1);
557+
558+ UINT16_TO_STREAM(p, HCI_READ_LOCAL_BDADDR);
559+ *p = 0; /* parameter length */
560+
561+ p_buf->len = HCI_CMD_PREAMBLE_SIZE;
562+ hw_cfg_cb.state = HW_CFG_READ_BD_ADDR;
563+
564+ retval = bt_vendor_cbacks->xmit_cb(HCI_READ_LOCAL_BDADDR, p_buf, \
565+ hw_config_cback);
566+
567+ return (retval);
568+}
569+#endif // (USE_CONTROLLER_BDADDR == TRUE)
570+
571+/*******************************************************************************
572+**
573+** Function hw_config_cback
574+**
575+** Description Callback function for controller configuration
576+**
577+** Returns None
578+**
579+*******************************************************************************/
580+void hw_config_cback(void *p_mem)
581+{
582+ HC_BT_HDR *p_evt_buf = (HC_BT_HDR *) p_mem;
583+ char *p_name, *p_tmp;
584+ uint8_t *p, status;
585+ uint16_t opcode;
586+ HC_BT_HDR *p_buf=NULL;
587+ uint8_t is_proceeding = FALSE;
588+ int i;
589+#if (USE_CONTROLLER_BDADDR == TRUE)
590+ const uint8_t null_bdaddr[BD_ADDR_LEN] = {0,0,0,0,0,0};
591+#endif
592+
593+ status = *((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_STATUS_RET_BYTE);
594+ p = (uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OPCODE;
595+ STREAM_TO_UINT16(opcode,p);
596+
597+ /* Ask a new buffer big enough to hold any HCI commands sent in here */
598+ if ((status == 0) && bt_vendor_cbacks)
599+ p_buf = (HC_BT_HDR *) bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + \
600+ HCI_CMD_MAX_LEN);
601+
602+ if (p_buf != NULL)
603+ {
604+ p_buf->event = MSG_STACK_TO_HC_HCI_CMD;
605+ p_buf->offset = 0;
606+ p_buf->len = 0;
607+ p_buf->layer_specific = 0;
608+
609+ p = (uint8_t *) (p_buf + 1);
610+
611+ switch (hw_cfg_cb.state)
612+ {
613+ case HW_CFG_SET_UART_BAUD_1:
614+ /* update baud rate of host's UART port */
615+ ALOGI("bt vendor lib: set UART baud %i", UART_TARGET_BAUD_RATE);
616+ userial_vendor_set_baud( \
617+ line_speed_to_userial_baud(UART_TARGET_BAUD_RATE) \
618+ );
619+
620+ /* read local name */
621+ UINT16_TO_STREAM(p, HCI_READ_LOCAL_NAME);
622+ *p = 0; /* parameter length */
623+
624+ p_buf->len = HCI_CMD_PREAMBLE_SIZE;
625+ hw_cfg_cb.state = HW_CFG_READ_LOCAL_NAME;
626+
627+ is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_READ_LOCAL_NAME, \
628+ p_buf, hw_config_cback);
629+ break;
630+
631+ case HW_CFG_READ_LOCAL_NAME:
632+ p_tmp = p_name = (char *) (p_evt_buf + 1) + \
633+ HCI_EVT_CMD_CMPL_LOCAL_NAME_STRING;
634+
635+ for (i=0; (i < LOCAL_NAME_BUFFER_LEN)||(*(p_name+i) != 0); i++)
636+ *(p_name+i) = toupper(*(p_name+i));
637+
638+ if ((p_name = strstr(p_name, "BCM")) != NULL)
639+ {
640+ strncpy(hw_cfg_cb.local_chip_name, p_name, \
641+ LOCAL_NAME_BUFFER_LEN-1);
642+ }
643+ else
644+ {
645+ strncpy(hw_cfg_cb.local_chip_name, "UNKNOWN", \
646+ LOCAL_NAME_BUFFER_LEN-1);
647+ p_name = p_tmp;
648+ }
649+
650+ hw_cfg_cb.local_chip_name[LOCAL_NAME_BUFFER_LEN-1] = 0;
651+
652+ BTHWDBG("Chipset %s", hw_cfg_cb.local_chip_name);
653+
654+ if ((status = hw_config_findpatch(p_name)) == TRUE)
655+ {
656+ if ((hw_cfg_cb.fw_fd = open(p_name, O_RDONLY)) == -1)
657+ {
658+ ALOGE("vendor lib preload failed to open [%s]", p_name);
659+ }
660+ else
661+ {
662+ /* vsc_download_minidriver */
663+ UINT16_TO_STREAM(p, HCI_VSC_DOWNLOAD_MINIDRV);
664+ *p = 0; /* parameter length */
665+
666+ p_buf->len = HCI_CMD_PREAMBLE_SIZE;
667+ hw_cfg_cb.state = HW_CFG_DL_MINIDRIVER;
668+
669+ is_proceeding = bt_vendor_cbacks->xmit_cb( \
670+ HCI_VSC_DOWNLOAD_MINIDRV, p_buf, \
671+ hw_config_cback);
672+ }
673+ }
674+ else
675+ {
676+ ALOGE( \
677+ "vendor lib preload failed to locate firmware patch file" \
678+ );
679+ }
680+
681+ if (is_proceeding == FALSE)
682+ {
683+ is_proceeding = hw_config_set_bdaddr(p_buf);
684+ }
685+ break;
686+
687+ case HW_CFG_DL_MINIDRIVER:
688+ /* give time for placing firmware in download mode */
689+ ms_delay(50);
690+ hw_cfg_cb.state = HW_CFG_DL_FW_PATCH;
691+ /* fall through intentionally */
692+ case HW_CFG_DL_FW_PATCH:
693+ p_buf->len = read(hw_cfg_cb.fw_fd, p, HCI_CMD_PREAMBLE_SIZE);
694+ if (p_buf->len > 0)
695+ {
696+ if ((p_buf->len < HCI_CMD_PREAMBLE_SIZE) || \
697+ (opcode == HCI_VSC_LAUNCH_RAM))
698+ {
699+ ALOGW("firmware patch file might be altered!");
700+ }
701+ else
702+ {
703+ p_buf->len += read(hw_cfg_cb.fw_fd, \
704+ p+HCI_CMD_PREAMBLE_SIZE,\
705+ *(p+HCD_REC_PAYLOAD_LEN_BYTE));
706+ STREAM_TO_UINT16(opcode,p);
707+ is_proceeding = bt_vendor_cbacks->xmit_cb(opcode, \
708+ p_buf, hw_config_cback);
709+ break;
710+ }
711+ }
712+
713+ close(hw_cfg_cb.fw_fd);
714+ hw_cfg_cb.fw_fd = -1;
715+
716+ /* Normally the firmware patch configuration file
717+ * sets the new starting baud rate at 115200.
718+ * So, we need update host's baud rate accordingly.
719+ */
720+ ALOGI("bt vendor lib: set UART baud 115200");
721+ userial_vendor_set_baud(USERIAL_BAUD_115200);
722+
723+ /* Next, we would like to boost baud rate up again
724+ * to desired working speed.
725+ */
726+ hw_cfg_cb.f_set_baud_2 = TRUE;
727+
728+ /* Check if we need to pause a few hundred milliseconds
729+ * before sending down any HCI command.
730+ */
731+ ms_delay(look_up_fw_settlement_delay());
732+
733+ /* fall through intentionally */
734+ case HW_CFG_START:
735+ if (UART_TARGET_BAUD_RATE > 3000000)
736+ {
737+ /* set UART clock to 48MHz */
738+ UINT16_TO_STREAM(p, HCI_VSC_WRITE_UART_CLOCK_SETTING);
739+ *p++ = 1; /* parameter length */
740+ *p = 1; /* (1,"UART CLOCK 48 MHz")(2,"UART CLOCK 24 MHz") */
741+
742+ p_buf->len = HCI_CMD_PREAMBLE_SIZE + 1;
743+ hw_cfg_cb.state = HW_CFG_SET_UART_CLOCK;
744+
745+ is_proceeding = bt_vendor_cbacks->xmit_cb( \
746+ HCI_VSC_WRITE_UART_CLOCK_SETTING, \
747+ p_buf, hw_config_cback);
748+ break;
749+ }
750+ /* fall through intentionally */
751+ case HW_CFG_SET_UART_CLOCK:
752+ /* set controller's UART baud rate to 3M */
753+ UINT16_TO_STREAM(p, HCI_VSC_UPDATE_BAUDRATE);
754+ *p++ = UPDATE_BAUDRATE_CMD_PARAM_SIZE; /* parameter length */
755+ *p++ = 0; /* encoded baud rate */
756+ *p++ = 0; /* use encoded form */
757+ UINT32_TO_STREAM(p, UART_TARGET_BAUD_RATE);
758+
759+ p_buf->len = HCI_CMD_PREAMBLE_SIZE + \
760+ UPDATE_BAUDRATE_CMD_PARAM_SIZE;
761+ hw_cfg_cb.state = (hw_cfg_cb.f_set_baud_2) ? \
762+ HW_CFG_SET_UART_BAUD_2 : HW_CFG_SET_UART_BAUD_1;
763+
764+ is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_VSC_UPDATE_BAUDRATE, \
765+ p_buf, hw_config_cback);
766+ break;
767+
768+ case HW_CFG_SET_UART_BAUD_2:
769+ /* update baud rate of host's UART port */
770+ ALOGI("bt vendor lib: set UART baud %i", UART_TARGET_BAUD_RATE);
771+ userial_vendor_set_baud( \
772+ line_speed_to_userial_baud(UART_TARGET_BAUD_RATE) \
773+ );
774+
775+#if (USE_CONTROLLER_BDADDR == TRUE)
776+ if ((is_proceeding = hw_config_read_bdaddr(p_buf)) == TRUE)
777+ break;
778+#else
779+ if ((is_proceeding = hw_config_set_bdaddr(p_buf)) == TRUE)
780+ break;
781+#endif
782+ /* fall through intentionally */
783+ case HW_CFG_SET_BD_ADDR:
784+ ALOGI("vendor lib fwcfg completed");
785+ bt_vendor_cbacks->dealloc(p_buf);
786+ bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_SUCCESS);
787+
788+ hw_cfg_cb.state = 0;
789+
790+ if (hw_cfg_cb.fw_fd != -1)
791+ {
792+ close(hw_cfg_cb.fw_fd);
793+ hw_cfg_cb.fw_fd = -1;
794+ }
795+
796+ is_proceeding = TRUE;
797+ break;
798+
799+#if (USE_CONTROLLER_BDADDR == TRUE)
800+ case HW_CFG_READ_BD_ADDR:
801+ p_tmp = (char *) (p_evt_buf + 1) + \
802+ HCI_EVT_CMD_CMPL_LOCAL_BDADDR_ARRAY;
803+
804+ if (memcmp(p_tmp, null_bdaddr, BD_ADDR_LEN) == 0)
805+ {
806+ // Controller does not have a valid OTP BDADDR!
807+ // Set the BTIF initial BDADDR instead.
808+ if ((is_proceeding = hw_config_set_bdaddr(p_buf)) == TRUE)
809+ break;
810+ }
811+ else
812+ {
813+ ALOGI("Controller OTP bdaddr %02X:%02X:%02X:%02X:%02X:%02X",
814+ *(p_tmp+5), *(p_tmp+4), *(p_tmp+3),
815+ *(p_tmp+2), *(p_tmp+1), *p_tmp);
816+ }
817+
818+ ALOGI("vendor lib fwcfg completed");
819+ bt_vendor_cbacks->dealloc(p_buf);
820+ bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_SUCCESS);
821+
822+ hw_cfg_cb.state = 0;
823+
824+ if (hw_cfg_cb.fw_fd != -1)
825+ {
826+ close(hw_cfg_cb.fw_fd);
827+ hw_cfg_cb.fw_fd = -1;
828+ }
829+
830+ is_proceeding = TRUE;
831+ break;
832+#endif // (USE_CONTROLLER_BDADDR == TRUE)
833+ } // switch(hw_cfg_cb.state)
834+ } // if (p_buf != NULL)
835+
836+ /* Free the RX event buffer */
837+ if (bt_vendor_cbacks)
838+ bt_vendor_cbacks->dealloc(p_evt_buf);
839+
840+ if (is_proceeding == FALSE)
841+ {
842+ ALOGE("vendor lib fwcfg aborted!!!");
843+ if (bt_vendor_cbacks)
844+ {
845+ if (p_buf != NULL)
846+ bt_vendor_cbacks->dealloc(p_buf);
847+
848+ bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_FAIL);
849+ }
850+
851+ if (hw_cfg_cb.fw_fd != -1)
852+ {
853+ close(hw_cfg_cb.fw_fd);
854+ hw_cfg_cb.fw_fd = -1;
855+ }
856+
857+ hw_cfg_cb.state = 0;
858+ }
859+}
860+
861+/******************************************************************************
862+** LPM Static Functions
863+******************************************************************************/
864+
865+/*******************************************************************************
866+**
867+** Function hw_lpm_ctrl_cback
868+**
869+** Description Callback function for lpm enable/disable rquest
870+**
871+** Returns None
872+**
873+*******************************************************************************/
874+void hw_lpm_ctrl_cback(void *p_mem)
875+{
876+ HC_BT_HDR *p_evt_buf = (HC_BT_HDR *) p_mem;
877+ bt_vendor_op_result_t status = BT_VND_OP_RESULT_FAIL;
878+
879+ if (*((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_STATUS_RET_BYTE) == 0)
880+ {
881+ status = BT_VND_OP_RESULT_SUCCESS;
882+ }
883+
884+ if (bt_vendor_cbacks)
885+ {
886+ bt_vendor_cbacks->lpm_cb(status);
887+ bt_vendor_cbacks->dealloc(p_evt_buf);
888+ }
889+}
890+
891+
892+#if (SCO_CFG_INCLUDED == TRUE)
893+/*****************************************************************************
894+** SCO Configuration Static Functions
895+*****************************************************************************/
896+
897+/*******************************************************************************
898+**
899+** Function hw_sco_cfg_cback
900+**
901+** Description Callback function for SCO configuration rquest
902+**
903+** Returns None
904+**
905+*******************************************************************************/
906+void hw_sco_cfg_cback(void *p_mem)
907+{
908+ HC_BT_HDR *p_evt_buf = (HC_BT_HDR *) p_mem;
909+ uint8_t *p;
910+ uint16_t opcode;
911+ HC_BT_HDR *p_buf=NULL;
912+
913+ p = (uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OPCODE;
914+ STREAM_TO_UINT16(opcode,p);
915+
916+ /* Free the RX event buffer */
917+ if (bt_vendor_cbacks)
918+ bt_vendor_cbacks->dealloc(p_evt_buf);
919+
920+#if (!defined(SCO_USE_I2S_INTERFACE) || (SCO_USE_I2S_INTERFACE == FALSE))
921+ if (opcode == HCI_VSC_WRITE_SCO_PCM_INT_PARAM)
922+ {
923+ uint8_t ret = FALSE;
924+
925+ /* Ask a new buffer to hold WRITE_PCM_DATA_FORMAT_PARAM command */
926+ if (bt_vendor_cbacks)
927+ p_buf = (HC_BT_HDR *) bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + \
928+ HCI_CMD_PREAMBLE_SIZE + \
929+ PCM_DATA_FORMAT_PARAM_SIZE);
930+ if (p_buf)
931+ {
932+ p_buf->event = MSG_STACK_TO_HC_HCI_CMD;
933+ p_buf->offset = 0;
934+ p_buf->layer_specific = 0;
935+ p_buf->len = HCI_CMD_PREAMBLE_SIZE + PCM_DATA_FORMAT_PARAM_SIZE;
936+
937+ p = (uint8_t *) (p_buf + 1);
938+ UINT16_TO_STREAM(p, HCI_VSC_WRITE_PCM_DATA_FORMAT_PARAM);
939+ *p++ = PCM_DATA_FORMAT_PARAM_SIZE;
940+ memcpy(p, &bt_pcm_data_fmt_param, PCM_DATA_FORMAT_PARAM_SIZE);
941+
942+ if ((ret = bt_vendor_cbacks->xmit_cb(HCI_VSC_WRITE_PCM_DATA_FORMAT_PARAM,\
943+ p_buf, hw_sco_cfg_cback)) == FALSE)
944+ {
945+ bt_vendor_cbacks->dealloc(p_buf);
946+ }
947+ else
948+ return;
949+ }
950+ }
951+#endif // !SCO_USE_I2S_INTERFACE
952+
953+if (bt_vendor_cbacks)
954+ bt_vendor_cbacks->scocfg_cb(BT_VND_OP_RESULT_SUCCESS);
955+}
956+#endif // SCO_CFG_INCLUDED
957+
958+/*****************************************************************************
959+** Hardware Configuration Interface Functions
960+*****************************************************************************/
961+
962+
963+/*******************************************************************************
964+**
965+** Function hw_config_start
966+**
967+** Description Kick off controller initialization process
968+**
969+** Returns None
970+**
971+*******************************************************************************/
972+void hw_config_start(void)
973+{
974+ HC_BT_HDR *p_buf = NULL;
975+ uint8_t *p;
976+
977+ hw_cfg_cb.state = 0;
978+ hw_cfg_cb.fw_fd = -1;
979+ hw_cfg_cb.f_set_baud_2 = FALSE;
980+
981+ /* Start from sending HCI_RESET */
982+
983+ if (bt_vendor_cbacks)
984+ {
985+ p_buf = (HC_BT_HDR *) bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + \
986+ HCI_CMD_PREAMBLE_SIZE);
987+ }
988+
989+ if (p_buf)
990+ {
991+ p_buf->event = MSG_STACK_TO_HC_HCI_CMD;
992+ p_buf->offset = 0;
993+ p_buf->layer_specific = 0;
994+ p_buf->len = HCI_CMD_PREAMBLE_SIZE;
995+
996+ p = (uint8_t *) (p_buf + 1);
997+ UINT16_TO_STREAM(p, HCI_RESET);
998+ *p = 0; /* parameter length */
999+
1000+ hw_cfg_cb.state = HW_CFG_START;
1001+
1002+ bt_vendor_cbacks->xmit_cb(HCI_RESET, p_buf, hw_config_cback);
1003+ }
1004+ else
1005+ {
1006+ if (bt_vendor_cbacks)
1007+ {
1008+ ALOGE("vendor lib fw conf aborted [no buffer]");
1009+ bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_FAIL);
1010+ }
1011+ }
1012+}
1013+
1014+/*******************************************************************************
1015+**
1016+** Function hw_lpm_enable
1017+**
1018+** Description Enalbe/Disable LPM
1019+**
1020+** Returns TRUE/FALSE
1021+**
1022+*******************************************************************************/
1023+uint8_t hw_lpm_enable(uint8_t turn_on)
1024+{
1025+ HC_BT_HDR *p_buf = NULL;
1026+ uint8_t *p;
1027+ uint8_t ret = FALSE;
1028+
1029+ if (bt_vendor_cbacks)
1030+ p_buf = (HC_BT_HDR *) bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + \
1031+ HCI_CMD_PREAMBLE_SIZE + \
1032+ LPM_CMD_PARAM_SIZE);
1033+
1034+ if (p_buf)
1035+ {
1036+ p_buf->event = MSG_STACK_TO_HC_HCI_CMD;
1037+ p_buf->offset = 0;
1038+ p_buf->layer_specific = 0;
1039+ p_buf->len = HCI_CMD_PREAMBLE_SIZE + LPM_CMD_PARAM_SIZE;
1040+
1041+ p = (uint8_t *) (p_buf + 1);
1042+ UINT16_TO_STREAM(p, HCI_VSC_WRITE_SLEEP_MODE);
1043+ *p++ = LPM_CMD_PARAM_SIZE; /* parameter length */
1044+
1045+ if (turn_on)
1046+ {
1047+ memcpy(p, &lpm_param, LPM_CMD_PARAM_SIZE);
1048+ upio_set(UPIO_LPM_MODE, UPIO_ASSERT, 0);
1049+ }
1050+ else
1051+ {
1052+ memset(p, 0, LPM_CMD_PARAM_SIZE);
1053+ upio_set(UPIO_LPM_MODE, UPIO_DEASSERT, 0);
1054+ }
1055+
1056+ if ((ret = bt_vendor_cbacks->xmit_cb(HCI_VSC_WRITE_SLEEP_MODE, p_buf, \
1057+ hw_lpm_ctrl_cback)) == FALSE)
1058+ {
1059+ bt_vendor_cbacks->dealloc(p_buf);
1060+ }
1061+ }
1062+
1063+ if ((ret == FALSE) && bt_vendor_cbacks)
1064+ bt_vendor_cbacks->lpm_cb(BT_VND_OP_RESULT_FAIL);
1065+
1066+ return ret;
1067+}
1068+
1069+/*******************************************************************************
1070+**
1071+** Function hw_lpm_get_idle_timeout
1072+**
1073+** Description Calculate idle time based on host stack idle threshold
1074+**
1075+** Returns idle timeout value
1076+**
1077+*******************************************************************************/
1078+uint32_t hw_lpm_get_idle_timeout(void)
1079+{
1080+ uint32_t timeout_ms;
1081+
1082+ /* set idle time to be LPM_IDLE_TIMEOUT_MULTIPLE times of
1083+ * host stack idle threshold (in 300ms/25ms)
1084+ */
1085+ timeout_ms = (uint32_t)lpm_param.host_stack_idle_threshold \
1086+ * LPM_IDLE_TIMEOUT_MULTIPLE;
1087+
1088+ if (strstr(hw_cfg_cb.local_chip_name, "BCM4325") != NULL)
1089+ timeout_ms *= 25; // 12.5 or 25 ?
1090+ else
1091+ timeout_ms *= 300;
1092+
1093+ return timeout_ms;
1094+}
1095+
1096+/*******************************************************************************
1097+**
1098+** Function hw_lpm_set_wake_state
1099+**
1100+** Description Assert/Deassert BT_WAKE
1101+**
1102+** Returns None
1103+**
1104+*******************************************************************************/
1105+void hw_lpm_set_wake_state(uint8_t wake_assert)
1106+{
1107+ uint8_t state = (wake_assert) ? UPIO_ASSERT : UPIO_DEASSERT;
1108+
1109+ upio_set(UPIO_BT_WAKE, state, lpm_param.bt_wake_polarity);
1110+}
1111+
1112+#if (SCO_CFG_INCLUDED == TRUE)
1113+/*******************************************************************************
1114+**
1115+** Function hw_sco_config
1116+**
1117+** Description Configure SCO related hardware settings
1118+**
1119+** Returns None
1120+**
1121+*******************************************************************************/
1122+void hw_sco_config(void)
1123+{
1124+ HC_BT_HDR *p_buf = NULL;
1125+ uint8_t *p, ret;
1126+
1127+#if (!defined(SCO_USE_I2S_INTERFACE) || (SCO_USE_I2S_INTERFACE == FALSE))
1128+ uint16_t cmd_u16 = HCI_CMD_PREAMBLE_SIZE + SCO_PCM_PARAM_SIZE;
1129+#else
1130+ uint16_t cmd_u16 = HCI_CMD_PREAMBLE_SIZE + SCO_I2SPCM_PARAM_SIZE;
1131+#endif
1132+
1133+ if (bt_vendor_cbacks)
1134+ p_buf = (HC_BT_HDR *) bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE+cmd_u16);
1135+
1136+ if (p_buf)
1137+ {
1138+ p_buf->event = MSG_STACK_TO_HC_HCI_CMD;
1139+ p_buf->offset = 0;
1140+ p_buf->layer_specific = 0;
1141+ p_buf->len = cmd_u16;
1142+
1143+ p = (uint8_t *) (p_buf + 1);
1144+#if (!defined(SCO_USE_I2S_INTERFACE) || (SCO_USE_I2S_INTERFACE == FALSE))
1145+ UINT16_TO_STREAM(p, HCI_VSC_WRITE_SCO_PCM_INT_PARAM);
1146+ *p++ = SCO_PCM_PARAM_SIZE;
1147+ memcpy(p, &bt_sco_param, SCO_PCM_PARAM_SIZE);
1148+ cmd_u16 = HCI_VSC_WRITE_SCO_PCM_INT_PARAM;
1149+ ALOGI("SCO PCM configure {%d, %d, %d, %d, %d}",
1150+ bt_sco_param[0], bt_sco_param[1], bt_sco_param[2], bt_sco_param[3], \
1151+ bt_sco_param[4]);
1152+
1153+#else
1154+ UINT16_TO_STREAM(p, HCI_VSC_WRITE_I2SPCM_INTERFACE_PARAM);
1155+ *p++ = SCO_I2SPCM_PARAM_SIZE;
1156+ memcpy(p, &bt_sco_param, SCO_I2SPCM_PARAM_SIZE);
1157+ cmd_u16 = HCI_VSC_WRITE_I2SPCM_INTERFACE_PARAM;
1158+ ALOGI("SCO over I2SPCM interface {%d, %d, %d, %d}",
1159+ bt_sco_param[0], bt_sco_param[1], bt_sco_param[2], bt_sco_param[3]);
1160+#endif
1161+
1162+ if ((ret=bt_vendor_cbacks->xmit_cb(cmd_u16, p_buf, hw_sco_cfg_cback)) \
1163+ == FALSE)
1164+ {
1165+ bt_vendor_cbacks->dealloc(p_buf);
1166+ }
1167+ else
1168+ return;
1169+ }
1170+
1171+ if (bt_vendor_cbacks)
1172+ {
1173+ ALOGE("vendor lib scocfg aborted");
1174+ bt_vendor_cbacks->scocfg_cb(BT_VND_OP_RESULT_FAIL);
1175+ }
1176+}
1177+#endif // SCO_CFG_INCLUDED
1178+
1179+/*******************************************************************************
1180+**
1181+** Function hw_set_patch_file_path
1182+**
1183+** Description Set the location of firmware patch file
1184+**
1185+** Returns 0 : Success
1186+** Otherwise : Fail
1187+**
1188+*******************************************************************************/
1189+int hw_set_patch_file_path(char *p_conf_name, char *p_conf_value, int param)
1190+{
1191+
1192+ strcpy(fw_patchfile_path, p_conf_value);
1193+
1194+ return 0;
1195+}
1196+
1197+/*******************************************************************************
1198+**
1199+** Function hw_set_patch_file_name
1200+**
1201+** Description Give the specific firmware patch filename
1202+**
1203+** Returns 0 : Success
1204+** Otherwise : Fail
1205+**
1206+*******************************************************************************/
1207+int hw_set_patch_file_name(char *p_conf_name, char *p_conf_value, int param)
1208+{
1209+
1210+ strcpy(fw_patchfile_name, p_conf_value);
1211+
1212+ return 0;
1213+}
1214+
1215+#if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE)
1216+/*******************************************************************************
1217+**
1218+** Function hw_set_patch_settlement_delay
1219+**
1220+** Description Give the specific firmware patch settlement time in milliseconds
1221+**
1222+** Returns 0 : Success
1223+** Otherwise : Fail
1224+**
1225+*******************************************************************************/
1226+int hw_set_patch_settlement_delay(char *p_conf_name, char *p_conf_value, int param)
1227+{
1228+ fw_patch_settlement_delay = atoi(p_conf_value);
1229+
1230+ return 0;
1231+}
1232+#endif //VENDOR_LIB_RUNTIME_TUNING_ENABLED
1233+
--- /dev/null
+++ b/src/upio.c
@@ -0,0 +1,487 @@
1+/******************************************************************************
2+ *
3+ * Copyright (C) 2009-2012 Broadcom Corporation
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ ******************************************************************************/
18+
19+/******************************************************************************
20+ *
21+ * Filename: upio.c
22+ *
23+ * Description: Contains I/O functions, like
24+ * rfkill control
25+ * BT_WAKE/HOST_WAKE control
26+ *
27+ ******************************************************************************/
28+
29+#define LOG_TAG "bt_upio"
30+
31+#include <utils/Log.h>
32+#include <fcntl.h>
33+#include <errno.h>
34+#include <cutils/properties.h>
35+#include "bt_vendor_brcm.h"
36+#include "upio.h"
37+#include "userial_vendor.h"
38+
39+/******************************************************************************
40+** Constants & Macros
41+******************************************************************************/
42+
43+#ifndef UPIO_DBG
44+#define UPIO_DBG FALSE
45+#endif
46+
47+#if (UPIO_DBG == TRUE)
48+#define UPIODBG(param, ...) {ALOGD(param, ## __VA_ARGS__);}
49+#else
50+#define UPIODBG(param, ...) {}
51+#endif
52+
53+/******************************************************************************
54+** Local type definitions
55+******************************************************************************/
56+
57+#if (BT_WAKE_VIA_PROC == TRUE)
58+
59+/* proc fs node for enable/disable lpm mode */
60+#ifndef VENDOR_LPM_PROC_NODE
61+#define VENDOR_LPM_PROC_NODE "/proc/bluetooth/sleep/lpm"
62+#endif
63+
64+/* proc fs node for notifying write request */
65+#ifndef VENDOR_BTWRITE_PROC_NODE
66+#define VENDOR_BTWRITE_PROC_NODE "/proc/bluetooth/sleep/btwrite"
67+#endif
68+
69+/*
70+ * Maximum btwrite assertion holding time without consecutive btwrite kicking.
71+ * This value is correlative(shorter) to the in-activity timeout period set in
72+ * the bluesleep LPM code. The current value used in bluesleep is 10sec.
73+ */
74+#ifndef PROC_BTWRITE_TIMER_TIMEOUT_MS
75+#define PROC_BTWRITE_TIMER_TIMEOUT_MS 8000
76+#endif
77+
78+/* lpm proc control block */
79+typedef struct
80+{
81+ uint8_t btwrite_active;
82+ uint8_t timer_created;
83+ timer_t timer_id;
84+ uint32_t timeout_ms;
85+} vnd_lpm_proc_cb_t;
86+
87+static vnd_lpm_proc_cb_t lpm_proc_cb;
88+#endif
89+
90+/******************************************************************************
91+** Static variables
92+******************************************************************************/
93+
94+static uint8_t upio_state[UPIO_MAX_COUNT];
95+static int rfkill_id = -1;
96+static int bt_emul_enable = 0;
97+static char *rfkill_state_path = NULL;
98+
99+/******************************************************************************
100+** Static functions
101+******************************************************************************/
102+
103+/* for friendly debugging outpout string */
104+static char *lpm_mode[] = {
105+ "UNKNOWN",
106+ "disabled",
107+ "enabled"
108+};
109+
110+static char *lpm_state[] = {
111+ "UNKNOWN",
112+ "de-asserted",
113+ "asserted"
114+};
115+
116+/*****************************************************************************
117+** Bluetooth On/Off Static Functions
118+*****************************************************************************/
119+static int is_emulator_context(void)
120+{
121+ char value[PROPERTY_VALUE_MAX];
122+
123+ property_get("ro.kernel.qemu", value, "0");
124+ UPIODBG("is_emulator_context : %s", value);
125+ if (strcmp(value, "1") == 0) {
126+ return 1;
127+ }
128+ return 0;
129+}
130+
131+static int is_rfkill_disabled(void)
132+{
133+ char value[PROPERTY_VALUE_MAX];
134+
135+ property_get("ro.rfkilldisabled", value, "0");
136+ UPIODBG("is_rfkill_disabled ? [%s]", value);
137+
138+ if (strcmp(value, "1") == 0) {
139+ return UPIO_BT_POWER_ON;
140+ }
141+
142+ return UPIO_BT_POWER_OFF;
143+}
144+
145+static int init_rfkill()
146+{
147+ char path[64];
148+ char buf[16];
149+ int fd, sz, id;
150+
151+ if (is_rfkill_disabled())
152+ return -1;
153+
154+ for (id = 0; ; id++)
155+ {
156+ snprintf(path, sizeof(path), "/sys/class/rfkill/rfkill%d/type", id);
157+ fd = open(path, O_RDONLY);
158+ if (fd < 0)
159+ {
160+ ALOGE("init_rfkill : open(%s) failed: %s (%d)\n", \
161+ path, strerror(errno), errno);
162+ return -1;
163+ }
164+
165+ sz = read(fd, &buf, sizeof(buf));
166+ close(fd);
167+
168+ if (sz >= 9 && memcmp(buf, "bluetooth", 9) == 0)
169+ {
170+ rfkill_id = id;
171+ break;
172+ }
173+ }
174+
175+ asprintf(&rfkill_state_path, "/sys/class/rfkill/rfkill%d/state", rfkill_id);
176+ return 0;
177+}
178+
179+/*****************************************************************************
180+** LPM Static Functions
181+*****************************************************************************/
182+
183+#if (BT_WAKE_VIA_PROC == TRUE)
184+/*******************************************************************************
185+**
186+** Function proc_btwrite_timeout
187+**
188+** Description Timeout thread of proc/.../btwrite assertion holding timer
189+**
190+** Returns None
191+**
192+*******************************************************************************/
193+static void proc_btwrite_timeout(union sigval arg)
194+{
195+ UPIODBG("..%s..", __FUNCTION__);
196+ lpm_proc_cb.btwrite_active = FALSE;
197+}
198+#endif
199+
200+/*****************************************************************************
201+** UPIO Interface Functions
202+*****************************************************************************/
203+
204+/*******************************************************************************
205+**
206+** Function upio_init
207+**
208+** Description Initialization
209+**
210+** Returns None
211+**
212+*******************************************************************************/
213+void upio_init(void)
214+{
215+ memset(upio_state, UPIO_UNKNOWN, UPIO_MAX_COUNT);
216+#if (BT_WAKE_VIA_PROC == TRUE)
217+ memset(&lpm_proc_cb, 0, sizeof(vnd_lpm_proc_cb_t));
218+#endif
219+}
220+
221+/*******************************************************************************
222+**
223+** Function upio_cleanup
224+**
225+** Description Clean up
226+**
227+** Returns None
228+**
229+*******************************************************************************/
230+void upio_cleanup(void)
231+{
232+#if (BT_WAKE_VIA_PROC == TRUE)
233+ if (lpm_proc_cb.timer_created == TRUE)
234+ timer_delete(lpm_proc_cb.timer_id);
235+
236+ lpm_proc_cb.timer_created = FALSE;
237+#endif
238+}
239+
240+/*******************************************************************************
241+**
242+** Function upio_set_bluetooth_power
243+**
244+** Description Interact with low layer driver to set Bluetooth power
245+** on/off.
246+**
247+** Returns 0 : SUCCESS or Not-Applicable
248+** <0 : ERROR
249+**
250+*******************************************************************************/
251+int upio_set_bluetooth_power(int on)
252+{
253+ int sz;
254+ int fd = -1;
255+ int ret = -1;
256+ char buffer = '0';
257+
258+ switch(on)
259+ {
260+ case UPIO_BT_POWER_OFF:
261+ buffer = '0';
262+ break;
263+
264+ case UPIO_BT_POWER_ON:
265+ buffer = '1';
266+ break;
267+ }
268+
269+ if (is_emulator_context())
270+ {
271+ /* if new value is same as current, return -1 */
272+ if (bt_emul_enable == on)
273+ return ret;
274+
275+ UPIODBG("set_bluetooth_power [emul] %d", on);
276+
277+ bt_emul_enable = on;
278+ return 0;
279+ }
280+
281+ /* check if we have rfkill interface */
282+ if (is_rfkill_disabled())
283+ return 0;
284+
285+ if (rfkill_id == -1)
286+ {
287+ if (init_rfkill())
288+ return ret;
289+ }
290+
291+ fd = open(rfkill_state_path, O_WRONLY);
292+
293+ if (fd < 0)
294+ {
295+ ALOGE("set_bluetooth_power : open(%s) for write failed: %s (%d)",
296+ rfkill_state_path, strerror(errno), errno);
297+ return ret;
298+ }
299+
300+ sz = write(fd, &buffer, 1);
301+
302+ if (sz < 0) {
303+ ALOGE("set_bluetooth_power : write(%s) failed: %s (%d)",
304+ rfkill_state_path, strerror(errno),errno);
305+ }
306+ else
307+ ret = 0;
308+
309+ if (fd >= 0)
310+ close(fd);
311+
312+ return ret;
313+}
314+
315+
316+/*******************************************************************************
317+**
318+** Function upio_set
319+**
320+** Description Set i/o based on polarity
321+**
322+** Returns None
323+**
324+*******************************************************************************/
325+void upio_set(uint8_t pio, uint8_t action, uint8_t polarity)
326+{
327+ int rc;
328+#if (BT_WAKE_VIA_PROC == TRUE)
329+ int fd = -1;
330+ char buffer;
331+#endif
332+
333+ switch (pio)
334+ {
335+ case UPIO_LPM_MODE:
336+ if (upio_state[UPIO_LPM_MODE] == action)
337+ {
338+ UPIODBG("LPM is %s already", lpm_mode[action]);
339+ return;
340+ }
341+
342+ upio_state[UPIO_LPM_MODE] = action;
343+
344+#if (BT_WAKE_VIA_PROC == TRUE)
345+ fd = open(VENDOR_LPM_PROC_NODE, O_WRONLY);
346+
347+ if (fd < 0)
348+ {
349+ ALOGE("upio_set : open(%s) for write failed: %s (%d)",
350+ VENDOR_LPM_PROC_NODE, strerror(errno), errno);
351+ return;
352+ }
353+
354+ if (action == UPIO_ASSERT)
355+ {
356+ buffer = '1';
357+ }
358+ else
359+ {
360+ buffer = '0';
361+
362+ // delete btwrite assertion holding timer
363+ if (lpm_proc_cb.timer_created == TRUE)
364+ {
365+ timer_delete(lpm_proc_cb.timer_id);
366+ lpm_proc_cb.timer_created = FALSE;
367+ }
368+ }
369+
370+ if (write(fd, &buffer, 1) < 0)
371+ {
372+ ALOGE("upio_set : write(%s) failed: %s (%d)",
373+ VENDOR_LPM_PROC_NODE, strerror(errno),errno);
374+ }
375+ else
376+ {
377+ if (action == UPIO_ASSERT)
378+ {
379+ // create btwrite assertion holding timer
380+ if (lpm_proc_cb.timer_created == FALSE)
381+ {
382+ int status;
383+ struct sigevent se;
384+
385+ se.sigev_notify = SIGEV_THREAD;
386+ se.sigev_value.sival_ptr = &lpm_proc_cb.timer_id;
387+ se.sigev_notify_function = proc_btwrite_timeout;
388+ se.sigev_notify_attributes = NULL;
389+
390+ status = timer_create(CLOCK_MONOTONIC, &se,
391+ &lpm_proc_cb.timer_id);
392+
393+ if (status == 0)
394+ lpm_proc_cb.timer_created = TRUE;
395+ }
396+ }
397+ }
398+
399+ if (fd >= 0)
400+ close(fd);
401+#endif
402+ break;
403+
404+ case UPIO_BT_WAKE:
405+ if (upio_state[UPIO_BT_WAKE] == action)
406+ {
407+ UPIODBG("BT_WAKE is %s already", lpm_state[action]);
408+
409+#if (BT_WAKE_VIA_PROC == TRUE)
410+ if (lpm_proc_cb.btwrite_active == TRUE)
411+ /*
412+ * The proc btwrite node could have not been updated for
413+ * certain time already due to heavy downstream path flow.
414+ * In this case, we want to explicity touch proc btwrite
415+ * node to keep the bt_wake assertion in the LPM kernel
416+ * driver. The current kernel bluesleep LPM code starts
417+ * a 10sec internal in-activity timeout timer before it
418+ * attempts to deassert BT_WAKE line.
419+ */
420+#endif
421+ return;
422+ }
423+
424+ upio_state[UPIO_BT_WAKE] = action;
425+
426+#if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE)
427+
428+ userial_vendor_ioctl( ( (action==UPIO_ASSERT) ? \
429+ USERIAL_OP_ASSERT_BT_WAKE : USERIAL_OP_DEASSERT_BT_WAKE),\
430+ NULL);
431+
432+#elif (BT_WAKE_VIA_PROC == TRUE)
433+
434+ /*
435+ * Kick proc btwrite node only at UPIO_ASSERT
436+ */
437+ if (action == UPIO_DEASSERT)
438+ return;
439+
440+ fd = open(VENDOR_BTWRITE_PROC_NODE, O_WRONLY);
441+
442+ if (fd < 0)
443+ {
444+ ALOGE("upio_set : open(%s) for write failed: %s (%d)",
445+ VENDOR_BTWRITE_PROC_NODE, strerror(errno), errno);
446+ return;
447+ }
448+
449+ buffer = '1';
450+
451+ if (write(fd, &buffer, 1) < 0)
452+ {
453+ ALOGE("upio_set : write(%s) failed: %s (%d)",
454+ VENDOR_BTWRITE_PROC_NODE, strerror(errno),errno);
455+ }
456+ else
457+ {
458+ lpm_proc_cb.btwrite_active = TRUE;
459+
460+ if (lpm_proc_cb.timer_created == TRUE)
461+ {
462+ struct itimerspec ts;
463+
464+ ts.it_value.tv_sec = PROC_BTWRITE_TIMER_TIMEOUT_MS/1000;
465+ ts.it_value.tv_nsec = 1000*(PROC_BTWRITE_TIMER_TIMEOUT_MS%1000);
466+ ts.it_interval.tv_sec = 0;
467+ ts.it_interval.tv_nsec = 0;
468+
469+ timer_settime(lpm_proc_cb.timer_id, 0, &ts, 0);
470+ }
471+ }
472+
473+ UPIODBG("proc btwrite assertion");
474+
475+ if (fd >= 0)
476+ close(fd);
477+#endif
478+
479+ break;
480+
481+ case UPIO_HOST_WAKE:
482+ UPIODBG("upio_set: UPIO_HOST_WAKE");
483+ break;
484+ }
485+}
486+
487+
--- /dev/null
+++ b/src/userial_vendor.c
@@ -0,0 +1,361 @@
1+/******************************************************************************
2+ *
3+ * Copyright (C) 2009-2012 Broadcom Corporation
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at:
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ ******************************************************************************/
18+
19+/******************************************************************************
20+ *
21+ * Filename: userial_vendor.c
22+ *
23+ * Description: Contains vendor-specific userial functions
24+ *
25+ ******************************************************************************/
26+
27+#define LOG_TAG "bt_userial_vendor"
28+
29+#include <utils/Log.h>
30+#include <termios.h>
31+#include <fcntl.h>
32+#include <errno.h>
33+#include <stdio.h>
34+#include "bt_vendor_brcm.h"
35+#include "userial.h"
36+#include "userial_vendor.h"
37+
38+/******************************************************************************
39+** Constants & Macros
40+******************************************************************************/
41+
42+#ifndef VNDUSERIAL_DBG
43+#define VNDUSERIAL_DBG FALSE
44+#endif
45+
46+#if (VNDUSERIAL_DBG == TRUE)
47+#define VNDUSERIALDBG(param, ...) {ALOGD(param, ## __VA_ARGS__);}
48+#else
49+#define VNDUSERIALDBG(param, ...) {}
50+#endif
51+
52+#define VND_PORT_NAME_MAXLEN 256
53+
54+/******************************************************************************
55+** Local type definitions
56+******************************************************************************/
57+
58+/* vendor serial control block */
59+typedef struct
60+{
61+ int fd; /* fd to Bluetooth device */
62+ struct termios termios; /* serial terminal of BT port */
63+ char port_name[VND_PORT_NAME_MAXLEN];
64+} vnd_userial_cb_t;
65+
66+/******************************************************************************
67+** Static variables
68+******************************************************************************/
69+
70+static vnd_userial_cb_t vnd_userial;
71+
72+/*****************************************************************************
73+** Helper Functions
74+*****************************************************************************/
75+
76+/*******************************************************************************
77+**
78+** Function userial_to_tcio_baud
79+**
80+** Description helper function converts USERIAL baud rates into TCIO
81+** conforming baud rates
82+**
83+** Returns TRUE/FALSE
84+**
85+*******************************************************************************/
86+uint8_t userial_to_tcio_baud(uint8_t cfg_baud, uint32_t *baud)
87+{
88+ if (cfg_baud == USERIAL_BAUD_115200)
89+ *baud = B115200;
90+ else if (cfg_baud == USERIAL_BAUD_4M)
91+ *baud = B4000000;
92+ else if (cfg_baud == USERIAL_BAUD_3M)
93+ *baud = B3000000;
94+ else if (cfg_baud == USERIAL_BAUD_2M)
95+ *baud = B2000000;
96+ else if (cfg_baud == USERIAL_BAUD_1M)
97+ *baud = B1000000;
98+ else if (cfg_baud == USERIAL_BAUD_921600)
99+ *baud = B921600;
100+ else if (cfg_baud == USERIAL_BAUD_460800)
101+ *baud = B460800;
102+ else if (cfg_baud == USERIAL_BAUD_230400)
103+ *baud = B230400;
104+ else if (cfg_baud == USERIAL_BAUD_57600)
105+ *baud = B57600;
106+ else if (cfg_baud == USERIAL_BAUD_19200)
107+ *baud = B19200;
108+ else if (cfg_baud == USERIAL_BAUD_9600)
109+ *baud = B9600;
110+ else if (cfg_baud == USERIAL_BAUD_1200)
111+ *baud = B1200;
112+ else if (cfg_baud == USERIAL_BAUD_600)
113+ *baud = B600;
114+ else
115+ {
116+ ALOGE( "userial vendor open: unsupported baud idx %i", cfg_baud);
117+ *baud = B115200;
118+ return FALSE;
119+ }
120+
121+ return TRUE;
122+}
123+
124+#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
125+/*******************************************************************************
126+**
127+** Function userial_ioctl_init_bt_wake
128+**
129+** Description helper function to set the open state of the bt_wake if ioctl
130+** is used. it should not hurt in the rfkill case but it might
131+** be better to compile it out.
132+**
133+** Returns none
134+**
135+*******************************************************************************/
136+void userial_ioctl_init_bt_wake(int fd)
137+{
138+ uint32_t bt_wake_state;
139+
140+ /* assert BT_WAKE through ioctl */
141+ ioctl(fd, USERIAL_IOCTL_BT_WAKE_ASSERT, NULL);
142+ ioctl(fd, USERIAL_IOCTL_BT_WAKE_GET_ST, &bt_wake_state);
143+ VNDUSERIALDBG("userial_ioctl_init_bt_wake read back BT_WAKE state=%i", \
144+ bt_wake_state);
145+}
146+#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
147+
148+
149+/*****************************************************************************
150+** Userial Vendor API Functions
151+*****************************************************************************/
152+
153+/*******************************************************************************
154+**
155+** Function userial_vendor_init
156+**
157+** Description Initialize userial vendor-specific control block
158+**
159+** Returns None
160+**
161+*******************************************************************************/
162+void userial_vendor_init(void)
163+{
164+ vnd_userial.fd = -1;
165+ snprintf(vnd_userial.port_name, VND_PORT_NAME_MAXLEN, "%s", \
166+ BLUETOOTH_UART_DEVICE_PORT);
167+}
168+
169+/*******************************************************************************
170+**
171+** Function userial_vendor_open
172+**
173+** Description Open the serial port with the given configuration
174+**
175+** Returns device fd
176+**
177+*******************************************************************************/
178+int userial_vendor_open(tUSERIAL_CFG *p_cfg)
179+{
180+ uint32_t baud;
181+ uint8_t data_bits;
182+ uint16_t parity;
183+ uint8_t stop_bits;
184+
185+ vnd_userial.fd = -1;
186+
187+ if (!userial_to_tcio_baud(p_cfg->baud, &baud))
188+ {
189+ return -1;
190+ }
191+
192+ if(p_cfg->fmt & USERIAL_DATABITS_8)
193+ data_bits = CS8;
194+ else if(p_cfg->fmt & USERIAL_DATABITS_7)
195+ data_bits = CS7;
196+ else if(p_cfg->fmt & USERIAL_DATABITS_6)
197+ data_bits = CS6;
198+ else if(p_cfg->fmt & USERIAL_DATABITS_5)
199+ data_bits = CS5;
200+ else
201+ {
202+ ALOGE("userial vendor open: unsupported data bits");
203+ return -1;
204+ }
205+
206+ if(p_cfg->fmt & USERIAL_PARITY_NONE)
207+ parity = 0;
208+ else if(p_cfg->fmt & USERIAL_PARITY_EVEN)
209+ parity = PARENB;
210+ else if(p_cfg->fmt & USERIAL_PARITY_ODD)
211+ parity = (PARENB | PARODD);
212+ else
213+ {
214+ ALOGE("userial vendor open: unsupported parity bit mode");
215+ return -1;
216+ }
217+
218+ if(p_cfg->fmt & USERIAL_STOPBITS_1)
219+ stop_bits = 0;
220+ else if(p_cfg->fmt & USERIAL_STOPBITS_2)
221+ stop_bits = CSTOPB;
222+ else
223+ {
224+ ALOGE("userial vendor open: unsupported stop bits");
225+ return -1;
226+ }
227+
228+ ALOGI("userial vendor open: opening %s", vnd_userial.port_name);
229+
230+ if ((vnd_userial.fd = open(vnd_userial.port_name, O_RDWR)) == -1)
231+ {
232+ ALOGE("userial vendor open: unable to open %s", vnd_userial.port_name);
233+ return -1;
234+ }
235+
236+ tcflush(vnd_userial.fd, TCIOFLUSH);
237+
238+ tcgetattr(vnd_userial.fd, &vnd_userial.termios);
239+ cfmakeraw(&vnd_userial.termios);
240+ vnd_userial.termios.c_cflag |= (CRTSCTS | stop_bits);
241+ tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios);
242+ tcflush(vnd_userial.fd, TCIOFLUSH);
243+
244+ tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios);
245+ tcflush(vnd_userial.fd, TCIOFLUSH);
246+ tcflush(vnd_userial.fd, TCIOFLUSH);
247+
248+ /* set input/output baudrate */
249+ cfsetospeed(&vnd_userial.termios, baud);
250+ cfsetispeed(&vnd_userial.termios, baud);
251+ tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios);
252+
253+#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
254+ userial_ioctl_init_bt_wake(vnd_userial.fd);
255+#endif
256+
257+ ALOGI("device fd = %d open", vnd_userial.fd);
258+
259+ return vnd_userial.fd;
260+}
261+
262+/*******************************************************************************
263+**
264+** Function userial_vendor_close
265+**
266+** Description Conduct vendor-specific close work
267+**
268+** Returns None
269+**
270+*******************************************************************************/
271+void userial_vendor_close(void)
272+{
273+ int result;
274+
275+ if (vnd_userial.fd == -1)
276+ return;
277+
278+#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
279+ /* de-assert bt_wake BEFORE closing port */
280+ ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_DEASSERT, NULL);
281+#endif
282+
283+ ALOGI("device fd = %d close", vnd_userial.fd);
284+
285+ if ((result = close(vnd_userial.fd)) < 0)
286+ ALOGE( "close(fd:%d) FAILED result:%d", vnd_userial.fd, result);
287+
288+ vnd_userial.fd = -1;
289+}
290+
291+/*******************************************************************************
292+**
293+** Function userial_vendor_set_baud
294+**
295+** Description Set new baud rate
296+**
297+** Returns None
298+**
299+*******************************************************************************/
300+void userial_vendor_set_baud(uint8_t userial_baud)
301+{
302+ uint32_t tcio_baud;
303+
304+ userial_to_tcio_baud(userial_baud, &tcio_baud);
305+
306+ cfsetospeed(&vnd_userial.termios, tcio_baud);
307+ cfsetispeed(&vnd_userial.termios, tcio_baud);
308+ tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios);
309+}
310+
311+/*******************************************************************************
312+**
313+** Function userial_vendor_ioctl
314+**
315+** Description ioctl inteface
316+**
317+** Returns None
318+**
319+*******************************************************************************/
320+void userial_vendor_ioctl(userial_vendor_ioctl_op_t op, void *p_data)
321+{
322+ switch(op)
323+ {
324+#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
325+ case USERIAL_OP_ASSERT_BT_WAKE:
326+ VNDUSERIALDBG("## userial_vendor_ioctl: Asserting BT_Wake ##");
327+ ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_ASSERT, NULL);
328+ break;
329+
330+ case USERIAL_OP_DEASSERT_BT_WAKE:
331+ VNDUSERIALDBG("## userial_vendor_ioctl: De-asserting BT_Wake ##");
332+ ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_DEASSERT, NULL);
333+ break;
334+
335+ case USERIAL_OP_GET_BT_WAKE_STATE:
336+ ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_GET_ST, p_data);
337+ break;
338+#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
339+
340+ default:
341+ break;
342+ }
343+}
344+
345+/*******************************************************************************
346+**
347+** Function userial_set_port
348+**
349+** Description Configure UART port name
350+**
351+** Returns 0 : Success
352+** Otherwise : Fail
353+**
354+*******************************************************************************/
355+int userial_set_port(char *p_conf_name, char *p_conf_value, int param)
356+{
357+ strcpy(vnd_userial.port_name, p_conf_value);
358+
359+ return 0;
360+}
361+
--- /dev/null
+++ b/vnd_buildcfg.mk
@@ -0,0 +1,16 @@
1+intermediates := $(local-intermediates-dir)
2+
3+SRC := $(call my-dir)/include/$(addprefix vnd_, $(addsuffix .txt,$(basename $(TARGET_DEVICE))))
4+ifeq (,$(wildcard $(SRC)))
5+# configuration file does not exist. Use default one
6+SRC := $(call my-dir)/include/vnd_generic.txt
7+endif
8+GEN := $(intermediates)/vnd_buildcfg.h
9+TOOL := $(TOP_DIR)external/bluetooth/bluedroid/tools/gen-buildcfg.sh
10+
11+$(GEN): PRIVATE_PATH := $(call my-dir)
12+$(GEN): PRIVATE_CUSTOM_TOOL = $(TOOL) $< $@
13+$(GEN): $(SRC) $(TOOL)
14+ $(transform-generated-source)
15+
16+LOCAL_GENERATED_SOURCES += $(GEN)
Show on old repository browser