diff options
Diffstat (limited to 'extras/recipes-kernel/linux/linux-omap/wl1271/0015-Bluetooth-btwilink-driver.patch')
-rw-r--r-- | extras/recipes-kernel/linux/linux-omap/wl1271/0015-Bluetooth-btwilink-driver.patch | 463 |
1 files changed, 463 insertions, 0 deletions
diff --git a/extras/recipes-kernel/linux/linux-omap/wl1271/0015-Bluetooth-btwilink-driver.patch b/extras/recipes-kernel/linux/linux-omap/wl1271/0015-Bluetooth-btwilink-driver.patch new file mode 100644 index 00000000..f45149f3 --- /dev/null +++ b/extras/recipes-kernel/linux/linux-omap/wl1271/0015-Bluetooth-btwilink-driver.patch | |||
@@ -0,0 +1,463 @@ | |||
1 | From e3948bda11a3a0d938500ffbc7ef43603909cc15 Mon Sep 17 00:00:00 2001 | ||
2 | From: Pavan Savoy <pavan_savoy@ti.com> | ||
3 | Date: Tue, 4 Jan 2011 10:59:48 +0000 | ||
4 | Subject: [PATCH 15/15] Bluetooth: btwilink driver | ||
5 | |||
6 | -- patch description -- | ||
7 | |||
8 | This is the bluetooth protocol driver for the TI WiLink7 chipsets. | ||
9 | Texas Instrument's WiLink chipsets combine wireless technologies | ||
10 | like BT, FM, GPS and WLAN onto a single chip. | ||
11 | |||
12 | This Bluetooth driver works on top of the TI_ST shared transport | ||
13 | line discipline driver which also allows other drivers like | ||
14 | FM V4L2 and GPS character driver to make use of the same UART interface. | ||
15 | |||
16 | Kconfig and Makefile modifications to enable the Bluetooth | ||
17 | driver for Texas Instrument's WiLink 7 chipset. | ||
18 | |||
19 | Signed-off-by: Pavan Savoy <pavan_savoy@ti.com> | ||
20 | --- | ||
21 | drivers/bluetooth/Kconfig | 10 + | ||
22 | drivers/bluetooth/Makefile | 1 + | ||
23 | drivers/bluetooth/btwilink.c | 397 ++++++++++++++++++++++++++++++++++++++++++ | ||
24 | 3 files changed, 408 insertions(+), 0 deletions(-) | ||
25 | create mode 100644 drivers/bluetooth/btwilink.c | ||
26 | |||
27 | diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig | ||
28 | index 02deef4..8e0de9a 100644 | ||
29 | --- a/drivers/bluetooth/Kconfig | ||
30 | +++ b/drivers/bluetooth/Kconfig | ||
31 | @@ -219,4 +219,14 @@ config BT_ATH3K | ||
32 | Say Y here to compile support for "Atheros firmware download driver" | ||
33 | into the kernel or say M to compile it as module (ath3k). | ||
34 | |||
35 | +config BT_WILINK | ||
36 | + tristate "Texas Instruments WiLink7 driver" | ||
37 | + depends on TI_ST | ||
38 | + help | ||
39 | + This enables the Bluetooth driver for Texas Instrument's BT/FM/GPS | ||
40 | + combo devices. This makes use of shared transport line discipline | ||
41 | + core driver to communicate with the BT core of the combo chip. | ||
42 | + | ||
43 | + Say Y here to compile support for Texas Instrument's WiLink7 driver | ||
44 | + into the kernel or say M to compile it as module. | ||
45 | endmenu | ||
46 | diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile | ||
47 | index 71bdf13..f4460f4 100644 | ||
48 | --- a/drivers/bluetooth/Makefile | ||
49 | +++ b/drivers/bluetooth/Makefile | ||
50 | @@ -18,6 +18,7 @@ obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o | ||
51 | obj-$(CONFIG_BT_ATH3K) += ath3k.o | ||
52 | obj-$(CONFIG_BT_MRVL) += btmrvl.o | ||
53 | obj-$(CONFIG_BT_MRVL_SDIO) += btmrvl_sdio.o | ||
54 | +obj-$(CONFIG_BT_WILINK) += btwilink.o | ||
55 | |||
56 | btmrvl-y := btmrvl_main.o | ||
57 | btmrvl-$(CONFIG_DEBUG_FS) += btmrvl_debugfs.o | ||
58 | diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c | ||
59 | new file mode 100644 | ||
60 | index 0000000..0201aca | ||
61 | --- /dev/null | ||
62 | +++ b/drivers/bluetooth/btwilink.c | ||
63 | @@ -0,0 +1,397 @@ | ||
64 | +/* | ||
65 | + * Texas Instrument's Bluetooth Driver For Shared Transport. | ||
66 | + * | ||
67 | + * Bluetooth Driver acts as interface between HCI core and | ||
68 | + * TI Shared Transport Layer. | ||
69 | + * | ||
70 | + * Copyright (C) 2009-2010 Texas Instruments | ||
71 | + * Author: Raja Mani <raja_mani@ti.com> | ||
72 | + * Pavan Savoy <pavan_savoy@ti.com> | ||
73 | + * | ||
74 | + * This program is free software; you can redistribute it and/or modify | ||
75 | + * it under the terms of the GNU General Public License version 2 as | ||
76 | + * published by the Free Software Foundation. | ||
77 | + * | ||
78 | + * This program is distributed in the hope that it will be useful, | ||
79 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
80 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
81 | + * GNU General Public License for more details. | ||
82 | + * | ||
83 | + * You should have received a copy of the GNU General Public License | ||
84 | + * along with this program; if not, write to the Free Software | ||
85 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
86 | + * | ||
87 | + */ | ||
88 | + | ||
89 | +#include <linux/platform_device.h> | ||
90 | +#include <net/bluetooth/bluetooth.h> | ||
91 | +#include <net/bluetooth/hci_core.h> | ||
92 | + | ||
93 | +#include <linux/ti_wilink_st.h> | ||
94 | + | ||
95 | +/* Bluetooth Driver Version */ | ||
96 | +#define VERSION "1.0" | ||
97 | + | ||
98 | +/* Number of seconds to wait for registration completion | ||
99 | + * when ST returns PENDING status. | ||
100 | + */ | ||
101 | +#define BT_REGISTER_TIMEOUT 6000 /* 6 sec */ | ||
102 | + | ||
103 | +/** | ||
104 | + * struct ti_st - driver operation structure | ||
105 | + * @hdev: hci device pointer which binds to bt driver | ||
106 | + * @reg_status: ST registration callback status | ||
107 | + * @st_write: write function provided by the ST driver | ||
108 | + * to be used by the driver during send_frame. | ||
109 | + * @wait_reg_completion - completion sync between ti_st_open | ||
110 | + * and ti_st_registration_completion_cb. | ||
111 | + */ | ||
112 | +struct ti_st { | ||
113 | + struct hci_dev *hdev; | ||
114 | + char reg_status; | ||
115 | + long (*st_write) (struct sk_buff *); | ||
116 | + struct completion wait_reg_completion; | ||
117 | +}; | ||
118 | + | ||
119 | +/* Increments HCI counters based on pocket ID (cmd,acl,sco) */ | ||
120 | +static inline void ti_st_tx_complete(struct ti_st *hst, int pkt_type) | ||
121 | +{ | ||
122 | + struct hci_dev *hdev = hst->hdev; | ||
123 | + | ||
124 | + /* Update HCI stat counters */ | ||
125 | + switch (pkt_type) { | ||
126 | + case HCI_COMMAND_PKT: | ||
127 | + hdev->stat.cmd_tx++; | ||
128 | + break; | ||
129 | + | ||
130 | + case HCI_ACLDATA_PKT: | ||
131 | + hdev->stat.acl_tx++; | ||
132 | + break; | ||
133 | + | ||
134 | + case HCI_SCODATA_PKT: | ||
135 | + hdev->stat.sco_tx++; | ||
136 | + break; | ||
137 | + } | ||
138 | +} | ||
139 | + | ||
140 | +/* ------- Interfaces to Shared Transport ------ */ | ||
141 | + | ||
142 | +/* Called by ST layer to indicate protocol registration completion | ||
143 | + * status.ti_st_open() function will wait for signal from this | ||
144 | + * API when st_register() function returns ST_PENDING. | ||
145 | + */ | ||
146 | +static void st_registration_completion_cb(void *priv_data, char data) | ||
147 | +{ | ||
148 | + struct ti_st *lhst = priv_data; | ||
149 | + | ||
150 | + /* Save registration status for use in ti_st_open() */ | ||
151 | + lhst->reg_status = data; | ||
152 | + /* complete the wait in ti_st_open() */ | ||
153 | + complete(&lhst->wait_reg_completion); | ||
154 | +} | ||
155 | + | ||
156 | +/* Called by Shared Transport layer when receive data is | ||
157 | + * available */ | ||
158 | +static long st_receive(void *priv_data, struct sk_buff *skb) | ||
159 | +{ | ||
160 | + struct ti_st *lhst = priv_data; | ||
161 | + int err; | ||
162 | + | ||
163 | + if (!skb) | ||
164 | + return -EFAULT; | ||
165 | + | ||
166 | + if (!lhst) { | ||
167 | + kfree_skb(skb); | ||
168 | + return -EFAULT; | ||
169 | + } | ||
170 | + | ||
171 | + skb->dev = (void *) lhst->hdev; | ||
172 | + | ||
173 | + /* Forward skb to HCI core layer */ | ||
174 | + err = hci_recv_frame(skb); | ||
175 | + if (err < 0) { | ||
176 | + BT_ERR("Unable to push skb to HCI core(%d)", err); | ||
177 | + return err; | ||
178 | + } | ||
179 | + | ||
180 | + lhst->hdev->stat.byte_rx += skb->len; | ||
181 | + | ||
182 | + return 0; | ||
183 | +} | ||
184 | + | ||
185 | +/* ------- Interfaces to HCI layer ------ */ | ||
186 | +/* protocol structure registered with shared transport */ | ||
187 | +static struct st_proto_s ti_st_proto[3] = { | ||
188 | + { | ||
189 | + .chnl_id = 0x02, /* ACL */ | ||
190 | + .recv = st_receive, | ||
191 | + .reg_complete_cb = st_registration_completion_cb, | ||
192 | + .hdr_len = 4, | ||
193 | + .offset_len_in_hdr = 2, | ||
194 | + .len_size = 2, | ||
195 | + .reserve = 8, | ||
196 | + }, | ||
197 | + { | ||
198 | + .chnl_id = 0x03, /* SCO */ | ||
199 | + .recv = st_receive, | ||
200 | + .reg_complete_cb = st_registration_completion_cb, | ||
201 | + .hdr_len = 3, | ||
202 | + .offset_len_in_hdr = 2, | ||
203 | + .len_size = 1, | ||
204 | + .reserve = 8, | ||
205 | + }, | ||
206 | + { | ||
207 | + .chnl_id = 0x04, /* HCI Events */ | ||
208 | + .recv = st_receive, | ||
209 | + .reg_complete_cb = st_registration_completion_cb, | ||
210 | + .hdr_len = 2, | ||
211 | + .offset_len_in_hdr = 1, | ||
212 | + .len_size = 1, | ||
213 | + .reserve = 8, | ||
214 | + }, | ||
215 | +}; | ||
216 | + | ||
217 | +/* Called from HCI core to initialize the device */ | ||
218 | +static int ti_st_open(struct hci_dev *hdev) | ||
219 | +{ | ||
220 | + unsigned long timeleft; | ||
221 | + struct ti_st *hst; | ||
222 | + int err, i; | ||
223 | + | ||
224 | + BT_DBG("%s %p", hdev->name, hdev); | ||
225 | + if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) { | ||
226 | + BT_ERR("btwilink already opened"); | ||
227 | + return -EBUSY; | ||
228 | + } | ||
229 | + | ||
230 | + /* provide contexts for callbacks from ST */ | ||
231 | + hst = hdev->driver_data; | ||
232 | + | ||
233 | + for (i = 0; i < 3; i++) { | ||
234 | + ti_st_proto[i].priv_data = hst; | ||
235 | + ti_st_proto[i].max_frame_size = HCI_MAX_FRAME_SIZE; | ||
236 | + | ||
237 | + err = st_register(&ti_st_proto[i]); | ||
238 | + if (err == -EINPROGRESS) { | ||
239 | + /* ST is busy with either protocol | ||
240 | + * registration or firmware download. | ||
241 | + */ | ||
242 | + /* Prepare wait-for-completion handler data structures. | ||
243 | + */ | ||
244 | + init_completion(&hst->wait_reg_completion); | ||
245 | + | ||
246 | + /* Reset ST registration callback status flag, | ||
247 | + * this value will be updated in | ||
248 | + * ti_st_registration_completion_cb() | ||
249 | + * function whenever it called from ST driver. | ||
250 | + */ | ||
251 | + hst->reg_status = -EINPROGRESS; | ||
252 | + | ||
253 | + BT_DBG("waiting for registration " | ||
254 | + "completion signal from ST"); | ||
255 | + timeleft = wait_for_completion_timeout | ||
256 | + (&hst->wait_reg_completion, | ||
257 | + msecs_to_jiffies(BT_REGISTER_TIMEOUT)); | ||
258 | + if (!timeleft) { | ||
259 | + clear_bit(HCI_RUNNING, &hdev->flags); | ||
260 | + BT_ERR("Timeout(%d sec),didn't get reg " | ||
261 | + "completion signal from ST", | ||
262 | + BT_REGISTER_TIMEOUT / 1000); | ||
263 | + return -ETIMEDOUT; | ||
264 | + } | ||
265 | + | ||
266 | + /* Is ST registration callback | ||
267 | + * called with ERROR status? */ | ||
268 | + if (hst->reg_status != 0) { | ||
269 | + clear_bit(HCI_RUNNING, &hdev->flags); | ||
270 | + BT_ERR("ST registration completed with invalid " | ||
271 | + "status %d", hst->reg_status); | ||
272 | + return -EAGAIN; | ||
273 | + } | ||
274 | + err = 0; | ||
275 | + } else if (err != 0) { | ||
276 | + clear_bit(HCI_RUNNING, &hdev->flags); | ||
277 | + BT_ERR("st_register failed %d", err); | ||
278 | + return err; | ||
279 | + } | ||
280 | + hst->st_write = ti_st_proto[i].write; | ||
281 | + if (!hst->st_write) { | ||
282 | + BT_ERR("undefined ST write function"); | ||
283 | + clear_bit(HCI_RUNNING, &hdev->flags); | ||
284 | + | ||
285 | + /* Undo registration with ST */ | ||
286 | + err = st_unregister(&ti_st_proto[i]); | ||
287 | + if (err) | ||
288 | + BT_ERR("st_unregister() failed with " | ||
289 | + "error %d", err); | ||
290 | + | ||
291 | + hst->st_write = NULL; | ||
292 | + /* ti_st_proto.write is filled up by the | ||
293 | + * underlying shared transport driver | ||
294 | + * upon registration | ||
295 | + */ | ||
296 | + return err; | ||
297 | + } | ||
298 | + } | ||
299 | + | ||
300 | + return err; | ||
301 | +} | ||
302 | + | ||
303 | +/* Close device */ | ||
304 | +static int ti_st_close(struct hci_dev *hdev) | ||
305 | +{ | ||
306 | + int err, i; | ||
307 | + struct ti_st *hst = hdev->driver_data; | ||
308 | + | ||
309 | + if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) | ||
310 | + return 0; | ||
311 | + | ||
312 | + for (i = 0; i < 3; i++) { | ||
313 | + /* continue to unregister from transport */ | ||
314 | + err = st_unregister(&ti_st_proto[i]); | ||
315 | + if (err) | ||
316 | + BT_ERR("st_unregister() failed with error %d", err); | ||
317 | + } | ||
318 | + | ||
319 | + hst->st_write = NULL; | ||
320 | + | ||
321 | + return err; | ||
322 | +} | ||
323 | + | ||
324 | +static int ti_st_send_frame(struct sk_buff *skb) | ||
325 | +{ | ||
326 | + struct hci_dev *hdev; | ||
327 | + struct ti_st *hst; | ||
328 | + long len; | ||
329 | + | ||
330 | + hdev = (struct hci_dev *)skb->dev; | ||
331 | + | ||
332 | + if (!test_bit(HCI_RUNNING, &hdev->flags)) | ||
333 | + return -EBUSY; | ||
334 | + | ||
335 | + hst = hdev->driver_data; | ||
336 | + | ||
337 | + /* Prepend skb with frame type */ | ||
338 | + memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); | ||
339 | + | ||
340 | + BT_DBG("%s: type %d len %d", hdev->name, bt_cb(skb)->pkt_type, | ||
341 | + skb->len); | ||
342 | + | ||
343 | + /* Insert skb to shared transport layer's transmit queue. | ||
344 | + * Freeing skb memory is taken care in shared transport layer, | ||
345 | + * so don't free skb memory here. | ||
346 | + */ | ||
347 | + len = hst->st_write(skb); | ||
348 | + if (len < 0) { | ||
349 | + kfree_skb(skb); | ||
350 | + BT_ERR("ST write failed (%ld)", len); | ||
351 | + /* Try Again, would only fail if UART has gone bad */ | ||
352 | + return -EAGAIN; | ||
353 | + } | ||
354 | + | ||
355 | + /* ST accepted our skb. So, Go ahead and do rest */ | ||
356 | + hdev->stat.byte_tx += len; | ||
357 | + ti_st_tx_complete(hst, bt_cb(skb)->pkt_type); | ||
358 | + | ||
359 | + return 0; | ||
360 | +} | ||
361 | + | ||
362 | +static void ti_st_destruct(struct hci_dev *hdev) | ||
363 | +{ | ||
364 | + BT_DBG("%s", hdev->name); | ||
365 | + kfree(hdev->driver_data); | ||
366 | +} | ||
367 | + | ||
368 | +static int bt_ti_probe(struct platform_device *pdev) | ||
369 | +{ | ||
370 | + static struct ti_st *hst; | ||
371 | + struct hci_dev *hdev; | ||
372 | + int err; | ||
373 | + | ||
374 | + hst = kzalloc(sizeof(struct ti_st), GFP_KERNEL); | ||
375 | + if (!hst) | ||
376 | + return -ENOMEM; | ||
377 | + | ||
378 | + /* Expose "hciX" device to user space */ | ||
379 | + hdev = hci_alloc_dev(); | ||
380 | + if (!hdev) { | ||
381 | + kfree(hst); | ||
382 | + return -ENOMEM; | ||
383 | + } | ||
384 | + | ||
385 | + BT_DBG("hdev %p", hdev); | ||
386 | + | ||
387 | + hst->hdev = hdev; | ||
388 | + hdev->bus = HCI_UART; | ||
389 | + hdev->driver_data = hst; | ||
390 | + hdev->open = ti_st_open; | ||
391 | + hdev->close = ti_st_close; | ||
392 | + hdev->flush = NULL; | ||
393 | + hdev->send = ti_st_send_frame; | ||
394 | + hdev->destruct = ti_st_destruct; | ||
395 | + hdev->owner = THIS_MODULE; | ||
396 | + | ||
397 | + err = hci_register_dev(hdev); | ||
398 | + if (err < 0) { | ||
399 | + BT_ERR("Can't register HCI device error %d", err); | ||
400 | + kfree(hst); | ||
401 | + hci_free_dev(hdev); | ||
402 | + return err; | ||
403 | + } | ||
404 | + | ||
405 | + BT_DBG("HCI device registered (hdev %p)", hdev); | ||
406 | + | ||
407 | + dev_set_drvdata(&pdev->dev, hst); | ||
408 | + return err; | ||
409 | +} | ||
410 | + | ||
411 | +static int bt_ti_remove(struct platform_device *pdev) | ||
412 | +{ | ||
413 | + struct hci_dev *hdev; | ||
414 | + struct ti_st *hst = dev_get_drvdata(&pdev->dev); | ||
415 | + | ||
416 | + if (!hst) | ||
417 | + return -EFAULT; | ||
418 | + | ||
419 | + hdev = hst->hdev; | ||
420 | + ti_st_close(hdev); | ||
421 | + hci_unregister_dev(hdev); | ||
422 | + | ||
423 | + hci_free_dev(hdev); | ||
424 | + kfree(hst); | ||
425 | + | ||
426 | + dev_set_drvdata(&pdev->dev, NULL); | ||
427 | + return 0; | ||
428 | +} | ||
429 | + | ||
430 | +static struct platform_driver btwilink_driver = { | ||
431 | + .probe = bt_ti_probe, | ||
432 | + .remove = bt_ti_remove, | ||
433 | + .driver = { | ||
434 | + .name = "btwilink", | ||
435 | + .owner = THIS_MODULE, | ||
436 | + }, | ||
437 | +}; | ||
438 | + | ||
439 | +/* ------- Module Init/Exit interfaces ------ */ | ||
440 | +static int __init btwilink_init(void) | ||
441 | +{ | ||
442 | + BT_INFO("Bluetooth Driver for TI WiLink - Version %s", VERSION); | ||
443 | + | ||
444 | + return platform_driver_register(&btwilink_driver); | ||
445 | +} | ||
446 | + | ||
447 | +static void __exit btwilink_exit(void) | ||
448 | +{ | ||
449 | + platform_driver_unregister(&btwilink_driver); | ||
450 | +} | ||
451 | + | ||
452 | +module_init(btwilink_init); | ||
453 | +module_exit(btwilink_exit); | ||
454 | + | ||
455 | +/* ------ Module Info ------ */ | ||
456 | + | ||
457 | +MODULE_AUTHOR("Raja Mani <raja_mani@ti.com>"); | ||
458 | +MODULE_DESCRIPTION("Bluetooth Driver for TI Shared Transport" VERSION); | ||
459 | +MODULE_VERSION(VERSION); | ||
460 | +MODULE_LICENSE("GPL"); | ||
461 | -- | ||
462 | 1.6.6.1 | ||
463 | |||