1 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/core.c
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/core.c 2010-08-08 12:57:24.000000000 +0200
7 + * This file is part of hci_h4p bluetooth driver
9 + * Copyright (C) 2005, 2006 Nokia Corporation.
11 + * Contact: Ville Tervo <ville.tervo@nokia.com>
13 + * This program is free software; you can redistribute it and/or
14 + * modify it under the terms of the GNU General Public License
15 + * version 2 as published by the Free Software Foundation.
17 + * This program is distributed in the hope that it will be useful, but
18 + * WITHOUT ANY WARRANTY; without even the implied warranty of
19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 + * General Public License for more details.
22 + * You should have received a copy of the GNU General Public License
23 + * along with this program; if not, write to the Free Software
24 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 +#include <linux/module.h>
31 +#include <linux/kernel.h>
32 +#include <linux/init.h>
33 +#include <linux/errno.h>
34 +#include <linux/delay.h>
35 +#include <linux/spinlock.h>
36 +#include <linux/serial_reg.h>
37 +#include <linux/skbuff.h>
38 +#include <linux/timer.h>
39 +#include <linux/device.h>
40 +#include <linux/platform_device.h>
41 +#include <linux/clk.h>
42 +#include <linux/gpio.h>
44 +#include <mach/hardware.h>
45 +#include <mach/board.h>
46 +#include <mach/irqs.h>
47 +//#include <mach/pm.h>
49 +#include <net/bluetooth/bluetooth.h>
50 +#include <net/bluetooth/hci_core.h>
51 +#include <net/bluetooth/hci.h>
55 +#define PM_TIMEOUT 200
57 +struct omap_bluetooth_config {
60 + u8 host_wakeup_gpio;
67 +/* This should be used in function that cannot release clocks */
68 +static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
70 + unsigned long flags;
72 + spin_lock_irqsave(&info->clocks_lock, flags);
73 + if (enable && !*clock) {
74 + NBT_DBG_POWER("Enabling %p\n", clock);
75 + clk_enable(info->uart_fclk);
76 +#ifdef CONFIG_ARCH_OMAP2
77 + if (cpu_is_omap24xx()) {
78 + clk_enable(info->uart_iclk);
79 + //omap2_block_sleep();
83 + if (!enable && *clock) {
84 + NBT_DBG_POWER("Disabling %p\n", clock);
85 + clk_disable(info->uart_fclk);
86 +#ifdef CONFIG_ARCH_OMAP2
87 + if (cpu_is_omap24xx()) {
88 + clk_disable(info->uart_iclk);
89 + //omap2_allow_sleep();
95 + spin_unlock_irqrestore(&info->clocks_lock, flags);
98 +/* Power management functions */
99 +static void hci_h4p_disable_tx(struct hci_h4p_info *info)
101 + NBT_DBG_POWER("\n");
103 + if (!info->pm_enabled)
106 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
109 +static void hci_h4p_enable_tx(struct hci_h4p_info *info)
111 + NBT_DBG_POWER("\n");
113 + if (!info->pm_enabled)
116 + del_timer_sync(&info->tx_pm_timer);
117 + if (info->tx_pm_enabled) {
118 + info->tx_pm_enabled = 0;
119 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
120 + gpio_set_value(info->bt_wakeup_gpio, 1);
124 +static void hci_h4p_tx_pm_timer(unsigned long data)
126 + struct hci_h4p_info *info;
128 + NBT_DBG_POWER("\n");
130 + info = (struct hci_h4p_info *)data;
132 + if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
133 + gpio_set_value(info->bt_wakeup_gpio, 0);
134 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
135 + info->tx_pm_enabled = 1;
138 + mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
142 +static void hci_h4p_disable_rx(struct hci_h4p_info *info)
144 + if (!info->pm_enabled)
147 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
150 +static void hci_h4p_enable_rx(struct hci_h4p_info *info)
152 + unsigned long flags;
154 + if (!info->pm_enabled)
157 + del_timer_sync(&info->rx_pm_timer);
158 + spin_lock_irqsave(&info->lock, flags);
159 + if (info->rx_pm_enabled) {
160 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
161 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
162 + __hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
163 + info->rx_pm_enabled = 0;
165 + spin_unlock_irqrestore(&info->lock, flags);
168 +static void hci_h4p_rx_pm_timer(unsigned long data)
170 + unsigned long flags;
171 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
173 + spin_lock_irqsave(&info->lock, flags);
174 + if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_DR)) {
175 + __hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
176 + hci_h4p_set_rts(info, 0);
177 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
178 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
179 + info->rx_pm_enabled = 1;
182 + mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
184 + spin_unlock_irqrestore(&info->lock, flags);
187 +/* Negotiation functions */
188 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
190 + NBT_DBG("Sending alive packet\n");
192 + if (!info->alive_cmd_skb)
195 + /* Keep reference to buffer so we can reuse it */
196 + info->alive_cmd_skb = skb_get(info->alive_cmd_skb);
198 + skb_queue_tail(&info->txq, info->alive_cmd_skb);
199 + tasklet_schedule(&info->tx_task);
201 + NBT_DBG("Alive packet sent\n");
206 +static void hci_h4p_alive_packet(struct hci_h4p_info *info, struct sk_buff *skb)
208 + NBT_DBG("Received alive packet\n");
209 + if (skb->data[1] == 0xCC) {
210 + complete(&info->init_completion);
216 +static int hci_h4p_send_negotiation(struct hci_h4p_info *info, struct sk_buff *skb)
218 + NBT_DBG("Sending negotiation..\n");
220 + hci_h4p_change_speed(info, INIT_SPEED);
222 + info->init_error = 0;
223 + init_completion(&info->init_completion);
224 + skb_queue_tail(&info->txq, skb);
225 + tasklet_schedule(&info->tx_task);
227 + if (!wait_for_completion_interruptible_timeout(&info->init_completion,
228 + msecs_to_jiffies(1000)))
231 + NBT_DBG("Negotiation sent\n");
232 + return info->init_error;
235 +static void hci_h4p_negotiation_packet(struct hci_h4p_info *info,
236 + struct sk_buff *skb)
240 + if (skb->data[1] == 0x20) {
241 + /* Change to operational settings */
242 + hci_h4p_set_rts(info, 0);
244 + err = hci_h4p_wait_for_cts(info, 0, 100);
248 + hci_h4p_change_speed(info, MAX_BAUD_RATE);
250 + err = hci_h4p_wait_for_cts(info, 1, 100);
254 + hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
256 + err = hci_h4p_send_alive_packet(info);
260 + dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
269 + info->init_error = err;
270 + complete(&info->init_completion);
274 +/* H4 packet handling functions */
275 +static int hci_h4p_get_hdr_len(struct hci_h4p_info *info, u8 pkt_type)
279 + switch (pkt_type) {
281 + retval = HCI_EVENT_HDR_SIZE;
284 + retval = HCI_ACL_HDR_SIZE;
287 + retval = HCI_SCO_HDR_SIZE;
296 + dev_err(info->dev, "Unknown H4 packet type 0x%.2x\n", pkt_type);
304 +static unsigned int hci_h4p_get_data_len(struct hci_h4p_info *info,
305 + struct sk_buff *skb)
308 + struct hci_event_hdr *evt_hdr;
309 + struct hci_acl_hdr *acl_hdr;
310 + struct hci_sco_hdr *sco_hdr;
312 + switch (bt_cb(skb)->pkt_type) {
314 + evt_hdr = (struct hci_event_hdr *)skb->data;
315 + retval = evt_hdr->plen;
318 + acl_hdr = (struct hci_acl_hdr *)skb->data;
319 + retval = le16_to_cpu(acl_hdr->dlen);
322 + sco_hdr = (struct hci_sco_hdr *)skb->data;
323 + retval = sco_hdr->dlen;
336 +static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
337 + struct sk_buff *skb)
340 + if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
341 + NBT_DBG("fw_event\n");
342 + hci_h4p_parse_fw_event(info, skb);
344 + hci_recv_frame(skb);
345 + NBT_DBG("Frame sent to upper layer\n");
349 +static void hci_h4p_rx_tasklet(unsigned long data)
352 + unsigned long flags;
353 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
355 + NBT_DBG("tasklet woke up\n");
356 + NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
358 + while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
359 + byte = hci_h4p_inb(info, UART_RX);
360 + if (info->garbage_bytes) {
361 + info->garbage_bytes--;
364 + if (info->rx_skb == NULL) {
365 + info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC | GFP_DMA);
366 + if (!info->rx_skb) {
367 + dev_err(info->dev, "Can't allocate memory for new packet\n");
370 + info->rx_state = WAIT_FOR_PKT_TYPE;
371 + info->rx_skb->dev = (void *)info->hdev;
373 + info->hdev->stat.byte_rx++;
374 + NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
375 + switch (info->rx_state) {
376 + case WAIT_FOR_PKT_TYPE:
377 + bt_cb(info->rx_skb)->pkt_type = byte;
378 + info->rx_count = hci_h4p_get_hdr_len(info, byte);
379 + if (info->rx_count < 0) {
380 + info->hdev->stat.err_rx++;
381 + kfree_skb(info->rx_skb);
382 + info->rx_skb = NULL;
384 + info->rx_state = WAIT_FOR_HEADER;
387 + case WAIT_FOR_HEADER:
389 + *skb_put(info->rx_skb, 1) = byte;
390 + if (info->rx_count == 0) {
391 + info->rx_count = hci_h4p_get_data_len(info, info->rx_skb);
392 + if (info->rx_count > skb_tailroom(info->rx_skb)) {
393 + dev_err(info->dev, "Frame is %ld bytes too long.\n",
394 + info->rx_count - skb_tailroom(info->rx_skb));
395 + kfree_skb(info->rx_skb);
396 + info->rx_skb = NULL;
397 + info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
400 + info->rx_state = WAIT_FOR_DATA;
402 + if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
403 + hci_h4p_negotiation_packet(info, info->rx_skb);
404 + info->rx_skb = NULL;
405 + info->rx_state = WAIT_FOR_PKT_TYPE;
408 + if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
409 + hci_h4p_alive_packet(info, info->rx_skb);
410 + info->rx_skb = NULL;
411 + info->rx_state = WAIT_FOR_PKT_TYPE;
416 + case WAIT_FOR_DATA:
418 + *skb_put(info->rx_skb, 1) = byte;
419 + if (info->rx_count == 0) {
420 + /* H4+ devices should allways send word aligned packets */
421 + if (!(info->rx_skb->len % 2)) {
422 + info->garbage_bytes++;
424 + hci_h4p_recv_frame(info, info->rx_skb);
425 + info->rx_skb = NULL;
435 + spin_lock_irqsave(&info->lock, flags);
436 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
437 + spin_unlock_irqrestore(&info->lock, flags);
439 + NBT_DBG_TRANSFER_NF("\n");
440 + NBT_DBG("rx_ended\n");
443 +static void hci_h4p_tx_tasklet(unsigned long data)
445 + unsigned int sent = 0;
446 + unsigned long flags;
447 + struct sk_buff *skb;
448 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
450 + NBT_DBG("tasklet woke up\n");
451 + NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
453 + skb = skb_dequeue(&info->txq);
455 + /* No data in buffer */
456 + NBT_DBG("skb ready\n");
457 + hci_h4p_disable_tx(info);
461 + /* Copy data to tx fifo */
462 + while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
463 + (sent < skb->len)) {
464 + NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
465 + hci_h4p_outb(info, UART_TX, skb->data[sent]);
469 + info->hdev->stat.byte_tx += sent;
470 + NBT_DBG_TRANSFER_NF("\n");
471 + if (skb->len == sent) {
474 + skb_pull(skb, sent);
475 + skb_queue_head(&info->txq, skb);
478 + spin_lock_irqsave(&info->lock, flags);
479 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_THRI);
480 + spin_unlock_irqrestore(&info->lock, flags);
483 +static irqreturn_t hci_h4p_interrupt(int irq, void *data)
485 + struct hci_h4p_info *info = (struct hci_h4p_info *)data;
488 + unsigned long flags;
492 + iir = hci_h4p_inb(info, UART_IIR);
493 + if (iir & UART_IIR_NO_INT) {
494 + dev_err(info->dev, "Interrupt but no reason irq 0x%.2x\n", iir);
495 + return IRQ_HANDLED;
498 + NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
500 + iir &= UART_IIR_ID;
502 + if (iir == UART_IIR_MSI) {
503 + msr = hci_h4p_inb(info, UART_MSR);
506 + if (iir == UART_IIR_RLSI) {
507 + hci_h4p_inb(info, UART_RX);
508 + hci_h4p_inb(info, UART_LSR);
512 + if (iir == UART_IIR_RDI) {
513 + spin_lock_irqsave(&info->lock, flags);
514 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
515 + spin_unlock_irqrestore(&info->lock, flags);
516 + tasklet_schedule(&info->rx_task);
520 + if (iir == UART_IIR_THRI) {
521 + spin_lock_irqsave(&info->lock, flags);
522 + hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_THRI);
523 + spin_unlock_irqrestore(&info->lock, flags);
524 + tasklet_schedule(&info->tx_task);
531 +static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
533 + struct hci_h4p_info *info = dev_inst;
535 + struct hci_dev *hdev;
538 + return IRQ_HANDLED;
542 + if (!test_bit(HCI_RUNNING, &hdev->flags))
543 + return IRQ_HANDLED;
545 + should_wakeup = gpio_get_value(info->host_wakeup_gpio);
546 + NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
547 + if (should_wakeup) {
548 + hci_h4p_enable_rx(info);
550 + hci_h4p_disable_rx(info);
553 + return IRQ_HANDLED;
556 +static int hci_h4p_reset(struct hci_h4p_info *info)
560 + hci_h4p_init_uart(info);
561 + hci_h4p_set_rts(info, 0);
563 + gpio_set_value(info->reset_gpio, 0);
565 + gpio_set_value(info->bt_wakeup_gpio, 1);
566 + gpio_set_value(info->reset_gpio, 1);
569 + err = hci_h4p_wait_for_cts(info, 1, 10);
571 + dev_err(info->dev, "No cts from bt chip\n");
575 + hci_h4p_set_rts(info, 1);
580 +/* hci callback functions */
581 +static int hci_h4p_hci_flush(struct hci_dev *hdev)
583 + struct hci_h4p_info *info;
584 + info = hdev->driver_data;
586 + skb_queue_purge(&info->txq);
591 +static int hci_h4p_hci_open(struct hci_dev *hdev)
593 + struct hci_h4p_info *info;
595 + struct sk_buff *neg_cmd_skb;
596 + struct sk_buff_head fw_queue;
598 + info = hdev->driver_data;
600 + if (test_bit(HCI_RUNNING, &hdev->flags))
603 + skb_queue_head_init(&fw_queue);
604 + err = hci_h4p_read_fw(info, &fw_queue);
606 + dev_err(info->dev, "Cannot read firmware\n");
609 + neg_cmd_skb = skb_dequeue(&fw_queue);
610 + if (!neg_cmd_skb) {
614 + info->alive_cmd_skb = skb_dequeue(&fw_queue);
615 + if (!info->alive_cmd_skb) {
620 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
621 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
623 + tasklet_enable(&info->tx_task);
624 + tasklet_enable(&info->rx_task);
625 + info->rx_state = WAIT_FOR_PKT_TYPE;
626 + info->rx_count = 0;
627 + info->garbage_bytes = 0;
628 + info->rx_skb = NULL;
629 + info->pm_enabled = 0;
630 + init_completion(&info->fw_completion);
632 + err = hci_h4p_reset(info);
636 + err = hci_h4p_send_negotiation(info, neg_cmd_skb);
637 + neg_cmd_skb = NULL;
641 + err = hci_h4p_send_fw(info, &fw_queue);
643 + dev_err(info->dev, "Sending firmware failed.\n");
647 + kfree_skb(info->alive_cmd_skb);
648 + info->alive_cmd_skb = NULL;
649 + info->pm_enabled = 1;
650 + info->tx_pm_enabled = 1;
651 + info->rx_pm_enabled = 0;
652 + set_bit(HCI_RUNNING, &hdev->flags);
654 + NBT_DBG("hci up and running\n");
658 + hci_h4p_hci_flush(hdev);
659 + tasklet_disable(&info->tx_task);
660 + tasklet_disable(&info->rx_task);
661 + hci_h4p_reset_uart(info);
662 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
663 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
664 + gpio_set_value(info->reset_gpio, 0);
665 + gpio_set_value(info->bt_wakeup_gpio, 0);
666 + skb_queue_purge(&fw_queue);
667 + kfree_skb(neg_cmd_skb);
668 + neg_cmd_skb = NULL;
669 + kfree_skb(info->alive_cmd_skb);
670 + info->alive_cmd_skb = NULL;
671 + kfree_skb(info->rx_skb);
676 +static int hci_h4p_hci_close(struct hci_dev *hdev)
678 + struct hci_h4p_info *info = hdev->driver_data;
680 + if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
683 + hci_h4p_hci_flush(hdev);
684 + del_timer_sync(&info->tx_pm_timer);
685 + del_timer_sync(&info->rx_pm_timer);
686 + tasklet_disable(&info->tx_task);
687 + tasklet_disable(&info->rx_task);
688 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
689 + hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
690 + hci_h4p_reset_uart(info);
691 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
692 + hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
693 + gpio_set_value(info->reset_gpio, 0);
694 + gpio_set_value(info->bt_wakeup_gpio, 0);
695 + kfree_skb(info->rx_skb);
700 +static void hci_h4p_hci_destruct(struct hci_dev *hdev)
704 +static int hci_h4p_hci_send_frame(struct sk_buff *skb)
706 + struct hci_h4p_info *info;
707 + struct hci_dev *hdev = (struct hci_dev *)skb->dev;
711 + printk(KERN_WARNING "hci_h4p: Frame for unknown device\n");
715 + NBT_DBG("dev %p, skb %p\n", hdev, skb);
717 + info = hdev->driver_data;
719 + if (!test_bit(HCI_RUNNING, &hdev->flags)) {
720 + dev_warn(info->dev, "Frame for non-running device\n");
724 + switch (bt_cb(skb)->pkt_type) {
725 + case HCI_COMMAND_PKT:
726 + hdev->stat.cmd_tx++;
728 + case HCI_ACLDATA_PKT:
729 + hdev->stat.acl_tx++;
731 + case HCI_SCODATA_PKT:
732 + hdev->stat.sco_tx++;
736 + /* Push frame type to skb */
737 + *skb_push(skb, 1) = (bt_cb(skb)->pkt_type);
738 + /* We should allways send word aligned data to h4+ devices */
739 + if (skb->len % 2) {
740 + err = skb_pad(skb, 1);
745 + hci_h4p_enable_tx(info);
746 + skb_queue_tail(&info->txq, skb);
747 + tasklet_schedule(&info->tx_task);
752 +static int hci_h4p_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
754 + return -ENOIOCTLCMD;
757 +static int hci_h4p_register_hdev(struct hci_h4p_info *info)
759 + struct hci_dev *hdev;
761 + /* Initialize and register HCI device */
763 + hdev = hci_alloc_dev();
765 + dev_err(info->dev, "Can't allocate memory for device\n");
770 + hdev->type = HCI_UART;
771 + hdev->driver_data = info;
773 + hdev->open = hci_h4p_hci_open;
774 + hdev->close = hci_h4p_hci_close;
775 + hdev->flush = hci_h4p_hci_flush;
776 + hdev->send = hci_h4p_hci_send_frame;
777 + hdev->destruct = hci_h4p_hci_destruct;
778 + hdev->ioctl = hci_h4p_hci_ioctl;
780 + hdev->owner = THIS_MODULE;
782 + if (hci_register_dev(hdev) < 0) {
783 + dev_err(info->dev, "hci_h4p: Can't register HCI device %s.\n", hdev->name);
790 +static int hci_h4p_probe(struct platform_device *pdev)
792 + struct omap_bluetooth_config *bt_config;
793 + struct hci_h4p_info *info;
796 + dev_info(&pdev->dev, "Registering HCI H4P device\n");
797 + info = kzalloc(sizeof(struct hci_h4p_info), GFP_KERNEL);
801 + info->dev = &pdev->dev;
802 + info->pm_enabled = 0;
803 + info->tx_pm_enabled = 0;
804 + info->rx_pm_enabled = 0;
805 + info->garbage_bytes = 0;
806 + info->tx_clocks_en = 0;
807 + info->rx_clocks_en = 0;
808 + tasklet_init(&info->tx_task, hci_h4p_tx_tasklet, (unsigned long)info);
809 + tasklet_init(&info->rx_task, hci_h4p_rx_tasklet, (unsigned long)info);
810 + /* hci_h4p_hci_open assumes that tasklet is disabled in startup */
811 + tasklet_disable(&info->tx_task);
812 + tasklet_disable(&info->rx_task);
813 + spin_lock_init(&info->lock);
814 + spin_lock_init(&info->clocks_lock);
815 + skb_queue_head_init(&info->txq);
816 + init_timer(&info->tx_pm_timer);
817 + info->tx_pm_timer.function = hci_h4p_tx_pm_timer;
818 + info->tx_pm_timer.data = (unsigned long)info;
819 + init_timer(&info->rx_pm_timer);
820 + info->rx_pm_timer.function = hci_h4p_rx_pm_timer;
821 + info->rx_pm_timer.data = (unsigned long)info;
823 + if (pdev->dev.platform_data == NULL) {
824 + dev_err(&pdev->dev, "Could not get Bluetooth config data\n");
828 + bt_config = pdev->dev.platform_data;
829 + info->chip_type = bt_config->chip_type;
830 + info->bt_wakeup_gpio = bt_config->bt_wakeup_gpio;
831 + info->host_wakeup_gpio = bt_config->host_wakeup_gpio;
832 + info->reset_gpio = bt_config->reset_gpio;
833 + info->bt_sysclk = bt_config->bt_sysclk;
835 + NBT_DBG("RESET gpio: %d\n", info->reset_gpio);
836 + NBT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
837 + NBT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
838 + NBT_DBG("Uart: %d\n", bt_config->bt_uart);
839 + NBT_DBG("sysclk: %d\n", info->bt_sysclk);
841 + err = gpio_request(info->reset_gpio, "BT reset");
843 + dev_err(&pdev->dev, "Cannot get GPIO line %d\n",
849 + err = gpio_request(info->bt_wakeup_gpio, "BT wakeup");
852 + dev_err(info->dev, "Cannot get GPIO line 0x%d",
853 + info->bt_wakeup_gpio);
854 + gpio_free(info->reset_gpio);
859 + err = gpio_request(info->host_wakeup_gpio, "BT host wakeup");
862 + dev_err(info->dev, "Cannot get GPIO line %d",
863 + info->host_wakeup_gpio);
864 + gpio_free(info->reset_gpio);
865 + gpio_free(info->bt_wakeup_gpio);
870 + gpio_direction_output(info->reset_gpio, 0);
871 + gpio_direction_output(info->bt_wakeup_gpio, 0);
872 + gpio_direction_input(info->host_wakeup_gpio);
874 + switch (bt_config->bt_uart) {
876 + if (cpu_is_omap16xx()) {
878 + info->uart_fclk = clk_get(NULL, "uart1_ck");
879 + } else if (cpu_is_omap24xx()) {
880 + irq = INT_24XX_UART1_IRQ;
881 + info->uart_iclk = clk_get(NULL, "uart1_ick");
882 + info->uart_fclk = clk_get(NULL, "uart1_fck");
884 + /* FIXME: Use platform_get_resource for the port */
885 + info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
886 + if (!info->uart_base)
890 + if (cpu_is_omap16xx()) {
892 + info->uart_fclk = clk_get(NULL, "uart2_ck");
894 + irq = INT_24XX_UART2_IRQ;
895 + info->uart_iclk = clk_get(NULL, "uart2_ick");
896 + info->uart_fclk = clk_get(NULL, "uart2_fck");
898 + /* FIXME: Use platform_get_resource for the port */
899 + info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
900 + if (!info->uart_base)
904 + if (cpu_is_omap16xx()) {
906 + info->uart_fclk = clk_get(NULL, "uart3_ck");
908 + irq = INT_24XX_UART3_IRQ;
909 + info->uart_iclk = clk_get(NULL, "uart3_ick");
910 + info->uart_fclk = clk_get(NULL, "uart3_fck");
912 + /* FIXME: Use platform_get_resource for the port */
913 + info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
914 + if (!info->uart_base)
918 + dev_err(info->dev, "No uart defined\n");
923 + err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
925 + dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
929 + err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
930 + hci_h4p_wakeup_interrupt,
931 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
932 + "hci_h4p_wkup", (void *)info);
934 + dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
935 + gpio_to_irq(info->host_wakeup_gpio));
936 + free_irq(irq, (void *)info);
940 + hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
941 + hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
942 + err = hci_h4p_init_uart(info);
945 + err = hci_h4p_reset(info);
948 + err = hci_h4p_wait_for_cts(info, 1, 10);
951 + hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
953 + platform_set_drvdata(pdev, info);
954 + err = hci_h4p_sysfs_create_files(info->dev);
958 + if (hci_h4p_register_hdev(info) < 0) {
959 + dev_err(info->dev, "failed to register hci_h4p hci device\n");
962 + gpio_set_value(info->reset_gpio, 0);
967 + free_irq(irq, (void *)info);
968 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *)info);
970 + gpio_set_value(info->reset_gpio, 0);
971 + gpio_free(info->reset_gpio);
972 + gpio_free(info->bt_wakeup_gpio);
973 + gpio_free(info->host_wakeup_gpio);
980 +static int hci_h4p_remove(struct platform_device *dev)
982 + struct hci_h4p_info *info;
984 + info = platform_get_drvdata(dev);
986 + hci_h4p_hci_close(info->hdev);
987 + free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *) info);
988 + hci_free_dev(info->hdev);
989 + gpio_free(info->reset_gpio);
990 + gpio_free(info->bt_wakeup_gpio);
991 + gpio_free(info->host_wakeup_gpio);
992 + free_irq(info->irq, (void *) info);
998 +static struct platform_driver hci_h4p_driver = {
999 + .probe = hci_h4p_probe,
1000 + .remove = hci_h4p_remove,
1002 + .name = "hci_h4p",
1006 +static int __init hci_h4p_init(void)
1010 + /* Register the driver with LDM */
1011 + err = platform_driver_register(&hci_h4p_driver);
1013 + printk(KERN_WARNING "failed to register hci_h4p driver\n");
1018 +static void __exit hci_h4p_exit(void)
1020 + platform_driver_unregister(&hci_h4p_driver);
1023 +module_init(hci_h4p_init);
1024 +module_exit(hci_h4p_exit);
1026 +MODULE_DESCRIPTION("h4 driver with nokia extensions");
1027 +MODULE_LICENSE("GPL");
1028 +MODULE_AUTHOR("Ville Tervo");
1029 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/fw.c
1030 ===================================================================
1031 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1032 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/fw.c 2010-08-08 12:57:24.000000000 +0200
1035 + * This file is part of hci_h4p bluetooth driver
1037 + * Copyright (C) 2005, 2006 Nokia Corporation.
1039 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1041 + * This program is free software; you can redistribute it and/or
1042 + * modify it under the terms of the GNU General Public License
1043 + * version 2 as published by the Free Software Foundation.
1045 + * This program is distributed in the hope that it will be useful, but
1046 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1047 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1048 + * General Public License for more details.
1050 + * You should have received a copy of the GNU General Public License
1051 + * along with this program; if not, write to the Free Software
1052 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1057 +#include <linux/skbuff.h>
1058 +#include <linux/firmware.h>
1059 +#include <linux/clk.h>
1061 +#include <net/bluetooth/bluetooth.h>
1063 +#include "hci_h4p.h"
1065 +#define BT_CHIP_TI 2
1066 +#define BT_CHIP_CSR 1
1070 +/* Firmware handling */
1071 +static int hci_h4p_open_firmware(struct hci_h4p_info *info,
1072 + const struct firmware **fw_entry)
1077 + NBT_DBG_FW("Opening %d firmware\n", info->chip_type);
1078 + switch (info->chip_type) {
1080 + err = request_firmware(fw_entry, "brf6150fw.bin", info->dev);
1083 + err = request_firmware(fw_entry, "bc4fw.bin", info->dev);
1086 + dev_err(info->dev, "Invalid chip type\n");
1094 +static void hci_h4p_close_firmware(const struct firmware *fw_entry)
1096 + release_firmware(fw_entry);
1099 +/* Read fw. Return length of the command. If no more commands in
1100 + * fw 0 is returned. In error case return value is negative.
1102 +static int hci_h4p_read_fw_cmd(struct hci_h4p_info *info, struct sk_buff **skb,
1103 + const struct firmware *fw_entry, int how)
1105 + unsigned int cmd_len;
1107 + if (fw_pos >= fw_entry->size) {
1111 + cmd_len = fw_entry->data[fw_pos++];
1115 + if (fw_pos + cmd_len > fw_entry->size) {
1116 + dev_err(info->dev, "Corrupted firmware image\n");
1120 + *skb = bt_skb_alloc(cmd_len, how);
1122 + dev_err(info->dev, "Cannot reserve memory for buffer\n");
1125 + memcpy(skb_put(*skb, cmd_len), &fw_entry->data[fw_pos], cmd_len);
1127 + fw_pos += cmd_len;
1129 + return (*skb)->len;
1132 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1134 + const struct firmware *fw_entry = NULL;
1135 + struct sk_buff *skb = NULL;
1138 + err = hci_h4p_open_firmware(info, &fw_entry);
1139 + if (err < 0 || !fw_entry)
1142 + while ((err = hci_h4p_read_fw_cmd(info, &skb, fw_entry, GFP_KERNEL))) {
1143 + if (err < 0 || !skb)
1146 + skb_queue_tail(fw_queue, skb);
1150 + hci_h4p_close_firmware(fw_entry);
1154 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1158 + switch(info->chip_type) {
1160 + err = hci_h4p_bc4_send_fw(info, fw_queue);
1163 + err = hci_h4p_brf6150_send_fw(info, fw_queue);
1166 + dev_err(info->dev, "Don't know how to send firmware\n");
1173 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1175 + switch (info->chip_type) {
1177 + hci_h4p_bc4_parse_fw_event(info, skb);
1180 + hci_h4p_brf6150_parse_fw_event(info, skb);
1183 + dev_err(info->dev, "Don't know how to parse fw event\n");
1184 + info->fw_error = -EINVAL;
1189 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/fw-csr.c
1190 ===================================================================
1191 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1192 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/fw-csr.c 2010-08-08 12:57:25.000000000 +0200
1195 + * This file is part of hci_h4p bluetooth driver
1197 + * Copyright (C) 2005, 2006 Nokia Corporation.
1199 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1201 + * This program is free software; you can redistribute it and/or
1202 + * modify it under the terms of the GNU General Public License
1203 + * version 2 as published by the Free Software Foundation.
1205 + * This program is distributed in the hope that it will be useful, but
1206 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1207 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1208 + * General Public License for more details.
1210 + * You should have received a copy of the GNU General Public License
1211 + * along with this program; if not, write to the Free Software
1212 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1217 +#include <linux/skbuff.h>
1218 +#include <linux/delay.h>
1219 +#include <linux/serial_reg.h>
1221 +#include "hci_h4p.h"
1223 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
1225 + /* Check if this is fw packet */
1226 + if (skb->data[0] != 0xff) {
1227 + hci_recv_frame(skb);
1231 + if (skb->data[11] || skb->data[12]) {
1232 + dev_err(info->dev, "Firmware sending command failed\n");
1233 + info->fw_error = -EPROTO;
1237 + complete(&info->fw_completion);
1240 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1241 + struct sk_buff_head *fw_queue)
1243 + struct sk_buff *skb;
1244 + unsigned int offset;
1245 + int retries, count, i;
1247 + info->fw_error = 0;
1249 + NBT_DBG_FW("Sending firmware\n");
1250 + skb = skb_dequeue(fw_queue);
1255 + info->bdaddr[0] = 0x00;
1256 + info->bdaddr[1] = 0x1D;
1257 + info->bdaddr[2] = 0x6E;
1258 + info->bdaddr[3] = 0xD4;
1259 + info->bdaddr[4] = 0xF0;
1260 + info->bdaddr[5] = 0x37;
1262 + /* Check if this is bd_address packet */
1263 + if (skb->data[15] == 0x01 && skb->data[16] == 0x00) {
1264 + dev_info(info->dev, "bd_address packet found\n");
1266 + skb->data[offset + 1] = 0x00;
1267 + skb->data[offset + 5] = 0x00;
1268 + skb->data[offset + 7] = info->bdaddr[0];
1269 + skb->data[offset + 6] = info->bdaddr[1];
1270 + skb->data[offset + 4] = info->bdaddr[2];
1271 + skb->data[offset + 0] = info->bdaddr[3];
1272 + skb->data[offset + 3] = info->bdaddr[4];
1273 + skb->data[offset + 2] = info->bdaddr[5];
1276 + for (i = 0; i < 6; i++) {
1277 + if (info->bdaddr[i] != 0x00)
1282 + dev_info(info->dev, "Valid bluetooth address not found.\n");
1287 + for (count = 1; ; count++) {
1288 + NBT_DBG_FW("Sending firmware command %d\n", count);
1289 + init_completion(&info->fw_completion);
1290 + skb_queue_tail(&info->txq, skb);
1291 + tasklet_schedule(&info->tx_task);
1293 + skb = skb_dequeue(fw_queue);
1297 + if (!wait_for_completion_timeout(&info->fw_completion,
1298 + msecs_to_jiffies(1000))) {
1299 + dev_err(info->dev, "No reply to fw command\n");
1300 + return -ETIMEDOUT;
1303 + if (info->fw_error) {
1304 + dev_err(info->dev, "FW error\n");
1309 + /* Wait for chip warm reset */
1311 + while ((!skb_queue_empty(&info->txq) ||
1312 + !(hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT)) &&
1317 + dev_err(info->dev, "Transmitter not empty\n");
1318 + return -ETIMEDOUT;
1321 + hci_h4p_change_speed(info, BC4_MAX_BAUD_RATE);
1323 + if (hci_h4p_wait_for_cts(info, 1, 100)) {
1324 + dev_err(info->dev, "cts didn't go down after final speed change\n");
1325 + return -ETIMEDOUT;
1330 + init_completion(&info->init_completion);
1331 + hci_h4p_send_alive_packet(info);
1333 + } while (!wait_for_completion_timeout(&info->init_completion, 100) &&
1337 + dev_err(info->dev, "No alive reply after speed change\n");
1338 + return -ETIMEDOUT;
1343 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/fw-ti.c
1344 ===================================================================
1345 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1346 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/fw-ti.c 2010-08-08 12:57:26.000000000 +0200
1349 + * This file is part of hci_h4p bluetooth driver
1351 + * Copyright (C) 2005, 2006 Nokia Corporation.
1353 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1355 + * This program is free software; you can redistribute it and/or
1356 + * modify it under the terms of the GNU General Public License
1357 + * version 2 as published by the Free Software Foundation.
1359 + * This program is distributed in the hope that it will be useful, but
1360 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1361 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1362 + * General Public License for more details.
1364 + * You should have received a copy of the GNU General Public License
1365 + * along with this program; if not, write to the Free Software
1366 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1371 +#include <linux/skbuff.h>
1373 +#include "hci_h4p.h"
1375 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1376 + struct sk_buff *skb)
1378 + struct hci_fw_event *ev;
1381 + if (bt_cb(skb)->pkt_type != H4_EVT_PKT) {
1382 + dev_err(info->dev, "Got non event fw packet.\n");
1387 + ev = (struct hci_fw_event *)skb->data;
1388 + if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
1389 + dev_err(info->dev, "Got non cmd complete fw event\n");
1394 + if (ev->status != 0) {
1395 + dev_err(info->dev, "Got error status from fw command\n");
1401 + info->fw_error = err;
1402 + complete(&info->fw_completion);
1405 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue)
1407 + struct sk_buff *skb;
1410 + info->fw_error = 0;
1412 + while ((skb = skb_dequeue(fw_queue)) != NULL) {
1413 + /* We should allways send word aligned data to h4+ devices */
1414 + if (skb->len % 2) {
1415 + err = skb_pad(skb, 1);
1420 + init_completion(&info->fw_completion);
1421 + skb_queue_tail(&info->txq, skb);
1422 + tasklet_schedule(&info->tx_task);
1424 + if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
1425 + dev_err(info->dev, "Timeout while sending brf6150 fw\n");
1426 + return -ETIMEDOUT;
1429 + if (info->fw_error) {
1430 + dev_err(info->dev, "There was fw_error while sending bfr6150 fw\n");
1434 + NBT_DBG_FW("Firmware sent\n");
1438 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/hci_h4p.h
1439 ===================================================================
1440 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1441 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/hci_h4p.h 2010-08-08 12:57:26.000000000 +0200
1444 + * This file is part of hci_h4p bluetooth driver
1446 + * Copyright (C) 2005, 2006 Nokia Corporation.
1448 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1450 + * This program is free software; you can redistribute it and/or
1451 + * modify it under the terms of the GNU General Public License
1452 + * version 2 as published by the Free Software Foundation.
1454 + * This program is distributed in the hope that it will be useful, but
1455 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1456 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1457 + * General Public License for more details.
1459 + * You should have received a copy of the GNU General Public License
1460 + * along with this program; if not, write to the Free Software
1461 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1466 +#include <mach/board.h>
1468 +#include <net/bluetooth/bluetooth.h>
1469 +#include <net/bluetooth/hci_core.h>
1470 +#include <net/bluetooth/hci.h>
1472 +#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
1473 +#define __DRIVERS_BLUETOOTH_HCI_H4P_H
1475 +#define UART_SYSC_OMAP_RESET 0x03
1476 +#define UART_SYSS_RESETDONE 0x01
1477 +#define UART_OMAP_SCR_EMPTY_THR 0x08
1478 +#define UART_OMAP_SCR_WAKEUP 0x10
1479 +#define UART_OMAP_SSR_WAKEUP 0x02
1480 +#define UART_OMAP_SSR_TXFULL 0x01
1483 +#define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1485 +#define NBT_DBG(...)
1489 +#define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1491 +#define NBT_DBG_FW(...)
1495 +#define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1497 +#define NBT_DBG_POWER(...)
1501 +#define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1503 +#define NBT_DBG_TRANSFER(...)
1507 +#define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
1509 +#define NBT_DBG_TRANSFER_NF(...)
1513 +#define NBT_DBG_DMA(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
1515 +#define NBT_DBG_DMA(...)
1518 +struct hci_h4p_info {
1519 + struct hci_dev *hdev;
1522 + void __iomem *uart_base;
1523 + unsigned long uart_phys_base;
1525 + struct device *dev;
1528 + u8 bt_wakeup_gpio;
1529 + u8 host_wakeup_gpio;
1534 + struct sk_buff_head fw_queue;
1535 + struct sk_buff *alive_cmd_skb;
1536 + struct completion init_completion;
1537 + struct completion fw_completion;
1541 + struct sk_buff_head txq;
1542 + struct tasklet_struct tx_task;
1544 + struct sk_buff *rx_skb;
1546 + unsigned long rx_state;
1547 + unsigned long garbage_bytes;
1548 + struct tasklet_struct rx_task;
1551 + int tx_pm_enabled;
1552 + int rx_pm_enabled;
1553 + struct timer_list tx_pm_timer;
1554 + struct timer_list rx_pm_timer;
1558 + spinlock_t clocks_lock;
1559 + struct clk *uart_iclk;
1560 + struct clk *uart_fclk;
1563 +#define MAX_BAUD_RATE 921600
1564 +#define BC4_MAX_BAUD_RATE 3692300
1565 +#define UART_CLOCK 48000000
1566 +#define BT_INIT_DIVIDER 320
1567 +#define BT_BAUDRATE_DIVIDER 384000000
1568 +#define BT_SYSCLK_DIV 1000
1569 +#define INIT_SPEED 120000
1571 +#define H4_TYPE_SIZE 1
1573 +/* H4+ packet types */
1574 +#define H4_CMD_PKT 0x01
1575 +#define H4_ACL_PKT 0x02
1576 +#define H4_SCO_PKT 0x03
1577 +#define H4_EVT_PKT 0x04
1578 +#define H4_NEG_PKT 0x06
1579 +#define H4_ALIVE_PKT 0x07
1582 +#define WAIT_FOR_PKT_TYPE 1
1583 +#define WAIT_FOR_HEADER 2
1584 +#define WAIT_FOR_DATA 3
1586 +struct hci_fw_event {
1587 + struct hci_event_hdr hev;
1588 + struct hci_ev_cmd_complete cmd;
1590 +} __attribute__ ((packed));
1592 +struct hci_bc4_set_bdaddr {
1594 + struct hci_command_hdr cmd_hdr;
1595 +} __attribute__ ((packed));
1597 +int hci_h4p_send_alive_packet(struct hci_h4p_info *info);
1599 +void hci_h4p_bc4_parse_fw_event(struct hci_h4p_info *info,
1600 + struct sk_buff *skb);
1601 +int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
1602 + struct sk_buff_head *fw_queue);
1604 +void hci_h4p_brf6150_parse_fw_event(struct hci_h4p_info *info,
1605 + struct sk_buff *skb);
1606 +int hci_h4p_brf6150_send_fw(struct hci_h4p_info *info,
1607 + struct sk_buff_head *fw_queue);
1609 +int hci_h4p_read_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1610 +int hci_h4p_send_fw(struct hci_h4p_info *info, struct sk_buff_head *fw_queue);
1611 +void hci_h4p_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb);
1613 +int hci_h4p_sysfs_create_files(struct device *dev);
1615 +void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val);
1616 +u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset);
1617 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active);
1618 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active, int timeout_ms);
1619 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1620 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which);
1621 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed);
1622 +int hci_h4p_reset_uart(struct hci_h4p_info *info);
1623 +int hci_h4p_init_uart(struct hci_h4p_info *info);
1625 +#endif /* __DRIVERS_BLUETOOTH_HCI_H4P_H */
1626 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/Makefile
1627 ===================================================================
1628 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1629 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/Makefile 2010-08-08 12:57:27.000000000 +0200
1632 +# Makefile for the Linux Bluetooth HCI device drivers.
1635 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p.o
1637 +hci_h4p-objs := core.o fw.o uart.o sysfs.o fw-ti.o fw-csr.o
1638 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/sysfs.c
1639 ===================================================================
1640 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1641 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/sysfs.c 2010-08-08 12:57:27.000000000 +0200
1644 + * This file is part of hci_h4p bluetooth driver
1646 + * Copyright (C) 2005, 2006 Nokia Corporation.
1648 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1650 + * This program is free software; you can redistribute it and/or
1651 + * modify it under the terms of the GNU General Public License
1652 + * version 2 as published by the Free Software Foundation.
1654 + * This program is distributed in the hope that it will be useful, but
1655 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1656 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1657 + * General Public License for more details.
1659 + * You should have received a copy of the GNU General Public License
1660 + * along with this program; if not, write to the Free Software
1661 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1666 +#include <linux/kernel.h>
1667 +#include <linux/init.h>
1668 +#include <linux/device.h>
1669 +#include <linux/platform_device.h>
1671 +#include "hci_h4p.h"
1673 +#ifdef CONFIG_SYSFS
1675 +static ssize_t hci_h4p_store_bdaddr(struct device *dev, struct device_attribute *attr,
1676 + const char *buf, size_t count)
1678 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1679 + unsigned int bdaddr[6];
1682 + dev_info(info->dev, "HCI_H4P_STORE_BDADDR called\n");
1684 + ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n",
1685 + &bdaddr[0], &bdaddr[1], &bdaddr[2],
1686 + &bdaddr[3], &bdaddr[4], &bdaddr[5]);
1689 + dev_info(info->dev, "bdaddr isn't found\n");
1693 + //for (i = 0; i < 6; i++)
1694 + //info->bdaddr[i] = bdaddr[i] & 0xff;
1696 + info->bdaddr[0] = 0x00;
1697 + info->bdaddr[1] = 0x1D;
1698 + info->bdaddr[2] = 0x6E;
1699 + info->bdaddr[3] = 0xD4;
1700 + info->bdaddr[4] = 0xF0;
1701 + info->bdaddr[5] = 0x37;
1706 +static ssize_t hci_h4p_show_bdaddr(struct device *dev, struct device_attribute *attr,
1709 + struct hci_h4p_info *info = (struct hci_h4p_info*)dev_get_drvdata(dev);
1711 + return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
1720 +static DEVICE_ATTR(bdaddr, S_IRUGO | S_IWUSR, hci_h4p_show_bdaddr, hci_h4p_store_bdaddr);
1721 +int hci_h4p_sysfs_create_files(struct device *dev)
1723 + return device_create_file(dev, &dev_attr_bdaddr);
1727 Index: linux-2.6.35/drivers/bluetooth/hci_h4p/uart.c
1728 ===================================================================
1729 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1730 +++ linux-2.6.35/drivers/bluetooth/hci_h4p/uart.c 2010-08-08 12:57:28.000000000 +0200
1733 + * This file is part of hci_h4p bluetooth driver
1735 + * Copyright (C) 2005, 2006 Nokia Corporation.
1737 + * Contact: Ville Tervo <ville.tervo@nokia.com>
1739 + * This program is free software; you can redistribute it and/or
1740 + * modify it under the terms of the GNU General Public License
1741 + * version 2 as published by the Free Software Foundation.
1743 + * This program is distributed in the hope that it will be useful, but
1744 + * WITHOUT ANY WARRANTY; without even the implied warranty of
1745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1746 + * General Public License for more details.
1748 + * You should have received a copy of the GNU General Public License
1749 + * along with this program; if not, write to the Free Software
1750 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1755 +#include <linux/serial_reg.h>
1756 +#include <linux/delay.h>
1757 +#include <linux/clk.h>
1759 +#include <asm/io.h>
1761 +#include "hci_h4p.h"
1763 +inline void hci_h4p_outb(struct hci_h4p_info *info, unsigned int offset, u8 val)
1766 + __raw_writeb(val, info->uart_base + offset);
1767 + //outb(val, info->uart_base + (offset << 2));
1770 +inline u8 hci_h4p_inb(struct hci_h4p_info *info, unsigned int offset)
1773 + return (u8)__raw_readb(info->uart_base + offset);
1774 + //return (unsigned int)__raw_readb(up->membase + offset);
1775 + //return inb(info->uart_base + (offset << 2));
1778 +void hci_h4p_set_rts(struct hci_h4p_info *info, int active)
1782 + b = hci_h4p_inb(info, UART_MCR);
1784 + b |= UART_MCR_RTS;
1786 + b &= ~UART_MCR_RTS;
1787 + hci_h4p_outb(info, UART_MCR, b);
1790 +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
1794 + unsigned long timeout;
1797 + timeout = jiffies + msecs_to_jiffies(timeout_ms);
1801 + state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
1809 + if (time_after(jiffies, timeout))
1810 + return -ETIMEDOUT;
1814 +void __hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1818 + lcr = hci_h4p_inb(info, UART_LCR);
1819 + hci_h4p_outb(info, UART_LCR, 0xbf);
1820 + b = hci_h4p_inb(info, UART_EFR);
1825 + hci_h4p_outb(info, UART_EFR, b);
1826 + hci_h4p_outb(info, UART_LCR, lcr);
1829 +void hci_h4p_set_auto_ctsrts(struct hci_h4p_info *info, int on, u8 which)
1831 + unsigned long flags;
1833 + spin_lock_irqsave(&info->lock, flags);
1834 + __hci_h4p_set_auto_ctsrts(info, on, which);
1835 + spin_unlock_irqrestore(&info->lock, flags);
1838 +void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
1840 + unsigned int divisor;
1843 + NBT_DBG("Setting speed %lu\n", speed);
1845 + if (speed >= 460800) {
1846 + divisor = UART_CLOCK / 13 / speed;
1849 + divisor = UART_CLOCK / 16 / speed;
1853 + hci_h4p_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
1854 + lcr = hci_h4p_inb(info, UART_LCR);
1855 + hci_h4p_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
1856 + hci_h4p_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
1857 + hci_h4p_outb(info, UART_DLM, divisor >> 8);
1858 + hci_h4p_outb(info, UART_LCR, lcr);
1859 + hci_h4p_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
1862 +int hci_h4p_reset_uart(struct hci_h4p_info *info)
1866 + /* Reset the UART */
1867 + hci_h4p_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
1868 + while (!(hci_h4p_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
1869 + if (count++ > 20000) {
1870 + dev_err(info->dev, "hci_h4p: UART reset timeout\n");
1879 +int hci_h4p_init_uart(struct hci_h4p_info *info)
1883 + err = hci_h4p_reset_uart(info);
1887 + /* Enable and setup FIFO */
1888 + hci_h4p_outb(info, UART_LCR, UART_LCR_WLEN8);
1889 + hci_h4p_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
1890 + hci_h4p_outb(info, UART_OMAP_SCR, 0x80);
1891 + hci_h4p_outb(info, UART_EFR, UART_EFR_ECB);
1892 + hci_h4p_outb(info, UART_MCR, UART_MCR_TCRTLR);
1893 + hci_h4p_outb(info, UART_TI752_TLR, 0x1f);
1894 + hci_h4p_outb(info, UART_TI752_TCR, 0xef);
1895 + hci_h4p_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
1896 + UART_FCR_CLEAR_XMIT | UART_FCR_R_TRIG_00);
1897 + hci_h4p_outb(info, UART_IER, UART_IER_RDI);
1901 Index: linux-2.6.35/drivers/bluetooth/Kconfig
1902 ===================================================================
1903 --- linux-2.6.35.orig/drivers/bluetooth/Kconfig 2010-08-08 12:56:10.000000000 +0200
1904 +++ linux-2.6.35/drivers/bluetooth/Kconfig 2010-08-08 12:57:29.000000000 +0200
1905 @@ -161,6 +161,16 @@ config BT_HCIBTUART
1906 Say Y here to compile support for HCI UART devices into the
1907 kernel or say M to compile it as module (btuart_cs).
1910 + tristate "HCI driver with H4 Nokia extensions"
1911 + depends on BT && ARCH_OMAP
1913 + Bluetooth HCI driver with H4 extensions. This driver provides
1914 + support for H4+ Bluetooth chip with vendor-specific H4 extensions.
1916 + Say Y here to compile support for h4 extended devices into the kernel
1917 + or say M to compile it as module (hci_h4p).
1920 tristate "HCI VHCI (Virtual HCI device) driver"
1922 Index: linux-2.6.35/drivers/bluetooth/Makefile
1923 ===================================================================
1924 --- linux-2.6.35.orig/drivers/bluetooth/Makefile 2010-08-08 12:56:10.000000000 +0200
1925 +++ linux-2.6.35/drivers/bluetooth/Makefile 2010-08-08 12:57:29.000000000 +0200
1926 @@ -11,6 +11,7 @@ obj-$(CONFIG_BT_HCIDTL1) += dtl1_cs.o
1927 obj-$(CONFIG_BT_HCIBT3C) += bt3c_cs.o
1928 obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o
1929 obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
1930 +obj-$(CONFIG_BT_HCIH4P) += hci_h4p/
1932 obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
1933 obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o