81301e21f40221ff7221310f356c75486b6007cd
[openwrt/openwrt.git] / target / linux / omap24xx / patches-2.6.35 / 400-bluetooth-hci_h4p.patch
1 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/core.c
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/core.c 2010-08-08 12:57:24.000000000 +0200
5 @@ -0,0 +1,1023 @@
6 +/*
7 + * This file is part of hci_h4p bluetooth driver
8 + *
9 + * Copyright (C) 2005, 2006 Nokia Corporation.
10 + *
11 + * Contact: Ville Tervo <ville.tervo@nokia.com>
12 + *
13 + * This program is free software; you can redistribute it and/or
14 + * modify it under the terms of the GNU General Public License
15 + * version 2 as published by the Free Software Foundation.
16 + *
17 + * This program is distributed in the hope that it will be useful, but
18 + * WITHOUT ANY WARRANTY; without even the implied warranty of
19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 + * General Public License for more details.
21 + *
22 + * You should have received a copy of the GNU General Public License
23 + * along with this program; if not, write to the Free Software
24 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 + * 02110-1301 USA
26 + *
27 + */
28 +
29 +#include <linux/module.h>
30 +
31 +#include <linux/kernel.h>
32 +#include <linux/init.h>
33 +#include <linux/errno.h>
34 +#include <linux/delay.h>
35 +#include <linux/spinlock.h>
36 +#include <linux/serial_reg.h>
37 +#include <linux/skbuff.h>
38 +#include <linux/timer.h>
39 +#include <linux/device.h>
40 +#include <linux/platform_device.h>
41 +#include <linux/clk.h>
42 +#include <linux/gpio.h>
43 +
44 +#include <mach/hardware.h>
45 +#include <mach/board.h>
46 +#include <mach/irqs.h>
47 +//#include <mach/pm.h>
48 +
49 +#include <net/bluetooth/bluetooth.h>
50 +#include <net/bluetooth/hci_core.h>
51 +#include <net/bluetooth/hci.h>
52 +
53 +#include "hci_h4p.h"
54 +
55 +#define PM_TIMEOUT 200
56 +
57 +struct omap_bluetooth_config {
58 + u8 chip_type;
59 + u8 bt_wakeup_gpio;
60 + u8 host_wakeup_gpio;
61 + u8 reset_gpio;
62 + u8 bt_uart;
63 + u8 bd_addr[6];
64 + u8 bt_sysclk;
65 +};
66 +
67 +/* This should be used in function that cannot release clocks */
68 +static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
69 +{
70 + unsigned long flags;
71 +
72 + spin_lock_irqsave(&info->clocks_lock, flags);
73 + if (enable && !*clock) {
74 + NBT_DBG_POWER("Enabling %p\n", clock);
75 + clk_enable(info->uart_fclk);
76 +#ifdef CONFIG_ARCH_OMAP2
77 + if (cpu_is_omap24xx()) {
78 + clk_enable(info->uart_iclk);
79 + //omap2_block_sleep();
80 + }
81 +#endif
82 + }
83 + if (!enable && *clock) {
84 + NBT_DBG_POWER("Disabling %p\n", clock);
85 + clk_disable(info->uart_fclk);
86 +#ifdef CONFIG_ARCH_OMAP2
87 + if (cpu_is_omap24xx()) {
88 + clk_disable(info->uart_iclk);
89 + //omap2_allow_sleep();
90 + }
91 +#endif
92 + }
93 +
94 + *clock = enable;
95 + spin_unlock_irqrestore(&info->clocks_lock, flags);
96 +}
97 +
98 +/* Power management functions */
99 +static void hci_h4p_disable_tx(struct hci_h4p_info *info)
100 +{
101 + NBT_DBG_POWER("\n");
102 +
103 + if (!info->pm_enabled)
104 + return;
105 +
106 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
107 +}
108 +
109 +static void hci_h4p_enable_tx(struct hci_h4p_info *info)
110 +{
111 + NBT_DBG_POWER("\n");
112 +
113 + if (!info->pm_enabled)
114 + return;
115 +
116 + del_timer_sync(&info->tx_pm_timer);
117 + if (info->tx_pm_enabled) {
118 + info->tx_pm_enabled = 0;
119 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
120 + gpio_set_value(info->bt_wakeup_gpio, 1);
121 + }
122 +}
123 +
124 +static void hci_h4p_tx_pm_timer(unsigned long data)
125 +{
126 + struct hci_h4p_info *info;
127 +
128 + NBT_DBG_POWER("\n");
129 +
130 + info = (struct hci_h4p_info *)data;
131 +
132 + if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
133 + gpio_set_value(info->bt_wakeup_gpio, 0);
134 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
135 + info->tx_pm_enabled = 1;
136 + }
137 + else {
138 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
139 + }
140 +}
141 +
142 +static void hci_h4p_disable_rx(struct hci_h4p_info *info)
143 +{
144 + if (!info->pm_enabled)
145 + return;
146 +
147 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
148 +}
149 +
150 +static void hci_h4p_enable_rx(struct hci_h4p_info *info)
151 +{
152 + unsigned long flags;
153 +
154 + if (!info->pm_enabled)
155 + return;
156 +
157 + del_timer_sync(&info->rx_pm_timer);
158 + spin_lock_irqsave(&info->lock, flags);
159 + if (info->rx_pm_enabled) {
160 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
161 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
162 + __hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
163 + info->rx_pm_enabled = 0;
164 + }
165 + spin_unlock_irqrestore(&info->lock, flags);
166 +}
167 +
168 +static void hci_h4p_rx_pm_timer(unsigned long data)
169 +{
170 + unsigned long flags;
171 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
172 +
173 + spin_lock_irqsave(&info->lock, flags);
174 + if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_DR)) {
175 + __hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
176 + hci_h4p_set_rts(info, 0);
177 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
178 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
179 + info->rx_pm_enabled = 1;
180 + }
181 + else {
182 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
183 + }
184 + spin_unlock_irqrestore(&info->lock, flags);
185 +}
186 +
187 +/* Negotiation functions */
188 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
189 +{
190 + NBT_DBG("Sending alive packet\n");
191 +
192 + if (!info->alive_cmd_skb)
193 + return -EINVAL;
194 +
195 + /* Keep reference to buffer so we can reuse it */
196 + info->alive_cmd_skb = skb_get(info->alive_cmd_skb);
197 +
198 + skb_queue_tail(&info->txq, info->alive_cmd_skb);
199 + tasklet_schedule(&info->tx_task);
200 +
201 + NBT_DBG("Alive packet sent\n");
202 +
203 + return 0;
204 +}
205 +
206 +static void hci_h4p_alive_packet(struct hci_h4p_info *info, struct sk_buff *skb)
207 +{
208 + NBT_DBG("Received alive packet\n");
209 + if (skb->data[1] == 0xCC) {
210 + complete(&info->init_completion);
211 + }
212 +
213 + kfree_skb(skb);
214 +}
215 +
216 +static int hci_h4p_send_negotiation(struct hci_h4p_info *info, struct sk_buff *skb)
217 +{
218 + NBT_DBG("Sending negotiation..\n");
219 +
220 + hci_h4p_change_speed(info, INIT_SPEED);
221 +
222 + info->init_error = 0;
223 + init_completion(&info->init_completion);
224 + skb_queue_tail(&info->txq, skb);
225 + tasklet_schedule(&info->tx_task);
226 +
227 + if (!wait_for_completion_interruptible_timeout(&info->init_completion,
228 + msecs_to_jiffies(1000)))
229 + return -ETIMEDOUT;
230 +
231 + NBT_DBG("Negotiation sent\n");
232 + return info->init_error;
233 +}
234 +
235 +static void hci_h4p_negotiation_packet(struct hci_h4p_info *info,
236 + struct sk_buff *skb)
237 +{
238 + int err = 0;
239 +
240 + if (skb->data[1] == 0x20) {
241 + /* Change to operational settings */
242 + hci_h4p_set_rts(info, 0);
243 +
244 + err = hci_h4p_wait_for_cts(info, 0, 100);
245 + if (err < 0)
246 + goto neg_ret;
247 +
248 + hci_h4p_change_speed(info, MAX_BAUD_RATE);
249 +
250 + err = hci_h4p_wait_for_cts(info, 1, 100);
251 + if (err < 0)
252 + goto neg_ret;
253 +
254 + hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
255 +
256 + err = hci_h4p_send_alive_packet(info);
257 + if (err < 0)
258 + goto neg_ret;
259 + } else {
260 + dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
261 + err = -EINVAL;
262 + goto neg_ret;
263 + }
264 +
265 + kfree_skb(skb);
266 + return;
267 +
268 +neg_ret:
269 + info->init_error = err;
270 + complete(&info->init_completion);
271 + kfree_skb(skb);
272 +}
273 +
274 +/* H4 packet handling functions */
275 +static int hci_h4p_get_hdr_len(struct hci_h4p_info *info, u8 pkt_type)
276 +{
277 + long retval;
278 +
279 + switch (pkt_type) {
280 + case H4_EVT_PKT:
281 + retval = HCI_EVENT_HDR_SIZE;
282 + break;
283 + case H4_ACL_PKT:
284 + retval = HCI_ACL_HDR_SIZE;
285 + break;
286 + case H4_SCO_PKT:
287 + retval = HCI_SCO_HDR_SIZE;
288 + break;
289 + case H4_NEG_PKT:
290 + retval = 11;
291 + break;
292 + case H4_ALIVE_PKT:
293 + retval = 3;
294 + break;
295 + default:
296 + dev_err(info->dev, "Unknown H4 packet type 0x%.2x\n", pkt_type);
297 + retval = -1;
298 + break;
299 + }
300 +
301 + return retval;
302 +}
303 +
304 +static unsigned int hci_h4p_get_data_len(struct hci_h4p_info *info,
305 + struct sk_buff *skb)
306 +{
307 + long retval = -1;
308 + struct hci_event_hdr *evt_hdr;
309 + struct hci_acl_hdr *acl_hdr;
310 + struct hci_sco_hdr *sco_hdr;
311 +
312 + switch (bt_cb(skb)->pkt_type) {
313 + case H4_EVT_PKT:
314 + evt_hdr = (struct hci_event_hdr *)skb->data;
315 + retval = evt_hdr->plen;
316 + break;
317 + case H4_ACL_PKT:
318 + acl_hdr = (struct hci_acl_hdr *)skb->data;
319 + retval = le16_to_cpu(acl_hdr->dlen);
320 + break;
321 + case H4_SCO_PKT:
322 + sco_hdr = (struct hci_sco_hdr *)skb->data;
323 + retval = sco_hdr->dlen;
324 + break;
325 + case H4_NEG_PKT:
326 + retval = 0;
327 + break;
328 + case H4_ALIVE_PKT:
329 + retval = 0;
330 + break;
331 + }
332 +
333 + return retval;
334 +}
335 +
336 +static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
337 + struct sk_buff *skb)
338 +{
339 +
340 + if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
341 + NBT_DBG("fw_event\n");
342 + hci_h4p_parse_fw_event(info, skb);
343 + } else {
344 + hci_recv_frame(skb);
345 + NBT_DBG("Frame sent to upper layer\n");
346 + }
347 +}
348 +
349 +static void hci_h4p_rx_tasklet(unsigned long data)
350 +{
351 + u8 byte;
352 + unsigned long flags;
353 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
354 +
355 + NBT_DBG("tasklet woke up\n");
356 + NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
357 +
358 + while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
359 + byte = hci_h4p_inb(info, UART_RX);
360 + if (info->garbage_bytes) {
361 + info->garbage_bytes--;
362 + continue;
363 + }
364 + if (info->rx_skb == NULL) {
365 + info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC | GFP_DMA);
366 + if (!info->rx_skb) {
367 + dev_err(info->dev, "Can't allocate memory for new packet\n");
368 + goto finish_task;
369 + }
370 + info->rx_state = WAIT_FOR_PKT_TYPE;
371 + info->rx_skb->dev = (void *)info->hdev;
372 + }
373 + info->hdev->stat.byte_rx++;
374 + NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
375 + switch (info->rx_state) {
376 + case WAIT_FOR_PKT_TYPE:
377 + bt_cb(info->rx_skb)->pkt_type = byte;
378 + info->rx_count = hci_h4p_get_hdr_len(info, byte);
379 + if (info->rx_count < 0) {
380 + info->hdev->stat.err_rx++;
381 + kfree_skb(info->rx_skb);
382 + info->rx_skb = NULL;
383 + } else {
384 + info->rx_state = WAIT_FOR_HEADER;
385 + }
386 + break;
387 + case WAIT_FOR_HEADER:
388 + info->rx_count--;
389 + *skb_put(info->rx_skb, 1) = byte;
390 + if (info->rx_count == 0) {
391 + info->rx_count = hci_h4p_get_data_len(info, info->rx_skb);
392 + if (info->rx_count > skb_tailroom(info->rx_skb)) {
393 + dev_err(info->dev, "Frame is %ld bytes too long.\n",
394 + info->rx_count - skb_tailroom(info->rx_skb));
395 + kfree_skb(info->rx_skb);
396 + info->rx_skb = NULL;
397 + info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
398 + break;
399 + }
400 + info->rx_state = WAIT_FOR_DATA;
401 +
402 + if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
403 + hci_h4p_negotiation_packet(info, info->rx_skb);
404 + info->rx_skb = NULL;
405 + info->rx_state = WAIT_FOR_PKT_TYPE;
406 + goto finish_task;
407 + }
408 + if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
409 + hci_h4p_alive_packet(info, info->rx_skb);
410 + info->rx_skb = NULL;
411 + info->rx_state = WAIT_FOR_PKT_TYPE;
412 + goto finish_task;
413 + }
414 + }
415 + break;
416 + case WAIT_FOR_DATA:
417 + info->rx_count--;
418 + *skb_put(info->rx_skb, 1) = byte;
419 + if (info->rx_count == 0) {
420 + /* H4+ devices should allways send word aligned packets */
421 + if (!(info->rx_skb->len % 2)) {
422 + info->garbage_bytes++;
423 + }
424 + hci_h4p_recv_frame(info, info->rx_skb);
425 + info->rx_skb = NULL;
426 + }
427 + break;
428 + default:
429 + WARN_ON(1);
430 + break;
431 + }
432 + }
433 +
434 +finish_task:
435 + spin_lock_irqsave(&info->lock, flags);
436 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
437 + spin_unlock_irqrestore(&info->lock, flags);
438 +
439 + NBT_DBG_TRANSFER_NF("\n");
440 + NBT_DBG("rx_ended\n");
441 +}
442 +
443 +static void hci_h4p_tx_tasklet(unsigned long data)
444 +{
445 + unsigned int sent = 0;
446 + unsigned long flags;
447 + struct sk_buff *skb;
448 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
449 +
450 + NBT_DBG("tasklet woke up\n");
451 + NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
452 +
453 + skb = skb_dequeue(&info->txq);
454 + if (!skb) {
455 + /* No data in buffer */
456 + NBT_DBG("skb ready\n");
457 + hci_h4p_disable_tx(info);
458 + return;
459 + }
460 +
461 + /* Copy data to tx fifo */
462 + while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
463 + (sent < skb->len)) {
464 + NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
465 + hci_h4p_outb(info, UART_TX, skb->data[sent]);
466 + sent++;
467 + }
468 +
469 + info->hdev->stat.byte_tx += sent;
470 + NBT_DBG_TRANSFER_NF("\n");
471 + if (skb->len == sent) {
472 + kfree_skb(skb);
473 + } else {
474 + skb_pull(skb, sent);
475 + skb_queue_head(&info->txq, skb);
476 + }
477 +
478 + spin_lock_irqsave(&info->lock, flags);
479 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_THRI);
480 + spin_unlock_irqrestore(&info->lock, flags);
481 +}
482 +
483 +static irqreturn_t hci_h4p_interrupt(int irq, void *data)
484 +{
485 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
486 + u8 iir, msr;
487 + int ret;
488 + unsigned long flags;
489 +
490 + ret = IRQ_NONE;
491 +
492 + iir = hci_h4p_inb(info, UART_IIR);
493 + if (iir & UART_IIR_NO_INT) {
494 + dev_err(info->dev, "Interrupt but no reason irq 0x%.2x\n", iir);
495 + return IRQ_HANDLED;
496 + }
497 +
498 + NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
499 +
500 + iir &= UART_IIR_ID;
501 +
502 + if (iir == UART_IIR_MSI) {
503 + msr = hci_h4p_inb(info, UART_MSR);
504 + ret = IRQ_HANDLED;
505 + }
506 + if (iir == UART_IIR_RLSI) {
507 + hci_h4p_inb(info, UART_RX);
508 + hci_h4p_inb(info, UART_LSR);
509 + ret = IRQ_HANDLED;
510 + }
511 +
512 + if (iir == UART_IIR_RDI) {
513 + spin_lock_irqsave(&info->lock, flags);
514 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
515 + spin_unlock_irqrestore(&info->lock, flags);
516 + tasklet_schedule(&info->rx_task);
517 + ret = IRQ_HANDLED;
518 + }
519 +
520 + if (iir == UART_IIR_THRI) {
521 + spin_lock_irqsave(&info->lock, flags);
522 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_THRI);
523 + spin_unlock_irqrestore(&info->lock, flags);
524 + tasklet_schedule(&info->tx_task);
525 + ret = IRQ_HANDLED;
526 + }
527 +
528 + return ret;
529 +}
530 +
531 +static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
532 +{
533 + struct hci_h4p_info *info = dev_inst;
534 + int should_wakeup;
535 + struct hci_dev *hdev;
536 +
537 + if (!info->hdev)
538 + return IRQ_HANDLED;
539 +
540 + hdev = info->hdev;
541 +
542 + if (!test_bit(HCI_RUNNING, &hdev->flags))
543 + return IRQ_HANDLED;
544 +
545 + should_wakeup = gpio_get_value(info->host_wakeup_gpio);
546 + NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
547 + if (should_wakeup) {
548 + hci_h4p_enable_rx(info);
549 + } else {
550 + hci_h4p_disable_rx(info);
551 + }
552 +
553 + return IRQ_HANDLED;
554 +}
555 +
556 +static int hci_h4p_reset(struct hci_h4p_info *info)
557 +{
558 + int err;
559 +
560 + hci_h4p_init_uart(info);
561 + hci_h4p_set_rts(info, 0);
562 +
563 + gpio_set_value(info->reset_gpio, 0);
564 + msleep(100);
565 + gpio_set_value(info->bt_wakeup_gpio, 1);
566 + gpio_set_value(info->reset_gpio, 1);
567 + msleep(100);
568 +
569 + err = hci_h4p_wait_for_cts(info, 1, 10);
570 + if (err < 0) {
571 + dev_err(info->dev, "No cts from bt chip\n");
572 + return err;
573 + }
574 +
575 + hci_h4p_set_rts(info, 1);
576 +
577 + return 0;
578 +}
579 +
580 +/* hci callback functions */
581 +static int hci_h4p_hci_flush(struct hci_dev *hdev)
582 +{
583 + struct hci_h4p_info *info;
584 + info = hdev->driver_data;
585 +
586 + skb_queue_purge(&info->txq);
587 +
588 + return 0;
589 +}
590 +
591 +static int hci_h4p_hci_open(struct hci_dev *hdev)
592 +{
593 + struct hci_h4p_info *info;
594 + int err;
595 + struct sk_buff *neg_cmd_skb;
596 + struct sk_buff_head fw_queue;
597 +
598 + info = hdev->driver_data;
599 +
600 + if (test_bit(HCI_RUNNING, &hdev->flags))
601 + return 0;
602 +
603 + skb_queue_head_init(&fw_queue);
604 + err = hci_h4p_read_fw(info, &fw_queue);
605 + if (err < 0) {
606 + dev_err(info->dev, "Cannot read firmware\n");
607 + return err;
608 + }
609 + neg_cmd_skb = skb_dequeue(&fw_queue);
610 + if (!neg_cmd_skb) {
611 + err = -EPROTO;
612 + goto err_clean;
613 + }
614 + info->alive_cmd_skb = skb_dequeue(&fw_queue);
615 + if (!info->alive_cmd_skb) {
616 + err = -EPROTO;
617 + goto err_clean;
618 + }
619 +
620 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
621 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
622 +
623 + tasklet_enable(&info->tx_task);
624 + tasklet_enable(&info->rx_task);
625 + info->rx_state = WAIT_FOR_PKT_TYPE;
626 + info->rx_count = 0;
627 + info->garbage_bytes = 0;
628 + info->rx_skb = NULL;
629 + info->pm_enabled = 0;
630 + init_completion(&info->fw_completion);
631 +
632 + err = hci_h4p_reset(info);
633 + if (err < 0)
634 + goto err_clean;
635 +
636 + err = hci_h4p_send_negotiation(info, neg_cmd_skb);
637 + neg_cmd_skb = NULL;
638 + if (err < 0)
639 + goto err_clean;
640 +
641 + err = hci_h4p_send_fw(info, &fw_queue);
642 + if (err < 0) {
643 + dev_err(info->dev, "Sending firmware failed.\n");
644 + goto err_clean;
645 + }
646 +
647 + kfree_skb(info->alive_cmd_skb);
648 + info->alive_cmd_skb = NULL;
649 + info->pm_enabled = 1;
650 + info->tx_pm_enabled = 1;
651 + info->rx_pm_enabled = 0;
652 + set_bit(HCI_RUNNING, &hdev->flags);
653 +
654 + NBT_DBG("hci up and running\n");
655 + return 0;
656 +
657 +err_clean:
658 + hci_h4p_hci_flush(hdev);
659 + tasklet_disable(&info->tx_task);
660 + tasklet_disable(&info->rx_task);
661 + hci_h4p_reset_uart(info);
662 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
663 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
664 + gpio_set_value(info->reset_gpio, 0);
665 + gpio_set_value(info->bt_wakeup_gpio, 0);
666 + skb_queue_purge(&fw_queue);
667 + kfree_skb(neg_cmd_skb);
668 + neg_cmd_skb = NULL;
669 + kfree_skb(info->alive_cmd_skb);
670 + info->alive_cmd_skb = NULL;
671 + kfree_skb(info->rx_skb);
672 +
673 + return err;
674 +}
675 +
676 +static int hci_h4p_hci_close(struct hci_dev *hdev)
677 +{
678 + struct hci_h4p_info *info = hdev->driver_data;
679 +
680 + if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
681 + return 0;
682 +
683 + hci_h4p_hci_flush(hdev);
684 + del_timer_sync(&info->tx_pm_timer);
685 + del_timer_sync(&info->rx_pm_timer);
686 + tasklet_disable(&info->tx_task);
687 + tasklet_disable(&info->rx_task);
688 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
689 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
690 + hci_h4p_reset_uart(info);
691 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
692 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
693 + gpio_set_value(info->reset_gpio, 0);
694 + gpio_set_value(info->bt_wakeup_gpio, 0);
695 + kfree_skb(info->rx_skb);
696 +
697 + return 0;
698 +}
699 +
700 +static void hci_h4p_hci_destruct(struct hci_dev *hdev)
701 +{
702 +}
703 +
704 +static int hci_h4p_hci_send_frame(struct sk_buff *skb)
705 +{
706 + struct hci_h4p_info *info;
707 + struct hci_dev *hdev = (struct hci_dev *)skb->dev;
708 + int err = 0;
709 +
710 + if (!hdev) {
711 + printk(KERN_WARNING "hci_h4p: Frame for unknown device\n");
712 + return -ENODEV;
713 + }
714 +
715 + NBT_DBG("dev %p, skb %p\n", hdev, skb);
716 +
717 + info = hdev->driver_data;
718 +
719 + if (!test_bit(HCI_RUNNING, &hdev->flags)) {
720 + dev_warn(info->dev, "Frame for non-running device\n");
721 + return -EIO;
722 + }
723 +
724 + switch (bt_cb(skb)->pkt_type) {
725 + case HCI_COMMAND_PKT:
726 + hdev->stat.cmd_tx++;
727 + break;
728 + case HCI_ACLDATA_PKT:
729 + hdev->stat.acl_tx++;
730 + break;
731 + case HCI_SCODATA_PKT:
732 + hdev->stat.sco_tx++;
733 + break;
734 + }
735 +
736 + /* Push frame type to skb */
737 + *skb_push(skb, 1) = (bt_cb(skb)->pkt_type);
738 + /* We should allways send word aligned data to h4+ devices */
739 + if (skb->len % 2) {
740 + err = skb_pad(skb, 1);
741 + }
742 + if (err)
743 + return err;
744 +
745 + hci_h4p_enable_tx(info);
746 + skb_queue_tail(&info->txq, skb);
747 + tasklet_schedule(&info->tx_task);
748 +
749 + return 0;
750 +}
751 +
752 +static int hci_h4p_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
753 +{
754 + return -ENOIOCTLCMD;
755 +}
756 +
757 +static int hci_h4p_register_hdev(struct hci_h4p_info *info)
758 +{
759 + struct hci_dev *hdev;
760 +
761 + /* Initialize and register HCI device */
762 +
763 + hdev = hci_alloc_dev();
764 + if (!hdev) {
765 + dev_err(info->dev, "Can't allocate memory for device\n");
766 + return -ENOMEM;
767 + }
768 + info->hdev = hdev;
769 +
770 + hdev->type = HCI_UART;
771 + hdev->driver_data = info;
772 +
773 + hdev->open = hci_h4p_hci_open;
774 + hdev->close = hci_h4p_hci_close;
775 + hdev->flush = hci_h4p_hci_flush;
776 + hdev->send = hci_h4p_hci_send_frame;
777 + hdev->destruct = hci_h4p_hci_destruct;
778 + hdev->ioctl = hci_h4p_hci_ioctl;
779 +
780 + hdev->owner = THIS_MODULE;
781 +
782 + if (hci_register_dev(hdev) < 0) {
783 + dev_err(info->dev, "hci_h4p: Can't register HCI device %s.\n", hdev->name);
784 + return -ENODEV;
785 + }
786 +
787 + return 0;
788 +}
789 +
790 +static int hci_h4p_probe(struct platform_device *pdev)
791 +{
792 + struct omap_bluetooth_config *bt_config;
793 + struct hci_h4p_info *info;
794 + int irq, err;
795 +
796 + dev_info(&pdev->dev, "Registering HCI H4P device\n");
797 + info = kzalloc(sizeof(struct hci_h4p_info), GFP_KERNEL);
798 + if (!info)
799 + return -ENOMEM;
800 +
801 + info->dev = &pdev->dev;
802 + info->pm_enabled = 0;
803 + info->tx_pm_enabled = 0;
804 + info->rx_pm_enabled = 0;
805 + info->garbage_bytes = 0;
806 + info->tx_clocks_en = 0;
807 + info->rx_clocks_en = 0;
808 + tasklet_init(&info->tx_task, hci_h4p_tx_tasklet, (unsigned long)info);
809 + tasklet_init(&info->rx_task, hci_h4p_rx_tasklet, (unsigned long)info);
810 + /* hci_h4p_hci_open assumes that tasklet is disabled in startup */
811 + tasklet_disable(&info->tx_task);
812 + tasklet_disable(&info->rx_task);
813 + spin_lock_init(&info->lock);
814 + spin_lock_init(&info->clocks_lock);
815 + skb_queue_head_init(&info->txq);
816 + init_timer(&info->tx_pm_timer);
817 + info->tx_pm_timer.function = hci_h4p_tx_pm_timer;
818 + info->tx_pm_timer.data = (unsigned long)info;
819 + init_timer(&info->rx_pm_timer);
820 + info->rx_pm_timer.function = hci_h4p_rx_pm_timer;
821 + info->rx_pm_timer.data = (unsigned long)info;
822 +
823 + if (pdev->dev.platform_data == NULL) {
824 + dev_err(&pdev->dev, "Could not get Bluetooth config data\n");
825 + return -ENODATA;
826 + }
827 +
828 + bt_config = pdev->dev.platform_data;
829 + info->chip_type = bt_config->chip_type;
830 + info->bt_wakeup_gpio = bt_config->bt_wakeup_gpio;
831 + info->host_wakeup_gpio = bt_config->host_wakeup_gpio;
832 + info->reset_gpio = bt_config->reset_gpio;
833 + info->bt_sysclk = bt_config->bt_sysclk;
834 +
835 + NBT_DBG("RESET gpio: %d\n", info->reset_gpio);
836 + NBT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
837 + NBT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
838 + NBT_DBG("Uart: %d\n", bt_config->bt_uart);
839 + NBT_DBG("sysclk: %d\n", info->bt_sysclk);
840 +
841 + err = gpio_request(info->reset_gpio, "BT reset");
842 + if (err < 0) {
843 + dev_err(&pdev->dev, "Cannot get GPIO line %d\n",
844 + info->reset_gpio);
845 + kfree(info);
846 + goto cleanup;
847 + }
848 +
849 + err = gpio_request(info->bt_wakeup_gpio, "BT wakeup");
850 + if (err < 0)
851 + {
852 + dev_err(info->dev, "Cannot get GPIO line 0x%d",
853 + info->bt_wakeup_gpio);
854 + gpio_free(info->reset_gpio);
855 + kfree(info);
856 + goto cleanup;
857 + }
858 +
859 + err = gpio_request(info->host_wakeup_gpio, "BT host wakeup");
860 + if (err < 0)
861 + {
862 + dev_err(info->dev, "Cannot get GPIO line %d",
863 + info->host_wakeup_gpio);
864 + gpio_free(info->reset_gpio);
865 + gpio_free(info->bt_wakeup_gpio);
866 + kfree(info);
867 + goto cleanup;
868 + }
869 +
870 + gpio_direction_output(info->reset_gpio, 0);
871 + gpio_direction_output(info->bt_wakeup_gpio, 0);
872 + gpio_direction_input(info->host_wakeup_gpio);
873 +
874 + switch (bt_config->bt_uart) {
875 + case 1:
876 + if (cpu_is_omap16xx()) {
877 + irq = INT_UART1;
878 + info->uart_fclk = clk_get(NULL, "uart1_ck");
879 + } else if (cpu_is_omap24xx()) {
880 + irq = INT_24XX_UART1_IRQ;
881 + info->uart_iclk = clk_get(NULL, "uart1_ick");
882 + info->uart_fclk = clk_get(NULL, "uart1_fck");
883 + }
884 + /* FIXME: Use platform_get_resource for the port */
885 + info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
886 + if (!info->uart_base)
887 + goto cleanup;
888 + break;
889 + case 2:
890 + if (cpu_is_omap16xx()) {
891 + irq = INT_UART2;
892 + info->uart_fclk = clk_get(NULL, "uart2_ck");
893 + } else {
894 + irq = INT_24XX_UART2_IRQ;
895 + info->uart_iclk = clk_get(NULL, "uart2_ick");
896 + info->uart_fclk = clk_get(NULL, "uart2_fck");
897 + }
898 + /* FIXME: Use platform_get_resource for the port */
899 + info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
900 + if (!info->uart_base)
901 + goto cleanup;
902 + break;
903 + case 3:
904 + if (cpu_is_omap16xx()) {
905 + irq = INT_UART3;
906 + info->uart_fclk = clk_get(NULL, "uart3_ck");
907 + } else {
908 + irq = INT_24XX_UART3_IRQ;
909 + info->uart_iclk = clk_get(NULL, "uart3_ick");
910 + info->uart_fclk = clk_get(NULL, "uart3_fck");
911 + }
912 + /* FIXME: Use platform_get_resource for the port */
913 + info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
914 + if (!info->uart_base)
915 + goto cleanup;
916 + break;
917 + default:
918 + dev_err(info->dev, "No uart defined\n");
919 + goto cleanup;
920 + }
921 +
922 + info->irq = irq;
923 + err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
924 + if (err < 0) {
925 + dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
926 + goto cleanup;
927 + }
928 +
929 + err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
930 + hci_h4p_wakeup_interrupt,
931 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
932 + "hci_h4p_wkup", (void *)info);
933 + if (err < 0) {
934 + dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
935 + gpio_to_irq(info->host_wakeup_gpio));
936 + free_irq(irq, (void *)info);
937 + goto cleanup;
938 + }
939 +
940 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
941 + hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
942 + err = hci_h4p_init_uart(info);
943 + if (err < 0)
944 + goto cleanup_irq;
945 + err = hci_h4p_reset(info);
946 + if (err < 0)
947 + goto cleanup_irq;
948 + err = hci_h4p_wait_for_cts(info, 1, 10);
949 + if (err < 0)
950 + goto cleanup_irq;
951 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
952 +
953 + platform_set_drvdata(pdev, info);
954 + err = hci_h4p_sysfs_create_files(info->dev);
955 + if (err < 0)
956 + goto cleanup_irq;
957 +
958 + if (hci_h4p_register_hdev(info) < 0) {
959 + dev_err(info->dev, "failed to register hci_h4p hci device\n");
960 + goto cleanup_irq;
961 + }
962 + gpio_set_value(info->reset_gpio, 0);
963 +
964 + return 0;
965 +
966 +cleanup_irq:
967 + free_irq(irq, (void *)info);
968 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *)info);
969 +cleanup:
970 + gpio_set_value(info->reset_gpio, 0);
971 + gpio_free(info->reset_gpio);
972 + gpio_free(info->bt_wakeup_gpio);
973 + gpio_free(info->host_wakeup_gpio);
974 + kfree(info);
975 +
976 + return err;
977 +
978 +}
979 +
980 +static int hci_h4p_remove(struct platform_device *dev)
981 +{
982 + struct hci_h4p_info *info;
983 +
984 + info = platform_get_drvdata(dev);
985 +
986 + hci_h4p_hci_close(info->hdev);
987 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *) info);
988 + hci_free_dev(info->hdev);
989 + gpio_free(info->reset_gpio);
990 + gpio_free(info->bt_wakeup_gpio);
991 + gpio_free(info->host_wakeup_gpio);
992 + free_irq(info->irq, (void *) info);
993 + kfree(info);
994 +
995 + return 0;
996 +}
997 +
998 +static struct platform_driver hci_h4p_driver = {
999 + .probe = hci_h4p_probe,
1000 + .remove = hci_h4p_remove,
1001 + .driver = {
1002 + .name = "hci_h4p",
1003 + },
1004 +};
1005 +
1006 +static int __init hci_h4p_init(void)
1007 +{
1008 + int err = 0;
1009 +
1010 + /* Register the driver with LDM */
1011 + err = platform_driver_register(&hci_h4p_driver);
1012 + if (err < 0)
1013 + printk(KERN_WARNING "failed to register hci_h4p driver\n");
1014 +
1015 + return err;
1016 +}
1017 +
1018 +static void __exit hci_h4p_exit(void)
1019 +{
1020 + platform_driver_unregister(&hci_h4p_driver);
1021 +}
1022 +
1023 +module_init(hci_h4p_init);
1024 +module_exit(hci_h4p_exit);
1025 +
1026 +MODULE_DESCRIPTION("h4 driver with nokia extensions");
1027 +MODULE_LICENSE("GPL");
1028 +MODULE_AUTHOR("Ville Tervo");
1029 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/fw.c
1030 ===================================================================
1031 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1032 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/fw.c 2010-08-08 12:57:24.000000000 +0200
1033 @@ -0,0 +1,155 @@
1034 +/*
1035 + * This file is part of hci_h4p bluetooth driver
1036 + *
1037 + * Copyright (C) 2005, 2006 Nokia Corporation.
1038 + *
1039 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1040 + *
1041 + * This program is free software; you can redistribute it and/or
1042 + * modify it under the terms of the GNU General Public License
1043 + * version 2 as published by the Free Software Foundation.
1044 + *
1045 + * This program is distributed in the hope that it will be useful, but
1046 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1047 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1048 + * General Public License for more details.
1049 + *
1050 + * You should have received a copy of the GNU General Public License
1051 + * along with this program; if not, write to the Free Software
1052 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1053 + * 02110-1301 USA
1054 + *
1055 + */
1056 +
1057 +#include <linux/skbuff.h>
1058 +#include <linux/firmware.h>
1059 +#include <linux/clk.h>
1060 +
1061 +#include <net/bluetooth/bluetooth.h>
1062 +
1063 +#include "hci_h4p.h"
1064 +
1065 +#define BT_CHIP_TI 2
1066 +#define BT_CHIP_CSR 1
1067 +
1068 +static int fw_pos;
1069 +
1070 +/* Firmware handling */
1071 +static int hci_h4p_open_firmware(struct hci_h4p_info *info,
1072 + const struct firmware **fw_entry)
1073 +{
1074 + int err;
1075 +
1076 + fw_pos = 0;
1077 + NBT_DBG_FW("Opening %d firmware\n", info->chip_type);
1078 + switch (info->chip_type) {
1079 + case BT_CHIP_TI:
1080 + err = request_firmware(fw_entry, "brf6150fw.bin", info->dev);
1081 + break;
1082 + case BT_CHIP_CSR:
1083 + err = request_firmware(fw_entry, "bc4fw.bin", info->dev);
1084 + break;
1085 + default:
1086 + dev_err(info->dev, "Invalid chip type\n");
1087 + *fw_entry = NULL;
1088 + err = -EINVAL;
1089 + }
1090 +
1091 + return err;
1092 +}
1093 +
1094 +static void hci_h4p_close_firmware(const struct firmware *fw_entry)
1095 +{
1096 + release_firmware(fw_entry);
1097 +}
1098 +
1099 +/* Read fw. Return length of the command. If no more commands in
1100 + * fw 0 is returned. In error case return value is negative.
1101 + */
1102 +static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
1103 + const struct firmware *fw_entry, int how)
1104 +{
1105 + unsigned int cmd_len;
1106 +
1107 + if (fw_pos >= fw_entry->size) {
1108 + return 0;
1109 + }
1110 +
1111 + cmd_len = fw_entry->data[fw_pos++];
1112 + if (!cmd_len)
1113 + return 0;
1114 +
1115 + if (fw_pos + cmd_len > fw_entry->size) {
1116 + dev_err(info->dev, "Corrupted firmware image\n");
1117 + return -EMSGSIZE;
1118 + }
1119 +
1120 + *skb = bt_skb_alloc(cmd_len, how);
1121 + if (!*skb) {
1122 + dev_err(info->dev, "Cannot reserve memory for buffer\n");
1123 + return -ENOMEM;
1124 + }
1125 + memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
1126 +
1127 + fw_pos += cmd_len;
1128 +
1129 + return (*skb)->len;
1130 +}
1131 +
1132 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1133 +{
1134 + const struct firmware *fw_entry = NULL;
1135 + struct sk_buff *skb = NULL;
1136 + int err;
1137 +
1138 + err = hci_h4p_open_firmware(info, &fw_entry);
1139 + if (err < 0 || !fw_entry)
1140 + goto err_clean;
1141 +
1142 + while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
1143 + if (err < 0 || !skb)
1144 + goto err_clean;
1145 +
1146 + skb_queue_tail(fw_queue, skb);
1147 + }
1148 +
1149 +err_clean:
1150 + hci_h4p_close_firmware(fw_entry);
1151 + return err;
1152 +}
1153 +
1154 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1155 +{
1156 + int err;
1157 +
1158 + switch(info->chip_type) {
1159 + case BT_CHIP_CSR:
1160 + err = hci_h4p_bc4_send_fw(info, fw_queue);
1161 + break;
1162 + case BT_CHIP_TI:
1163 + err = hci_h4p_brf6150_send_fw(info, fw_queue);
1164 + break;
1165 + default:
1166 + dev_err(info->dev, "Don't know how to send firmware\n");
1167 + err = -EINVAL;
1168 + }
1169 +
1170 + return err;
1171 +}
1172 +
1173 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1174 +{
1175 + switch (info->chip_type) {
1176 + case BT_CHIP_CSR:
1177 + hci_h4p_bc4_parse_fw_event(info, skb);
1178 + break;
1179 + case BT_CHIP_TI:
1180 + hci_h4p_brf6150_parse_fw_event(info, skb);
1181 + break;
1182 + default:
1183 + dev_err(info->dev, "Don't know how to parse fw event\n");
1184 + info->fw_error = -EINVAL;
1185 + }
1186 +
1187 + return;
1188 +}
1189 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/fw-csr.c
1190 ===================================================================
1191 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1192 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/fw-csr.c 2010-08-08 12:57:25.000000000 +0200
1193 @@ -0,0 +1,149 @@
1194 +/*
1195 + * This file is part of hci_h4p bluetooth driver
1196 + *
1197 + * Copyright (C) 2005, 2006 Nokia Corporation.
1198 + *
1199 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1200 + *
1201 + * This program is free software; you can redistribute it and/or
1202 + * modify it under the terms of the GNU General Public License
1203 + * version 2 as published by the Free Software Foundation.
1204 + *
1205 + * This program is distributed in the hope that it will be useful, but
1206 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1207 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1208 + * General Public License for more details.
1209 + *
1210 + * You should have received a copy of the GNU General Public License
1211 + * along with this program; if not, write to the Free Software
1212 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1213 + * 02110-1301 USA
1214 + *
1215 + */
1216 +
1217 +#include <linux/skbuff.h>
1218 +#include <linux/delay.h>
1219 +#include <linux/serial_reg.h>
1220 +
1221 +#include "hci_h4p.h"
1222 +
1223 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1224 +{
1225 + /* Check if this is fw packet */
1226 + if (skb->data[0] != 0xff) {
1227 + hci_recv_frame(skb);
1228 + return;
1229 + }
1230 +
1231 + if (skb->data[11] || skb->data[12]) {
1232 + dev_err(info->dev, "Firmware sending command failed\n");
1233 + info->fw_error = -EPROTO;
1234 + }
1235 +
1236 + kfree_skb(skb);
1237 + complete(&info->fw_completion);
1238 +}
1239 +
1240 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1241 + struct sk_buff_head *fw_queue)
1242 +{
1243 + struct sk_buff *skb;
1244 + unsigned int offset;
1245 + int retries, count, i;
1246 +
1247 + info->fw_error = 0;
1248 +
1249 + NBT_DBG_FW("Sending firmware\n");
1250 + skb = skb_dequeue(fw_queue);
1251 +
1252 + if (!skb)
1253 + return -ENOMSG;
1254 +
1255 + info->bdaddr[0] = 0x00;
1256 + info->bdaddr[1] = 0x1D;
1257 + info->bdaddr[2] = 0x6E;
1258 + info->bdaddr[3] = 0xD4;
1259 + info->bdaddr[4] = 0xF0;
1260 + info->bdaddr[5] = 0x37;
1261 +
1262 + /* Check if this is bd_address packet */
1263 + if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
1264 + dev_info(info->dev, "bd_address packet found\n");
1265 + offset = 21;
1266 + skb->data[offset + 1] = 0x00;
1267 + skb->data[offset + 5] = 0x00;
1268 + skb->data[offset + 7] = info->bdaddr[0];
1269 + skb->data[offset + 6] = info->bdaddr[1];
1270 + skb->data[offset + 4] = info->bdaddr[2];
1271 + skb->data[offset + 0] = info->bdaddr[3];
1272 + skb->data[offset + 3] = info->bdaddr[4];
1273 + skb->data[offset + 2] = info->bdaddr[5];
1274 + }
1275 +
1276 + for (i = 0; i < 6; i++) {
1277 + if (info->bdaddr[i] != 0x00)
1278 + break;
1279 + }
1280 +
1281 + /* if (i > 5) {
1282 + dev_info(info->dev, "Valid bluetooth address not found.\n");
1283 + kfree_skb(skb);
1284 + return -ENODEV;
1285 + } */
1286 +
1287 + for (count = 1; ; count++) {
1288 + NBT_DBG_FW("Sending firmware command %d\n", count);
1289 + init_completion(&info->fw_completion);
1290 + skb_queue_tail(&info->txq, skb);
1291 + tasklet_schedule(&info->tx_task);
1292 +
1293 + skb = skb_dequeue(fw_queue);
1294 + if (!skb)
1295 + break;
1296 +
1297 + if (!wait_for_completion_timeout(&info->fw_completion,
1298 + msecs_to_jiffies(1000))) {
1299 + dev_err(info->dev, "No reply to fw command\n");
1300 + return -ETIMEDOUT;
1301 + }
1302 +
1303 + if (info->fw_error) {
1304 + dev_err(info->dev, "FW error\n");
1305 + return -EPROTO;
1306 + }
1307 + };
1308 +
1309 + /* Wait for chip warm reset */
1310 + retries = 100;
1311 + while ((!skb_queue_empty(&info->txq) ||
1312 + !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
1313 + retries--) {
1314 + msleep(10);
1315 + }
1316 + if (!retries) {
1317 + dev_err(info->dev, "Transmitter not empty\n");
1318 + return -ETIMEDOUT;
1319 + }
1320 +
1321 + hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
1322 +
1323 + if (hci_h4p_wait_for_cts(info, 1, 100)) {
1324 + dev_err(info->dev, "cts didn't go down after final speed change\n");
1325 + return -ETIMEDOUT;
1326 + }
1327 +
1328 + retries = 100;
1329 + do {
1330 + init_completion(&info->init_completion);
1331 + hci_h4p_send_alive_packet(info);
1332 + retries--;
1333 + } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
1334 + retries > 0);
1335 +
1336 + if (!retries) {
1337 + dev_err(info->dev, "No alive reply after speed change\n");
1338 + return -ETIMEDOUT;
1339 + }
1340 +
1341 + return 0;
1342 +}
1343 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/fw-ti.c
1344 ===================================================================
1345 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1346 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/fw-ti.c 2010-08-08 12:57:26.000000000 +0200
1347 @@ -0,0 +1,90 @@
1348 +/*
1349 + * This file is part of hci_h4p bluetooth driver
1350 + *
1351 + * Copyright (C) 2005, 2006 Nokia Corporation.
1352 + *
1353 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1354 + *
1355 + * This program is free software; you can redistribute it and/or
1356 + * modify it under the terms of the GNU General Public License
1357 + * version 2 as published by the Free Software Foundation.
1358 + *
1359 + * This program is distributed in the hope that it will be useful, but
1360 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1361 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1362 + * General Public License for more details.
1363 + *
1364 + * You should have received a copy of the GNU General Public License
1365 + * along with this program; if not, write to the Free Software
1366 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1367 + * 02110-1301 USA
1368 + *
1369 + */
1370 +
1371 +#include <linux/skbuff.h>
1372 +
1373 +#include "hci_h4p.h"
1374 +
1375 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1376 + struct sk_buff *skb)
1377 +{
1378 + struct hci_fw_event *ev;
1379 + int err = 0;
1380 +
1381 + if (bt_cb(skb)->pkt_type != H4_EVT_PKT) {
1382 + dev_err(info->dev, "Got non event fw packet.\n");
1383 + err = -EPROTO;
1384 + goto ret;
1385 + }
1386 +
1387 + ev = (struct hci_fw_event *)skb->data;
1388 + if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
1389 + dev_err(info->dev, "Got non cmd complete fw event\n");
1390 + err = -EPROTO;
1391 + goto ret;
1392 + }
1393 +
1394 + if (ev->status != 0) {
1395 + dev_err(info->dev, "Got error status from fw command\n");
1396 + err = -EPROTO;
1397 + goto ret;
1398 + }
1399 +
1400 +ret:
1401 + info->fw_error = err;
1402 + complete(&info->fw_completion);
1403 +}
1404 +
1405 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1406 +{
1407 + struct sk_buff *skb;
1408 + int err = 0;
1409 +
1410 + info->fw_error = 0;
1411 +
1412 + while ((skb = skb_dequeue(fw_queue)) != NULL) {
1413 + /* We should allways send word aligned data to h4+ devices */
1414 + if (skb->len % 2) {
1415 + err = skb_pad(skb, 1);
1416 + }
1417 + if (err)
1418 + return err;
1419 +
1420 + init_completion(&info->fw_completion);
1421 + skb_queue_tail(&info->txq, skb);
1422 + tasklet_schedule(&info->tx_task);
1423 +
1424 + if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
1425 + dev_err(info->dev, "Timeout while sending brf6150 fw\n");
1426 + return -ETIMEDOUT;
1427 + }
1428 +
1429 + if (info->fw_error) {
1430 + dev_err(info->dev, "There was fw_error while sending bfr6150 fw\n");
1431 + return -EPROTO;
1432 + }
1433 + }
1434 + NBT_DBG_FW("Firmware sent\n");
1435 +
1436 + return 0;
1437 +}
1438 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/hci_h4p.h
1439 ===================================================================
1440 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1441 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/hci_h4p.h 2010-08-08 12:57:26.000000000 +0200
1442 @@ -0,0 +1,183 @@
1443 +/*
1444 + * This file is part of hci_h4p bluetooth driver
1445 + *
1446 + * Copyright (C) 2005, 2006 Nokia Corporation.
1447 + *
1448 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1449 + *
1450 + * This program is free software; you can redistribute it and/or
1451 + * modify it under the terms of the GNU General Public License
1452 + * version 2 as published by the Free Software Foundation.
1453 + *
1454 + * This program is distributed in the hope that it will be useful, but
1455 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1456 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1457 + * General Public License for more details.
1458 + *
1459 + * You should have received a copy of the GNU General Public License
1460 + * along with this program; if not, write to the Free Software
1461 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1462 + * 02110-1301 USA
1463 + *
1464 + */
1465 +
1466 +#include <mach/board.h>
1467 +
1468 +#include <net/bluetooth/bluetooth.h>
1469 +#include <net/bluetooth/hci_core.h>
1470 +#include <net/bluetooth/hci.h>
1471 +
1472 +#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
1473 +#define __DRIVERS_BLUETOOTH_HCI_H4P_H
1474 +
1475 +#define UART_SYSC_OMAP_RESET 0x03
1476 +#define UART_SYSS_RESETDONE 0x01
1477 +#define UART_OMAP_SCR_EMPTY_THR 0x08
1478 +#define UART_OMAP_SCR_WAKEUP 0x10
1479 +#define UART_OMAP_SSR_WAKEUP 0x02
1480 +#define UART_OMAP_SSR_TXFULL 0x01
1481 +
1482 +#if 0
1483 +#define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1484 +#else
1485 +#define NBT_DBG(...)
1486 +#endif
1487 +
1488 +#if 0
1489 +#define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1490 +#else
1491 +#define NBT_DBG_FW(...)
1492 +#endif
1493 +
1494 +#if 0
1495 +#define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1496 +#else
1497 +#define NBT_DBG_POWER(...)
1498 +#endif
1499 +
1500 +#if 0
1501 +#define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1502 +#else
1503 +#define NBT_DBG_TRANSFER(...)
1504 +#endif
1505 +
1506 +#if 0
1507 +#define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
1508 +#else
1509 +#define NBT_DBG_TRANSFER_NF(...)
1510 +#endif
1511 +
1512 +#if 0
1513 +#define NBT_DBG_DMA(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1514 +#else
1515 +#define NBT_DBG_DMA(...)
1516 +#endif
1517 +
1518 +struct hci_h4p_info {
1519 + struct hci_dev *hdev;
1520 + spinlock_t lock;
1521 +
1522 + void __iomem *uart_base;
1523 + unsigned long uart_phys_base;
1524 + int irq;
1525 + struct device *dev;
1526 + u8 bdaddr[6];
1527 + u8 chip_type;
1528 + u8 bt_wakeup_gpio;
1529 + u8 host_wakeup_gpio;
1530 + u8 reset_gpio;
1531 + u8 bt_sysclk;
1532 +
1533 +
1534 + struct sk_buff_head fw_queue;
1535 + struct sk_buff *alive_cmd_skb;
1536 + struct completion init_completion;
1537 + struct completion fw_completion;
1538 + int fw_error;
1539 + int init_error;
1540 +
1541 + struct sk_buff_head txq;
1542 + struct tasklet_struct tx_task;
1543 +
1544 + struct sk_buff *rx_skb;
1545 + long rx_count;
1546 + unsigned long rx_state;
1547 + unsigned long garbage_bytes;
1548 + struct tasklet_struct rx_task;
1549 +
1550 + int pm_enabled;
1551 + int tx_pm_enabled;
1552 + int rx_pm_enabled;
1553 + struct timer_list tx_pm_timer;
1554 + struct timer_list rx_pm_timer;
1555 +
1556 + int tx_clocks_en;
1557 + int rx_clocks_en;
1558 + spinlock_t clocks_lock;
1559 + struct clk *uart_iclk;
1560 + struct clk *uart_fclk;
1561 +};
1562 +
1563 +#define MAX_BAUD_RATE 921600
1564 +#define BC4_MAX_BAUD_RATE 3692300
1565 +#define UART_CLOCK 48000000
1566 +#define BT_INIT_DIVIDER 320
1567 +#define BT_BAUDRATE_DIVIDER 384000000
1568 +#define BT_SYSCLK_DIV 1000
1569 +#define INIT_SPEED 120000
1570 +
1571 +#define H4_TYPE_SIZE 1
1572 +
1573 +/* H4+ packet types */
1574 +#define H4_CMD_PKT 0x01
1575 +#define H4_ACL_PKT 0x02
1576 +#define H4_SCO_PKT 0x03
1577 +#define H4_EVT_PKT 0x04
1578 +#define H4_NEG_PKT 0x06
1579 +#define H4_ALIVE_PKT 0x07
1580 +
1581 +/* TX states */
1582 +#define WAIT_FOR_PKT_TYPE 1
1583 +#define WAIT_FOR_HEADER 2
1584 +#define WAIT_FOR_DATA 3
1585 +
1586 +struct hci_fw_event {
1587 + struct hci_event_hdr hev;
1588 + struct hci_ev_cmd_complete cmd;
1589 + u8 status;
1590 +} __attribute__ ((packed));
1591 +
1592 +struct hci_bc4_set_bdaddr {
1593 + u8 type;
1594 + struct hci_command_hdr cmd_hdr;
1595 +} __attribute__ ((packed));
1596 +
1597 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
1598 +
1599 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
1600 + struct sk_buff *skb);
1601 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1602 + struct sk_buff_head *fw_queue);
1603 +
1604 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1605 + struct sk_buff *skb);
1606 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info,
1607 + struct sk_buff_head *fw_queue);
1608 +
1609 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1610 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1611 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
1612 +
1613 +int hci_h4p_sysfs_create_files(struct device *dev);
1614 +
1615 +void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
1616 +u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
1617 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
1618 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
1619 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1620 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1621 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
1622 +int hci_h4p_reset_uart(struct hci_h4p_info *info);
1623 +int hci_h4p_init_uart(struct hci_h4p_info *info);
1624 +
1625 +#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */
1626 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/Makefile
1627 ===================================================================
1628 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1629 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/Makefile 2010-08-08 12:57:27.000000000 +0200
1630 @@ -0,0 +1,7 @@
1631 +#
1632 +# Makefile for the Linux Bluetooth HCI device drivers.
1633 +#
1634 +
1635 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p.o
1636 +
1637 +hci_h4p-objs := core.o fw.o uart.o sysfs.o fw-ti.o fw-csr.o
1638 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/sysfs.c
1639 ===================================================================
1640 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1641 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/sysfs.c 2010-08-08 12:57:27.000000000 +0200
1642 @@ -0,0 +1,84 @@
1643 +/*
1644 + * This file is part of hci_h4p bluetooth driver
1645 + *
1646 + * Copyright (C) 2005, 2006 Nokia Corporation.
1647 + *
1648 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1649 + *
1650 + * This program is free software; you can redistribute it and/or
1651 + * modify it under the terms of the GNU General Public License
1652 + * version 2 as published by the Free Software Foundation.
1653 + *
1654 + * This program is distributed in the hope that it will be useful, but
1655 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1656 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1657 + * General Public License for more details.
1658 + *
1659 + * You should have received a copy of the GNU General Public License
1660 + * along with this program; if not, write to the Free Software
1661 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1662 + * 02110-1301 USA
1663 + *
1664 + */
1665 +
1666 +#include <linux/kernel.h>
1667 +#include <linux/init.h>
1668 +#include <linux/device.h>
1669 +#include <linux/platform_device.h>
1670 +
1671 +#include "hci_h4p.h"
1672 +
1673 +#ifdef CONFIG_SYSFS
1674 +
1675 +static ssize_t hci_h4p_store_bdaddr(struct device *dev, struct device_attribute *attr,
1676 + const char *buf, size_t count)
1677 +{
1678 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1679 + unsigned int bdaddr[6];
1680 + int ret, i;
1681 +
1682 + dev_info(info->dev, "HCI_H4P_STORE_BDADDR called\n");
1683 +
1684 + ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n",
1685 + &bdaddr[0], &bdaddr[1], &bdaddr[2],
1686 + &bdaddr[3], &bdaddr[4], &bdaddr[5]);
1687 +
1688 + if (ret != 6) {
1689 + dev_info(info->dev, "bdaddr isn't found\n");
1690 + return -EINVAL;
1691 + }
1692 +
1693 + //for (i = 0; i < 6; i++)
1694 + //info->bdaddr[i] = bdaddr[i] & 0xff;
1695 +
1696 + info->bdaddr[0] = 0x00;
1697 + info->bdaddr[1] = 0x1D;
1698 + info->bdaddr[2] = 0x6E;
1699 + info->bdaddr[3] = 0xD4;
1700 + info->bdaddr[4] = 0xF0;
1701 + info->bdaddr[5] = 0x37;
1702 +
1703 + return count;
1704 +}
1705 +
1706 +static ssize_t hci_h4p_show_bdaddr(struct device *dev, struct device_attribute *attr,
1707 + char *buf)
1708 +{
1709 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1710 +
1711 + return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
1712 + info->bdaddr[0],
1713 + info->bdaddr[1],
1714 + info->bdaddr[2],
1715 + info->bdaddr[3],
1716 + info->bdaddr[4],
1717 + info->bdaddr[5]);
1718 +}
1719 +
1720 +static DEVICE_ATTR(bdaddr, S_IRUGO | S_IWUSR, hci_h4p_show_bdaddr, hci_h4p_store_bdaddr);
1721 +int hci_h4p_sysfs_create_files(struct device *dev)
1722 +{
1723 + return device_create_file(dev, &dev_attr_bdaddr);
1724 +}
1725 +
1726 +#endif
1727 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/uart.c
1728 ===================================================================
1729 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1730 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/uart.c 2010-08-08 12:57:28.000000000 +0200
1731 @@ -0,0 +1,169 @@
1732 +/*
1733 + * This file is part of hci_h4p bluetooth driver
1734 + *
1735 + * Copyright (C) 2005, 2006 Nokia Corporation.
1736 + *
1737 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1738 + *
1739 + * This program is free software; you can redistribute it and/or
1740 + * modify it under the terms of the GNU General Public License
1741 + * version 2 as published by the Free Software Foundation.
1742 + *
1743 + * This program is distributed in the hope that it will be useful, but
1744 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1746 + * General Public License for more details.
1747 + *
1748 + * You should have received a copy of the GNU General Public License
1749 + * along with this program; if not, write to the Free Software
1750 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1751 + * 02110-1301 USA
1752 + *
1753 + */
1754 +
1755 +#include <linux/serial_reg.h>
1756 +#include <linux/delay.h>
1757 +#include <linux/clk.h>
1758 +
1759 +#include <asm/io.h>
1760 +
1761 +#include "hci_h4p.h"
1762 +
1763 +inline void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val)
1764 +{
1765 + offset <<= 2;
1766 + __raw_writeb(val, info->uart_base + offset);
1767 + //outb(val, info->uart_base + (offset << 2));
1768 +}
1769 +
1770 +inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
1771 +{
1772 + offset <<= 2;
1773 + return (u8)__raw_readb(info->uart_base + offset);
1774 + //return (unsigned int)__raw_readb(up->membase + offset);
1775 + //return inb(info->uart_base + (offset << 2));
1776 +}
1777 +
1778 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active)
1779 +{
1780 + u8 b;
1781 +
1782 + b = hci_h4p_inb(info, UART_MCR);
1783 + if (active)
1784 + b |= UART_MCR_RTS;
1785 + else
1786 + b &= ~UART_MCR_RTS;
1787 + hci_h4p_outb(info, UART_MCR, b);
1788 +}
1789 +
1790 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
1791 + int timeout_ms)
1792 +{
1793 + int okay;
1794 + unsigned long timeout;
1795 +
1796 + okay = 0;
1797 + timeout = jiffies + msecs_to_jiffies(timeout_ms);
1798 + for (;;) {
1799 + int state;
1800 +
1801 + state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
1802 + if (active) {
1803 + if (state)
1804 + return 0;
1805 + } else {
1806 + if (!state)
1807 + return 0;
1808 + }
1809 + if (time_after(jiffies, timeout))
1810 + return -ETIMEDOUT;
1811 + }
1812 +}
1813 +
1814 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1815 +{
1816 + u8 lcr, b;
1817 +
1818 + lcr = hci_h4p_inb(info, UART_LCR);
1819 + hci_h4p_outb(info, UART_LCR, 0xbf);
1820 + b = hci_h4p_inb(info, UART_EFR);
1821 + if (on)
1822 + b |= which;
1823 + else
1824 + b &= ~which;
1825 + hci_h4p_outb(info, UART_EFR, b);
1826 + hci_h4p_outb(info, UART_LCR, lcr);
1827 +}
1828 +
1829 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1830 +{
1831 + unsigned long flags;
1832 +
1833 + spin_lock_irqsave(&info->lock, flags);
1834 + __hci_h4p_set_auto_ctsrts(info, on, which);
1835 + spin_unlock_irqrestore(&info->lock, flags);
1836 +}
1837 +
1838 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
1839 +{
1840 + unsigned int divisor;
1841 + u8 lcr, mdr1;
1842 +
1843 + NBT_DBG("Setting speed %lu\n", speed);
1844 +
1845 + if (speed >= 460800) {
1846 + divisor = UART_CLOCK / 13 / speed;
1847 + mdr1 = 3;
1848 + } else {
1849 + divisor = UART_CLOCK / 16 / speed;
1850 + mdr1 = 0;
1851 + }
1852 +
1853 + hci_h4p_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
1854 + lcr = hci_h4p_inb(info, UART_LCR);
1855 + hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
1856 + hci_h4p_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
1857 + hci_h4p_outb(info, UART_DLM, divisor >> 8);
1858 + hci_h4p_outb(info, UART_LCR, lcr);
1859 + hci_h4p_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
1860 +}
1861 +
1862 +int hci_h4p_reset_uart(struct hci_h4p_info *info)
1863 +{
1864 + int count = 0;
1865 +
1866 + /* Reset the UART */
1867 + hci_h4p_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
1868 + while (!(hci_h4p_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
1869 + if (count++ > 20000) {
1870 + dev_err(info->dev, "hci_h4p: UART reset timeout\n");
1871 + return -ENODEV;
1872 + }
1873 + udelay(1);
1874 + }
1875 +
1876 + return 0;
1877 +}
1878 +
1879 +int hci_h4p_init_uart(struct hci_h4p_info *info)
1880 +{
1881 + int err;
1882 +
1883 + err = hci_h4p_reset_uart(info);
1884 + if (err < 0)
1885 + return err;
1886 +
1887 + /* Enable and setup FIFO */
1888 + hci_h4p_outb(info, UART_LCR, UART_LCR_WLEN8);
1889 + hci_h4p_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
1890 + hci_h4p_outb(info, UART_OMAP_SCR, 0x80);
1891 + hci_h4p_outb(info, UART_EFR, UART_EFR_ECB);
1892 + hci_h4p_outb(info, UART_MCR, UART_MCR_TCRTLR);
1893 + hci_h4p_outb(info, UART_TI752_TLR, 0x1f);
1894 + hci_h4p_outb(info, UART_TI752_TCR, 0xef);
1895 + hci_h4p_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
1896 + UART_FCR_CLEAR_XMIT | UART_FCR_R_TRIG_00);
1897 + hci_h4p_outb(info, UART_IER, UART_IER_RDI);
1898 +
1899 + return 0;
1900 +}
1901 Index: linux-2.6.35/drivers/bluetooth/Kconfig
1902 ===================================================================
1903 --- linux-2.6.35.orig/drivers/bluetooth/Kconfig 2010-08-08 12:56:10.000000000 +0200
1904 +++ linux-2.6.35/drivers/bluetooth/Kconfig 2010-08-08 12:57:29.000000000 +0200
1905 @@ -161,6 +161,16 @@ config BT_HCIBTUART
1906 Say Y here to compile support for HCI UART devices into the
1907 kernel or say M to compile it as module (btuart_cs).
1908
1909 +config BT_HCIH4P
1910 + tristate "HCI driver with H4 Nokia extensions"
1911 + depends on BT && ARCH_OMAP
1912 + help
1913 + Bluetooth HCI driver with H4 extensions. This driver provides
1914 + support for H4+ Bluetooth chip with vendor-specific H4 extensions.
1915 +
1916 + Say Y here to compile support for h4 extended devices into the kernel
1917 + or say M to compile it as module (hci_h4p).
1918 +
1919 config BT_HCIVHCI
1920 tristate "HCI VHCI (Virtual HCI device) driver"
1921 help
1922 Index: linux-2.6.35/drivers/bluetooth/Makefile
1923 ===================================================================
1924 --- linux-2.6.35.orig/drivers/bluetooth/Makefile 2010-08-08 12:56:10.000000000 +0200
1925 +++ linux-2.6.35/drivers/bluetooth/Makefile 2010-08-08 12:57:29.000000000 +0200
1926 @@ -11,6 +11,7 @@ obj-$(CONFIG_BT_HCIDTL1) += dtl1_cs.o
1927 obj-$(CONFIG_BT_HCIBT3C) += bt3c_cs.o
1928 obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o
1929 obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
1930 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p/
1931
1932 obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
1933 obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o