2 drivers/bluetooth/Kconfig | 10
3 drivers/bluetooth/Makefile | 1
4 drivers/bluetooth/hci_h4p/Makefile | 7
5 drivers/bluetooth/hci_h4p/core.c | 1023 ++++++++++++++++++++++++++++++++++++
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, 1871 insertions(+)
15 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/core.c
18 + * This file is part of hci_h4p bluetooth driver
20 + * Copyright (C) 2005, 2006 Nokia Corporation.
22 + * Contact: Ville Tervo <ville.tervo@nokia.com>
24 + * This program is free software; you can redistribute it and/or
25 + * modify it under the terms of the GNU General Public License
26 + * version 2 as published by the Free Software Foundation.
28 + * This program is distributed in the hope that it will be useful, but
29 + * WITHOUT ANY WARRANTY; without even the implied warranty of
30 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 + * General Public License for more details.
33 + * You should have received a copy of the GNU General Public License
34 + * along with this program; if not, write to the Free Software
35 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
40 +#include <linux/module.h>
42 +#include <linux/kernel.h>
43 +#include <linux/init.h>
44 +#include <linux/errno.h>
45 +#include <linux/delay.h>
46 +#include <linux/spinlock.h>
47 +#include <linux/serial_reg.h>
48 +#include <linux/skbuff.h>
49 +#include <linux/timer.h>
50 +#include <linux/device.h>
51 +#include <linux/platform_device.h>
52 +#include <linux/clk.h>
53 +#include <linux/gpio.h>
55 +#include <mach/hardware.h>
56 +#include <mach/board.h>
57 +#include <mach/irqs.h>
58 +//#include <mach/pm.h>
60 +#include <net/bluetooth/bluetooth.h>
61 +#include <net/bluetooth/hci_core.h>
62 +#include <net/bluetooth/hci.h>
66 +#define PM_TIMEOUT 200
68 +struct omap_bluetooth_config {
71 + u8 host_wakeup_gpio;
78 +/* This should be used in function that cannot release clocks */
79 +static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
81 + unsigned long flags;
83 + spin_lock_irqsave(&info->clocks_lock, flags);
84 + if (enable && !*clock) {
85 + NBT_DBG_POWER("Enabling %p\n", clock);
86 + clk_enable(info->uart_fclk);
87 +#ifdef CONFIG_ARCH_OMAP2
88 + if (cpu_is_omap24xx()) {
89 + clk_enable(info->uart_iclk);
90 + //omap2_block_sleep();
94 + if (!enable && *clock) {
95 + NBT_DBG_POWER("Disabling %p\n", clock);
96 + clk_disable(info->uart_fclk);
97 +#ifdef CONFIG_ARCH_OMAP2
98 + if (cpu_is_omap24xx()) {
99 + clk_disable(info->uart_iclk);
100 + //omap2_allow_sleep();
106 + spin_unlock_irqrestore(&info->clocks_lock, flags);
109 +/* Power management functions */
110 +static void hci_h4p_disable_tx(struct hci_h4p_info *info)
112 + NBT_DBG_POWER("\n");
114 + if (!info->pm_enabled)
117 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
120 +static void hci_h4p_enable_tx(struct hci_h4p_info *info)
122 + NBT_DBG_POWER("\n");
124 + if (!info->pm_enabled)
127 + del_timer_sync(&info->tx_pm_timer);
128 + if (info->tx_pm_enabled) {
129 + info->tx_pm_enabled = 0;
130 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
131 + gpio_set_value(info->bt_wakeup_gpio, 1);
135 +static void hci_h4p_tx_pm_timer(unsigned long data)
137 + struct hci_h4p_info *info;
139 + NBT_DBG_POWER("\n");
141 + info = (struct hci_h4p_info *)data;
143 + if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
144 + gpio_set_value(info->bt_wakeup_gpio, 0);
145 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
146 + info->tx_pm_enabled = 1;
149 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
153 +static void hci_h4p_disable_rx(struct hci_h4p_info *info)
155 + if (!info->pm_enabled)
158 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
161 +static void hci_h4p_enable_rx(struct hci_h4p_info *info)
163 + unsigned long flags;
165 + if (!info->pm_enabled)
168 + del_timer_sync(&info->rx_pm_timer);
169 + spin_lock_irqsave(&info->lock, flags);
170 + if (info->rx_pm_enabled) {
171 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
172 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
173 + __hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
174 + info->rx_pm_enabled = 0;
176 + spin_unlock_irqrestore(&info->lock, flags);
179 +static void hci_h4p_rx_pm_timer(unsigned long data)
181 + unsigned long flags;
182 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
184 + spin_lock_irqsave(&info->lock, flags);
185 + if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_DR)) {
186 + __hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
187 + hci_h4p_set_rts(info, 0);
188 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
189 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
190 + info->rx_pm_enabled = 1;
193 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
195 + spin_unlock_irqrestore(&info->lock, flags);
198 +/* Negotiation functions */
199 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
201 + NBT_DBG("Sending alive packet\n");
203 + if (!info->alive_cmd_skb)
206 + /* Keep reference to buffer so we can reuse it */
207 + info->alive_cmd_skb = skb_get(info->alive_cmd_skb);
209 + skb_queue_tail(&info->txq, info->alive_cmd_skb);
210 + tasklet_schedule(&info->tx_task);
212 + NBT_DBG("Alive packet sent\n");
217 +static void hci_h4p_alive_packet(struct hci_h4p_info *info, struct sk_buff *skb)
219 + NBT_DBG("Received alive packet\n");
220 + if (skb->data[1] == 0xCC) {
221 + complete(&info->init_completion);
227 +static int hci_h4p_send_negotiation(struct hci_h4p_info *info, struct sk_buff *skb)
229 + NBT_DBG("Sending negotiation..\n");
231 + hci_h4p_change_speed(info, INIT_SPEED);
233 + info->init_error = 0;
234 + init_completion(&info->init_completion);
235 + skb_queue_tail(&info->txq, skb);
236 + tasklet_schedule(&info->tx_task);
238 + if (!wait_for_completion_interruptible_timeout(&info->init_completion,
239 + msecs_to_jiffies(1000)))
242 + NBT_DBG("Negotiation sent\n");
243 + return info->init_error;
246 +static void hci_h4p_negotiation_packet(struct hci_h4p_info *info,
247 + struct sk_buff *skb)
251 + if (skb->data[1] == 0x20) {
252 + /* Change to operational settings */
253 + hci_h4p_set_rts(info, 0);
255 + err = hci_h4p_wait_for_cts(info, 0, 100);
259 + hci_h4p_change_speed(info, MAX_BAUD_RATE);
261 + err = hci_h4p_wait_for_cts(info, 1, 100);
265 + hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
267 + err = hci_h4p_send_alive_packet(info);
271 + dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
280 + info->init_error = err;
281 + complete(&info->init_completion);
285 +/* H4 packet handling functions */
286 +static int hci_h4p_get_hdr_len(struct hci_h4p_info *info, u8 pkt_type)
290 + switch (pkt_type) {
292 + retval = HCI_EVENT_HDR_SIZE;
295 + retval = HCI_ACL_HDR_SIZE;
298 + retval = HCI_SCO_HDR_SIZE;
307 + dev_err(info->dev, "Unknown H4 packet type 0x%.2x\n", pkt_type);
315 +static unsigned int hci_h4p_get_data_len(struct hci_h4p_info *info,
316 + struct sk_buff *skb)
319 + struct hci_event_hdr *evt_hdr;
320 + struct hci_acl_hdr *acl_hdr;
321 + struct hci_sco_hdr *sco_hdr;
323 + switch (bt_cb(skb)->pkt_type) {
325 + evt_hdr = (struct hci_event_hdr *)skb->data;
326 + retval = evt_hdr->plen;
329 + acl_hdr = (struct hci_acl_hdr *)skb->data;
330 + retval = le16_to_cpu(acl_hdr->dlen);
333 + sco_hdr = (struct hci_sco_hdr *)skb->data;
334 + retval = sco_hdr->dlen;
347 +static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
348 + struct sk_buff *skb)
351 + if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
352 + NBT_DBG("fw_event\n");
353 + hci_h4p_parse_fw_event(info, skb);
355 + hci_recv_frame(skb);
356 + NBT_DBG("Frame sent to upper layer\n");
360 +static void hci_h4p_rx_tasklet(unsigned long data)
363 + unsigned long flags;
364 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
366 + NBT_DBG("tasklet woke up\n");
367 + NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
369 + while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
370 + byte = hci_h4p_inb(info, UART_RX);
371 + if (info->garbage_bytes) {
372 + info->garbage_bytes--;
375 + if (info->rx_skb == NULL) {
376 + info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC | GFP_DMA);
377 + if (!info->rx_skb) {
378 + dev_err(info->dev, "Can't allocate memory for new packet\n");
381 + info->rx_state = WAIT_FOR_PKT_TYPE;
382 + info->rx_skb->dev = (void *)info->hdev;
384 + info->hdev->stat.byte_rx++;
385 + NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
386 + switch (info->rx_state) {
387 + case WAIT_FOR_PKT_TYPE:
388 + bt_cb(info->rx_skb)->pkt_type = byte;
389 + info->rx_count = hci_h4p_get_hdr_len(info, byte);
390 + if (info->rx_count < 0) {
391 + info->hdev->stat.err_rx++;
392 + kfree_skb(info->rx_skb);
393 + info->rx_skb = NULL;
395 + info->rx_state = WAIT_FOR_HEADER;
398 + case WAIT_FOR_HEADER:
400 + *skb_put(info->rx_skb, 1) = byte;
401 + if (info->rx_count == 0) {
402 + info->rx_count = hci_h4p_get_data_len(info, info->rx_skb);
403 + if (info->rx_count > skb_tailroom(info->rx_skb)) {
404 + dev_err(info->dev, "Frame is %ld bytes too long.\n",
405 + info->rx_count - skb_tailroom(info->rx_skb));
406 + kfree_skb(info->rx_skb);
407 + info->rx_skb = NULL;
408 + info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
411 + info->rx_state = WAIT_FOR_DATA;
413 + if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
414 + hci_h4p_negotiation_packet(info, info->rx_skb);
415 + info->rx_skb = NULL;
416 + info->rx_state = WAIT_FOR_PKT_TYPE;
419 + if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
420 + hci_h4p_alive_packet(info, info->rx_skb);
421 + info->rx_skb = NULL;
422 + info->rx_state = WAIT_FOR_PKT_TYPE;
427 + case WAIT_FOR_DATA:
429 + *skb_put(info->rx_skb, 1) = byte;
430 + if (info->rx_count == 0) {
431 + /* H4+ devices should allways send word aligned packets */
432 + if (!(info->rx_skb->len % 2)) {
433 + info->garbage_bytes++;
435 + hci_h4p_recv_frame(info, info->rx_skb);
436 + info->rx_skb = NULL;
446 + spin_lock_irqsave(&info->lock, flags);
447 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
448 + spin_unlock_irqrestore(&info->lock, flags);
450 + NBT_DBG_TRANSFER_NF("\n");
451 + NBT_DBG("rx_ended\n");
454 +static void hci_h4p_tx_tasklet(unsigned long data)
456 + unsigned int sent = 0;
457 + unsigned long flags;
458 + struct sk_buff *skb;
459 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
461 + NBT_DBG("tasklet woke up\n");
462 + NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
464 + skb = skb_dequeue(&info->txq);
466 + /* No data in buffer */
467 + NBT_DBG("skb ready\n");
468 + hci_h4p_disable_tx(info);
472 + /* Copy data to tx fifo */
473 + while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
474 + (sent < skb->len)) {
475 + NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
476 + hci_h4p_outb(info, UART_TX, skb->data[sent]);
480 + info->hdev->stat.byte_tx += sent;
481 + NBT_DBG_TRANSFER_NF("\n");
482 + if (skb->len == sent) {
485 + skb_pull(skb, sent);
486 + skb_queue_head(&info->txq, skb);
489 + spin_lock_irqsave(&info->lock, flags);
490 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_THRI);
491 + spin_unlock_irqrestore(&info->lock, flags);
494 +static irqreturn_t hci_h4p_interrupt(int irq, void *data)
496 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
499 + unsigned long flags;
503 + iir = hci_h4p_inb(info, UART_IIR);
504 + if (iir & UART_IIR_NO_INT) {
505 + dev_err(info->dev, "Interrupt but no reason irq 0x%.2x\n", iir);
506 + return IRQ_HANDLED;
509 + NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
511 + iir &= UART_IIR_ID;
513 + if (iir == UART_IIR_MSI) {
514 + msr = hci_h4p_inb(info, UART_MSR);
517 + if (iir == UART_IIR_RLSI) {
518 + hci_h4p_inb(info, UART_RX);
519 + hci_h4p_inb(info, UART_LSR);
523 + if (iir == UART_IIR_RDI) {
524 + spin_lock_irqsave(&info->lock, flags);
525 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
526 + spin_unlock_irqrestore(&info->lock, flags);
527 + tasklet_schedule(&info->rx_task);
531 + if (iir == UART_IIR_THRI) {
532 + spin_lock_irqsave(&info->lock, flags);
533 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_THRI);
534 + spin_unlock_irqrestore(&info->lock, flags);
535 + tasklet_schedule(&info->tx_task);
542 +static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
544 + struct hci_h4p_info *info = dev_inst;
546 + struct hci_dev *hdev;
549 + return IRQ_HANDLED;
553 + if (!test_bit(HCI_RUNNING, &hdev->flags))
554 + return IRQ_HANDLED;
556 + should_wakeup = gpio_get_value(info->host_wakeup_gpio);
557 + NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
558 + if (should_wakeup) {
559 + hci_h4p_enable_rx(info);
561 + hci_h4p_disable_rx(info);
564 + return IRQ_HANDLED;
567 +static int hci_h4p_reset(struct hci_h4p_info *info)
571 + hci_h4p_init_uart(info);
572 + hci_h4p_set_rts(info, 0);
574 + gpio_set_value(info->reset_gpio, 0);
576 + gpio_set_value(info->bt_wakeup_gpio, 1);
577 + gpio_set_value(info->reset_gpio, 1);
580 + err = hci_h4p_wait_for_cts(info, 1, 10);
582 + dev_err(info->dev, "No cts from bt chip\n");
586 + hci_h4p_set_rts(info, 1);
591 +/* hci callback functions */
592 +static int hci_h4p_hci_flush(struct hci_dev *hdev)
594 + struct hci_h4p_info *info;
595 + info = hdev->driver_data;
597 + skb_queue_purge(&info->txq);
602 +static int hci_h4p_hci_open(struct hci_dev *hdev)
604 + struct hci_h4p_info *info;
606 + struct sk_buff *neg_cmd_skb;
607 + struct sk_buff_head fw_queue;
609 + info = hdev->driver_data;
611 + if (test_bit(HCI_RUNNING, &hdev->flags))
614 + skb_queue_head_init(&fw_queue);
615 + err = hci_h4p_read_fw(info, &fw_queue);
617 + dev_err(info->dev, "Cannot read firmware\n");
620 + neg_cmd_skb = skb_dequeue(&fw_queue);
621 + if (!neg_cmd_skb) {
625 + info->alive_cmd_skb = skb_dequeue(&fw_queue);
626 + if (!info->alive_cmd_skb) {
631 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
632 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
634 + tasklet_enable(&info->tx_task);
635 + tasklet_enable(&info->rx_task);
636 + info->rx_state = WAIT_FOR_PKT_TYPE;
637 + info->rx_count = 0;
638 + info->garbage_bytes = 0;
639 + info->rx_skb = NULL;
640 + info->pm_enabled = 0;
641 + init_completion(&info->fw_completion);
643 + err = hci_h4p_reset(info);
647 + err = hci_h4p_send_negotiation(info, neg_cmd_skb);
648 + neg_cmd_skb = NULL;
652 + err = hci_h4p_send_fw(info, &fw_queue);
654 + dev_err(info->dev, "Sending firmware failed.\n");
658 + kfree_skb(info->alive_cmd_skb);
659 + info->alive_cmd_skb = NULL;
660 + info->pm_enabled = 1;
661 + info->tx_pm_enabled = 1;
662 + info->rx_pm_enabled = 0;
663 + set_bit(HCI_RUNNING, &hdev->flags);
665 + NBT_DBG("hci up and running\n");
669 + hci_h4p_hci_flush(hdev);
670 + tasklet_disable(&info->tx_task);
671 + tasklet_disable(&info->rx_task);
672 + hci_h4p_reset_uart(info);
673 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
674 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
675 + gpio_set_value(info->reset_gpio, 0);
676 + gpio_set_value(info->bt_wakeup_gpio, 0);
677 + skb_queue_purge(&fw_queue);
678 + kfree_skb(neg_cmd_skb);
679 + neg_cmd_skb = NULL;
680 + kfree_skb(info->alive_cmd_skb);
681 + info->alive_cmd_skb = NULL;
682 + kfree_skb(info->rx_skb);
687 +static int hci_h4p_hci_close(struct hci_dev *hdev)
689 + struct hci_h4p_info *info = hdev->driver_data;
691 + if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
694 + hci_h4p_hci_flush(hdev);
695 + del_timer_sync(&info->tx_pm_timer);
696 + del_timer_sync(&info->rx_pm_timer);
697 + tasklet_disable(&info->tx_task);
698 + tasklet_disable(&info->rx_task);
699 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
700 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
701 + hci_h4p_reset_uart(info);
702 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
703 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
704 + gpio_set_value(info->reset_gpio, 0);
705 + gpio_set_value(info->bt_wakeup_gpio, 0);
706 + kfree_skb(info->rx_skb);
711 +static void hci_h4p_hci_destruct(struct hci_dev *hdev)
715 +static int hci_h4p_hci_send_frame(struct sk_buff *skb)
717 + struct hci_h4p_info *info;
718 + struct hci_dev *hdev = (struct hci_dev *)skb->dev;
722 + printk(KERN_WARNING "hci_h4p: Frame for unknown device\n");
726 + NBT_DBG("dev %p, skb %p\n", hdev, skb);
728 + info = hdev->driver_data;
730 + if (!test_bit(HCI_RUNNING, &hdev->flags)) {
731 + dev_warn(info->dev, "Frame for non-running device\n");
735 + switch (bt_cb(skb)->pkt_type) {
736 + case HCI_COMMAND_PKT:
737 + hdev->stat.cmd_tx++;
739 + case HCI_ACLDATA_PKT:
740 + hdev->stat.acl_tx++;
742 + case HCI_SCODATA_PKT:
743 + hdev->stat.sco_tx++;
747 + /* Push frame type to skb */
748 + *skb_push(skb, 1) = (bt_cb(skb)->pkt_type);
749 + /* We should allways send word aligned data to h4+ devices */
750 + if (skb->len % 2) {
751 + err = skb_pad(skb, 1);
756 + hci_h4p_enable_tx(info);
757 + skb_queue_tail(&info->txq, skb);
758 + tasklet_schedule(&info->tx_task);
763 +static int hci_h4p_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
765 + return -ENOIOCTLCMD;
768 +static int hci_h4p_register_hdev(struct hci_h4p_info *info)
770 + struct hci_dev *hdev;
772 + /* Initialize and register HCI device */
774 + hdev = hci_alloc_dev();
776 + dev_err(info->dev, "Can't allocate memory for device\n");
781 + hdev->type = HCI_UART;
782 + hdev->driver_data = info;
784 + hdev->open = hci_h4p_hci_open;
785 + hdev->close = hci_h4p_hci_close;
786 + hdev->flush = hci_h4p_hci_flush;
787 + hdev->send = hci_h4p_hci_send_frame;
788 + hdev->destruct = hci_h4p_hci_destruct;
789 + hdev->ioctl = hci_h4p_hci_ioctl;
791 + hdev->owner = THIS_MODULE;
793 + if (hci_register_dev(hdev) < 0) {
794 + dev_err(info->dev, "hci_h4p: Can't register HCI device %s.\n", hdev->name);
801 +static int hci_h4p_probe(struct platform_device *pdev)
803 + struct omap_bluetooth_config *bt_config;
804 + struct hci_h4p_info *info;
807 + dev_info(&pdev->dev, "Registering HCI H4P device\n");
808 + info = kzalloc(sizeof(struct hci_h4p_info), GFP_KERNEL);
812 + info->dev = &pdev->dev;
813 + info->pm_enabled = 0;
814 + info->tx_pm_enabled = 0;
815 + info->rx_pm_enabled = 0;
816 + info->garbage_bytes = 0;
817 + info->tx_clocks_en = 0;
818 + info->rx_clocks_en = 0;
819 + tasklet_init(&info->tx_task, hci_h4p_tx_tasklet, (unsigned long)info);
820 + tasklet_init(&info->rx_task, hci_h4p_rx_tasklet, (unsigned long)info);
821 + /* hci_h4p_hci_open assumes that tasklet is disabled in startup */
822 + tasklet_disable(&info->tx_task);
823 + tasklet_disable(&info->rx_task);
824 + spin_lock_init(&info->lock);
825 + spin_lock_init(&info->clocks_lock);
826 + skb_queue_head_init(&info->txq);
827 + init_timer(&info->tx_pm_timer);
828 + info->tx_pm_timer.function = hci_h4p_tx_pm_timer;
829 + info->tx_pm_timer.data = (unsigned long)info;
830 + init_timer(&info->rx_pm_timer);
831 + info->rx_pm_timer.function = hci_h4p_rx_pm_timer;
832 + info->rx_pm_timer.data = (unsigned long)info;
834 + if (pdev->dev.platform_data == NULL) {
835 + dev_err(&pdev->dev, "Could not get Bluetooth config data\n");
839 + bt_config = pdev->dev.platform_data;
840 + info->chip_type = bt_config->chip_type;
841 + info->bt_wakeup_gpio = bt_config->bt_wakeup_gpio;
842 + info->host_wakeup_gpio = bt_config->host_wakeup_gpio;
843 + info->reset_gpio = bt_config->reset_gpio;
844 + info->bt_sysclk = bt_config->bt_sysclk;
846 + NBT_DBG("RESET gpio: %d\n", info->reset_gpio);
847 + NBT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
848 + NBT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
849 + NBT_DBG("Uart: %d\n", bt_config->bt_uart);
850 + NBT_DBG("sysclk: %d\n", info->bt_sysclk);
852 + err = gpio_request(info->reset_gpio, "BT reset");
854 + dev_err(&pdev->dev, "Cannot get GPIO line %d\n",
860 + err = gpio_request(info->bt_wakeup_gpio, "BT wakeup");
863 + dev_err(info->dev, "Cannot get GPIO line 0x%d",
864 + info->bt_wakeup_gpio);
865 + gpio_free(info->reset_gpio);
870 + err = gpio_request(info->host_wakeup_gpio, "BT host wakeup");
873 + dev_err(info->dev, "Cannot get GPIO line %d",
874 + info->host_wakeup_gpio);
875 + gpio_free(info->reset_gpio);
876 + gpio_free(info->bt_wakeup_gpio);
881 + gpio_direction_output(info->reset_gpio, 0);
882 + gpio_direction_output(info->bt_wakeup_gpio, 0);
883 + gpio_direction_input(info->host_wakeup_gpio);
885 + switch (bt_config->bt_uart) {
887 + if (cpu_is_omap16xx()) {
889 + info->uart_fclk = clk_get(NULL, "uart1_ck");
890 + } else if (cpu_is_omap24xx()) {
891 + irq = INT_24XX_UART1_IRQ;
892 + info->uart_iclk = clk_get(NULL, "uart1_ick");
893 + info->uart_fclk = clk_get(NULL, "uart1_fck");
895 + /* FIXME: Use platform_get_resource for the port */
896 + info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
897 + if (!info->uart_base)
901 + if (cpu_is_omap16xx()) {
903 + info->uart_fclk = clk_get(NULL, "uart2_ck");
905 + irq = INT_24XX_UART2_IRQ;
906 + info->uart_iclk = clk_get(NULL, "uart2_ick");
907 + info->uart_fclk = clk_get(NULL, "uart2_fck");
909 + /* FIXME: Use platform_get_resource for the port */
910 + info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
911 + if (!info->uart_base)
915 + if (cpu_is_omap16xx()) {
917 + info->uart_fclk = clk_get(NULL, "uart3_ck");
919 + irq = INT_24XX_UART3_IRQ;
920 + info->uart_iclk = clk_get(NULL, "uart3_ick");
921 + info->uart_fclk = clk_get(NULL, "uart3_fck");
923 + /* FIXME: Use platform_get_resource for the port */
924 + info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
925 + if (!info->uart_base)
929 + dev_err(info->dev, "No uart defined\n");
934 + err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
936 + dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
940 + err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
941 + hci_h4p_wakeup_interrupt,
942 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
943 + "hci_h4p_wkup", (void *)info);
945 + dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
946 + gpio_to_irq(info->host_wakeup_gpio));
947 + free_irq(irq, (void *)info);
951 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
952 + hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
953 + err = hci_h4p_init_uart(info);
956 + err = hci_h4p_reset(info);
959 + err = hci_h4p_wait_for_cts(info, 1, 10);
962 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
964 + platform_set_drvdata(pdev, info);
965 + err = hci_h4p_sysfs_create_files(info->dev);
969 + if (hci_h4p_register_hdev(info) < 0) {
970 + dev_err(info->dev, "failed to register hci_h4p hci device\n");
973 + gpio_set_value(info->reset_gpio, 0);
978 + free_irq(irq, (void *)info);
979 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *)info);
981 + gpio_set_value(info->reset_gpio, 0);
982 + gpio_free(info->reset_gpio);
983 + gpio_free(info->bt_wakeup_gpio);
984 + gpio_free(info->host_wakeup_gpio);
991 +static int hci_h4p_remove(struct platform_device *dev)
993 + struct hci_h4p_info *info;
995 + info = platform_get_drvdata(dev);
997 + hci_h4p_hci_close(info->hdev);
998 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *) info);
999 + hci_free_dev(info->hdev);
1000 + gpio_free(info->reset_gpio);
1001 + gpio_free(info->bt_wakeup_gpio);
1002 + gpio_free(info->host_wakeup_gpio);
1003 + free_irq(info->irq, (void *) info);
1009 +static struct platform_driver hci_h4p_driver = {
1010 + .probe = hci_h4p_probe,
1011 + .remove = hci_h4p_remove,
1013 + .name = "hci_h4p",
1017 +static int __init hci_h4p_init(void)
1021 + /* Register the driver with LDM */
1022 + err = platform_driver_register(&hci_h4p_driver);
1024 + printk(KERN_WARNING "failed to register hci_h4p driver\n");
1029 +static void __exit hci_h4p_exit(void)
1031 + platform_driver_unregister(&hci_h4p_driver);
1034 +module_init(hci_h4p_init);
1035 +module_exit(hci_h4p_exit);
1037 +MODULE_DESCRIPTION("h4 driver with nokia extensions");
1038 +MODULE_LICENSE("GPL");
1039 +MODULE_AUTHOR("Ville Tervo");
1041 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/fw.c
1044 + * This file is part of hci_h4p bluetooth driver
1046 + * Copyright (C) 2005, 2006 Nokia Corporation.
1048 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1050 + * This program is free software; you can redistribute it and/or
1051 + * modify it under the terms of the GNU General Public License
1052 + * version 2 as published by the Free Software Foundation.
1054 + * This program is distributed in the hope that it will be useful, but
1055 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1056 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1057 + * General Public License for more details.
1059 + * You should have received a copy of the GNU General Public License
1060 + * along with this program; if not, write to the Free Software
1061 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1066 +#include <linux/skbuff.h>
1067 +#include <linux/firmware.h>
1068 +#include <linux/clk.h>
1070 +#include <net/bluetooth/bluetooth.h>
1072 +#include "hci_h4p.h"
1074 +#define BT_CHIP_TI 2
1075 +#define BT_CHIP_CSR 1
1079 +/* Firmware handling */
1080 +static int hci_h4p_open_firmware(struct hci_h4p_info *info,
1081 + const struct firmware **fw_entry)
1086 + NBT_DBG_FW("Opening %d firmware\n", info->chip_type);
1087 + switch (info->chip_type) {
1089 + err = request_firmware(fw_entry, "brf6150fw.bin", info->dev);
1092 + err = request_firmware(fw_entry, "bc4fw.bin", info->dev);
1095 + dev_err(info->dev, "Invalid chip type\n");
1103 +static void hci_h4p_close_firmware(const struct firmware *fw_entry)
1105 + release_firmware(fw_entry);
1108 +/* Read fw. Return length of the command. If no more commands in
1109 + * fw 0 is returned. In error case return value is negative.
1111 +static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
1112 + const struct firmware *fw_entry, int how)
1114 + unsigned int cmd_len;
1116 + if (fw_pos >= fw_entry->size) {
1120 + cmd_len = fw_entry->data[fw_pos++];
1124 + if (fw_pos + cmd_len > fw_entry->size) {
1125 + dev_err(info->dev, "Corrupted firmware image\n");
1129 + *skb = bt_skb_alloc(cmd_len, how);
1131 + dev_err(info->dev, "Cannot reserve memory for buffer\n");
1134 + memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
1136 + fw_pos += cmd_len;
1138 + return (*skb)->len;
1141 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1143 + const struct firmware *fw_entry = NULL;
1144 + struct sk_buff *skb = NULL;
1147 + err = hci_h4p_open_firmware(info, &fw_entry);
1148 + if (err < 0 || !fw_entry)
1151 + while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
1152 + if (err < 0 || !skb)
1155 + skb_queue_tail(fw_queue, skb);
1159 + hci_h4p_close_firmware(fw_entry);
1163 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1167 + switch(info->chip_type) {
1169 + err = hci_h4p_bc4_send_fw(info, fw_queue);
1172 + err = hci_h4p_brf6150_send_fw(info, fw_queue);
1175 + dev_err(info->dev, "Don't know how to send firmware\n");
1182 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1184 + switch (info->chip_type) {
1186 + hci_h4p_bc4_parse_fw_event(info, skb);
1189 + hci_h4p_brf6150_parse_fw_event(info, skb);
1192 + dev_err(info->dev, "Don't know how to parse fw event\n");
1193 + info->fw_error = -EINVAL;
1199 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/fw-csr.c
1202 + * This file is part of hci_h4p bluetooth driver
1204 + * Copyright (C) 2005, 2006 Nokia Corporation.
1206 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1208 + * This program is free software; you can redistribute it and/or
1209 + * modify it under the terms of the GNU General Public License
1210 + * version 2 as published by the Free Software Foundation.
1212 + * This program is distributed in the hope that it will be useful, but
1213 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1215 + * General Public License for more details.
1217 + * You should have received a copy of the GNU General Public License
1218 + * along with this program; if not, write to the Free Software
1219 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1224 +#include <linux/skbuff.h>
1225 +#include <linux/delay.h>
1226 +#include <linux/serial_reg.h>
1228 +#include "hci_h4p.h"
1230 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1232 + /* Check if this is fw packet */
1233 + if (skb->data[0] != 0xff) {
1234 + hci_recv_frame(skb);
1238 + if (skb->data[11] || skb->data[12]) {
1239 + dev_err(info->dev, "Firmware sending command failed\n");
1240 + info->fw_error = -EPROTO;
1244 + complete(&info->fw_completion);
1247 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1248 + struct sk_buff_head *fw_queue)
1250 + struct sk_buff *skb;
1251 + unsigned int offset;
1252 + int retries, count, i;
1254 + info->fw_error = 0;
1256 + NBT_DBG_FW("Sending firmware\n");
1257 + skb = skb_dequeue(fw_queue);
1262 + info->bdaddr[0] = 0x00;
1263 + info->bdaddr[1] = 0x1D;
1264 + info->bdaddr[2] = 0x6E;
1265 + info->bdaddr[3] = 0xD4;
1266 + info->bdaddr[4] = 0xF0;
1267 + info->bdaddr[5] = 0x37;
1269 + /* Check if this is bd_address packet */
1270 + if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
1271 + dev_info(info->dev, "bd_address packet found\n");
1273 + skb->data[offset + 1] = 0x00;
1274 + skb->data[offset + 5] = 0x00;
1275 + skb->data[offset + 7] = info->bdaddr[0];
1276 + skb->data[offset + 6] = info->bdaddr[1];
1277 + skb->data[offset + 4] = info->bdaddr[2];
1278 + skb->data[offset + 0] = info->bdaddr[3];
1279 + skb->data[offset + 3] = info->bdaddr[4];
1280 + skb->data[offset + 2] = info->bdaddr[5];
1283 + for (i = 0; i < 6; i++) {
1284 + if (info->bdaddr[i] != 0x00)
1289 + dev_info(info->dev, "Valid bluetooth address not found.\n");
1294 + for (count = 1; ; count++) {
1295 + NBT_DBG_FW("Sending firmware command %d\n", count);
1296 + init_completion(&info->fw_completion);
1297 + skb_queue_tail(&info->txq, skb);
1298 + tasklet_schedule(&info->tx_task);
1300 + skb = skb_dequeue(fw_queue);
1304 + if (!wait_for_completion_timeout(&info->fw_completion,
1305 + msecs_to_jiffies(1000))) {
1306 + dev_err(info->dev, "No reply to fw command\n");
1307 + return -ETIMEDOUT;
1310 + if (info->fw_error) {
1311 + dev_err(info->dev, "FW error\n");
1316 + /* Wait for chip warm reset */
1318 + while ((!skb_queue_empty(&info->txq) ||
1319 + !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
1324 + dev_err(info->dev, "Transmitter not empty\n");
1325 + return -ETIMEDOUT;
1328 + hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
1330 + if (hci_h4p_wait_for_cts(info, 1, 100)) {
1331 + dev_err(info->dev, "cts didn't go down after final speed change\n");
1332 + return -ETIMEDOUT;
1337 + init_completion(&info->init_completion);
1338 + hci_h4p_send_alive_packet(info);
1340 + } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
1344 + dev_err(info->dev, "No alive reply after speed change\n");
1345 + return -ETIMEDOUT;
1351 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/fw-ti.c
1354 + * This file is part of hci_h4p bluetooth driver
1356 + * Copyright (C) 2005, 2006 Nokia Corporation.
1358 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1360 + * This program is free software; you can redistribute it and/or
1361 + * modify it under the terms of the GNU General Public License
1362 + * version 2 as published by the Free Software Foundation.
1364 + * This program is distributed in the hope that it will be useful, but
1365 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1366 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1367 + * General Public License for more details.
1369 + * You should have received a copy of the GNU General Public License
1370 + * along with this program; if not, write to the Free Software
1371 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1376 +#include <linux/skbuff.h>
1378 +#include "hci_h4p.h"
1380 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1381 + struct sk_buff *skb)
1383 + struct hci_fw_event *ev;
1386 + if (bt_cb(skb)->pkt_type != H4_EVT_PKT) {
1387 + dev_err(info->dev, "Got non event fw packet.\n");
1392 + ev = (struct hci_fw_event *)skb->data;
1393 + if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
1394 + dev_err(info->dev, "Got non cmd complete fw event\n");
1399 + if (ev->status != 0) {
1400 + dev_err(info->dev, "Got error status from fw command\n");
1406 + info->fw_error = err;
1407 + complete(&info->fw_completion);
1410 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1412 + struct sk_buff *skb;
1415 + info->fw_error = 0;
1417 + while ((skb = skb_dequeue(fw_queue)) != NULL) {
1418 + /* We should allways send word aligned data to h4+ devices */
1419 + if (skb->len % 2) {
1420 + err = skb_pad(skb, 1);
1425 + init_completion(&info->fw_completion);
1426 + skb_queue_tail(&info->txq, skb);
1427 + tasklet_schedule(&info->tx_task);
1429 + if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
1430 + dev_err(info->dev, "Timeout while sending brf6150 fw\n");
1431 + return -ETIMEDOUT;
1434 + if (info->fw_error) {
1435 + dev_err(info->dev, "There was fw_error while sending bfr6150 fw\n");
1439 + NBT_DBG_FW("Firmware sent\n");
1444 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/hci_h4p.h
1447 + * This file is part of hci_h4p bluetooth driver
1449 + * Copyright (C) 2005, 2006 Nokia Corporation.
1451 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1453 + * This program is free software; you can redistribute it and/or
1454 + * modify it under the terms of the GNU General Public License
1455 + * version 2 as published by the Free Software Foundation.
1457 + * This program is distributed in the hope that it will be useful, but
1458 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1459 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1460 + * General Public License for more details.
1462 + * You should have received a copy of the GNU General Public License
1463 + * along with this program; if not, write to the Free Software
1464 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1469 +#include <mach/board.h>
1471 +#include <net/bluetooth/bluetooth.h>
1472 +#include <net/bluetooth/hci_core.h>
1473 +#include <net/bluetooth/hci.h>
1475 +#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
1476 +#define __DRIVERS_BLUETOOTH_HCI_H4P_H
1478 +#define UART_SYSC_OMAP_RESET 0x03
1479 +#define UART_SYSS_RESETDONE 0x01
1480 +#define UART_OMAP_SCR_EMPTY_THR 0x08
1481 +#define UART_OMAP_SCR_WAKEUP 0x10
1482 +#define UART_OMAP_SSR_WAKEUP 0x02
1483 +#define UART_OMAP_SSR_TXFULL 0x01
1486 +#define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1488 +#define NBT_DBG(...)
1492 +#define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1494 +#define NBT_DBG_FW(...)
1498 +#define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1500 +#define NBT_DBG_POWER(...)
1504 +#define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1506 +#define NBT_DBG_TRANSFER(...)
1510 +#define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
1512 +#define NBT_DBG_TRANSFER_NF(...)
1516 +#define NBT_DBG_DMA(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1518 +#define NBT_DBG_DMA(...)
1521 +struct hci_h4p_info {
1522 + struct hci_dev *hdev;
1525 + void __iomem *uart_base;
1526 + unsigned long uart_phys_base;
1528 + struct device *dev;
1531 + u8 bt_wakeup_gpio;
1532 + u8 host_wakeup_gpio;
1537 + struct sk_buff_head fw_queue;
1538 + struct sk_buff *alive_cmd_skb;
1539 + struct completion init_completion;
1540 + struct completion fw_completion;
1544 + struct sk_buff_head txq;
1545 + struct tasklet_struct tx_task;
1547 + struct sk_buff *rx_skb;
1549 + unsigned long rx_state;
1550 + unsigned long garbage_bytes;
1551 + struct tasklet_struct rx_task;
1554 + int tx_pm_enabled;
1555 + int rx_pm_enabled;
1556 + struct timer_list tx_pm_timer;
1557 + struct timer_list rx_pm_timer;
1561 + spinlock_t clocks_lock;
1562 + struct clk *uart_iclk;
1563 + struct clk *uart_fclk;
1566 +#define MAX_BAUD_RATE 921600
1567 +#define BC4_MAX_BAUD_RATE 3692300
1568 +#define UART_CLOCK 48000000
1569 +#define BT_INIT_DIVIDER 320
1570 +#define BT_BAUDRATE_DIVIDER 384000000
1571 +#define BT_SYSCLK_DIV 1000
1572 +#define INIT_SPEED 120000
1574 +#define H4_TYPE_SIZE 1
1576 +/* H4+ packet types */
1577 +#define H4_CMD_PKT 0x01
1578 +#define H4_ACL_PKT 0x02
1579 +#define H4_SCO_PKT 0x03
1580 +#define H4_EVT_PKT 0x04
1581 +#define H4_NEG_PKT 0x06
1582 +#define H4_ALIVE_PKT 0x07
1585 +#define WAIT_FOR_PKT_TYPE 1
1586 +#define WAIT_FOR_HEADER 2
1587 +#define WAIT_FOR_DATA 3
1589 +struct hci_fw_event {
1590 + struct hci_event_hdr hev;
1591 + struct hci_ev_cmd_complete cmd;
1593 +} __attribute__ ((packed));
1595 +struct hci_bc4_set_bdaddr {
1597 + struct hci_command_hdr cmd_hdr;
1598 +} __attribute__ ((packed));
1600 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
1602 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
1603 + struct sk_buff *skb);
1604 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1605 + struct sk_buff_head *fw_queue);
1607 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1608 + struct sk_buff *skb);
1609 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info,
1610 + struct sk_buff_head *fw_queue);
1612 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1613 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1614 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
1616 +int hci_h4p_sysfs_create_files(struct device *dev);
1618 +void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
1619 +u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
1620 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
1621 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
1622 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1623 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1624 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
1625 +int hci_h4p_reset_uart(struct hci_h4p_info *info);
1626 +int hci_h4p_init_uart(struct hci_h4p_info *info);
1628 +#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */
1630 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/Makefile
1633 +# Makefile for the Linux Bluetooth HCI device drivers.
1636 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p.o
1638 +hci_h4p-objs := core.o fw.o uart.o sysfs.o fw-ti.o fw-csr.o
1640 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/sysfs.c
1643 + * This file is part of hci_h4p bluetooth driver
1645 + * Copyright (C) 2005, 2006 Nokia Corporation.
1647 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1649 + * This program is free software; you can redistribute it and/or
1650 + * modify it under the terms of the GNU General Public License
1651 + * version 2 as published by the Free Software Foundation.
1653 + * This program is distributed in the hope that it will be useful, but
1654 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1655 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1656 + * General Public License for more details.
1658 + * You should have received a copy of the GNU General Public License
1659 + * along with this program; if not, write to the Free Software
1660 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1665 +#include <linux/kernel.h>
1666 +#include <linux/init.h>
1667 +#include <linux/device.h>
1668 +#include <linux/platform_device.h>
1670 +#include "hci_h4p.h"
1672 +#ifdef CONFIG_SYSFS
1674 +static ssize_t hci_h4p_store_bdaddr(struct device *dev, struct device_attribute *attr,
1675 + const char *buf, size_t count)
1677 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1678 + unsigned int bdaddr[6];
1681 + dev_info(info->dev, "HCI_H4P_STORE_BDADDR called\n");
1683 + ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n",
1684 + &bdaddr[0], &bdaddr[1], &bdaddr[2],
1685 + &bdaddr[3], &bdaddr[4], &bdaddr[5]);
1688 + dev_info(info->dev, "bdaddr isn't found\n");
1692 + //for (i = 0; i < 6; i++)
1693 + //info->bdaddr[i] = bdaddr[i] & 0xff;
1695 + info->bdaddr[0] = 0x00;
1696 + info->bdaddr[1] = 0x1D;
1697 + info->bdaddr[2] = 0x6E;
1698 + info->bdaddr[3] = 0xD4;
1699 + info->bdaddr[4] = 0xF0;
1700 + info->bdaddr[5] = 0x37;
1705 +static ssize_t hci_h4p_show_bdaddr(struct device *dev, struct device_attribute *attr,
1708 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1710 + return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
1719 +static DEVICE_ATTR(bdaddr, S_IRUGO | S_IWUSR, hci_h4p_show_bdaddr, hci_h4p_store_bdaddr);
1720 +int hci_h4p_sysfs_create_files(struct device *dev)
1722 + return device_create_file(dev, &dev_attr_bdaddr);
1727 +++ linux-2.6.36-rc4/drivers/bluetooth/hci_h4p/uart.c
1730 + * This file is part of hci_h4p bluetooth driver
1732 + * Copyright (C) 2005, 2006 Nokia Corporation.
1734 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1736 + * This program is free software; you can redistribute it and/or
1737 + * modify it under the terms of the GNU General Public License
1738 + * version 2 as published by the Free Software Foundation.
1740 + * This program is distributed in the hope that it will be useful, but
1741 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1743 + * General Public License for more details.
1745 + * You should have received a copy of the GNU General Public License
1746 + * along with this program; if not, write to the Free Software
1747 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1752 +#include <linux/serial_reg.h>
1753 +#include <linux/delay.h>
1754 +#include <linux/clk.h>
1756 +#include <asm/io.h>
1758 +#include "hci_h4p.h"
1760 +inline void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val)
1763 + __raw_writeb(val, info->uart_base + offset);
1764 + //outb(val, info->uart_base + (offset << 2));
1767 +inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
1770 + return (u8)__raw_readb(info->uart_base + offset);
1771 + //return (unsigned int)__raw_readb(up->membase + offset);
1772 + //return inb(info->uart_base + (offset << 2));
1775 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active)
1779 + b = hci_h4p_inb(info, UART_MCR);
1781 + b |= UART_MCR_RTS;
1783 + b &= ~UART_MCR_RTS;
1784 + hci_h4p_outb(info, UART_MCR, b);
1787 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
1791 + unsigned long timeout;
1794 + timeout = jiffies + msecs_to_jiffies(timeout_ms);
1798 + state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
1806 + if (time_after(jiffies, timeout))
1807 + return -ETIMEDOUT;
1811 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1815 + lcr = hci_h4p_inb(info, UART_LCR);
1816 + hci_h4p_outb(info, UART_LCR, 0xbf);
1817 + b = hci_h4p_inb(info, UART_EFR);
1822 + hci_h4p_outb(info, UART_EFR, b);
1823 + hci_h4p_outb(info, UART_LCR, lcr);
1826 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1828 + unsigned long flags;
1830 + spin_lock_irqsave(&info->lock, flags);
1831 + __hci_h4p_set_auto_ctsrts(info, on, which);
1832 + spin_unlock_irqrestore(&info->lock, flags);
1835 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
1837 + unsigned int divisor;
1840 + NBT_DBG("Setting speed %lu\n", speed);
1842 + if (speed >= 460800) {
1843 + divisor = UART_CLOCK / 13 / speed;
1846 + divisor = UART_CLOCK / 16 / speed;
1850 + hci_h4p_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
1851 + lcr = hci_h4p_inb(info, UART_LCR);
1852 + hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
1853 + hci_h4p_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
1854 + hci_h4p_outb(info, UART_DLM, divisor >> 8);
1855 + hci_h4p_outb(info, UART_LCR, lcr);
1856 + hci_h4p_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
1859 +int hci_h4p_reset_uart(struct hci_h4p_info *info)
1863 + /* Reset the UART */
1864 + hci_h4p_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
1865 + while (!(hci_h4p_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
1866 + if (count++ > 20000) {
1867 + dev_err(info->dev, "hci_h4p: UART reset timeout\n");
1876 +int hci_h4p_init_uart(struct hci_h4p_info *info)
1880 + err = hci_h4p_reset_uart(info);
1884 + /* Enable and setup FIFO */
1885 + hci_h4p_outb(info, UART_LCR, UART_LCR_WLEN8);
1886 + hci_h4p_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
1887 + hci_h4p_outb(info, UART_OMAP_SCR, 0x80);
1888 + hci_h4p_outb(info, UART_EFR, UART_EFR_ECB);
1889 + hci_h4p_outb(info, UART_MCR, UART_MCR_TCRTLR);
1890 + hci_h4p_outb(info, UART_TI752_TLR, 0x1f);
1891 + hci_h4p_outb(info, UART_TI752_TCR, 0xef);
1892 + hci_h4p_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
1893 + UART_FCR_CLEAR_XMIT | UART_FCR_R_TRIG_00);
1894 + hci_h4p_outb(info, UART_IER, UART_IER_RDI);
1898 --- linux-2.6.36-rc4.orig/drivers/bluetooth/Kconfig
1899 +++ linux-2.6.36-rc4/drivers/bluetooth/Kconfig
1900 @@ -173,6 +173,16 @@ config BT_HCIBTUART
1901 Say Y here to compile support for HCI UART devices into the
1902 kernel or say M to compile it as module (btuart_cs).
1905 + tristate "HCI driver with H4 Nokia extensions"
1906 + depends on BT && ARCH_OMAP
1908 + Bluetooth HCI driver with H4 extensions. This driver provides
1909 + support for H4+ Bluetooth chip with vendor-specific H4 extensions.
1911 + Say Y here to compile support for h4 extended devices into the kernel
1912 + or say M to compile it as module (hci_h4p).
1915 tristate "HCI VHCI (Virtual HCI device) driver"
1917 --- linux-2.6.36-rc4.orig/drivers/bluetooth/Makefile
1918 +++ linux-2.6.36-rc4/drivers/bluetooth/Makefile
1919 @@ -11,6 +11,7 @@ obj-$(CONFIG_BT_HCIDTL1) += dtl1_cs.o
1920 obj-$(CONFIG_BT_HCIBT3C) += bt3c_cs.o
1921 obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o
1922 obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
1923 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p/
1925 obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
1926 obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o