2 * linux/drivers/bluetooth/brf6150/brf6150.c
4 * Copyright (C) 2005 Nokia Corporation
5 * Written by Ville Tervo <ville.tervo@nokia.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/init.h>
26 #include <linux/errno.h>
27 #include <linux/delay.h>
28 #include <linux/spinlock.h>
29 #include <linux/serial_reg.h>
30 #include <linux/skbuff.h>
31 #include <linux/firmware.h>
32 #include <linux/irq.h>
33 #include <linux/timer.h>
34 #include <linux/clk.h>
35 #include <linux/platform_device.h>
36 #include <linux/gpio.h>
38 #include <mach/hardware.h>
39 #include <mach/board.h>
40 #include <mach/irqs.h>
41 #include <mach/board-nokia.h>
43 #include <net/bluetooth/bluetooth.h>
44 #include <net/bluetooth/hci_core.h>
45 #include <net/bluetooth/hci.h>
50 #define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
56 #define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
58 #define NBT_DBG_FW(...)
62 #define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
64 #define NBT_DBG_POWER(...)
68 #define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
70 #define NBT_DBG_TRANSFER(...)
74 #define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
76 #define NBT_DBG_TRANSFER_NF(...)
79 #define PM_TIMEOUT (2000)
81 static void brf6150_device_release(struct device *dev);
82 static struct brf6150_info *exit_info;
84 static struct platform_device brf6150_device = {
89 .release = brf6150_device_release,
93 static struct device_driver brf6150_driver = {
95 .bus = &platform_bus_type,
98 static inline void brf6150_outb(struct brf6150_info *info, unsigned int offset, u8 val)
100 outb(val, info->uart_base + (offset << 2));
103 static inline u8 brf6150_inb(struct brf6150_info *info, unsigned int offset)
105 return inb(info->uart_base + (offset << 2));
108 static void brf6150_set_rts(struct brf6150_info *info, int active)
112 b = brf6150_inb(info, UART_MCR);
117 brf6150_outb(info, UART_MCR, b);
120 static void brf6150_wait_for_cts(struct brf6150_info *info, int active,
124 unsigned long timeout;
127 timeout = jiffies + msecs_to_jiffies(timeout_ms);
131 state = brf6150_inb(info, UART_MSR) & UART_MSR_CTS;
139 if (jiffies > timeout)
144 static inline void brf6150_set_auto_ctsrts(struct brf6150_info *info, int on)
148 lcr = brf6150_inb(info, UART_LCR);
149 brf6150_outb(info, UART_LCR, 0xbf);
150 b = brf6150_inb(info, UART_EFR);
152 b |= UART_EFR_CTS | UART_EFR_RTS;
154 b &= ~(UART_EFR_CTS | UART_EFR_RTS);
155 brf6150_outb(info, UART_EFR, b);
156 brf6150_outb(info, UART_LCR, lcr);
159 static inline void brf6150_enable_pm_rx(struct brf6150_info *info)
161 if (info->pm_enabled) {
162 info->rx_pm_enabled = 1;
166 static inline void brf6150_disable_pm_rx(struct brf6150_info *info)
168 if (info->pm_enabled) {
169 info->rx_pm_enabled = 0;
173 static void brf6150_enable_pm_tx(struct brf6150_info *info)
175 if (info->pm_enabled) {
176 mod_timer(&info->pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
177 info->tx_pm_enabled = 1;
181 static void brf6150_disable_pm_tx(struct brf6150_info *info)
183 if (info->pm_enabled) {
184 info->tx_pm_enabled = 0;
185 gpio_set_value(info->btinfo->bt_wakeup_gpio, 1);
187 if (gpio_get_value(info->btinfo->host_wakeup_gpio))
188 tasklet_schedule(&info->tx_task);
191 static void brf6150_pm_timer(unsigned long data)
193 struct brf6150_info *info;
195 info = (struct brf6150_info *)data;
196 if (info->tx_pm_enabled && info->rx_pm_enabled && !test_bit(HCI_INQUIRY, &info->hdev->flags))
197 gpio_set_value(info->btinfo->bt_wakeup_gpio, 0);
199 mod_timer(&info->pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
202 static int brf6150_change_speed(struct brf6150_info *info, unsigned long speed)
204 unsigned int divisor;
207 NBT_DBG("Setting speed %lu\n", speed);
209 if (speed >= 460800) {
210 divisor = UART_CLOCK / 13 / speed;
213 divisor = UART_CLOCK / 16 / speed;
217 brf6150_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
218 lcr = brf6150_inb(info, UART_LCR);
219 brf6150_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
220 brf6150_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
221 brf6150_outb(info, UART_DLM, divisor >> 8);
222 brf6150_outb(info, UART_LCR, lcr);
223 brf6150_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
228 /* Firmware handling */
229 static int brf6150_open_firmware(struct brf6150_info *info)
234 err = request_firmware(&info->fw_entry, "brf6150fw.bin", &brf6150_device.dev);
239 static struct sk_buff *brf6150_read_fw_cmd(struct brf6150_info *info, int how)
242 unsigned int cmd_len;
244 if (info->fw_pos >= info->fw_entry->size) {
248 cmd_len = info->fw_entry->data[info->fw_pos++];
252 if (info->fw_pos + cmd_len > info->fw_entry->size) {
253 printk(KERN_WARNING "Corrupted firmware image\n");
257 skb = bt_skb_alloc(cmd_len, how);
259 printk(KERN_WARNING "Cannot reserve memory for buffer\n");
262 memcpy(skb_put(skb, cmd_len), &info->fw_entry->data[info->fw_pos], cmd_len);
264 info->fw_pos += cmd_len;
269 static int brf6150_close_firmware(struct brf6150_info *info)
271 release_firmware(info->fw_entry);
275 static int brf6150_send_alive_packet(struct brf6150_info *info)
279 NBT_DBG("Sending alive packet\n");
280 skb = brf6150_read_fw_cmd(info, GFP_ATOMIC);
282 printk(KERN_WARNING "Cannot read alive command");
286 clk_enable(info->uart_ck);
287 skb_queue_tail(&info->txq, skb);
288 tasklet_schedule(&info->tx_task);
290 NBT_DBG("Alive packet sent\n");
294 static void brf6150_alive_packet(struct brf6150_info *info, struct sk_buff *skb)
296 NBT_DBG("Received alive packet\n");
297 if (skb->data[1] == 0xCC) {
298 complete(&info->init_completion);
304 static int brf6150_send_negotiation(struct brf6150_info *info)
307 NBT_DBG("Sending negotiation..\n");
309 brf6150_change_speed(info, INIT_SPEED);
311 skb = brf6150_read_fw_cmd(info, GFP_KERNEL);
314 printk(KERN_WARNING "Cannot read negoatiation message");
318 clk_enable(info->uart_ck);
319 skb_queue_tail(&info->txq, skb);
320 tasklet_schedule(&info->tx_task);
323 NBT_DBG("Negotiation sent\n");
327 static void brf6150_negotiation_packet(struct brf6150_info *info,
330 if (skb->data[1] == 0x20) {
331 /* Change to operational settings */
332 brf6150_set_rts(info, 0);
333 brf6150_wait_for_cts(info, 0, 100);
334 brf6150_change_speed(info, MAX_BAUD_RATE);
335 brf6150_set_rts(info, 1);
336 brf6150_wait_for_cts(info, 1, 100);
337 brf6150_set_auto_ctsrts(info, 1);
338 brf6150_send_alive_packet(info);
340 printk(KERN_WARNING "Could not negotiate brf6150 settings\n");
345 static int brf6150_get_hdr_len(u8 pkt_type)
351 retval = HCI_EVENT_HDR_SIZE;
354 retval = HCI_ACL_HDR_SIZE;
357 retval = HCI_SCO_HDR_SIZE;
366 printk(KERN_ERR "brf6150: Unknown H4 packet");
374 static unsigned int brf6150_get_data_len(struct brf6150_info *info,
378 struct hci_event_hdr *evt_hdr;
379 struct hci_acl_hdr *acl_hdr;
380 struct hci_sco_hdr *sco_hdr;
382 switch (bt_cb(skb)->pkt_type) {
384 evt_hdr = (struct hci_event_hdr *)skb->data;
385 retval = evt_hdr->plen;
388 acl_hdr = (struct hci_acl_hdr *)skb->data;
389 retval = le16_to_cpu(acl_hdr->dlen);
392 sco_hdr = (struct hci_sco_hdr *)skb->data;
393 retval = sco_hdr->dlen;
406 static void brf6150_parse_fw_event(struct brf6150_info *info)
408 struct hci_fw_event *ev;
410 if (bt_cb(info->rx_skb)->pkt_type != H4_EVT_PKT) {
411 printk(KERN_WARNING "Got non event fw packet.\n");
416 ev = (struct hci_fw_event *)info->rx_skb->data;
417 if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
418 printk(KERN_WARNING "Got non cmd complete fw event\n");
423 if (ev->status != 0) {
424 printk(KERN_WARNING "Got error status from fw command\n");
429 complete(&info->fw_completion);
432 static inline void brf6150_recv_frame(struct brf6150_info *info,
435 if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
436 NBT_DBG("fw_event\n");
437 brf6150_parse_fw_event(info);
441 if (!(brf6150_inb(info, UART_LSR) & UART_LSR_DR))
442 brf6150_enable_pm_rx(info);
443 NBT_DBG("Frame sent to upper layer\n");
448 static inline void brf6150_rx(struct brf6150_info *info)
452 NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
454 while (brf6150_inb(info, UART_LSR) & UART_LSR_DR) {
455 if (info->rx_skb == NULL) {
456 info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
458 printk(KERN_WARNING "brf6150: Can't allocate memory for new packet\n");
461 info->rx_state = WAIT_FOR_PKT_TYPE;
462 info->rx_skb->dev = (void *)info->hdev;
463 brf6150_disable_pm_rx(info);
464 clk_enable(info->uart_ck);
467 byte = brf6150_inb(info, UART_RX);
468 if (info->garbage_bytes) {
469 info->garbage_bytes--;
470 info->hdev->stat.err_rx++;
473 info->hdev->stat.byte_rx++;
474 NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
475 switch (info->rx_state) {
476 case WAIT_FOR_PKT_TYPE:
477 bt_cb(info->rx_skb)->pkt_type = byte;
478 info->rx_count = brf6150_get_hdr_len(byte);
479 if (info->rx_count >= 0) {
480 info->rx_state = WAIT_FOR_HEADER;
482 info->hdev->stat.err_rx++;
483 kfree_skb(info->rx_skb);
485 clk_disable(info->uart_ck);
488 case WAIT_FOR_HEADER:
490 *skb_put(info->rx_skb, 1) = byte;
491 if (info->rx_count == 0) {
492 info->rx_count = brf6150_get_data_len(info, info->rx_skb);
493 if (info->rx_count > skb_tailroom(info->rx_skb)) {
494 printk(KERN_WARNING "brf6150: Frame is %ld bytes too long.\n",
495 info->rx_count - skb_tailroom(info->rx_skb));
497 info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
498 clk_disable(info->uart_ck);
501 info->rx_state = WAIT_FOR_DATA;
502 if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
503 brf6150_negotiation_packet(info, info->rx_skb);
505 clk_disable(info->uart_ck);
508 if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
509 brf6150_alive_packet(info, info->rx_skb);
511 clk_disable(info->uart_ck);
518 *skb_put(info->rx_skb, 1) = byte;
519 if (info->rx_count == 0) {
520 brf6150_recv_frame(info, info->rx_skb);
522 clk_disable(info->uart_ck);
531 NBT_DBG_TRANSFER_NF("\n");
534 static void brf6150_tx_tasklet(unsigned long data)
536 unsigned int sent = 0;
539 struct brf6150_info *info = (struct brf6150_info *)data;
541 NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
543 skb = skb_dequeue(&info->txq);
545 /* No data in buffer */
546 brf6150_enable_pm_tx(info);
550 /* Copy data to tx fifo */
551 while (!(brf6150_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
553 NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
554 brf6150_outb(info, UART_TX, skb->data[sent]);
558 info->hdev->stat.byte_tx += sent;
559 NBT_DBG_TRANSFER_NF("\n");
560 if (skb->len == sent) {
562 clk_disable(info->uart_ck);
565 skb_queue_head(&info->txq, skb);
568 spin_lock_irqsave(&info->lock, flags);
569 brf6150_outb(info, UART_IER, brf6150_inb(info, UART_IER) | UART_IER_THRI);
570 spin_unlock_irqrestore(&info->lock, flags);
573 static irqreturn_t brf6150_interrupt(int irq, void *data)
575 struct brf6150_info *info = (struct brf6150_info *)data;
582 clk_enable(info->uart_ck);
583 iir = brf6150_inb(info, UART_IIR);
584 if (iir & UART_IIR_NO_INT) {
585 printk("Interrupt but no reason irq 0x%.2x\n", iir);
586 clk_disable(info->uart_ck);
590 NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
594 if (iir == UART_IIR_MSI) {
595 msr = brf6150_inb(info, UART_MSR);
598 if (iir == UART_IIR_RLSI) {
599 brf6150_inb(info, UART_RX);
600 brf6150_inb(info, UART_LSR);
604 if (iir == UART_IIR_RDI) {
609 if (iir == UART_IIR_THRI) {
610 spin_lock_irqsave(&info->lock, flags);
611 brf6150_outb(info, UART_IER, brf6150_inb(info, UART_IER) & ~UART_IER_THRI);
612 spin_unlock_irqrestore(&info->lock, flags);
613 tasklet_schedule(&info->tx_task);
617 clk_disable(info->uart_ck);
621 static irqreturn_t brf6150_wakeup_interrupt(int irq, void *dev_inst)
623 struct brf6150_info *info = dev_inst;
627 spin_lock_irqsave(&info->lock, flags);
628 should_wakeup = gpio_get_value(info->btinfo->host_wakeup_gpio);
629 NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
631 clk_enable(info->uart_ck);
632 brf6150_set_auto_ctsrts(info, 1);
634 tasklet_schedule(&info->tx_task);
636 brf6150_set_auto_ctsrts(info, 0);
637 brf6150_set_rts(info, 0);
638 clk_disable(info->uart_ck);
641 spin_unlock_irqrestore(&info->lock, flags);
645 static int brf6150_init_uart(struct brf6150_info *info)
650 brf6150_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
651 while (!(brf6150_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
653 printk(KERN_ERR "brf6150: UART reset timeout\n");
659 /* Enable and setup FIFO */
660 brf6150_outb(info, UART_LCR, UART_LCR_WLEN8);
661 brf6150_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
662 brf6150_outb(info, UART_OMAP_SCR, 0x00);
663 brf6150_outb(info, UART_EFR, brf6150_inb(info, UART_EFR) | UART_EFR_ECB);
664 brf6150_outb(info, UART_MCR, brf6150_inb(info, UART_MCR) | UART_MCR_TCRTLR);
665 brf6150_outb(info, UART_TI752_TLR, 0xff);
666 brf6150_outb(info, UART_TI752_TCR, 0x1f);
667 brf6150_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
668 brf6150_outb(info, UART_IER, UART_IER_RDI);
673 static int brf6150_reset(struct brf6150_info *info)
675 gpio_set_value(info->btinfo->bt_wakeup_gpio, 0);
676 gpio_set_value(info->btinfo->reset_gpio, 0);
677 current->state = TASK_UNINTERRUPTIBLE;
678 schedule_timeout(msecs_to_jiffies(10));
679 gpio_set_value(info->btinfo->bt_wakeup_gpio, 1);
680 current->state = TASK_UNINTERRUPTIBLE;
681 schedule_timeout(msecs_to_jiffies(100));
682 gpio_set_value(info->btinfo->reset_gpio, 1);
683 current->state = TASK_UNINTERRUPTIBLE;
684 schedule_timeout(msecs_to_jiffies(100));
689 static int brf6150_send_firmware(struct brf6150_info *info)
693 init_completion(&info->fw_completion);
696 while ((skb = brf6150_read_fw_cmd(info, GFP_KERNEL)) != NULL) {
697 clk_enable(info->uart_ck);
698 skb_queue_tail(&info->txq, skb);
699 tasklet_schedule(&info->tx_task);
701 if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
705 if (info->fw_error) {
709 NBT_DBG_FW("Firmware sent\n");
715 /* hci callback functions */
716 static int brf6150_hci_flush(struct hci_dev *hdev)
718 struct brf6150_info *info;
719 info = hdev->driver_data;
721 skb_queue_purge(&info->txq);
726 static int brf6150_hci_open(struct hci_dev *hdev)
728 struct brf6150_info *info;
731 info = hdev->driver_data;
733 if (test_bit(HCI_RUNNING, &hdev->flags))
736 if (brf6150_open_firmware(info) < 0) {
737 printk("Cannot open firmware\n");
741 info->rx_state = WAIT_FOR_PKT_TYPE;
743 info->garbage_bytes = 0;
745 info->pm_enabled = 0;
746 set_irq_type(gpio_to_irq(info->btinfo->host_wakeup_gpio), IRQ_TYPE_NONE);
747 init_completion(&info->fw_completion);
749 clk_enable(info->uart_ck);
751 brf6150_init_uart(info);
752 brf6150_set_auto_ctsrts(info, 0);
753 brf6150_set_rts(info, 0);
755 brf6150_wait_for_cts(info, 1, 10);
756 brf6150_set_rts(info, 1);
757 if (brf6150_send_negotiation(info)) {
758 brf6150_close_firmware(info);
762 if (!wait_for_completion_interruptible_timeout(&info->init_completion, HZ)) {
763 brf6150_close_firmware(info);
764 clk_disable(info->uart_ck);
765 clear_bit(HCI_RUNNING, &hdev->flags);
768 brf6150_set_auto_ctsrts(info, 1);
770 err = brf6150_send_firmware(info);
771 brf6150_close_firmware(info);
773 printk(KERN_ERR "brf6150: Sending firmware failed. Bluetooth won't work properly\n");
775 set_irq_type(gpio_to_irq(info->btinfo->host_wakeup_gpio), IRQ_TYPE_EDGE_BOTH);
776 info->pm_enabled = 1;
777 set_bit(HCI_RUNNING, &hdev->flags);
781 static int brf6150_hci_close(struct hci_dev *hdev)
783 struct brf6150_info *info = hdev->driver_data;
784 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
787 brf6150_hci_flush(hdev);
788 clk_disable(info->uart_ck);
789 del_timer_sync(&info->pm_timer);
790 gpio_set_value(info->btinfo->bt_wakeup_gpio, 0);
791 set_irq_type(gpio_to_irq(info->btinfo->host_wakeup_gpio), IRQ_TYPE_NONE);
796 static void brf6150_hci_destruct(struct hci_dev *hdev)
800 static int brf6150_hci_send_frame(struct sk_buff *skb)
802 struct brf6150_info *info;
803 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
806 printk(KERN_WARNING "brf6150: Frame for unknown device\n");
810 if (!test_bit(HCI_RUNNING, &hdev->flags)) {
811 printk(KERN_WARNING "brf6150: Frame for non-running device\n");
815 info = hdev->driver_data;
817 switch (bt_cb(skb)->pkt_type) {
818 case HCI_COMMAND_PKT:
821 case HCI_ACLDATA_PKT:
824 case HCI_SCODATA_PKT:
829 /* Push frame type to skb */
830 clk_enable(info->uart_ck);
831 *skb_push(skb, 1) = bt_cb(skb)->pkt_type;
832 skb_queue_tail(&info->txq, skb);
834 brf6150_disable_pm_tx(info);
839 static int brf6150_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
844 static void brf6150_device_release(struct device *dev)
848 static int brf6150_register_hdev(struct brf6150_info *info)
850 struct hci_dev *hdev;
852 /* Initialize and register HCI device */
854 hdev = hci_alloc_dev();
856 printk(KERN_WARNING "brf6150: Can't allocate memory for device\n");
861 hdev->type = HCI_UART;
862 hdev->driver_data = info;
864 hdev->open = brf6150_hci_open;
865 hdev->close = brf6150_hci_close;
866 hdev->destruct = brf6150_hci_destruct;
867 hdev->flush = brf6150_hci_flush;
868 hdev->send = brf6150_hci_send_frame;
869 hdev->destruct = brf6150_hci_destruct;
870 hdev->ioctl = brf6150_hci_ioctl;
872 hdev->owner = THIS_MODULE;
874 if (hci_register_dev(hdev) < 0) {
875 printk(KERN_WARNING "brf6150: Can't register HCI device %s.\n", hdev->name);
882 static int __init brf6150_init(void)
884 struct brf6150_info *info;
887 info = kmalloc(sizeof(struct brf6150_info), GFP_KERNEL);
890 memset(info, 0, sizeof(struct brf6150_info));
892 brf6150_device.dev.driver_data = info;
893 init_completion(&info->init_completion);
894 init_completion(&info->fw_completion);
895 info->pm_enabled = 0;
896 info->rx_pm_enabled = 0;
897 info->tx_pm_enabled = 0;
898 info->garbage_bytes = 0;
899 tasklet_init(&info->tx_task, brf6150_tx_tasklet, (unsigned long)info);
900 spin_lock_init(&info->lock);
901 skb_queue_head_init(&info->txq);
902 init_timer(&info->pm_timer);
903 info->pm_timer.function = brf6150_pm_timer;
904 info->pm_timer.data = (unsigned long)info;
907 info->btinfo = omap_get_config(OMAP_TAG_NOKIA_BT, struct omap_bluetooth_config);
908 if (info->btinfo == NULL)
911 NBT_DBG("RESET gpio: %d\n", info->btinfo->reset_gpio);
912 NBT_DBG("BTWU gpio: %d\n", info->btinfo->bt_wakeup_gpio);
913 NBT_DBG("HOSTWU gpio: %d\n", info->btinfo->host_wakeup_gpio);
914 NBT_DBG("Uart: %d\n", info->btinfo->bt_uart);
915 NBT_DBG("sysclk: %d\n", info->btinfo->bt_sysclk);
917 err = gpio_request(info->btinfo->reset_gpio, "BT reset");
920 printk(KERN_WARNING "Cannot get GPIO line %d",
921 info->btinfo->reset_gpio);
926 err = gpio_request(info->btinfo->bt_wakeup_gpio, "BT wakeup");
929 printk(KERN_WARNING "Cannot get GPIO line 0x%d",
930 info->btinfo->bt_wakeup_gpio);
931 gpio_free(info->btinfo->reset_gpio);
936 err = gpio_request(info->btinfo->host_wakeup_gpio, "BT host wakeup");
939 printk(KERN_WARNING "Cannot get GPIO line %d",
940 info->btinfo->host_wakeup_gpio);
941 gpio_free(info->btinfo->reset_gpio);
942 gpio_free(info->btinfo->bt_wakeup_gpio);
947 gpio_direction_output(info->btinfo->reset_gpio, 0);
948 gpio_direction_output(info->btinfo->bt_wakeup_gpio, 0);
949 gpio_direction_input(info->btinfo->host_wakeup_gpio);
950 set_irq_type(gpio_to_irq(info->btinfo->host_wakeup_gpio), IRQ_TYPE_NONE);
952 switch (info->btinfo->bt_uart) {
955 info->uart_ck = clk_get(NULL, "uart1_ck");
956 /* FIXME: Use platform_get_resource for the port */
957 info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
958 if (!info->uart_base)
963 info->uart_ck = clk_get(NULL, "uart2_ck");
964 /* FIXME: Use platform_get_resource for the port */
965 info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
966 if (!info->uart_base)
971 info->uart_ck = clk_get(NULL, "uart3_ck");
972 /* FIXME: Use platform_get_resource for the port */
973 info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
974 if (!info->uart_base)
978 printk(KERN_ERR "No uart defined\n");
983 err = request_irq(irq, brf6150_interrupt, 0, "brf6150", (void *)info);
985 printk(KERN_ERR "brf6150: unable to get IRQ %d\n", irq);
989 err = request_irq(gpio_to_irq(info->btinfo->host_wakeup_gpio),
990 brf6150_wakeup_interrupt, 0, "brf6150_wkup", (void *)info);
992 printk(KERN_ERR "brf6150: unable to get wakeup IRQ %d\n",
993 gpio_to_irq(info->btinfo->host_wakeup_gpio));
994 free_irq(irq, (void *)info);
998 /* Register with LDM */
999 if (platform_device_register(&brf6150_device)) {
1000 printk(KERN_ERR "failed to register brf6150 device\n");
1004 /* Register the driver with LDM */
1005 if (driver_register(&brf6150_driver)) {
1006 printk(KERN_WARNING "failed to register brf6150 driver\n");
1007 platform_device_unregister(&brf6150_device);
1012 if (brf6150_register_hdev(info) < 0) {
1013 printk(KERN_WARNING "failed to register brf6150 hci device\n");
1014 platform_device_unregister(&brf6150_device);
1015 driver_unregister(&brf6150_driver);
1023 free_irq(irq, (void *)info);
1024 free_irq(gpio_to_irq(info->btinfo->host_wakeup_gpio), (void *)info);
1026 gpio_free(info->btinfo->reset_gpio);
1027 gpio_free(info->btinfo->bt_wakeup_gpio);
1028 gpio_free(info->btinfo->host_wakeup_gpio);
1034 static void __exit brf6150_exit(void)
1036 brf6150_hci_close(exit_info->hdev);
1037 hci_free_dev(exit_info->hdev);
1038 gpio_free(exit_info->btinfo->reset_gpio);
1039 gpio_free(exit_info->btinfo->bt_wakeup_gpio);
1040 gpio_free(exit_info->btinfo->host_wakeup_gpio);
1041 free_irq(exit_info->irq, (void *)exit_info);
1042 free_irq(gpio_to_irq(exit_info->btinfo->host_wakeup_gpio), (void *)exit_info);
1046 module_init(brf6150_init);
1047 module_exit(brf6150_exit);
1049 MODULE_DESCRIPTION("brf6150 hci driver");
1050 MODULE_LICENSE("GPL");
1051 MODULE_AUTHOR("Ville Tervo <ville.tervo@nokia.com>");