2 drivers/bluetooth/Kconfig | 10
3 drivers/bluetooth/Makefile | 1
4 drivers/bluetooth/hci_h4p/Makefile | 7
5 drivers/bluetooth/hci_h4p/core.c | 1043 ++++++++++++++++++++++++++++++++++++
6 drivers/bluetooth/hci_h4p/fw-csr.c | 149 +++++
7 drivers/bluetooth/hci_h4p/fw-ti.c | 90 +++
8 drivers/bluetooth/hci_h4p/fw.c | 155 +++++
9 drivers/bluetooth/hci_h4p/hci_h4p.h | 183 ++++++
10 drivers/bluetooth/hci_h4p/sysfs.c | 84 ++
11 drivers/bluetooth/hci_h4p/uart.c | 169 +++++
12 10 files changed, 1891 insertions(+)
14 Index: linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/core.c
15 ===================================================================
16 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
17 +++ linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/core.c 2010-11-05 17:04:44.762000001 +0100
20 + * This file is part of hci_h4p bluetooth driver
22 + * Copyright (C) 2005, 2006 Nokia Corporation.
24 + * Contact: Ville Tervo <ville.tervo@nokia.com>
26 + * This program is free software; you can redistribute it and/or
27 + * modify it under the terms of the GNU General Public License
28 + * version 2 as published by the Free Software Foundation.
30 + * This program is distributed in the hope that it will be useful, but
31 + * WITHOUT ANY WARRANTY; without even the implied warranty of
32 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 + * General Public License for more details.
35 + * You should have received a copy of the GNU General Public License
36 + * along with this program; if not, write to the Free Software
37 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
42 +#include <linux/module.h>
44 +#include <linux/kernel.h>
45 +#include <linux/init.h>
46 +#include <linux/errno.h>
47 +#include <linux/delay.h>
48 +#include <linux/spinlock.h>
49 +#include <linux/serial_reg.h>
50 +#include <linux/skbuff.h>
51 +#include <linux/timer.h>
52 +#include <linux/device.h>
53 +#include <linux/platform_device.h>
54 +#include <linux/clk.h>
55 +#include <linux/gpio.h>
57 +#include <mach/hardware.h>
58 +#include <mach/board.h>
59 +#include <mach/irqs.h>
60 +#include <plat/serial.h>
62 +#include <net/bluetooth/bluetooth.h>
63 +#include <net/bluetooth/hci_core.h>
64 +#include <net/bluetooth/hci.h>
68 +#define PM_TIMEOUT 200
70 +struct omap_bluetooth_config {
73 + u8 host_wakeup_gpio;
80 +/* This should be used in function that cannot release clocks */
81 +static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
83 + unsigned long flags;
85 + spin_lock_irqsave(&info->clocks_lock, flags);
86 + if (enable && !*clock) {
87 + NBT_DBG_POWER("Enabling %p\n", clock);
88 + clk_enable(info->uart_fclk);
89 +#ifdef CONFIG_ARCH_OMAP2
90 + if (cpu_is_omap24xx()) {
91 + clk_enable(info->uart_iclk);
92 + //omap2_block_sleep();
96 + if (!enable && *clock) {
97 + NBT_DBG_POWER("Disabling %p\n", clock);
98 + clk_disable(info->uart_fclk);
99 +#ifdef CONFIG_ARCH_OMAP2
100 + if (cpu_is_omap24xx()) {
101 + clk_disable(info->uart_iclk);
102 + //omap2_allow_sleep();
108 + spin_unlock_irqrestore(&info->clocks_lock, flags);
111 +/* Power management functions */
112 +static void hci_h4p_disable_tx(struct hci_h4p_info *info)
114 + NBT_DBG_POWER("\n");
116 + if (!info->pm_enabled)
119 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
122 +static void hci_h4p_enable_tx(struct hci_h4p_info *info)
124 + NBT_DBG_POWER("\n");
126 + if (!info->pm_enabled)
129 + del_timer_sync(&info->tx_pm_timer);
130 + if (info->tx_pm_enabled) {
131 + info->tx_pm_enabled = 0;
132 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
133 + gpio_set_value(info->bt_wakeup_gpio, 1);
137 +static void hci_h4p_tx_pm_timer(unsigned long data)
139 + struct hci_h4p_info *info;
141 + NBT_DBG_POWER("\n");
143 + info = (struct hci_h4p_info *)data;
145 + if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
146 + gpio_set_value(info->bt_wakeup_gpio, 0);
147 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
148 + info->tx_pm_enabled = 1;
151 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
155 +static void hci_h4p_disable_rx(struct hci_h4p_info *info)
157 + if (!info->pm_enabled)
160 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
163 +static void hci_h4p_enable_rx(struct hci_h4p_info *info)
165 + unsigned long flags;
167 + if (!info->pm_enabled)
170 + del_timer_sync(&info->rx_pm_timer);
171 + spin_lock_irqsave(&info->lock, flags);
172 + if (info->rx_pm_enabled) {
173 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
174 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
175 + __hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
176 + info->rx_pm_enabled = 0;
178 + spin_unlock_irqrestore(&info->lock, flags);
181 +static void hci_h4p_rx_pm_timer(unsigned long data)
183 + unsigned long flags;
184 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
186 + spin_lock_irqsave(&info->lock, flags);
187 + if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_DR)) {
188 + __hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
189 + hci_h4p_set_rts(info, 0);
190 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
191 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
192 + info->rx_pm_enabled = 1;
195 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
197 + spin_unlock_irqrestore(&info->lock, flags);
200 +/* Negotiation functions */
201 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
203 + NBT_DBG("Sending alive packet\n");
205 + if (!info->alive_cmd_skb)
208 + /* Keep reference to buffer so we can reuse it */
209 + info->alive_cmd_skb = skb_get(info->alive_cmd_skb);
211 + skb_queue_tail(&info->txq, info->alive_cmd_skb);
212 + tasklet_schedule(&info->tx_task);
214 + NBT_DBG("Alive packet sent\n");
219 +static void hci_h4p_alive_packet(struct hci_h4p_info *info, struct sk_buff *skb)
221 + NBT_DBG("Received alive packet\n");
222 + if (skb->data[1] == 0xCC) {
223 + complete(&info->init_completion);
229 +static int hci_h4p_send_negotiation(struct hci_h4p_info *info, struct sk_buff *skb)
231 + NBT_DBG("Sending negotiation..\n");
233 + hci_h4p_change_speed(info, INIT_SPEED);
235 + info->init_error = 0;
236 + init_completion(&info->init_completion);
237 + skb_queue_tail(&info->txq, skb);
238 + tasklet_schedule(&info->tx_task);
240 + if (!wait_for_completion_interruptible_timeout(&info->init_completion,
241 + msecs_to_jiffies(1000)))
244 + NBT_DBG("Negotiation sent\n");
245 + return info->init_error;
248 +static void hci_h4p_negotiation_packet(struct hci_h4p_info *info,
249 + struct sk_buff *skb)
253 + if (skb->data[1] == 0x20) {
254 + /* Change to operational settings */
255 + hci_h4p_set_rts(info, 0);
257 + err = hci_h4p_wait_for_cts(info, 0, 100);
261 + hci_h4p_change_speed(info, MAX_BAUD_RATE);
263 + err = hci_h4p_wait_for_cts(info, 1, 100);
267 + hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
269 + err = hci_h4p_send_alive_packet(info);
273 + dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
282 + info->init_error = err;
283 + complete(&info->init_completion);
287 +/* H4 packet handling functions */
288 +static int hci_h4p_get_hdr_len(struct hci_h4p_info *info, u8 pkt_type)
292 + switch (pkt_type) {
294 + retval = HCI_EVENT_HDR_SIZE;
297 + retval = HCI_ACL_HDR_SIZE;
300 + retval = HCI_SCO_HDR_SIZE;
309 + dev_err(info->dev, "Unknown H4 packet type 0x%.2x\n", pkt_type);
317 +static unsigned int hci_h4p_get_data_len(struct hci_h4p_info *info,
318 + struct sk_buff *skb)
321 + struct hci_event_hdr *evt_hdr;
322 + struct hci_acl_hdr *acl_hdr;
323 + struct hci_sco_hdr *sco_hdr;
325 + switch (bt_cb(skb)->pkt_type) {
327 + evt_hdr = (struct hci_event_hdr *)skb->data;
328 + retval = evt_hdr->plen;
331 + acl_hdr = (struct hci_acl_hdr *)skb->data;
332 + retval = le16_to_cpu(acl_hdr->dlen);
335 + sco_hdr = (struct hci_sco_hdr *)skb->data;
336 + retval = sco_hdr->dlen;
349 +static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
350 + struct sk_buff *skb)
353 + if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
354 + NBT_DBG("fw_event\n");
355 + hci_h4p_parse_fw_event(info, skb);
357 + hci_recv_frame(skb);
358 + NBT_DBG("Frame sent to upper layer\n");
362 +static void hci_h4p_rx_tasklet(unsigned long data)
365 + unsigned long flags;
366 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
368 + NBT_DBG("tasklet woke up\n");
369 + NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
371 + while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
372 + byte = hci_h4p_inb(info, UART_RX);
373 + if (info->garbage_bytes) {
374 + info->garbage_bytes--;
377 + if (info->rx_skb == NULL) {
378 + info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC | GFP_DMA);
379 + if (!info->rx_skb) {
380 + dev_err(info->dev, "Can't allocate memory for new packet\n");
383 + info->rx_state = WAIT_FOR_PKT_TYPE;
384 + info->rx_skb->dev = (void *)info->hdev;
386 + info->hdev->stat.byte_rx++;
387 + NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
388 + switch (info->rx_state) {
389 + case WAIT_FOR_PKT_TYPE:
390 + bt_cb(info->rx_skb)->pkt_type = byte;
391 + info->rx_count = hci_h4p_get_hdr_len(info, byte);
392 + if (info->rx_count < 0) {
393 + info->hdev->stat.err_rx++;
394 + kfree_skb(info->rx_skb);
395 + info->rx_skb = NULL;
397 + info->rx_state = WAIT_FOR_HEADER;
400 + case WAIT_FOR_HEADER:
402 + *skb_put(info->rx_skb, 1) = byte;
403 + if (info->rx_count == 0) {
404 + info->rx_count = hci_h4p_get_data_len(info, info->rx_skb);
405 + if (info->rx_count > skb_tailroom(info->rx_skb)) {
406 + dev_err(info->dev, "Frame is %ld bytes too long.\n",
407 + info->rx_count - skb_tailroom(info->rx_skb));
408 + kfree_skb(info->rx_skb);
409 + info->rx_skb = NULL;
410 + info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
413 + info->rx_state = WAIT_FOR_DATA;
415 + if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
416 + hci_h4p_negotiation_packet(info, info->rx_skb);
417 + info->rx_skb = NULL;
418 + info->rx_state = WAIT_FOR_PKT_TYPE;
421 + if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
422 + hci_h4p_alive_packet(info, info->rx_skb);
423 + info->rx_skb = NULL;
424 + info->rx_state = WAIT_FOR_PKT_TYPE;
429 + case WAIT_FOR_DATA:
431 + *skb_put(info->rx_skb, 1) = byte;
432 + if (info->rx_count == 0) {
433 + /* H4+ devices should allways send word aligned packets */
434 + if (!(info->rx_skb->len % 2)) {
435 + info->garbage_bytes++;
437 + hci_h4p_recv_frame(info, info->rx_skb);
438 + info->rx_skb = NULL;
448 + spin_lock_irqsave(&info->lock, flags);
449 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
450 + spin_unlock_irqrestore(&info->lock, flags);
452 + NBT_DBG_TRANSFER_NF("\n");
453 + NBT_DBG("rx_ended\n");
456 +static void hci_h4p_tx_tasklet(unsigned long data)
458 + unsigned int sent = 0;
459 + unsigned long flags;
460 + struct sk_buff *skb;
461 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
463 + NBT_DBG("tasklet woke up\n");
464 + NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
466 + skb = skb_dequeue(&info->txq);
468 + /* No data in buffer */
469 + NBT_DBG("skb ready\n");
470 + hci_h4p_disable_tx(info);
474 + /* Copy data to tx fifo */
475 + while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
476 + (sent < skb->len)) {
477 + NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
478 + hci_h4p_outb(info, UART_TX, skb->data[sent]);
482 + info->hdev->stat.byte_tx += sent;
483 + NBT_DBG_TRANSFER_NF("\n");
484 + if (skb->len == sent) {
487 + skb_pull(skb, sent);
488 + skb_queue_head(&info->txq, skb);
491 + spin_lock_irqsave(&info->lock, flags);
492 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_THRI);
493 + spin_unlock_irqrestore(&info->lock, flags);
496 +static irqreturn_t hci_h4p_interrupt(int irq, void *data)
498 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
501 + unsigned long flags;
505 + iir = hci_h4p_inb(info, UART_IIR);
506 + if (iir & UART_IIR_NO_INT) {
507 + dev_err(info->dev, "Interrupt but no reason irq 0x%.2x\n", iir);
508 + return IRQ_HANDLED;
511 + NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
513 + iir &= UART_IIR_ID;
515 + if (iir == UART_IIR_MSI) {
516 + msr = hci_h4p_inb(info, UART_MSR);
519 + if (iir == UART_IIR_RLSI) {
520 + hci_h4p_inb(info, UART_RX);
521 + hci_h4p_inb(info, UART_LSR);
525 + if (iir == UART_IIR_RDI) {
526 + spin_lock_irqsave(&info->lock, flags);
527 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
528 + spin_unlock_irqrestore(&info->lock, flags);
529 + tasklet_schedule(&info->rx_task);
533 + if (iir == UART_IIR_THRI) {
534 + spin_lock_irqsave(&info->lock, flags);
535 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_THRI);
536 + spin_unlock_irqrestore(&info->lock, flags);
537 + tasklet_schedule(&info->tx_task);
544 +static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
546 + struct hci_h4p_info *info = dev_inst;
548 + struct hci_dev *hdev;
551 + return IRQ_HANDLED;
555 + if (!test_bit(HCI_RUNNING, &hdev->flags))
556 + return IRQ_HANDLED;
558 + should_wakeup = gpio_get_value(info->host_wakeup_gpio);
559 + NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
560 + if (should_wakeup) {
561 + hci_h4p_enable_rx(info);
563 + hci_h4p_disable_rx(info);
566 + return IRQ_HANDLED;
569 +static int hci_h4p_reset(struct hci_h4p_info *info)
573 + hci_h4p_init_uart(info);
574 + hci_h4p_set_rts(info, 0);
576 + gpio_set_value(info->reset_gpio, 0);
578 + gpio_set_value(info->bt_wakeup_gpio, 1);
579 + gpio_set_value(info->reset_gpio, 1);
582 + err = hci_h4p_wait_for_cts(info, 1, 10);
584 + dev_err(info->dev, "No cts from bt chip\n");
588 + hci_h4p_set_rts(info, 1);
593 +/* hci callback functions */
594 +static int hci_h4p_hci_flush(struct hci_dev *hdev)
596 + struct hci_h4p_info *info;
597 + info = hdev->driver_data;
599 + skb_queue_purge(&info->txq);
604 +static int hci_h4p_hci_open(struct hci_dev *hdev)
606 + struct hci_h4p_info *info;
608 + struct sk_buff *neg_cmd_skb;
609 + struct sk_buff_head fw_queue;
611 + info = hdev->driver_data;
613 + if (test_bit(HCI_RUNNING, &hdev->flags))
616 + skb_queue_head_init(&fw_queue);
617 + err = hci_h4p_read_fw(info, &fw_queue);
619 + dev_err(info->dev, "Cannot read firmware\n");
622 + neg_cmd_skb = skb_dequeue(&fw_queue);
623 + if (!neg_cmd_skb) {
627 + info->alive_cmd_skb = skb_dequeue(&fw_queue);
628 + if (!info->alive_cmd_skb) {
633 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
634 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
636 + tasklet_enable(&info->tx_task);
637 + tasklet_enable(&info->rx_task);
638 + info->rx_state = WAIT_FOR_PKT_TYPE;
639 + info->rx_count = 0;
640 + info->garbage_bytes = 0;
641 + info->rx_skb = NULL;
642 + info->pm_enabled = 0;
643 + init_completion(&info->fw_completion);
645 + err = hci_h4p_reset(info);
649 + err = hci_h4p_send_negotiation(info, neg_cmd_skb);
650 + neg_cmd_skb = NULL;
654 + err = hci_h4p_send_fw(info, &fw_queue);
656 + dev_err(info->dev, "Sending firmware failed.\n");
660 + kfree_skb(info->alive_cmd_skb);
661 + info->alive_cmd_skb = NULL;
662 + info->pm_enabled = 1;
663 + info->tx_pm_enabled = 1;
664 + info->rx_pm_enabled = 0;
665 + set_bit(HCI_RUNNING, &hdev->flags);
667 + NBT_DBG("hci up and running\n");
671 + hci_h4p_hci_flush(hdev);
672 + tasklet_disable(&info->tx_task);
673 + tasklet_disable(&info->rx_task);
674 + hci_h4p_reset_uart(info);
675 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
676 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
677 + gpio_set_value(info->reset_gpio, 0);
678 + gpio_set_value(info->bt_wakeup_gpio, 0);
679 + skb_queue_purge(&fw_queue);
680 + kfree_skb(neg_cmd_skb);
681 + neg_cmd_skb = NULL;
682 + kfree_skb(info->alive_cmd_skb);
683 + info->alive_cmd_skb = NULL;
684 + kfree_skb(info->rx_skb);
689 +static int hci_h4p_hci_close(struct hci_dev *hdev)
691 + struct hci_h4p_info *info = hdev->driver_data;
693 + if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
696 + hci_h4p_hci_flush(hdev);
697 + del_timer_sync(&info->tx_pm_timer);
698 + del_timer_sync(&info->rx_pm_timer);
699 + tasklet_disable(&info->tx_task);
700 + tasklet_disable(&info->rx_task);
701 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
702 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
703 + hci_h4p_reset_uart(info);
704 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
705 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
706 + gpio_set_value(info->reset_gpio, 0);
707 + gpio_set_value(info->bt_wakeup_gpio, 0);
708 + kfree_skb(info->rx_skb);
713 +static void hci_h4p_hci_destruct(struct hci_dev *hdev)
717 +static int hci_h4p_hci_send_frame(struct sk_buff *skb)
719 + struct hci_h4p_info *info;
720 + struct hci_dev *hdev = (struct hci_dev *)skb->dev;
724 + printk(KERN_WARNING "hci_h4p: Frame for unknown device\n");
728 + NBT_DBG("dev %p, skb %p\n", hdev, skb);
730 + info = hdev->driver_data;
732 + if (!test_bit(HCI_RUNNING, &hdev->flags)) {
733 + dev_warn(info->dev, "Frame for non-running device\n");
737 + switch (bt_cb(skb)->pkt_type) {
738 + case HCI_COMMAND_PKT:
739 + hdev->stat.cmd_tx++;
741 + case HCI_ACLDATA_PKT:
742 + hdev->stat.acl_tx++;
744 + case HCI_SCODATA_PKT:
745 + hdev->stat.sco_tx++;
749 + /* Push frame type to skb */
750 + *skb_push(skb, 1) = (bt_cb(skb)->pkt_type);
751 + /* We should allways send word aligned data to h4+ devices */
752 + if (skb->len % 2) {
753 + err = skb_pad(skb, 1);
758 + hci_h4p_enable_tx(info);
759 + skb_queue_tail(&info->txq, skb);
760 + tasklet_schedule(&info->tx_task);
765 +static int hci_h4p_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
767 + return -ENOIOCTLCMD;
770 +static int hci_h4p_register_hdev(struct hci_h4p_info *info)
772 + struct hci_dev *hdev;
774 + /* Initialize and register HCI device */
776 + hdev = hci_alloc_dev();
778 + dev_err(info->dev, "Can't allocate memory for device\n");
783 + hdev->dev_type = HCI_UART;
784 + hdev->driver_data = info;
786 + hdev->open = hci_h4p_hci_open;
787 + hdev->close = hci_h4p_hci_close;
788 + hdev->flush = hci_h4p_hci_flush;
789 + hdev->send = hci_h4p_hci_send_frame;
790 + hdev->destruct = hci_h4p_hci_destruct;
791 + hdev->ioctl = hci_h4p_hci_ioctl;
793 + hdev->owner = THIS_MODULE;
795 + if (hci_register_dev(hdev) < 0) {
796 + dev_err(info->dev, "hci_h4p: Can't register HCI device %s.\n", hdev->name);
803 +static int hci_h4p_probe(struct platform_device *pdev)
805 + struct omap_bluetooth_config *bt_config;
806 + struct hci_h4p_info *info;
809 + dev_info(&pdev->dev, "Registering HCI H4P device\n");
810 + info = kzalloc(sizeof(struct hci_h4p_info), GFP_KERNEL);
814 + info->dev = &pdev->dev;
815 + info->pm_enabled = 0;
816 + info->tx_pm_enabled = 0;
817 + info->rx_pm_enabled = 0;
818 + info->garbage_bytes = 0;
819 + info->tx_clocks_en = 0;
820 + info->rx_clocks_en = 0;
821 + tasklet_init(&info->tx_task, hci_h4p_tx_tasklet, (unsigned long)info);
822 + tasklet_init(&info->rx_task, hci_h4p_rx_tasklet, (unsigned long)info);
823 + /* hci_h4p_hci_open assumes that tasklet is disabled in startup */
824 + tasklet_disable(&info->tx_task);
825 + tasklet_disable(&info->rx_task);
826 + spin_lock_init(&info->lock);
827 + spin_lock_init(&info->clocks_lock);
828 + skb_queue_head_init(&info->txq);
829 + init_timer(&info->tx_pm_timer);
830 + info->tx_pm_timer.function = hci_h4p_tx_pm_timer;
831 + info->tx_pm_timer.data = (unsigned long)info;
832 + init_timer(&info->rx_pm_timer);
833 + info->rx_pm_timer.function = hci_h4p_rx_pm_timer;
834 + info->rx_pm_timer.data = (unsigned long)info;
836 + if (pdev->dev.platform_data == NULL) {
837 + dev_err(&pdev->dev, "Could not get Bluetooth config data\n");
841 + bt_config = pdev->dev.platform_data;
842 + info->chip_type = bt_config->chip_type;
843 + info->bt_wakeup_gpio = bt_config->bt_wakeup_gpio;
844 + info->host_wakeup_gpio = bt_config->host_wakeup_gpio;
845 + info->reset_gpio = bt_config->reset_gpio;
846 + info->bt_sysclk = bt_config->bt_sysclk;
848 + NBT_DBG("RESET gpio: %d\n", info->reset_gpio);
849 + NBT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
850 + NBT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
851 + NBT_DBG("Uart: %d\n", bt_config->bt_uart);
852 + NBT_DBG("sysclk: %d\n", info->bt_sysclk);
854 + err = gpio_request(info->reset_gpio, "BT reset");
856 + dev_err(&pdev->dev, "Cannot get GPIO line %d\n",
862 + err = gpio_request(info->bt_wakeup_gpio, "BT wakeup");
865 + dev_err(info->dev, "Cannot get GPIO line 0x%d",
866 + info->bt_wakeup_gpio);
867 + gpio_free(info->reset_gpio);
872 + err = gpio_request(info->host_wakeup_gpio, "BT host wakeup");
875 + dev_err(info->dev, "Cannot get GPIO line %d",
876 + info->host_wakeup_gpio);
877 + gpio_free(info->reset_gpio);
878 + gpio_free(info->bt_wakeup_gpio);
883 + gpio_direction_output(info->reset_gpio, 0);
884 + gpio_direction_output(info->bt_wakeup_gpio, 0);
885 + gpio_direction_input(info->host_wakeup_gpio);
888 +#if defined(CONFIG_ARCH_OMAP1)
889 +# define OMAP_UART1_BASE OMAP1_UART1_BASE
890 +# define OMAP_UART2_BASE OMAP1_UART2_BASE
891 +# define OMAP_UART3_BASE OMAP1_UART3_BASE
892 +#elif defined(CONFIG_ARCH_OMAP2)
893 +# define OMAP_UART1_BASE OMAP2_UART1_BASE
894 +# define OMAP_UART2_BASE OMAP2_UART2_BASE
895 +# define OMAP_UART3_BASE OMAP2_UART3_BASE
896 +#elif defined(CONFIG_ARCH_OMAP3)
897 +# define OMAP_UART1_BASE OMAP3_UART1_BASE
898 +# define OMAP_UART2_BASE OMAP3_UART2_BASE
899 +# define OMAP_UART3_BASE OMAP3_UART3_BASE
900 +#elif defined(CONFIG_ARCH_OMAP4)
901 +# define OMAP_UART1_BASE OMAP4_UART1_BASE
902 +# define OMAP_UART2_BASE OMAP4_UART2_BASE
903 +# define OMAP_UART3_BASE OMAP4_UART3_BASE
907 + switch (bt_config->bt_uart) {
909 + if (cpu_is_omap16xx()) {
911 + info->uart_fclk = clk_get(NULL, "uart1_ck");
912 + } else if (cpu_is_omap24xx()) {
913 + irq = INT_24XX_UART1_IRQ;
914 + info->uart_iclk = clk_get(NULL, "uart1_ick");
915 + info->uart_fclk = clk_get(NULL, "uart1_fck");
917 + /* FIXME: Use platform_get_resource for the port */
918 + info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
919 + if (!info->uart_base)
923 + if (cpu_is_omap16xx()) {
925 + info->uart_fclk = clk_get(NULL, "uart2_ck");
927 + irq = INT_24XX_UART2_IRQ;
928 + info->uart_iclk = clk_get(NULL, "uart2_ick");
929 + info->uart_fclk = clk_get(NULL, "uart2_fck");
931 + /* FIXME: Use platform_get_resource for the port */
932 + info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
933 + if (!info->uart_base)
937 + if (cpu_is_omap16xx()) {
939 + info->uart_fclk = clk_get(NULL, "uart3_ck");
941 + irq = INT_24XX_UART3_IRQ;
942 + info->uart_iclk = clk_get(NULL, "uart3_ick");
943 + info->uart_fclk = clk_get(NULL, "uart3_fck");
945 + /* FIXME: Use platform_get_resource for the port */
946 + info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
947 + if (!info->uart_base)
951 + dev_err(info->dev, "No uart defined\n");
956 + err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
958 + dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
962 + err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
963 + hci_h4p_wakeup_interrupt,
964 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
965 + "hci_h4p_wkup", (void *)info);
967 + dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
968 + gpio_to_irq(info->host_wakeup_gpio));
969 + free_irq(irq, (void *)info);
973 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
974 + hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
975 + err = hci_h4p_init_uart(info);
978 + err = hci_h4p_reset(info);
981 + err = hci_h4p_wait_for_cts(info, 1, 10);
984 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
986 + platform_set_drvdata(pdev, info);
987 + err = hci_h4p_sysfs_create_files(info->dev);
991 + if (hci_h4p_register_hdev(info) < 0) {
992 + dev_err(info->dev, "failed to register hci_h4p hci device\n");
995 + gpio_set_value(info->reset_gpio, 0);
1000 + free_irq(irq, (void *)info);
1001 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *)info);
1003 + gpio_set_value(info->reset_gpio, 0);
1004 + gpio_free(info->reset_gpio);
1005 + gpio_free(info->bt_wakeup_gpio);
1006 + gpio_free(info->host_wakeup_gpio);
1013 +static int hci_h4p_remove(struct platform_device *dev)
1015 + struct hci_h4p_info *info;
1017 + info = platform_get_drvdata(dev);
1019 + hci_h4p_hci_close(info->hdev);
1020 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *) info);
1021 + hci_free_dev(info->hdev);
1022 + gpio_free(info->reset_gpio);
1023 + gpio_free(info->bt_wakeup_gpio);
1024 + gpio_free(info->host_wakeup_gpio);
1025 + free_irq(info->irq, (void *) info);
1031 +static struct platform_driver hci_h4p_driver = {
1032 + .probe = hci_h4p_probe,
1033 + .remove = hci_h4p_remove,
1035 + .name = "hci_h4p",
1039 +static int __init hci_h4p_init(void)
1043 + /* Register the driver with LDM */
1044 + err = platform_driver_register(&hci_h4p_driver);
1046 + printk(KERN_WARNING "failed to register hci_h4p driver\n");
1051 +static void __exit hci_h4p_exit(void)
1053 + platform_driver_unregister(&hci_h4p_driver);
1056 +module_init(hci_h4p_init);
1057 +module_exit(hci_h4p_exit);
1059 +MODULE_DESCRIPTION("h4 driver with nokia extensions");
1060 +MODULE_LICENSE("GPL");
1061 +MODULE_AUTHOR("Ville Tervo");
1062 Index: linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/fw.c
1063 ===================================================================
1064 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1065 +++ linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/fw.c 2010-11-05 17:04:44.762000001 +0100
1068 + * This file is part of hci_h4p bluetooth driver
1070 + * Copyright (C) 2005, 2006 Nokia Corporation.
1072 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1074 + * This program is free software; you can redistribute it and/or
1075 + * modify it under the terms of the GNU General Public License
1076 + * version 2 as published by the Free Software Foundation.
1078 + * This program is distributed in the hope that it will be useful, but
1079 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1080 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1081 + * General Public License for more details.
1083 + * You should have received a copy of the GNU General Public License
1084 + * along with this program; if not, write to the Free Software
1085 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1090 +#include <linux/skbuff.h>
1091 +#include <linux/firmware.h>
1092 +#include <linux/clk.h>
1094 +#include <net/bluetooth/bluetooth.h>
1096 +#include "hci_h4p.h"
1098 +#define BT_CHIP_TI 2
1099 +#define BT_CHIP_CSR 1
1103 +/* Firmware handling */
1104 +static int hci_h4p_open_firmware(struct hci_h4p_info *info,
1105 + const struct firmware **fw_entry)
1110 + NBT_DBG_FW("Opening %d firmware\n", info->chip_type);
1111 + switch (info->chip_type) {
1113 + err = request_firmware(fw_entry, "brf6150fw.bin", info->dev);
1116 + err = request_firmware(fw_entry, "bc4fw.bin", info->dev);
1119 + dev_err(info->dev, "Invalid chip type\n");
1127 +static void hci_h4p_close_firmware(const struct firmware *fw_entry)
1129 + release_firmware(fw_entry);
1132 +/* Read fw. Return length of the command. If no more commands in
1133 + * fw 0 is returned. In error case return value is negative.
1135 +static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
1136 + const struct firmware *fw_entry, int how)
1138 + unsigned int cmd_len;
1140 + if (fw_pos >= fw_entry->size) {
1144 + cmd_len = fw_entry->data[fw_pos++];
1148 + if (fw_pos + cmd_len > fw_entry->size) {
1149 + dev_err(info->dev, "Corrupted firmware image\n");
1153 + *skb = bt_skb_alloc(cmd_len, how);
1155 + dev_err(info->dev, "Cannot reserve memory for buffer\n");
1158 + memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
1160 + fw_pos += cmd_len;
1162 + return (*skb)->len;
1165 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1167 + const struct firmware *fw_entry = NULL;
1168 + struct sk_buff *skb = NULL;
1171 + err = hci_h4p_open_firmware(info, &fw_entry);
1172 + if (err < 0 || !fw_entry)
1175 + while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
1176 + if (err < 0 || !skb)
1179 + skb_queue_tail(fw_queue, skb);
1183 + hci_h4p_close_firmware(fw_entry);
1187 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1191 + switch(info->chip_type) {
1193 + err = hci_h4p_bc4_send_fw(info, fw_queue);
1196 + err = hci_h4p_brf6150_send_fw(info, fw_queue);
1199 + dev_err(info->dev, "Don't know how to send firmware\n");
1206 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1208 + switch (info->chip_type) {
1210 + hci_h4p_bc4_parse_fw_event(info, skb);
1213 + hci_h4p_brf6150_parse_fw_event(info, skb);
1216 + dev_err(info->dev, "Don't know how to parse fw event\n");
1217 + info->fw_error = -EINVAL;
1222 Index: linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/fw-csr.c
1223 ===================================================================
1224 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1225 +++ linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/fw-csr.c 2010-11-05 17:04:44.762000001 +0100
1228 + * This file is part of hci_h4p bluetooth driver
1230 + * Copyright (C) 2005, 2006 Nokia Corporation.
1232 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1234 + * This program is free software; you can redistribute it and/or
1235 + * modify it under the terms of the GNU General Public License
1236 + * version 2 as published by the Free Software Foundation.
1238 + * This program is distributed in the hope that it will be useful, but
1239 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1240 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1241 + * General Public License for more details.
1243 + * You should have received a copy of the GNU General Public License
1244 + * along with this program; if not, write to the Free Software
1245 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1250 +#include <linux/skbuff.h>
1251 +#include <linux/delay.h>
1252 +#include <linux/serial_reg.h>
1254 +#include "hci_h4p.h"
1256 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1258 + /* Check if this is fw packet */
1259 + if (skb->data[0] != 0xff) {
1260 + hci_recv_frame(skb);
1264 + if (skb->data[11] || skb->data[12]) {
1265 + dev_err(info->dev, "Firmware sending command failed\n");
1266 + info->fw_error = -EPROTO;
1270 + complete(&info->fw_completion);
1273 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1274 + struct sk_buff_head *fw_queue)
1276 + struct sk_buff *skb;
1277 + unsigned int offset;
1278 + int retries, count, i;
1280 + info->fw_error = 0;
1282 + NBT_DBG_FW("Sending firmware\n");
1283 + skb = skb_dequeue(fw_queue);
1288 + info->bdaddr[0] = 0x00;
1289 + info->bdaddr[1] = 0x1D;
1290 + info->bdaddr[2] = 0x6E;
1291 + info->bdaddr[3] = 0xD4;
1292 + info->bdaddr[4] = 0xF0;
1293 + info->bdaddr[5] = 0x37;
1295 + /* Check if this is bd_address packet */
1296 + if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
1297 + dev_info(info->dev, "bd_address packet found\n");
1299 + skb->data[offset + 1] = 0x00;
1300 + skb->data[offset + 5] = 0x00;
1301 + skb->data[offset + 7] = info->bdaddr[0];
1302 + skb->data[offset + 6] = info->bdaddr[1];
1303 + skb->data[offset + 4] = info->bdaddr[2];
1304 + skb->data[offset + 0] = info->bdaddr[3];
1305 + skb->data[offset + 3] = info->bdaddr[4];
1306 + skb->data[offset + 2] = info->bdaddr[5];
1309 + for (i = 0; i < 6; i++) {
1310 + if (info->bdaddr[i] != 0x00)
1315 + dev_info(info->dev, "Valid bluetooth address not found.\n");
1320 + for (count = 1; ; count++) {
1321 + NBT_DBG_FW("Sending firmware command %d\n", count);
1322 + init_completion(&info->fw_completion);
1323 + skb_queue_tail(&info->txq, skb);
1324 + tasklet_schedule(&info->tx_task);
1326 + skb = skb_dequeue(fw_queue);
1330 + if (!wait_for_completion_timeout(&info->fw_completion,
1331 + msecs_to_jiffies(1000))) {
1332 + dev_err(info->dev, "No reply to fw command\n");
1333 + return -ETIMEDOUT;
1336 + if (info->fw_error) {
1337 + dev_err(info->dev, "FW error\n");
1342 + /* Wait for chip warm reset */
1344 + while ((!skb_queue_empty(&info->txq) ||
1345 + !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
1350 + dev_err(info->dev, "Transmitter not empty\n");
1351 + return -ETIMEDOUT;
1354 + hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
1356 + if (hci_h4p_wait_for_cts(info, 1, 100)) {
1357 + dev_err(info->dev, "cts didn't go down after final speed change\n");
1358 + return -ETIMEDOUT;
1363 + init_completion(&info->init_completion);
1364 + hci_h4p_send_alive_packet(info);
1366 + } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
1370 + dev_err(info->dev, "No alive reply after speed change\n");
1371 + return -ETIMEDOUT;
1376 Index: linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/fw-ti.c
1377 ===================================================================
1378 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1379 +++ linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/fw-ti.c 2010-11-05 17:04:44.762000001 +0100
1382 + * This file is part of hci_h4p bluetooth driver
1384 + * Copyright (C) 2005, 2006 Nokia Corporation.
1386 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1388 + * This program is free software; you can redistribute it and/or
1389 + * modify it under the terms of the GNU General Public License
1390 + * version 2 as published by the Free Software Foundation.
1392 + * This program is distributed in the hope that it will be useful, but
1393 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1394 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1395 + * General Public License for more details.
1397 + * You should have received a copy of the GNU General Public License
1398 + * along with this program; if not, write to the Free Software
1399 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1404 +#include <linux/skbuff.h>
1406 +#include "hci_h4p.h"
1408 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1409 + struct sk_buff *skb)
1411 + struct hci_fw_event *ev;
1414 + if (bt_cb(skb)->pkt_type != H4_EVT_PKT) {
1415 + dev_err(info->dev, "Got non event fw packet.\n");
1420 + ev = (struct hci_fw_event *)skb->data;
1421 + if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
1422 + dev_err(info->dev, "Got non cmd complete fw event\n");
1427 + if (ev->status != 0) {
1428 + dev_err(info->dev, "Got error status from fw command\n");
1434 + info->fw_error = err;
1435 + complete(&info->fw_completion);
1438 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1440 + struct sk_buff *skb;
1443 + info->fw_error = 0;
1445 + while ((skb = skb_dequeue(fw_queue)) != NULL) {
1446 + /* We should allways send word aligned data to h4+ devices */
1447 + if (skb->len % 2) {
1448 + err = skb_pad(skb, 1);
1453 + init_completion(&info->fw_completion);
1454 + skb_queue_tail(&info->txq, skb);
1455 + tasklet_schedule(&info->tx_task);
1457 + if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
1458 + dev_err(info->dev, "Timeout while sending brf6150 fw\n");
1459 + return -ETIMEDOUT;
1462 + if (info->fw_error) {
1463 + dev_err(info->dev, "There was fw_error while sending bfr6150 fw\n");
1467 + NBT_DBG_FW("Firmware sent\n");
1471 Index: linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/hci_h4p.h
1472 ===================================================================
1473 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1474 +++ linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/hci_h4p.h 2010-11-05 17:04:44.762000001 +0100
1477 + * This file is part of hci_h4p bluetooth driver
1479 + * Copyright (C) 2005, 2006 Nokia Corporation.
1481 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1483 + * This program is free software; you can redistribute it and/or
1484 + * modify it under the terms of the GNU General Public License
1485 + * version 2 as published by the Free Software Foundation.
1487 + * This program is distributed in the hope that it will be useful, but
1488 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1489 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1490 + * General Public License for more details.
1492 + * You should have received a copy of the GNU General Public License
1493 + * along with this program; if not, write to the Free Software
1494 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1499 +#include <mach/board.h>
1501 +#include <net/bluetooth/bluetooth.h>
1502 +#include <net/bluetooth/hci_core.h>
1503 +#include <net/bluetooth/hci.h>
1505 +#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
1506 +#define __DRIVERS_BLUETOOTH_HCI_H4P_H
1508 +#define UART_SYSC_OMAP_RESET 0x03
1509 +#define UART_SYSS_RESETDONE 0x01
1510 +#define UART_OMAP_SCR_EMPTY_THR 0x08
1511 +#define UART_OMAP_SCR_WAKEUP 0x10
1512 +#define UART_OMAP_SSR_WAKEUP 0x02
1513 +#define UART_OMAP_SSR_TXFULL 0x01
1516 +#define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1518 +#define NBT_DBG(...)
1522 +#define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1524 +#define NBT_DBG_FW(...)
1528 +#define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1530 +#define NBT_DBG_POWER(...)
1534 +#define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1536 +#define NBT_DBG_TRANSFER(...)
1540 +#define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
1542 +#define NBT_DBG_TRANSFER_NF(...)
1546 +#define NBT_DBG_DMA(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1548 +#define NBT_DBG_DMA(...)
1551 +struct hci_h4p_info {
1552 + struct hci_dev *hdev;
1555 + void __iomem *uart_base;
1556 + unsigned long uart_phys_base;
1558 + struct device *dev;
1561 + u8 bt_wakeup_gpio;
1562 + u8 host_wakeup_gpio;
1567 + struct sk_buff_head fw_queue;
1568 + struct sk_buff *alive_cmd_skb;
1569 + struct completion init_completion;
1570 + struct completion fw_completion;
1574 + struct sk_buff_head txq;
1575 + struct tasklet_struct tx_task;
1577 + struct sk_buff *rx_skb;
1579 + unsigned long rx_state;
1580 + unsigned long garbage_bytes;
1581 + struct tasklet_struct rx_task;
1584 + int tx_pm_enabled;
1585 + int rx_pm_enabled;
1586 + struct timer_list tx_pm_timer;
1587 + struct timer_list rx_pm_timer;
1591 + spinlock_t clocks_lock;
1592 + struct clk *uart_iclk;
1593 + struct clk *uart_fclk;
1596 +#define MAX_BAUD_RATE 921600
1597 +#define BC4_MAX_BAUD_RATE 3692300
1598 +#define UART_CLOCK 48000000
1599 +#define BT_INIT_DIVIDER 320
1600 +#define BT_BAUDRATE_DIVIDER 384000000
1601 +#define BT_SYSCLK_DIV 1000
1602 +#define INIT_SPEED 120000
1604 +#define H4_TYPE_SIZE 1
1606 +/* H4+ packet types */
1607 +#define H4_CMD_PKT 0x01
1608 +#define H4_ACL_PKT 0x02
1609 +#define H4_SCO_PKT 0x03
1610 +#define H4_EVT_PKT 0x04
1611 +#define H4_NEG_PKT 0x06
1612 +#define H4_ALIVE_PKT 0x07
1615 +#define WAIT_FOR_PKT_TYPE 1
1616 +#define WAIT_FOR_HEADER 2
1617 +#define WAIT_FOR_DATA 3
1619 +struct hci_fw_event {
1620 + struct hci_event_hdr hev;
1621 + struct hci_ev_cmd_complete cmd;
1623 +} __attribute__ ((packed));
1625 +struct hci_bc4_set_bdaddr {
1627 + struct hci_command_hdr cmd_hdr;
1628 +} __attribute__ ((packed));
1630 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
1632 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
1633 + struct sk_buff *skb);
1634 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1635 + struct sk_buff_head *fw_queue);
1637 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1638 + struct sk_buff *skb);
1639 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info,
1640 + struct sk_buff_head *fw_queue);
1642 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1643 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1644 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
1646 +int hci_h4p_sysfs_create_files(struct device *dev);
1648 +void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
1649 +u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
1650 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
1651 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
1652 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1653 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1654 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
1655 +int hci_h4p_reset_uart(struct hci_h4p_info *info);
1656 +int hci_h4p_init_uart(struct hci_h4p_info *info);
1658 +#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */
1659 Index: linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/Makefile
1660 ===================================================================
1661 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1662 +++ linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/Makefile 2010-11-05 17:04:44.762000001 +0100
1665 +# Makefile for the Linux Bluetooth HCI device drivers.
1668 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p.o
1670 +hci_h4p-objs := core.o fw.o uart.o sysfs.o fw-ti.o fw-csr.o
1671 Index: linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/sysfs.c
1672 ===================================================================
1673 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1674 +++ linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/sysfs.c 2010-11-05 17:04:44.762000001 +0100
1677 + * This file is part of hci_h4p bluetooth driver
1679 + * Copyright (C) 2005, 2006 Nokia Corporation.
1681 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1683 + * This program is free software; you can redistribute it and/or
1684 + * modify it under the terms of the GNU General Public License
1685 + * version 2 as published by the Free Software Foundation.
1687 + * This program is distributed in the hope that it will be useful, but
1688 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1689 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1690 + * General Public License for more details.
1692 + * You should have received a copy of the GNU General Public License
1693 + * along with this program; if not, write to the Free Software
1694 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1699 +#include <linux/kernel.h>
1700 +#include <linux/init.h>
1701 +#include <linux/device.h>
1702 +#include <linux/platform_device.h>
1704 +#include "hci_h4p.h"
1706 +#ifdef CONFIG_SYSFS
1708 +static ssize_t hci_h4p_store_bdaddr(struct device *dev, struct device_attribute *attr,
1709 + const char *buf, size_t count)
1711 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1712 + unsigned int bdaddr[6];
1715 + dev_info(info->dev, "HCI_H4P_STORE_BDADDR called\n");
1717 + ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n",
1718 + &bdaddr[0], &bdaddr[1], &bdaddr[2],
1719 + &bdaddr[3], &bdaddr[4], &bdaddr[5]);
1722 + dev_info(info->dev, "bdaddr isn't found\n");
1726 + //for (i = 0; i < 6; i++)
1727 + //info->bdaddr[i] = bdaddr[i] & 0xff;
1729 + info->bdaddr[0] = 0x00;
1730 + info->bdaddr[1] = 0x1D;
1731 + info->bdaddr[2] = 0x6E;
1732 + info->bdaddr[3] = 0xD4;
1733 + info->bdaddr[4] = 0xF0;
1734 + info->bdaddr[5] = 0x37;
1739 +static ssize_t hci_h4p_show_bdaddr(struct device *dev, struct device_attribute *attr,
1742 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1744 + return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
1753 +static DEVICE_ATTR(bdaddr, S_IRUGO | S_IWUSR, hci_h4p_show_bdaddr, hci_h4p_store_bdaddr);
1754 +int hci_h4p_sysfs_create_files(struct device *dev)
1756 + return device_create_file(dev, &dev_attr_bdaddr);
1760 Index: linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/uart.c
1761 ===================================================================
1762 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1763 +++ linux-2.6.37-rc1/drivers/bluetooth/hci_h4p/uart.c 2010-11-05 17:04:44.762000001 +0100
1766 + * This file is part of hci_h4p bluetooth driver
1768 + * Copyright (C) 2005, 2006 Nokia Corporation.
1770 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1772 + * This program is free software; you can redistribute it and/or
1773 + * modify it under the terms of the GNU General Public License
1774 + * version 2 as published by the Free Software Foundation.
1776 + * This program is distributed in the hope that it will be useful, but
1777 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1778 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1779 + * General Public License for more details.
1781 + * You should have received a copy of the GNU General Public License
1782 + * along with this program; if not, write to the Free Software
1783 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1788 +#include <linux/serial_reg.h>
1789 +#include <linux/delay.h>
1790 +#include <linux/clk.h>
1792 +#include <asm/io.h>
1794 +#include "hci_h4p.h"
1796 +inline void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val)
1799 + __raw_writeb(val, info->uart_base + offset);
1800 + //outb(val, info->uart_base + (offset << 2));
1803 +inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
1806 + return (u8)__raw_readb(info->uart_base + offset);
1807 + //return (unsigned int)__raw_readb(up->membase + offset);
1808 + //return inb(info->uart_base + (offset << 2));
1811 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active)
1815 + b = hci_h4p_inb(info, UART_MCR);
1817 + b |= UART_MCR_RTS;
1819 + b &= ~UART_MCR_RTS;
1820 + hci_h4p_outb(info, UART_MCR, b);
1823 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
1827 + unsigned long timeout;
1830 + timeout = jiffies + msecs_to_jiffies(timeout_ms);
1834 + state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
1842 + if (time_after(jiffies, timeout))
1843 + return -ETIMEDOUT;
1847 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1851 + lcr = hci_h4p_inb(info, UART_LCR);
1852 + hci_h4p_outb(info, UART_LCR, 0xbf);
1853 + b = hci_h4p_inb(info, UART_EFR);
1858 + hci_h4p_outb(info, UART_EFR, b);
1859 + hci_h4p_outb(info, UART_LCR, lcr);
1862 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1864 + unsigned long flags;
1866 + spin_lock_irqsave(&info->lock, flags);
1867 + __hci_h4p_set_auto_ctsrts(info, on, which);
1868 + spin_unlock_irqrestore(&info->lock, flags);
1871 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
1873 + unsigned int divisor;
1876 + NBT_DBG("Setting speed %lu\n", speed);
1878 + if (speed >= 460800) {
1879 + divisor = UART_CLOCK / 13 / speed;
1882 + divisor = UART_CLOCK / 16 / speed;
1886 + hci_h4p_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
1887 + lcr = hci_h4p_inb(info, UART_LCR);
1888 + hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
1889 + hci_h4p_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
1890 + hci_h4p_outb(info, UART_DLM, divisor >> 8);
1891 + hci_h4p_outb(info, UART_LCR, lcr);
1892 + hci_h4p_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
1895 +int hci_h4p_reset_uart(struct hci_h4p_info *info)
1899 + /* Reset the UART */
1900 + hci_h4p_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
1901 + while (!(hci_h4p_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
1902 + if (count++ > 20000) {
1903 + dev_err(info->dev, "hci_h4p: UART reset timeout\n");
1912 +int hci_h4p_init_uart(struct hci_h4p_info *info)
1916 + err = hci_h4p_reset_uart(info);
1920 + /* Enable and setup FIFO */
1921 + hci_h4p_outb(info, UART_LCR, UART_LCR_WLEN8);
1922 + hci_h4p_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
1923 + hci_h4p_outb(info, UART_OMAP_SCR, 0x80);
1924 + hci_h4p_outb(info, UART_EFR, UART_EFR_ECB);
1925 + hci_h4p_outb(info, UART_MCR, UART_MCR_TCRTLR);
1926 + hci_h4p_outb(info, UART_TI752_TLR, 0x1f);
1927 + hci_h4p_outb(info, UART_TI752_TCR, 0xef);
1928 + hci_h4p_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
1929 + UART_FCR_CLEAR_XMIT | UART_FCR_R_TRIG_00);
1930 + hci_h4p_outb(info, UART_IER, UART_IER_RDI);
1934 Index: linux-2.6.37-rc1/drivers/bluetooth/Kconfig
1935 ===================================================================
1936 --- linux-2.6.37-rc1.orig/drivers/bluetooth/Kconfig 2010-11-01 12:54:12.000000000 +0100
1937 +++ linux-2.6.37-rc1/drivers/bluetooth/Kconfig 2010-11-05 17:04:44.762000001 +0100
1938 @@ -173,6 +173,16 @@
1939 Say Y here to compile support for HCI UART devices into the
1940 kernel or say M to compile it as module (btuart_cs).
1943 + tristate "HCI driver with H4 Nokia extensions"
1944 + depends on BT && ARCH_OMAP
1946 + Bluetooth HCI driver with H4 extensions. This driver provides
1947 + support for H4+ Bluetooth chip with vendor-specific H4 extensions.
1949 + Say Y here to compile support for h4 extended devices into the kernel
1950 + or say M to compile it as module (hci_h4p).
1953 tristate "HCI VHCI (Virtual HCI device) driver"
1955 Index: linux-2.6.37-rc1/drivers/bluetooth/Makefile
1956 ===================================================================
1957 --- linux-2.6.37-rc1.orig/drivers/bluetooth/Makefile 2010-11-01 12:54:12.000000000 +0100
1958 +++ linux-2.6.37-rc1/drivers/bluetooth/Makefile 2010-11-05 17:04:44.763000001 +0100
1960 obj-$(CONFIG_BT_HCIBT3C) += bt3c_cs.o
1961 obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o
1962 obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
1963 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p/
1965 obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
1966 obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o