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(+)
15 +++ linux-2.6.36-rc7/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 <plat/serial.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->dev_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);
886 +#if defined(CONFIG_ARCH_OMAP1)
887 +# define OMAP_UART1_BASE OMAP1_UART1_BASE
888 +# define OMAP_UART2_BASE OMAP1_UART2_BASE
889 +# define OMAP_UART3_BASE OMAP1_UART3_BASE
890 +#elif defined(CONFIG_ARCH_OMAP2)
891 +# define OMAP_UART1_BASE OMAP2_UART1_BASE
892 +# define OMAP_UART2_BASE OMAP2_UART2_BASE
893 +# define OMAP_UART3_BASE OMAP2_UART3_BASE
894 +#elif defined(CONFIG_ARCH_OMAP3)
895 +# define OMAP_UART1_BASE OMAP3_UART1_BASE
896 +# define OMAP_UART2_BASE OMAP3_UART2_BASE
897 +# define OMAP_UART3_BASE OMAP3_UART3_BASE
898 +#elif defined(CONFIG_ARCH_OMAP4)
899 +# define OMAP_UART1_BASE OMAP4_UART1_BASE
900 +# define OMAP_UART2_BASE OMAP4_UART2_BASE
901 +# define OMAP_UART3_BASE OMAP4_UART3_BASE
905 + switch (bt_config->bt_uart) {
907 + if (cpu_is_omap16xx()) {
909 + info->uart_fclk = clk_get(NULL, "uart1_ck");
910 + } else if (cpu_is_omap24xx()) {
911 + irq = INT_24XX_UART1_IRQ;
912 + info->uart_iclk = clk_get(NULL, "uart1_ick");
913 + info->uart_fclk = clk_get(NULL, "uart1_fck");
915 + /* FIXME: Use platform_get_resource for the port */
916 + info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
917 + if (!info->uart_base)
921 + if (cpu_is_omap16xx()) {
923 + info->uart_fclk = clk_get(NULL, "uart2_ck");
925 + irq = INT_24XX_UART2_IRQ;
926 + info->uart_iclk = clk_get(NULL, "uart2_ick");
927 + info->uart_fclk = clk_get(NULL, "uart2_fck");
929 + /* FIXME: Use platform_get_resource for the port */
930 + info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
931 + if (!info->uart_base)
935 + if (cpu_is_omap16xx()) {
937 + info->uart_fclk = clk_get(NULL, "uart3_ck");
939 + irq = INT_24XX_UART3_IRQ;
940 + info->uart_iclk = clk_get(NULL, "uart3_ick");
941 + info->uart_fclk = clk_get(NULL, "uart3_fck");
943 + /* FIXME: Use platform_get_resource for the port */
944 + info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
945 + if (!info->uart_base)
949 + dev_err(info->dev, "No uart defined\n");
954 + err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
956 + dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
960 + err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
961 + hci_h4p_wakeup_interrupt,
962 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
963 + "hci_h4p_wkup", (void *)info);
965 + dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
966 + gpio_to_irq(info->host_wakeup_gpio));
967 + free_irq(irq, (void *)info);
971 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
972 + hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
973 + err = hci_h4p_init_uart(info);
976 + err = hci_h4p_reset(info);
979 + err = hci_h4p_wait_for_cts(info, 1, 10);
982 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
984 + platform_set_drvdata(pdev, info);
985 + err = hci_h4p_sysfs_create_files(info->dev);
989 + if (hci_h4p_register_hdev(info) < 0) {
990 + dev_err(info->dev, "failed to register hci_h4p hci device\n");
993 + gpio_set_value(info->reset_gpio, 0);
998 + free_irq(irq, (void *)info);
999 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *)info);
1001 + gpio_set_value(info->reset_gpio, 0);
1002 + gpio_free(info->reset_gpio);
1003 + gpio_free(info->bt_wakeup_gpio);
1004 + gpio_free(info->host_wakeup_gpio);
1011 +static int hci_h4p_remove(struct platform_device *dev)
1013 + struct hci_h4p_info *info;
1015 + info = platform_get_drvdata(dev);
1017 + hci_h4p_hci_close(info->hdev);
1018 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *) info);
1019 + hci_free_dev(info->hdev);
1020 + gpio_free(info->reset_gpio);
1021 + gpio_free(info->bt_wakeup_gpio);
1022 + gpio_free(info->host_wakeup_gpio);
1023 + free_irq(info->irq, (void *) info);
1029 +static struct platform_driver hci_h4p_driver = {
1030 + .probe = hci_h4p_probe,
1031 + .remove = hci_h4p_remove,
1033 + .name = "hci_h4p",
1037 +static int __init hci_h4p_init(void)
1041 + /* Register the driver with LDM */
1042 + err = platform_driver_register(&hci_h4p_driver);
1044 + printk(KERN_WARNING "failed to register hci_h4p driver\n");
1049 +static void __exit hci_h4p_exit(void)
1051 + platform_driver_unregister(&hci_h4p_driver);
1054 +module_init(hci_h4p_init);
1055 +module_exit(hci_h4p_exit);
1057 +MODULE_DESCRIPTION("h4 driver with nokia extensions");
1058 +MODULE_LICENSE("GPL");
1059 +MODULE_AUTHOR("Ville Tervo");
1061 +++ linux-2.6.36-rc7/drivers/bluetooth/hci_h4p/fw.c
1064 + * This file is part of hci_h4p bluetooth driver
1066 + * Copyright (C) 2005, 2006 Nokia Corporation.
1068 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1070 + * This program is free software; you can redistribute it and/or
1071 + * modify it under the terms of the GNU General Public License
1072 + * version 2 as published by the Free Software Foundation.
1074 + * This program is distributed in the hope that it will be useful, but
1075 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1076 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1077 + * General Public License for more details.
1079 + * You should have received a copy of the GNU General Public License
1080 + * along with this program; if not, write to the Free Software
1081 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1086 +#include <linux/skbuff.h>
1087 +#include <linux/firmware.h>
1088 +#include <linux/clk.h>
1090 +#include <net/bluetooth/bluetooth.h>
1092 +#include "hci_h4p.h"
1094 +#define BT_CHIP_TI 2
1095 +#define BT_CHIP_CSR 1
1099 +/* Firmware handling */
1100 +static int hci_h4p_open_firmware(struct hci_h4p_info *info,
1101 + const struct firmware **fw_entry)
1106 + NBT_DBG_FW("Opening %d firmware\n", info->chip_type);
1107 + switch (info->chip_type) {
1109 + err = request_firmware(fw_entry, "brf6150fw.bin", info->dev);
1112 + err = request_firmware(fw_entry, "bc4fw.bin", info->dev);
1115 + dev_err(info->dev, "Invalid chip type\n");
1123 +static void hci_h4p_close_firmware(const struct firmware *fw_entry)
1125 + release_firmware(fw_entry);
1128 +/* Read fw. Return length of the command. If no more commands in
1129 + * fw 0 is returned. In error case return value is negative.
1131 +static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
1132 + const struct firmware *fw_entry, int how)
1134 + unsigned int cmd_len;
1136 + if (fw_pos >= fw_entry->size) {
1140 + cmd_len = fw_entry->data[fw_pos++];
1144 + if (fw_pos + cmd_len > fw_entry->size) {
1145 + dev_err(info->dev, "Corrupted firmware image\n");
1149 + *skb = bt_skb_alloc(cmd_len, how);
1151 + dev_err(info->dev, "Cannot reserve memory for buffer\n");
1154 + memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
1156 + fw_pos += cmd_len;
1158 + return (*skb)->len;
1161 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1163 + const struct firmware *fw_entry = NULL;
1164 + struct sk_buff *skb = NULL;
1167 + err = hci_h4p_open_firmware(info, &fw_entry);
1168 + if (err < 0 || !fw_entry)
1171 + while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
1172 + if (err < 0 || !skb)
1175 + skb_queue_tail(fw_queue, skb);
1179 + hci_h4p_close_firmware(fw_entry);
1183 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1187 + switch(info->chip_type) {
1189 + err = hci_h4p_bc4_send_fw(info, fw_queue);
1192 + err = hci_h4p_brf6150_send_fw(info, fw_queue);
1195 + dev_err(info->dev, "Don't know how to send firmware\n");
1202 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1204 + switch (info->chip_type) {
1206 + hci_h4p_bc4_parse_fw_event(info, skb);
1209 + hci_h4p_brf6150_parse_fw_event(info, skb);
1212 + dev_err(info->dev, "Don't know how to parse fw event\n");
1213 + info->fw_error = -EINVAL;
1219 +++ linux-2.6.36-rc7/drivers/bluetooth/hci_h4p/fw-csr.c
1222 + * This file is part of hci_h4p bluetooth driver
1224 + * Copyright (C) 2005, 2006 Nokia Corporation.
1226 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1228 + * This program is free software; you can redistribute it and/or
1229 + * modify it under the terms of the GNU General Public License
1230 + * version 2 as published by the Free Software Foundation.
1232 + * This program is distributed in the hope that it will be useful, but
1233 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1234 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1235 + * General Public License for more details.
1237 + * You should have received a copy of the GNU General Public License
1238 + * along with this program; if not, write to the Free Software
1239 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1244 +#include <linux/skbuff.h>
1245 +#include <linux/delay.h>
1246 +#include <linux/serial_reg.h>
1248 +#include "hci_h4p.h"
1250 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1252 + /* Check if this is fw packet */
1253 + if (skb->data[0] != 0xff) {
1254 + hci_recv_frame(skb);
1258 + if (skb->data[11] || skb->data[12]) {
1259 + dev_err(info->dev, "Firmware sending command failed\n");
1260 + info->fw_error = -EPROTO;
1264 + complete(&info->fw_completion);
1267 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1268 + struct sk_buff_head *fw_queue)
1270 + struct sk_buff *skb;
1271 + unsigned int offset;
1272 + int retries, count, i;
1274 + info->fw_error = 0;
1276 + NBT_DBG_FW("Sending firmware\n");
1277 + skb = skb_dequeue(fw_queue);
1282 + info->bdaddr[0] = 0x00;
1283 + info->bdaddr[1] = 0x1D;
1284 + info->bdaddr[2] = 0x6E;
1285 + info->bdaddr[3] = 0xD4;
1286 + info->bdaddr[4] = 0xF0;
1287 + info->bdaddr[5] = 0x37;
1289 + /* Check if this is bd_address packet */
1290 + if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
1291 + dev_info(info->dev, "bd_address packet found\n");
1293 + skb->data[offset + 1] = 0x00;
1294 + skb->data[offset + 5] = 0x00;
1295 + skb->data[offset + 7] = info->bdaddr[0];
1296 + skb->data[offset + 6] = info->bdaddr[1];
1297 + skb->data[offset + 4] = info->bdaddr[2];
1298 + skb->data[offset + 0] = info->bdaddr[3];
1299 + skb->data[offset + 3] = info->bdaddr[4];
1300 + skb->data[offset + 2] = info->bdaddr[5];
1303 + for (i = 0; i < 6; i++) {
1304 + if (info->bdaddr[i] != 0x00)
1309 + dev_info(info->dev, "Valid bluetooth address not found.\n");
1314 + for (count = 1; ; count++) {
1315 + NBT_DBG_FW("Sending firmware command %d\n", count);
1316 + init_completion(&info->fw_completion);
1317 + skb_queue_tail(&info->txq, skb);
1318 + tasklet_schedule(&info->tx_task);
1320 + skb = skb_dequeue(fw_queue);
1324 + if (!wait_for_completion_timeout(&info->fw_completion,
1325 + msecs_to_jiffies(1000))) {
1326 + dev_err(info->dev, "No reply to fw command\n");
1327 + return -ETIMEDOUT;
1330 + if (info->fw_error) {
1331 + dev_err(info->dev, "FW error\n");
1336 + /* Wait for chip warm reset */
1338 + while ((!skb_queue_empty(&info->txq) ||
1339 + !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
1344 + dev_err(info->dev, "Transmitter not empty\n");
1345 + return -ETIMEDOUT;
1348 + hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
1350 + if (hci_h4p_wait_for_cts(info, 1, 100)) {
1351 + dev_err(info->dev, "cts didn't go down after final speed change\n");
1352 + return -ETIMEDOUT;
1357 + init_completion(&info->init_completion);
1358 + hci_h4p_send_alive_packet(info);
1360 + } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
1364 + dev_err(info->dev, "No alive reply after speed change\n");
1365 + return -ETIMEDOUT;
1371 +++ linux-2.6.36-rc7/drivers/bluetooth/hci_h4p/fw-ti.c
1374 + * This file is part of hci_h4p bluetooth driver
1376 + * Copyright (C) 2005, 2006 Nokia Corporation.
1378 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1380 + * This program is free software; you can redistribute it and/or
1381 + * modify it under the terms of the GNU General Public License
1382 + * version 2 as published by the Free Software Foundation.
1384 + * This program is distributed in the hope that it will be useful, but
1385 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1386 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1387 + * General Public License for more details.
1389 + * You should have received a copy of the GNU General Public License
1390 + * along with this program; if not, write to the Free Software
1391 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1396 +#include <linux/skbuff.h>
1398 +#include "hci_h4p.h"
1400 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1401 + struct sk_buff *skb)
1403 + struct hci_fw_event *ev;
1406 + if (bt_cb(skb)->pkt_type != H4_EVT_PKT) {
1407 + dev_err(info->dev, "Got non event fw packet.\n");
1412 + ev = (struct hci_fw_event *)skb->data;
1413 + if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
1414 + dev_err(info->dev, "Got non cmd complete fw event\n");
1419 + if (ev->status != 0) {
1420 + dev_err(info->dev, "Got error status from fw command\n");
1426 + info->fw_error = err;
1427 + complete(&info->fw_completion);
1430 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1432 + struct sk_buff *skb;
1435 + info->fw_error = 0;
1437 + while ((skb = skb_dequeue(fw_queue)) != NULL) {
1438 + /* We should allways send word aligned data to h4+ devices */
1439 + if (skb->len % 2) {
1440 + err = skb_pad(skb, 1);
1445 + init_completion(&info->fw_completion);
1446 + skb_queue_tail(&info->txq, skb);
1447 + tasklet_schedule(&info->tx_task);
1449 + if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
1450 + dev_err(info->dev, "Timeout while sending brf6150 fw\n");
1451 + return -ETIMEDOUT;
1454 + if (info->fw_error) {
1455 + dev_err(info->dev, "There was fw_error while sending bfr6150 fw\n");
1459 + NBT_DBG_FW("Firmware sent\n");
1464 +++ linux-2.6.36-rc7/drivers/bluetooth/hci_h4p/hci_h4p.h
1467 + * This file is part of hci_h4p bluetooth driver
1469 + * Copyright (C) 2005, 2006 Nokia Corporation.
1471 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1473 + * This program is free software; you can redistribute it and/or
1474 + * modify it under the terms of the GNU General Public License
1475 + * version 2 as published by the Free Software Foundation.
1477 + * This program is distributed in the hope that it will be useful, but
1478 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1479 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1480 + * General Public License for more details.
1482 + * You should have received a copy of the GNU General Public License
1483 + * along with this program; if not, write to the Free Software
1484 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1489 +#include <mach/board.h>
1491 +#include <net/bluetooth/bluetooth.h>
1492 +#include <net/bluetooth/hci_core.h>
1493 +#include <net/bluetooth/hci.h>
1495 +#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
1496 +#define __DRIVERS_BLUETOOTH_HCI_H4P_H
1498 +#define UART_SYSC_OMAP_RESET 0x03
1499 +#define UART_SYSS_RESETDONE 0x01
1500 +#define UART_OMAP_SCR_EMPTY_THR 0x08
1501 +#define UART_OMAP_SCR_WAKEUP 0x10
1502 +#define UART_OMAP_SSR_WAKEUP 0x02
1503 +#define UART_OMAP_SSR_TXFULL 0x01
1506 +#define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1508 +#define NBT_DBG(...)
1512 +#define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1514 +#define NBT_DBG_FW(...)
1518 +#define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1520 +#define NBT_DBG_POWER(...)
1524 +#define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1526 +#define NBT_DBG_TRANSFER(...)
1530 +#define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
1532 +#define NBT_DBG_TRANSFER_NF(...)
1536 +#define NBT_DBG_DMA(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1538 +#define NBT_DBG_DMA(...)
1541 +struct hci_h4p_info {
1542 + struct hci_dev *hdev;
1545 + void __iomem *uart_base;
1546 + unsigned long uart_phys_base;
1548 + struct device *dev;
1551 + u8 bt_wakeup_gpio;
1552 + u8 host_wakeup_gpio;
1557 + struct sk_buff_head fw_queue;
1558 + struct sk_buff *alive_cmd_skb;
1559 + struct completion init_completion;
1560 + struct completion fw_completion;
1564 + struct sk_buff_head txq;
1565 + struct tasklet_struct tx_task;
1567 + struct sk_buff *rx_skb;
1569 + unsigned long rx_state;
1570 + unsigned long garbage_bytes;
1571 + struct tasklet_struct rx_task;
1574 + int tx_pm_enabled;
1575 + int rx_pm_enabled;
1576 + struct timer_list tx_pm_timer;
1577 + struct timer_list rx_pm_timer;
1581 + spinlock_t clocks_lock;
1582 + struct clk *uart_iclk;
1583 + struct clk *uart_fclk;
1586 +#define MAX_BAUD_RATE 921600
1587 +#define BC4_MAX_BAUD_RATE 3692300
1588 +#define UART_CLOCK 48000000
1589 +#define BT_INIT_DIVIDER 320
1590 +#define BT_BAUDRATE_DIVIDER 384000000
1591 +#define BT_SYSCLK_DIV 1000
1592 +#define INIT_SPEED 120000
1594 +#define H4_TYPE_SIZE 1
1596 +/* H4+ packet types */
1597 +#define H4_CMD_PKT 0x01
1598 +#define H4_ACL_PKT 0x02
1599 +#define H4_SCO_PKT 0x03
1600 +#define H4_EVT_PKT 0x04
1601 +#define H4_NEG_PKT 0x06
1602 +#define H4_ALIVE_PKT 0x07
1605 +#define WAIT_FOR_PKT_TYPE 1
1606 +#define WAIT_FOR_HEADER 2
1607 +#define WAIT_FOR_DATA 3
1609 +struct hci_fw_event {
1610 + struct hci_event_hdr hev;
1611 + struct hci_ev_cmd_complete cmd;
1613 +} __attribute__ ((packed));
1615 +struct hci_bc4_set_bdaddr {
1617 + struct hci_command_hdr cmd_hdr;
1618 +} __attribute__ ((packed));
1620 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
1622 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
1623 + struct sk_buff *skb);
1624 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1625 + struct sk_buff_head *fw_queue);
1627 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1628 + struct sk_buff *skb);
1629 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info,
1630 + struct sk_buff_head *fw_queue);
1632 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1633 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1634 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
1636 +int hci_h4p_sysfs_create_files(struct device *dev);
1638 +void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
1639 +u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
1640 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
1641 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
1642 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1643 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1644 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
1645 +int hci_h4p_reset_uart(struct hci_h4p_info *info);
1646 +int hci_h4p_init_uart(struct hci_h4p_info *info);
1648 +#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */
1650 +++ linux-2.6.36-rc7/drivers/bluetooth/hci_h4p/Makefile
1653 +# Makefile for the Linux Bluetooth HCI device drivers.
1656 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p.o
1658 +hci_h4p-objs := core.o fw.o uart.o sysfs.o fw-ti.o fw-csr.o
1660 +++ linux-2.6.36-rc7/drivers/bluetooth/hci_h4p/sysfs.c
1663 + * This file is part of hci_h4p bluetooth driver
1665 + * Copyright (C) 2005, 2006 Nokia Corporation.
1667 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1669 + * This program is free software; you can redistribute it and/or
1670 + * modify it under the terms of the GNU General Public License
1671 + * version 2 as published by the Free Software Foundation.
1673 + * This program is distributed in the hope that it will be useful, but
1674 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1676 + * General Public License for more details.
1678 + * You should have received a copy of the GNU General Public License
1679 + * along with this program; if not, write to the Free Software
1680 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1685 +#include <linux/kernel.h>
1686 +#include <linux/init.h>
1687 +#include <linux/device.h>
1688 +#include <linux/platform_device.h>
1690 +#include "hci_h4p.h"
1692 +#ifdef CONFIG_SYSFS
1694 +static ssize_t hci_h4p_store_bdaddr(struct device *dev, struct device_attribute *attr,
1695 + const char *buf, size_t count)
1697 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1698 + unsigned int bdaddr[6];
1701 + dev_info(info->dev, "HCI_H4P_STORE_BDADDR called\n");
1703 + ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n",
1704 + &bdaddr[0], &bdaddr[1], &bdaddr[2],
1705 + &bdaddr[3], &bdaddr[4], &bdaddr[5]);
1708 + dev_info(info->dev, "bdaddr isn't found\n");
1712 + //for (i = 0; i < 6; i++)
1713 + //info->bdaddr[i] = bdaddr[i] & 0xff;
1715 + info->bdaddr[0] = 0x00;
1716 + info->bdaddr[1] = 0x1D;
1717 + info->bdaddr[2] = 0x6E;
1718 + info->bdaddr[3] = 0xD4;
1719 + info->bdaddr[4] = 0xF0;
1720 + info->bdaddr[5] = 0x37;
1725 +static ssize_t hci_h4p_show_bdaddr(struct device *dev, struct device_attribute *attr,
1728 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1730 + return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
1739 +static DEVICE_ATTR(bdaddr, S_IRUGO | S_IWUSR, hci_h4p_show_bdaddr, hci_h4p_store_bdaddr);
1740 +int hci_h4p_sysfs_create_files(struct device *dev)
1742 + return device_create_file(dev, &dev_attr_bdaddr);
1747 +++ linux-2.6.36-rc7/drivers/bluetooth/hci_h4p/uart.c
1750 + * This file is part of hci_h4p bluetooth driver
1752 + * Copyright (C) 2005, 2006 Nokia Corporation.
1754 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1756 + * This program is free software; you can redistribute it and/or
1757 + * modify it under the terms of the GNU General Public License
1758 + * version 2 as published by the Free Software Foundation.
1760 + * This program is distributed in the hope that it will be useful, but
1761 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1762 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1763 + * General Public License for more details.
1765 + * You should have received a copy of the GNU General Public License
1766 + * along with this program; if not, write to the Free Software
1767 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1772 +#include <linux/serial_reg.h>
1773 +#include <linux/delay.h>
1774 +#include <linux/clk.h>
1776 +#include <asm/io.h>
1778 +#include "hci_h4p.h"
1780 +inline void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val)
1783 + __raw_writeb(val, info->uart_base + offset);
1784 + //outb(val, info->uart_base + (offset << 2));
1787 +inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
1790 + return (u8)__raw_readb(info->uart_base + offset);
1791 + //return (unsigned int)__raw_readb(up->membase + offset);
1792 + //return inb(info->uart_base + (offset << 2));
1795 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active)
1799 + b = hci_h4p_inb(info, UART_MCR);
1801 + b |= UART_MCR_RTS;
1803 + b &= ~UART_MCR_RTS;
1804 + hci_h4p_outb(info, UART_MCR, b);
1807 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
1811 + unsigned long timeout;
1814 + timeout = jiffies + msecs_to_jiffies(timeout_ms);
1818 + state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
1826 + if (time_after(jiffies, timeout))
1827 + return -ETIMEDOUT;
1831 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1835 + lcr = hci_h4p_inb(info, UART_LCR);
1836 + hci_h4p_outb(info, UART_LCR, 0xbf);
1837 + b = hci_h4p_inb(info, UART_EFR);
1842 + hci_h4p_outb(info, UART_EFR, b);
1843 + hci_h4p_outb(info, UART_LCR, lcr);
1846 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1848 + unsigned long flags;
1850 + spin_lock_irqsave(&info->lock, flags);
1851 + __hci_h4p_set_auto_ctsrts(info, on, which);
1852 + spin_unlock_irqrestore(&info->lock, flags);
1855 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
1857 + unsigned int divisor;
1860 + NBT_DBG("Setting speed %lu\n", speed);
1862 + if (speed >= 460800) {
1863 + divisor = UART_CLOCK / 13 / speed;
1866 + divisor = UART_CLOCK / 16 / speed;
1870 + hci_h4p_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
1871 + lcr = hci_h4p_inb(info, UART_LCR);
1872 + hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
1873 + hci_h4p_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
1874 + hci_h4p_outb(info, UART_DLM, divisor >> 8);
1875 + hci_h4p_outb(info, UART_LCR, lcr);
1876 + hci_h4p_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
1879 +int hci_h4p_reset_uart(struct hci_h4p_info *info)
1883 + /* Reset the UART */
1884 + hci_h4p_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
1885 + while (!(hci_h4p_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
1886 + if (count++ > 20000) {
1887 + dev_err(info->dev, "hci_h4p: UART reset timeout\n");
1896 +int hci_h4p_init_uart(struct hci_h4p_info *info)
1900 + err = hci_h4p_reset_uart(info);
1904 + /* Enable and setup FIFO */
1905 + hci_h4p_outb(info, UART_LCR, UART_LCR_WLEN8);
1906 + hci_h4p_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
1907 + hci_h4p_outb(info, UART_OMAP_SCR, 0x80);
1908 + hci_h4p_outb(info, UART_EFR, UART_EFR_ECB);
1909 + hci_h4p_outb(info, UART_MCR, UART_MCR_TCRTLR);
1910 + hci_h4p_outb(info, UART_TI752_TLR, 0x1f);
1911 + hci_h4p_outb(info, UART_TI752_TCR, 0xef);
1912 + hci_h4p_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
1913 + UART_FCR_CLEAR_XMIT | UART_FCR_R_TRIG_00);
1914 + hci_h4p_outb(info, UART_IER, UART_IER_RDI);
1918 --- linux-2.6.36-rc7.orig/drivers/bluetooth/Kconfig
1919 +++ linux-2.6.36-rc7/drivers/bluetooth/Kconfig
1920 @@ -173,6 +173,16 @@ config BT_HCIBTUART
1921 Say Y here to compile support for HCI UART devices into the
1922 kernel or say M to compile it as module (btuart_cs).
1925 + tristate "HCI driver with H4 Nokia extensions"
1926 + depends on BT && ARCH_OMAP
1928 + Bluetooth HCI driver with H4 extensions. This driver provides
1929 + support for H4+ Bluetooth chip with vendor-specific H4 extensions.
1931 + Say Y here to compile support for h4 extended devices into the kernel
1932 + or say M to compile it as module (hci_h4p).
1935 tristate "HCI VHCI (Virtual HCI device) driver"
1937 --- linux-2.6.36-rc7.orig/drivers/bluetooth/Makefile
1938 +++ linux-2.6.36-rc7/drivers/bluetooth/Makefile
1939 @@ -11,6 +11,7 @@ obj-$(CONFIG_BT_HCIDTL1) += dtl1_cs.o
1940 obj-$(CONFIG_BT_HCIBT3C) += bt3c_cs.o
1941 obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o
1942 obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
1943 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p/
1945 obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
1946 obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o