xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bluetooth_uart_driver/hci_uart.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  *  Bluetooth HCI UART driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (C) 2000-2001  Qualcomm Incorporated
6*4882a593Smuzhiyun  *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
7*4882a593Smuzhiyun  *  Copyright (C) 2004-2005  Marcel Holtmann <marcel@holtmann.org>
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  *  This program is free software; you can redistribute it and/or modify
11*4882a593Smuzhiyun  *  it under the terms of the GNU General Public License as published by
12*4882a593Smuzhiyun  *  the Free Software Foundation; either version 2 of the License, or
13*4882a593Smuzhiyun  *  (at your option) any later version.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  *  This program is distributed in the hope that it will be useful,
16*4882a593Smuzhiyun  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17*4882a593Smuzhiyun  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*4882a593Smuzhiyun  *  GNU General Public License for more details.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  *  You should have received a copy of the GNU General Public License
21*4882a593Smuzhiyun  *  along with this program; if not, write to the Free Software
22*4882a593Smuzhiyun  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  */
25*4882a593Smuzhiyun #include <linux/version.h>
26*4882a593Smuzhiyun #include <net/bluetooth/bluetooth.h>
27*4882a593Smuzhiyun #include <net/bluetooth/hci_core.h>
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /* #define HCI_VERSION_CODE KERNEL_VERSION(3, 14, 41) */
30*4882a593Smuzhiyun #define HCI_VERSION_CODE LINUX_VERSION_CODE
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #ifndef N_HCI
33*4882a593Smuzhiyun #define N_HCI	15
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #ifndef CONFIG_BT_HCIUART_H4
37*4882a593Smuzhiyun #define CONFIG_BT_HCIUART_H4
38*4882a593Smuzhiyun #endif
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #define BTCOEX
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /* Send host sleep notification to Controller */
43*4882a593Smuzhiyun #define WOBT_NOTIFY		0	/* 1  enable; 0  disable */
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* Send LE whitelist only for Background scan parameters */
46*4882a593Smuzhiyun #define WOBT_NOTIFY_BG_SCAN_LE_WHITELIST_ONLY	(0 * WOBT_NOTIFY)	/* 1  enable; 0  disable */
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* RTKBT Power-on Whitelist for sideband wake-up by LE Advertising from Remote.
49*4882a593Smuzhiyun * Note that it's necessary to apply TV FW Patch. */
50*4882a593Smuzhiyun #define RTKBT_TV_POWERON_WHITELIST	(0 * WOBT_NOTIFY)	/* 1  enable; 0  disable */
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /* RTKBT Power-on Data Filter for Manufacturer field */
53*4882a593Smuzhiyun /* Note that please edit the datafilter in
54*4882a593Smuzhiyun  *   rtkbt_set_le_device_poweron_data_filter() of hci_ldisc.c */
55*4882a593Smuzhiyun #define RTKBT_TV_POWERON_DATA_FILTER	(0 * WOBT_NOTIFY)	/* 1  enable; 0  disable */
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /* Ioctls */
58*4882a593Smuzhiyun #define HCIUARTSETPROTO		_IOW('U', 200, int)
59*4882a593Smuzhiyun #define HCIUARTGETPROTO		_IOR('U', 201, int)
60*4882a593Smuzhiyun #define HCIUARTGETDEVICE	_IOR('U', 202, int)
61*4882a593Smuzhiyun #define HCIUARTSETFLAGS		_IOW('U', 203, int)
62*4882a593Smuzhiyun #define HCIUARTGETFLAGS		_IOR('U', 204, int)
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /* UART protocols */
65*4882a593Smuzhiyun #define HCI_UART_MAX_PROTO	6
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #define HCI_UART_H4	0
68*4882a593Smuzhiyun #define HCI_UART_BCSP	1
69*4882a593Smuzhiyun #define HCI_UART_3WIRE	2
70*4882a593Smuzhiyun #define HCI_UART_H4DS	3
71*4882a593Smuzhiyun #define HCI_UART_LL	4
72*4882a593Smuzhiyun #define HCI_UART_ATH3K	5
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun #define HCI_UART_RAW_DEVICE	0
75*4882a593Smuzhiyun #define HCI_UART_RESET_ON_INIT	1
76*4882a593Smuzhiyun #define HCI_UART_CREATE_AMP	2
77*4882a593Smuzhiyun #define HCI_UART_INIT_PENDING	3
78*4882a593Smuzhiyun #define HCI_UART_EXT_CONFIG	4
79*4882a593Smuzhiyun #define HCI_UART_VND_DETECT	5
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun struct hci_uart;
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun struct hci_uart_proto {
84*4882a593Smuzhiyun 	unsigned int id;
85*4882a593Smuzhiyun 	int (*open)(struct hci_uart *hu);
86*4882a593Smuzhiyun 	int (*close)(struct hci_uart *hu);
87*4882a593Smuzhiyun 	int (*flush)(struct hci_uart *hu);
88*4882a593Smuzhiyun 	int (*recv)(struct hci_uart *hu, void *data, int len);
89*4882a593Smuzhiyun 	int (*enqueue)(struct hci_uart *hu, struct sk_buff *skb);
90*4882a593Smuzhiyun 	struct sk_buff *(*dequeue)(struct hci_uart *hu);
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun struct hci_uart {
94*4882a593Smuzhiyun 	struct tty_struct	*tty;
95*4882a593Smuzhiyun 	struct hci_dev		*hdev;
96*4882a593Smuzhiyun 	unsigned long		flags;
97*4882a593Smuzhiyun 	unsigned long		hdev_flags;
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun 	struct work_struct	write_work;
100*4882a593Smuzhiyun 	struct workqueue_struct *hci_uart_wq;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	struct hci_uart_proto	*proto;
103*4882a593Smuzhiyun #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
104*4882a593Smuzhiyun 	struct percpu_rw_semaphore proto_lock; /* Stop work for proto close */
105*4882a593Smuzhiyun #else
106*4882a593Smuzhiyun 	struct rw_semaphore proto_lock;
107*4882a593Smuzhiyun #endif
108*4882a593Smuzhiyun 	void			*priv;
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	struct semaphore tx_sem;	/* semaphore for tx */
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 	struct sk_buff		*tx_skb;
113*4882a593Smuzhiyun 	unsigned long		tx_state;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #if WOBT_NOTIFY
116*4882a593Smuzhiyun 	struct notifier_block pm_notify_block;
117*4882a593Smuzhiyun #endif
118*4882a593Smuzhiyun };
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun /* HCI_UART proto flag bits */
121*4882a593Smuzhiyun #define HCI_UART_PROTO_SET	0
122*4882a593Smuzhiyun #define HCI_UART_REGISTERED	1
123*4882a593Smuzhiyun #define HCI_UART_PROTO_READY	2
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /* TX states  */
126*4882a593Smuzhiyun #define HCI_UART_SENDING	1
127*4882a593Smuzhiyun #define HCI_UART_TX_WAKEUP	2
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun extern int hci_uart_register_proto(struct hci_uart_proto *p);
130*4882a593Smuzhiyun extern int hci_uart_unregister_proto(struct hci_uart_proto *p);
131*4882a593Smuzhiyun extern int hci_uart_tx_wakeup(struct hci_uart *hu);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun #ifdef CONFIG_BT_HCIUART_H4
134*4882a593Smuzhiyun extern int h4_init(void);
135*4882a593Smuzhiyun extern int h4_deinit(void);
136*4882a593Smuzhiyun #endif
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun extern int h5_init(void);
139*4882a593Smuzhiyun extern int h5_deinit(void);
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun #if HCI_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
142*4882a593Smuzhiyun extern int hci_uart_send_frame(struct sk_buff *skb);
143*4882a593Smuzhiyun #else
144*4882a593Smuzhiyun extern int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb);
145*4882a593Smuzhiyun #endif
146