xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bluetooth_usb_driver/rtk_bt.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  *  Realtek Bluetooth USB driver
4  *
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21 #include <linux/interrupt.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/types.h>
25 #include <linux/sched.h>
26 #include <linux/skbuff.h>
27 #include <linux/errno.h>
28 #include <linux/usb.h>
29 #include <linux/cdev.h>
30 #include <linux/device.h>
31 #include <linux/poll.h>
32 
33 #include <linux/version.h>
34 #include <linux/pm_runtime.h>
35 #include <linux/firmware.h>
36 #include <linux/suspend.h>
37 #include <net/bluetooth/bluetooth.h>
38 #include <net/bluetooth/hci_core.h>
39 #include <net/bluetooth/hci.h>
40 
41 /* #define HCI_VERSION_CODE KERNEL_VERSION(3, 14, 41) */
42 #define HCI_VERSION_CODE LINUX_VERSION_CODE
43 
44 #define BTCOEX
45 
46 /***********************************
47 ** Realtek - For rtk_btusb driver **
48 ***********************************/
49 #define BTUSB_WAKEUP_HOST		0	/* 1  enable; 0  disable */
50 
51 #define URB_CANCELING_DELAY_MS	10	// Added by Realtek
52 #if HCI_VERSION_CODE > KERNEL_VERSION(2, 6, 33)
53 #define HDEV_BUS		hdev->bus
54 #else
55 #define HDEV_BUS		hdev->type
56 #endif
57 
58 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 33)
59 #define USB_RPM			1
60 #else
61 #define USB_RPM			0
62 #endif
63 
64 #if HCI_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
65 #define NUM_REASSEMBLY 3
66 #endif
67 
68 #if HCI_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
69 #define GET_DRV_DATA(x)		hci_get_drvdata(x)
70 #else
71 #define GET_DRV_DATA(x)		x->driver_data
72 #endif
73 
74 #if HCI_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
75 #define SCO_NUM    hdev->conn_hash.sco_num
76 #else
77 #define SCO_NUM     hci_conn_num(hdev, SCO_LINK)
78 #endif
79 
80 int patch_add(struct usb_interface *intf);
81 void patch_remove(struct usb_interface *intf);
82 int download_patch(struct usb_interface *intf);
83 int set_btoff(struct usb_interface *intf);
84 void print_event(struct sk_buff *skb);
85 void print_command(struct sk_buff *skb);
86 void print_acl(struct sk_buff *skb, int dataOut);
87 
88 #if HCI_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
89 int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb);
90 #else
91 int btusb_send_frame(struct sk_buff *skb);
92 #endif
93 
94 #define BTUSB_MAX_ISOC_FRAMES	10
95 #define BTUSB_INTR_RUNNING		0
96 #define BTUSB_BULK_RUNNING		1
97 #define BTUSB_ISOC_RUNNING		2
98 #define BTUSB_SUSPENDING		3
99 #define BTUSB_DID_ISO_RESUME	4
100 
101 struct btusb_data {
102 	struct hci_dev *hdev;
103 	struct usb_device *udev;
104 	struct usb_interface *intf;
105 	struct usb_interface *isoc;
106 
107 	spinlock_t lock;
108 
109 	unsigned long flags;
110 
111 	struct work_struct work;
112 	struct work_struct waker;
113 
114 	struct usb_anchor tx_anchor;
115 	struct usb_anchor intr_anchor;
116 	struct usb_anchor bulk_anchor;
117 	struct usb_anchor isoc_anchor;
118 	struct usb_anchor deferred;
119 	int tx_in_flight;
120 	spinlock_t txlock;
121 
122 #if HCI_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
123 	spinlock_t rxlock;
124 	struct sk_buff *evt_skb;
125 	struct sk_buff *acl_skb;
126 	struct sk_buff *sco_skb;
127 #endif
128 
129 	struct usb_endpoint_descriptor *intr_ep;
130 	struct usb_endpoint_descriptor *bulk_tx_ep;
131 	struct usb_endpoint_descriptor *bulk_rx_ep;
132 	struct usb_endpoint_descriptor *isoc_tx_ep;
133 	struct usb_endpoint_descriptor *isoc_rx_ep;
134 
135 	__u8 cmdreq_type;
136 
137 	unsigned int sco_num;
138 	int isoc_altsetting;
139 	int suspend_count;
140 
141 #if HCI_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
142 	int (*recv_bulk) (struct btusb_data * data, void *buffer, int count);
143 #endif
144 	struct notifier_block pm_notifier;
145 	void *context;
146 };
147