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