1 /* Copyright Statement:
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
10 * MediaTek Inc. (C) 2010. All rights reserved.
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
38 * Bluetooth HCI UART driver
40 * Copyright (C) 2000-2001 Qualcomm Incorporated
41 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
42 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
45 * This program is free software; you can redistribute it and/or modify
46 * it under the terms of the GNU General Public License as published by
47 * the Free Software Foundation; either version 2 of the License, or
48 * (at your option) any later version.
50 * This program is distributed in the hope that it will be useful,
51 * but WITHOUT ANY WARRANTY; without even the implied warranty of
52 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53 * GNU General Public License for more details.
55 * You should have received a copy of the GNU General Public License
56 * along with this program; if not, write to the Free Software
57 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
61 /*******************************************************************************
62 * C O M P I L E R F L A G S
63 ********************************************************************************
68 #define HCI_STP_TX_TASKLET (0) /* do tx in a tasklet context */
69 #define HCI_STP_TX_THRD (1) /* do tx in an init thread context */
71 /* select tx context */
72 #define HCI_STP_TX (HCI_STP_TX_THRD)
74 #if (HCI_STP_TX == HCI_STP_TX_TASKLET)
75 #define HCI_STP_TX_TASKLET_RWLOCK (0) /* use rwlock_t */
76 #define HCI_STP_TX_TASKLET_SPINLOCK (1) /* use spinlock_t */
78 /* select txq protection method */
79 #define HCI_STP_TX_TASKLET_LOCK (HCI_STP_TX_TASKLET_SPINLOCK)
82 #define HCI_STP_DEV_INIT_OPEN_CTX (0) /* do init in hci_dev->open context, checked ok */
83 #define HCI_STP_DEV_INIT_THRD (1) /* do init in another thread context */
85 /* select init context */
86 #define HCI_STP_DEV_INIT (HCI_STP_DEV_INIT_THRD)
88 /*******************************************************************************
89 * E X T E R N A L R E F E R E N C E S
90 ********************************************************************************
93 #include <linux/module.h>
95 #include <linux/kernel.h>
96 #include <linux/init.h>
97 #include <linux/types.h>
98 #include <linux/fcntl.h>
99 #include <linux/interrupt.h>
100 #include <linux/ptrace.h>
101 #include <linux/poll.h>
103 #include <linux/slab.h>
104 #include <linux/tty.h>
105 #include <linux/errno.h>
106 #include <linux/string.h>
107 #include <linux/signal.h>
108 #include <linux/ioctl.h>
109 #include <linux/skbuff.h>
110 #include <linux/interrupt.h>
111 #include <linux/spinlock.h>
112 #include <linux/fs.h>
113 #include <asm/uaccess.h>
116 #include <linux/time.h>
117 #include <linux/delay.h>
119 /* constant of kernel version */
120 #include <linux/version.h>
123 #include <linux/kthread.h>
125 #include <net/bluetooth/bluetooth.h>
126 #include <net/bluetooth/hci_core.h>
128 /*******************************************************************************
130 ********************************************************************************
133 /* HCI-STP flag bits */
134 #define HCI_STP_PROTO_SET (0)
135 /* HCI-STP flag TX states bits */
136 #define HCI_STP_SENDING (1)
137 #define HCI_STP_TX_WAKEUP (2)
139 #if (HCI_STP_DEV_INIT == HCI_STP_DEV_INIT_THRD)
140 #define HCI_STP_INIT_TO_MSEC (5000) /* required time to finish init sequence */
143 /* maximum delay required */
144 #define BT_CMD_DELAY_MS_COMM (50)
145 #define BT_CMD_DELAY_MS_RESET (500)
146 #define BT_CMD_DELAY_SAFE_GUARD (20) /*(2)*/
148 /* HCI-STP safer hci_reset handling */
149 #define HCI_STP_SAFE_RESET (1)
151 /*******************************************************************************
153 ********************************************************************************
155 struct hci_stp_init_cmd {
156 unsigned char *hci_cmd;
158 unsigned char *hci_evt;
164 struct hci_dev *hdev;
167 struct sk_buff_head txq; /* used to queue TX packets */
168 unsigned long tx_state;
170 #if (HCI_STP_DEV_INIT == HCI_STP_DEV_INIT_THRD)
171 struct work_struct init_work;
172 struct completion *p_init_comp;
173 wait_queue_head_t *p_init_evt_wq;
174 spinlock_t init_lock; /* protect init variables: comp and wq */
175 unsigned int init_cmd_idx;
176 int init_evt_rx_flag; /* init result of last sent cmd */
179 #if HCI_STP_SAFE_RESET
180 wait_queue_head_t reset_wq;
181 atomic_t reset_count; /* !0: reset in progress */
183 //void *priv; /* unused? */
184 //struct sk_buff *tx_skb; /* unused? */
185 //spinlock_t rx_lock; /* unused? */
188 struct btradio_conf_data {
189 unsigned char addr[6];
190 unsigned char voice[2];
191 unsigned char codec[4];
192 unsigned char radio[6];
193 unsigned char sleep[7];
194 unsigned char feature[2];
195 unsigned char tx_pwr_offset[3];
197 /*******************************************************************************
199 ********************************************************************************
201 #define hci_stp_init_entry(c) {.hci_cmd=c, .cmdSz=sizeof(c), .hci_evt=c##_evt, .evtSz=sizeof(c##_evt), .str=#c}
203 #endif /* end of _HCI_STP_H */