diff options
-rw-r--r-- | drivers/bluetooth/Kconfig | 12 | ||||
-rw-r--r-- | drivers/bluetooth/Makefile | 1 | ||||
-rwxr-xr-x | drivers/bluetooth/hci_ath.c | 235 | ||||
-rw-r--r-- | drivers/bluetooth/hci_ldisc.c | 6 | ||||
-rw-r--r-- | drivers/bluetooth/hci_uart.h | 8 |
5 files changed, 261 insertions, 1 deletions
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 058fbccf2f52..02deef424926 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig | |||
@@ -58,6 +58,18 @@ config BT_HCIUART_BCSP | |||
58 | 58 | ||
59 | Say Y here to compile support for HCI BCSP protocol. | 59 | Say Y here to compile support for HCI BCSP protocol. |
60 | 60 | ||
61 | config BT_HCIUART_ATH3K | ||
62 | bool "Atheros AR300x serial support" | ||
63 | depends on BT_HCIUART | ||
64 | help | ||
65 | HCIATH3K (HCI Atheros AR300x) is a serial protocol for | ||
66 | communication between host and Atheros AR300x Bluetooth devices. | ||
67 | This protocol enables AR300x chips to be enabled with | ||
68 | power management support. | ||
69 | Enable this if you have Atheros AR300x serial Bluetooth device. | ||
70 | |||
71 | Say Y here to compile support for HCI UART ATH3K protocol. | ||
72 | |||
61 | config BT_HCIUART_LL | 73 | config BT_HCIUART_LL |
62 | bool "HCILL protocol support" | 74 | bool "HCILL protocol support" |
63 | depends on BT_HCIUART | 75 | depends on BT_HCIUART |
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index 7e5aed598121..71bdf13287c4 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile | |||
@@ -26,4 +26,5 @@ hci_uart-y := hci_ldisc.o | |||
26 | hci_uart-$(CONFIG_BT_HCIUART_H4) += hci_h4.o | 26 | hci_uart-$(CONFIG_BT_HCIUART_H4) += hci_h4.o |
27 | hci_uart-$(CONFIG_BT_HCIUART_BCSP) += hci_bcsp.o | 27 | hci_uart-$(CONFIG_BT_HCIUART_BCSP) += hci_bcsp.o |
28 | hci_uart-$(CONFIG_BT_HCIUART_LL) += hci_ll.o | 28 | hci_uart-$(CONFIG_BT_HCIUART_LL) += hci_ll.o |
29 | hci_uart-$(CONFIG_BT_HCIUART_ATH3K) += hci_ath.o | ||
29 | hci_uart-objs := $(hci_uart-y) | 30 | hci_uart-objs := $(hci_uart-y) |
diff --git a/drivers/bluetooth/hci_ath.c b/drivers/bluetooth/hci_ath.c new file mode 100755 index 000000000000..5ab258bccccb --- /dev/null +++ b/drivers/bluetooth/hci_ath.c | |||
@@ -0,0 +1,235 @@ | |||
1 | /* | ||
2 | * Atheros Communication Bluetooth HCIATH3K UART protocol | ||
3 | * | ||
4 | * HCIATH3K (HCI Atheros AR300x Protocol) is a Atheros Communication's | ||
5 | * power management protocol extension to H4 to support AR300x Bluetooth Chip. | ||
6 | * | ||
7 | * Copyright (c) 2009-2010 Atheros Communications Inc. | ||
8 | * | ||
9 | * Acknowledgements: | ||
10 | * This file is based on hci_h4.c, which was written | ||
11 | * by Maxim Krasnyansky and Marcel Holtmann. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | * GNU General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | #include <linux/module.h> | ||
30 | #include <linux/kernel.h> | ||
31 | |||
32 | #include <linux/init.h> | ||
33 | #include <linux/slab.h> | ||
34 | #include <linux/tty.h> | ||
35 | #include <linux/errno.h> | ||
36 | #include <linux/ioctl.h> | ||
37 | #include <linux/skbuff.h> | ||
38 | |||
39 | #include <net/bluetooth/bluetooth.h> | ||
40 | #include <net/bluetooth/hci_core.h> | ||
41 | |||
42 | #include "hci_uart.h" | ||
43 | |||
44 | struct ath_struct { | ||
45 | struct hci_uart *hu; | ||
46 | unsigned int cur_sleep; | ||
47 | |||
48 | struct sk_buff_head txq; | ||
49 | struct work_struct ctxtsw; | ||
50 | }; | ||
51 | |||
52 | static int ath_wakeup_ar3k(struct tty_struct *tty) | ||
53 | { | ||
54 | struct termios settings; | ||
55 | int status = tty->driver->ops->tiocmget(tty, NULL); | ||
56 | |||
57 | if (status & TIOCM_CTS) | ||
58 | return status; | ||
59 | |||
60 | /* Disable Automatic RTSCTS */ | ||
61 | n_tty_ioctl_helper(tty, NULL, TCGETS, (unsigned long)&settings); | ||
62 | settings.c_cflag &= ~CRTSCTS; | ||
63 | n_tty_ioctl_helper(tty, NULL, TCSETS, (unsigned long)&settings); | ||
64 | |||
65 | /* Clear RTS first */ | ||
66 | status = tty->driver->ops->tiocmget(tty, NULL); | ||
67 | tty->driver->ops->tiocmset(tty, NULL, 0x00, TIOCM_RTS); | ||
68 | mdelay(20); | ||
69 | |||
70 | /* Set RTS, wake up board */ | ||
71 | status = tty->driver->ops->tiocmget(tty, NULL); | ||
72 | tty->driver->ops->tiocmset(tty, NULL, TIOCM_RTS, 0x00); | ||
73 | mdelay(20); | ||
74 | |||
75 | status = tty->driver->ops->tiocmget(tty, NULL); | ||
76 | |||
77 | n_tty_ioctl_helper(tty, NULL, TCGETS, (unsigned long)&settings); | ||
78 | settings.c_cflag |= CRTSCTS; | ||
79 | n_tty_ioctl_helper(tty, NULL, TCSETS, (unsigned long)&settings); | ||
80 | |||
81 | return status; | ||
82 | } | ||
83 | |||
84 | static void ath_hci_uart_work(struct work_struct *work) | ||
85 | { | ||
86 | int status; | ||
87 | struct ath_struct *ath; | ||
88 | struct hci_uart *hu; | ||
89 | struct tty_struct *tty; | ||
90 | |||
91 | ath = container_of(work, struct ath_struct, ctxtsw); | ||
92 | |||
93 | hu = ath->hu; | ||
94 | tty = hu->tty; | ||
95 | |||
96 | /* verify and wake up controller */ | ||
97 | if (ath->cur_sleep) { | ||
98 | status = ath_wakeup_ar3k(tty); | ||
99 | if (!(status & TIOCM_CTS)) | ||
100 | return; | ||
101 | } | ||
102 | |||
103 | /* Ready to send Data */ | ||
104 | clear_bit(HCI_UART_SENDING, &hu->tx_state); | ||
105 | hci_uart_tx_wakeup(hu); | ||
106 | } | ||
107 | |||
108 | /* Initialize protocol */ | ||
109 | static int ath_open(struct hci_uart *hu) | ||
110 | { | ||
111 | struct ath_struct *ath; | ||
112 | |||
113 | BT_DBG("hu %p", hu); | ||
114 | |||
115 | ath = kzalloc(sizeof(*ath), GFP_ATOMIC); | ||
116 | if (!ath) | ||
117 | return -ENOMEM; | ||
118 | |||
119 | skb_queue_head_init(&ath->txq); | ||
120 | |||
121 | hu->priv = ath; | ||
122 | ath->hu = hu; | ||
123 | |||
124 | INIT_WORK(&ath->ctxtsw, ath_hci_uart_work); | ||
125 | |||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | /* Flush protocol data */ | ||
130 | static int ath_flush(struct hci_uart *hu) | ||
131 | { | ||
132 | struct ath_struct *ath = hu->priv; | ||
133 | |||
134 | BT_DBG("hu %p", hu); | ||
135 | |||
136 | skb_queue_purge(&ath->txq); | ||
137 | |||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | /* Close protocol */ | ||
142 | static int ath_close(struct hci_uart *hu) | ||
143 | { | ||
144 | struct ath_struct *ath = hu->priv; | ||
145 | |||
146 | BT_DBG("hu %p", hu); | ||
147 | |||
148 | skb_queue_purge(&ath->txq); | ||
149 | |||
150 | cancel_work_sync(&ath->ctxtsw); | ||
151 | |||
152 | hu->priv = NULL; | ||
153 | kfree(ath); | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | #define HCI_OP_ATH_SLEEP 0xFC04 | ||
159 | |||
160 | /* Enqueue frame for transmittion */ | ||
161 | static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb) | ||
162 | { | ||
163 | struct ath_struct *ath = hu->priv; | ||
164 | |||
165 | if (bt_cb(skb)->pkt_type == HCI_SCODATA_PKT) { | ||
166 | kfree(skb); | ||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | /* | ||
171 | * Update power management enable flag with parameters of | ||
172 | * HCI sleep enable vendor specific HCI command. | ||
173 | */ | ||
174 | if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) { | ||
175 | struct hci_command_hdr *hdr = (void *)skb->data; | ||
176 | |||
177 | if (__le16_to_cpu(hdr->opcode) == HCI_OP_ATH_SLEEP) | ||
178 | ath->cur_sleep = skb->data[HCI_COMMAND_HDR_SIZE]; | ||
179 | } | ||
180 | |||
181 | BT_DBG("hu %p skb %p", hu, skb); | ||
182 | |||
183 | /* Prepend skb with frame type */ | ||
184 | memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); | ||
185 | |||
186 | skb_queue_tail(&ath->txq, skb); | ||
187 | set_bit(HCI_UART_SENDING, &hu->tx_state); | ||
188 | |||
189 | schedule_work(&ath->ctxtsw); | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static struct sk_buff *ath_dequeue(struct hci_uart *hu) | ||
195 | { | ||
196 | struct ath_struct *ath = hu->priv; | ||
197 | |||
198 | return skb_dequeue(&ath->txq); | ||
199 | } | ||
200 | |||
201 | /* Recv data */ | ||
202 | static int ath_recv(struct hci_uart *hu, void *data, int count) | ||
203 | { | ||
204 | if (hci_recv_stream_fragment(hu->hdev, data, count) < 0) | ||
205 | BT_ERR("Frame Reassembly Failed"); | ||
206 | |||
207 | return count; | ||
208 | } | ||
209 | |||
210 | static struct hci_uart_proto athp = { | ||
211 | .id = HCI_UART_ATH3K, | ||
212 | .open = ath_open, | ||
213 | .close = ath_close, | ||
214 | .recv = ath_recv, | ||
215 | .enqueue = ath_enqueue, | ||
216 | .dequeue = ath_dequeue, | ||
217 | .flush = ath_flush, | ||
218 | }; | ||
219 | |||
220 | int ath_init(void) | ||
221 | { | ||
222 | int err = hci_uart_register_proto(&athp); | ||
223 | |||
224 | if (!err) | ||
225 | BT_INFO("HCIATH3K protocol initialized"); | ||
226 | else | ||
227 | BT_ERR("HCIATH3K protocol registration failed"); | ||
228 | |||
229 | return err; | ||
230 | } | ||
231 | |||
232 | int ath_deinit(void) | ||
233 | { | ||
234 | return hci_uart_unregister_proto(&athp); | ||
235 | } | ||
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index a57dbfccb3fb..998833d93c13 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c | |||
@@ -552,6 +552,9 @@ static int __init hci_uart_init(void) | |||
552 | #ifdef CONFIG_BT_HCIUART_LL | 552 | #ifdef CONFIG_BT_HCIUART_LL |
553 | ll_init(); | 553 | ll_init(); |
554 | #endif | 554 | #endif |
555 | #ifdef CONFIG_BT_HCIUART_ATH3K | ||
556 | ath_init(); | ||
557 | #endif | ||
555 | 558 | ||
556 | return 0; | 559 | return 0; |
557 | } | 560 | } |
@@ -569,6 +572,9 @@ static void __exit hci_uart_exit(void) | |||
569 | #ifdef CONFIG_BT_HCIUART_LL | 572 | #ifdef CONFIG_BT_HCIUART_LL |
570 | ll_deinit(); | 573 | ll_deinit(); |
571 | #endif | 574 | #endif |
575 | #ifdef CONFIG_BT_HCIUART_ATH3K | ||
576 | ath_deinit(); | ||
577 | #endif | ||
572 | 578 | ||
573 | /* Release tty registration of line discipline */ | 579 | /* Release tty registration of line discipline */ |
574 | if ((err = tty_unregister_ldisc(N_HCI))) | 580 | if ((err = tty_unregister_ldisc(N_HCI))) |
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h index 9694d9d60905..99fb35239d1f 100644 --- a/drivers/bluetooth/hci_uart.h +++ b/drivers/bluetooth/hci_uart.h | |||
@@ -35,13 +35,14 @@ | |||
35 | #define HCIUARTGETFLAGS _IOR('U', 204, int) | 35 | #define HCIUARTGETFLAGS _IOR('U', 204, int) |
36 | 36 | ||
37 | /* UART protocols */ | 37 | /* UART protocols */ |
38 | #define HCI_UART_MAX_PROTO 5 | 38 | #define HCI_UART_MAX_PROTO 6 |
39 | 39 | ||
40 | #define HCI_UART_H4 0 | 40 | #define HCI_UART_H4 0 |
41 | #define HCI_UART_BCSP 1 | 41 | #define HCI_UART_BCSP 1 |
42 | #define HCI_UART_3WIRE 2 | 42 | #define HCI_UART_3WIRE 2 |
43 | #define HCI_UART_H4DS 3 | 43 | #define HCI_UART_H4DS 3 |
44 | #define HCI_UART_LL 4 | 44 | #define HCI_UART_LL 4 |
45 | #define HCI_UART_ATH3K 5 | ||
45 | 46 | ||
46 | #define HCI_UART_RAW_DEVICE 0 | 47 | #define HCI_UART_RAW_DEVICE 0 |
47 | 48 | ||
@@ -96,3 +97,8 @@ int bcsp_deinit(void); | |||
96 | int ll_init(void); | 97 | int ll_init(void); |
97 | int ll_deinit(void); | 98 | int ll_deinit(void); |
98 | #endif | 99 | #endif |
100 | |||
101 | #ifdef CONFIG_BT_HCIUART_ATH3K | ||
102 | int ath_init(void); | ||
103 | int ath_deinit(void); | ||
104 | #endif | ||