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>
37 #include <asm/arch/hardware.h>
38 #include <asm/arch/gpio.h>
39 #include <asm/arch/board.h>
40 #include <asm/arch/irqs.h>
42 #include <net/bluetooth/bluetooth.h>
43 #include <net/bluetooth/hci_core.h>
44 #include <net/bluetooth/hci.h>
49 #define NBT_DBG(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
55 #define NBT_DBG_FW(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
57 #define NBT_DBG_FW(...)
61 #define NBT_DBG_POWER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
63 #define NBT_DBG_POWER(...)
67 #define NBT_DBG_TRANSFER(fmt, arg...) printk("%s: " fmt "" , __FUNCTION__ , ## arg)
69 #define NBT_DBG_TRANSFER(...)
73 #define NBT_DBG_TRANSFER_NF(fmt, arg...) printk(fmt "" , ## arg)
75 #define NBT_DBG_TRANSFER_NF(...)
78 #define PM_TIMEOUT (2000)
80 static void brf6150_device_release(struct device *dev);
81 static struct brf6150_info *exit_info;
83 static struct platform_device brf6150_device = {
88 .release = brf6150_device_release,
92 static struct device_driver brf6150_driver = {
94 .bus = &platform_bus_type,
97 static inline void brf6150_outb(struct brf6150_info *info, unsigned int offset, u8 val)
99 outb(val, info->uart_base + (offset << 2));
102 static inline u8 brf6150_inb(struct brf6150_info *info, unsigned int offset)
104 return inb(info->uart_base + (offset << 2));
107 static void brf6150_set_rts(struct brf6150_info *info, int active)
111 b = brf6150_inb(info, UART_MCR);
116 brf6150_outb(info, UART_MCR, b);
119 static void brf6150_wait_for_cts(struct brf6150_info *info, int active,
123 unsigned long timeout;
126 timeout = jiffies + msecs_to_jiffies(timeout_ms);
130 state = brf6150_inb(info, UART_MSR) & UART_MSR_CTS;
138 if (jiffies > timeout)
143 static inline void brf6150_set_auto_ctsrts(struct brf6150_info *info, int on)
147 lcr = brf6150_inb(info, UART_LCR);
148 brf6150_outb(info, UART_LCR, 0xbf);
149 b = brf6150_inb(info, UART_EFR);
151 b |= UART_EFR_CTS | UART_EFR_RTS;
153 b &= ~(UART_EFR_CTS | UART_EFR_RTS);
154 brf6150_outb(info, UART_EFR, b);
155 brf6150_outb(info, UART_LCR, lcr);
158 static inline void brf6150_enable_pm_rx(struct brf6150_info *info)
160 if (info->pm_enabled) {
161 info->rx_pm_enabled = 1;
165 static inline void brf6150_disable_pm_rx(struct brf6150_info *info)
167 if (info->pm_enabled) {
168 info->rx_pm_enabled = 0;
172 static void brf6150_enable_pm_tx(struct brf6150_info *info)
174 if (info->pm_enabled) {
175 mod_timer(&info->pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
176 info->tx_pm_enabled = 1;
180 static void brf6150_disable_pm_tx(struct brf6150_info *info)
182 if (info->pm_enabled) {
183 info->tx_pm_enabled = 0;
184 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 1);
186 if (omap_get_gpio_datain(info->btinfo->host_wakeup_gpio))
187 tasklet_schedule(&info->tx_task);
190 static void brf6150_pm_timer(unsigned long data)
192 struct brf6150_info *info;
194 info = (struct brf6150_info *)data;
195 if (info->tx_pm_enabled && info->rx_pm_enabled && !test_bit(HCI_INQUIRY, &info->hdev->flags))
196 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 0);
198 mod_timer(&info->pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
201 static int brf6150_change_speed(struct brf6150_info *info, unsigned long speed)
203 unsigned int divisor;
206 NBT_DBG("Setting speed %lu\n", speed);
208 if (speed >= 460800) {
209 divisor = UART_CLOCK / 13 / speed;
212 divisor = UART_CLOCK / 16 / speed;
216 brf6150_outb(info, UART_OMAP_MDR1, 7); /* Make sure UART mode is disabled */
217 lcr = brf6150_inb(info, UART_LCR);
218 brf6150_outb(info, UART_LCR, UART_LCR_DLAB); /* Set DLAB */
219 brf6150_outb(info, UART_DLL, divisor & 0xff); /* Set speed */
220 brf6150_outb(info, UART_DLM, divisor >> 8);
221 brf6150_outb(info, UART_LCR, lcr);
222 brf6150_outb(info, UART_OMAP_MDR1, mdr1); /* Make sure UART mode is enabled */
227 /* Firmware handling */
228 static int brf6150_open_firmware(struct brf6150_info *info)
233 err = request_firmware(&info->fw_entry, "brf6150fw.bin", &brf6150_device.dev);
238 static struct sk_buff *brf6150_read_fw_cmd(struct brf6150_info *info, int how)
241 unsigned int cmd_len;
243 if (info->fw_pos >= info->fw_entry->size) {
247 cmd_len = info->fw_entry->data[info->fw_pos++];
251 if (info->fw_pos + cmd_len > info->fw_entry->size) {
252 printk(KERN_WARNING "Corrupted firmware image\n");
256 skb = bt_skb_alloc(cmd_len, how);
258 printk(KERN_WARNING "Cannot reserve memory for buffer\n");
261 memcpy(skb_put(skb, cmd_len), &info->fw_entry->data[info->fw_pos], cmd_len);
263 info->fw_pos += cmd_len;
268 static int brf6150_close_firmware(struct brf6150_info *info)
270 release_firmware(info->fw_entry);
274 static int brf6150_send_alive_packet(struct brf6150_info *info)
278 NBT_DBG("Sending alive packet\n");
279 skb = brf6150_read_fw_cmd(info, GFP_ATOMIC);
281 printk(KERN_WARNING "Cannot read alive command");
285 clk_enable(info->uart_ck);
286 skb_queue_tail(&info->txq, skb);
287 tasklet_schedule(&info->tx_task);
289 NBT_DBG("Alive packet sent\n");
293 static void brf6150_alive_packet(struct brf6150_info *info, struct sk_buff *skb)
295 NBT_DBG("Received alive packet\n");
296 if (skb->data[1] == 0xCC) {
297 complete(&info->init_completion);
303 static int brf6150_send_negotiation(struct brf6150_info *info)
306 NBT_DBG("Sending negotiation..\n");
308 brf6150_change_speed(info, INIT_SPEED);
310 skb = brf6150_read_fw_cmd(info, GFP_KERNEL);
313 printk(KERN_WARNING "Cannot read negoatiation message");
317 clk_enable(info->uart_ck);
318 skb_queue_tail(&info->txq, skb);
319 tasklet_schedule(&info->tx_task);
322 NBT_DBG("Negotiation sent\n");
326 static void brf6150_negotiation_packet(struct brf6150_info *info,
329 if (skb->data[1] == 0x20) {
330 /* Change to operational settings */
331 brf6150_set_rts(info, 0);
332 brf6150_wait_for_cts(info, 0, 100);
333 brf6150_change_speed(info, MAX_BAUD_RATE);
334 brf6150_set_rts(info, 1);
335 brf6150_wait_for_cts(info, 1, 100);
336 brf6150_set_auto_ctsrts(info, 1);
337 brf6150_send_alive_packet(info);
339 printk(KERN_WARNING "Could not negotiate brf6150 settings\n");
344 static int brf6150_get_hdr_len(u8 pkt_type)
350 retval = HCI_EVENT_HDR_SIZE;
353 retval = HCI_ACL_HDR_SIZE;
356 retval = HCI_SCO_HDR_SIZE;
365 printk(KERN_ERR "brf6150: Unknown H4 packet");
373 static unsigned int brf6150_get_data_len(struct brf6150_info *info,
377 struct hci_event_hdr *evt_hdr;
378 struct hci_acl_hdr *acl_hdr;
379 struct hci_sco_hdr *sco_hdr;
381 switch (bt_cb(skb)->pkt_type) {
383 evt_hdr = (struct hci_event_hdr *)skb->data;
384 retval = evt_hdr->plen;
387 acl_hdr = (struct hci_acl_hdr *)skb->data;
388 retval = le16_to_cpu(acl_hdr->dlen);
391 sco_hdr = (struct hci_sco_hdr *)skb->data;
392 retval = sco_hdr->dlen;
405 static void brf6150_parse_fw_event(struct brf6150_info *info)
407 struct hci_fw_event *ev;
409 if (bt_cb(info->rx_skb)->pkt_type != H4_EVT_PKT) {
410 printk(KERN_WARNING "Got non event fw packet.\n");
415 ev = (struct hci_fw_event *)info->rx_skb->data;
416 if (ev->hev.evt != HCI_EV_CMD_COMPLETE) {
417 printk(KERN_WARNING "Got non cmd complete fw event\n");
422 if (ev->status != 0) {
423 printk(KERN_WARNING "Got error status from fw command\n");
428 complete(&info->fw_completion);
431 static inline void brf6150_recv_frame(struct brf6150_info *info,
434 if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
435 NBT_DBG("fw_event\n");
436 brf6150_parse_fw_event(info);
440 if (!(brf6150_inb(info, UART_LSR) & UART_LSR_DR))
441 brf6150_enable_pm_rx(info);
442 NBT_DBG("Frame sent to upper layer\n");
447 static inline void brf6150_rx(struct brf6150_info *info)
451 NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
453 while (brf6150_inb(info, UART_LSR) & UART_LSR_DR) {
454 if (info->rx_skb == NULL) {
455 info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
457 printk(KERN_WARNING "brf6150: Can't allocate memory for new packet\n");
460 info->rx_state = WAIT_FOR_PKT_TYPE;
461 info->rx_skb->dev = (void *)info->hdev;
462 brf6150_disable_pm_rx(info);
463 clk_enable(info->uart_ck);
466 byte = brf6150_inb(info, UART_RX);
467 if (info->garbage_bytes) {
468 info->garbage_bytes--;
469 info->hdev->stat.err_rx++;
472 info->hdev->stat.byte_rx++;
473 NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
474 switch (info->rx_state) {
475 case WAIT_FOR_PKT_TYPE:
476 bt_cb(info->rx_skb)->pkt_type = byte;
477 info->rx_count = brf6150_get_hdr_len(byte);
478 if (info->rx_count >= 0) {
479 info->rx_state = WAIT_FOR_HEADER;
481 info->hdev->stat.err_rx++;
482 kfree_skb(info->rx_skb);
484 clk_disable(info->uart_ck);
487 case WAIT_FOR_HEADER:
489 *skb_put(info->rx_skb, 1) = byte;
490 if (info->rx_count == 0) {
491 info->rx_count = brf6150_get_data_len(info, info->rx_skb);
492 if (info->rx_count > skb_tailroom(info->rx_skb)) {
493 printk(KERN_WARNING "brf6150: Frame is %ld bytes too long.\n",
494 info->rx_count - skb_tailroom(info->rx_skb));
496 info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
497 clk_disable(info->uart_ck);
500 info->rx_state = WAIT_FOR_DATA;
501 if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
502 brf6150_negotiation_packet(info, info->rx_skb);
504 clk_disable(info->uart_ck);
507 if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
508 brf6150_alive_packet(info, info->rx_skb);
510 clk_disable(info->uart_ck);
517 *skb_put(info->rx_skb, 1) = byte;
518 if (info->rx_count == 0) {
519 brf6150_recv_frame(info, info->rx_skb);
521 clk_disable(info->uart_ck);
530 NBT_DBG_TRANSFER_NF("\n");
533 static void brf6150_tx_tasklet(unsigned long data)
535 unsigned int sent = 0;
538 struct brf6150_info *info = (struct brf6150_info *)data;
540 NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
542 skb = skb_dequeue(&info->txq);
544 /* No data in buffer */
545 brf6150_enable_pm_tx(info);
549 /* Copy data to tx fifo */
550 while (!(brf6150_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
552 NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
553 brf6150_outb(info, UART_TX, skb->data[sent]);
557 info->hdev->stat.byte_tx += sent;
558 NBT_DBG_TRANSFER_NF("\n");
559 if (skb->len == sent) {
561 clk_disable(info->uart_ck);
564 skb_queue_head(&info->txq, skb);
567 spin_lock_irqsave(&info->lock, flags);
568 brf6150_outb(info, UART_IER, brf6150_inb(info, UART_IER) | UART_IER_THRI);
569 spin_unlock_irqrestore(&info->lock, flags);
572 static irqreturn_t brf6150_interrupt(int irq, void *data)
574 struct brf6150_info *info = (struct brf6150_info *)data;
581 clk_enable(info->uart_ck);
582 iir = brf6150_inb(info, UART_IIR);
583 if (iir & UART_IIR_NO_INT) {
584 printk("Interrupt but no reason irq 0x%.2x\n", iir);
585 clk_disable(info->uart_ck);
589 NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
593 if (iir == UART_IIR_MSI) {
594 msr = brf6150_inb(info, UART_MSR);
597 if (iir == UART_IIR_RLSI) {
598 brf6150_inb(info, UART_RX);
599 brf6150_inb(info, UART_LSR);
603 if (iir == UART_IIR_RDI) {
608 if (iir == UART_IIR_THRI) {
609 spin_lock_irqsave(&info->lock, flags);
610 brf6150_outb(info, UART_IER, brf6150_inb(info, UART_IER) & ~UART_IER_THRI);
611 spin_unlock_irqrestore(&info->lock, flags);
612 tasklet_schedule(&info->tx_task);
616 clk_disable(info->uart_ck);
620 static irqreturn_t brf6150_wakeup_interrupt(int irq, void *dev_inst)
622 struct brf6150_info *info = dev_inst;
626 spin_lock_irqsave(&info->lock, flags);
627 should_wakeup = omap_get_gpio_datain(info->btinfo->host_wakeup_gpio);
628 NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
630 clk_enable(info->uart_ck);
631 brf6150_set_auto_ctsrts(info, 1);
633 tasklet_schedule(&info->tx_task);
635 brf6150_set_auto_ctsrts(info, 0);
636 brf6150_set_rts(info, 0);
637 clk_disable(info->uart_ck);
640 spin_unlock_irqrestore(&info->lock, flags);
644 static int brf6150_init_uart(struct brf6150_info *info)
649 brf6150_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
650 while (!(brf6150_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
652 printk(KERN_ERR "brf6150: UART reset timeout\n");
658 /* Enable and setup FIFO */
659 brf6150_outb(info, UART_LCR, UART_LCR_WLEN8);
660 brf6150_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
661 brf6150_outb(info, UART_OMAP_SCR, 0x00);
662 brf6150_outb(info, UART_EFR, brf6150_inb(info, UART_EFR) | UART_EFR_ECB);
663 brf6150_outb(info, UART_MCR, brf6150_inb(info, UART_MCR) | UART_MCR_TCRTLR);
664 brf6150_outb(info, UART_TI752_TLR, 0xff);
665 brf6150_outb(info, UART_TI752_TCR, 0x1f);
666 brf6150_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
667 brf6150_outb(info, UART_IER, UART_IER_RDI);
672 static int brf6150_reset(struct brf6150_info *info)
674 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 0);
675 omap_set_gpio_dataout(info->btinfo->reset_gpio, 0);
676 current->state = TASK_UNINTERRUPTIBLE;
677 schedule_timeout(msecs_to_jiffies(10));
678 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 1);
679 current->state = TASK_UNINTERRUPTIBLE;
680 schedule_timeout(msecs_to_jiffies(100));
681 omap_set_gpio_dataout(info->btinfo->reset_gpio, 1);
682 current->state = TASK_UNINTERRUPTIBLE;
683 schedule_timeout(msecs_to_jiffies(100));
688 static int brf6150_send_firmware(struct brf6150_info *info)
692 init_completion(&info->fw_completion);
695 while ((skb = brf6150_read_fw_cmd(info, GFP_KERNEL)) != NULL) {
696 clk_enable(info->uart_ck);
697 skb_queue_tail(&info->txq, skb);
698 tasklet_schedule(&info->tx_task);
700 if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
704 if (info->fw_error) {
708 NBT_DBG_FW("Firmware sent\n");
714 /* hci callback functions */
715 static int brf6150_hci_flush(struct hci_dev *hdev)
717 struct brf6150_info *info;
718 info = hdev->driver_data;
720 skb_queue_purge(&info->txq);
725 static int brf6150_hci_open(struct hci_dev *hdev)
727 struct brf6150_info *info;
730 info = hdev->driver_data;
732 if (test_bit(HCI_RUNNING, &hdev->flags))
735 if (brf6150_open_firmware(info) < 0) {
736 printk("Cannot open firmware\n");
740 info->rx_state = WAIT_FOR_PKT_TYPE;
742 info->garbage_bytes = 0;
744 info->pm_enabled = 0;
745 set_irq_type(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), IRQT_NOEDGE);
746 init_completion(&info->fw_completion);
748 clk_enable(info->uart_ck);
750 brf6150_init_uart(info);
751 brf6150_set_auto_ctsrts(info, 0);
752 brf6150_set_rts(info, 0);
754 brf6150_wait_for_cts(info, 1, 10);
755 brf6150_set_rts(info, 1);
756 if (brf6150_send_negotiation(info)) {
757 brf6150_close_firmware(info);
761 if (!wait_for_completion_interruptible_timeout(&info->init_completion, HZ)) {
762 brf6150_close_firmware(info);
763 clk_disable(info->uart_ck);
764 clear_bit(HCI_RUNNING, &hdev->flags);
767 brf6150_set_auto_ctsrts(info, 1);
769 err = brf6150_send_firmware(info);
770 brf6150_close_firmware(info);
772 printk(KERN_ERR "brf6150: Sending firmware failed. Bluetooth won't work properly\n");
774 set_irq_type(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), IRQT_BOTHEDGE);
775 info->pm_enabled = 1;
776 set_bit(HCI_RUNNING, &hdev->flags);
780 static int brf6150_hci_close(struct hci_dev *hdev)
782 struct brf6150_info *info = hdev->driver_data;
783 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
786 brf6150_hci_flush(hdev);
787 clk_disable(info->uart_ck);
788 del_timer_sync(&info->pm_timer);
789 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 0);
790 set_irq_type(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), IRQT_NOEDGE);
795 static void brf6150_hci_destruct(struct hci_dev *hdev)
799 static int brf6150_hci_send_frame(struct sk_buff *skb)
801 struct brf6150_info *info;
802 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
805 printk(KERN_WARNING "brf6150: Frame for unknown device\n");
809 if (!test_bit(HCI_RUNNING, &hdev->flags)) {
810 printk(KERN_WARNING "brf6150: Frame for non-running device\n");
814 info = hdev->driver_data;
816 switch (bt_cb(skb)->pkt_type) {
817 case HCI_COMMAND_PKT:
820 case HCI_ACLDATA_PKT:
823 case HCI_SCODATA_PKT:
828 /* Push frame type to skb */
829 clk_enable(info->uart_ck);
830 *skb_push(skb, 1) = bt_cb(skb)->pkt_type;
831 skb_queue_tail(&info->txq, skb);
833 brf6150_disable_pm_tx(info);
838 static int brf6150_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
843 static void brf6150_device_release(struct device *dev)
847 static int brf6150_register_hdev(struct brf6150_info *info)
849 struct hci_dev *hdev;
851 /* Initialize and register HCI device */
853 hdev = hci_alloc_dev();
855 printk(KERN_WARNING "brf6150: Can't allocate memory for device\n");
860 hdev->type = HCI_UART;
861 hdev->driver_data = info;
863 hdev->open = brf6150_hci_open;
864 hdev->close = brf6150_hci_close;
865 hdev->destruct = brf6150_hci_destruct;
866 hdev->flush = brf6150_hci_flush;
867 hdev->send = brf6150_hci_send_frame;
868 hdev->destruct = brf6150_hci_destruct;
869 hdev->ioctl = brf6150_hci_ioctl;
871 hdev->owner = THIS_MODULE;
873 if (hci_register_dev(hdev) < 0) {
874 printk(KERN_WARNING "brf6150: Can't register HCI device %s.\n", hdev->name);
881 static int __init brf6150_init(void)
883 struct brf6150_info *info;
886 info = kmalloc(sizeof(struct brf6150_info), GFP_KERNEL);
889 memset(info, 0, sizeof(struct brf6150_info));
891 brf6150_device.dev.driver_data = info;
892 init_completion(&info->init_completion);
893 init_completion(&info->fw_completion);
894 info->pm_enabled = 0;
895 info->rx_pm_enabled = 0;
896 info->tx_pm_enabled = 0;
897 info->garbage_bytes = 0;
898 tasklet_init(&info->tx_task, brf6150_tx_tasklet, (unsigned long)info);
899 spin_lock_init(&info->lock);
900 skb_queue_head_init(&info->txq);
901 init_timer(&info->pm_timer);
902 info->pm_timer.function = brf6150_pm_timer;
903 info->pm_timer.data = (unsigned long)info;
906 info->btinfo = omap_get_config(OMAP_TAG_NOKIA_BT, struct omap_bluetooth_config);
907 if (info->btinfo == NULL)
910 NBT_DBG("RESET gpio: %d\n", info->btinfo->reset_gpio);
911 NBT_DBG("BTWU gpio: %d\n", info->btinfo->bt_wakeup_gpio);
912 NBT_DBG("HOSTWU gpio: %d\n", info->btinfo->host_wakeup_gpio);
913 NBT_DBG("Uart: %d\n", info->btinfo->bt_uart);
914 NBT_DBG("sysclk: %d\n", info->btinfo->bt_sysclk);
916 err = omap_request_gpio(info->btinfo->reset_gpio);
919 printk(KERN_WARNING "Cannot get GPIO line %d",
920 info->btinfo->reset_gpio);
925 err = omap_request_gpio(info->btinfo->bt_wakeup_gpio);
928 printk(KERN_WARNING "Cannot get GPIO line 0x%d",
929 info->btinfo->bt_wakeup_gpio);
930 omap_free_gpio(info->btinfo->reset_gpio);
935 err = omap_request_gpio(info->btinfo->host_wakeup_gpio);
938 printk(KERN_WARNING "Cannot get GPIO line %d",
939 info->btinfo->host_wakeup_gpio);
940 omap_free_gpio(info->btinfo->reset_gpio);
941 omap_free_gpio(info->btinfo->bt_wakeup_gpio);
946 omap_set_gpio_direction(info->btinfo->reset_gpio, 0);
947 omap_set_gpio_direction(info->btinfo->bt_wakeup_gpio, 0);
948 omap_set_gpio_direction(info->btinfo->host_wakeup_gpio, 1);
949 set_irq_type(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), IRQT_NOEDGE);
951 switch (info->btinfo->bt_uart) {
954 info->uart_ck = clk_get(NULL, "uart1_ck");
955 info->uart_base = io_p2v((unsigned long)OMAP_UART1_BASE);
959 info->uart_ck = clk_get(NULL, "uart2_ck");
960 info->uart_base = io_p2v((unsigned long)OMAP_UART2_BASE);
964 info->uart_ck = clk_get(NULL, "uart3_ck");
965 info->uart_base = io_p2v((unsigned long)OMAP_UART3_BASE);
968 printk(KERN_ERR "No uart defined\n");
973 err = request_irq(irq, brf6150_interrupt, 0, "brf6150", (void *)info);
975 printk(KERN_ERR "brf6150: unable to get IRQ %d\n", irq);
979 err = request_irq(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio),
980 brf6150_wakeup_interrupt, 0, "brf6150_wkup", (void *)info);
982 printk(KERN_ERR "brf6150: unable to get wakeup IRQ %d\n",
983 OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio));
984 free_irq(irq, (void *)info);
988 /* Register with LDM */
989 if (platform_device_register(&brf6150_device)) {
990 printk(KERN_ERR "failed to register brf6150 device\n");
994 /* Register the driver with LDM */
995 if (driver_register(&brf6150_driver)) {
996 printk(KERN_WARNING "failed to register brf6150 driver\n");
997 platform_device_unregister(&brf6150_device);
1002 if (brf6150_register_hdev(info) < 0) {
1003 printk(KERN_WARNING "failed to register brf6150 hci device\n");
1004 platform_device_unregister(&brf6150_device);
1005 driver_unregister(&brf6150_driver);
1013 free_irq(irq, (void *)info);
1014 free_irq(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), (void *)info);
1016 omap_free_gpio(info->btinfo->reset_gpio);
1017 omap_free_gpio(info->btinfo->bt_wakeup_gpio);
1018 omap_free_gpio(info->btinfo->host_wakeup_gpio);
1024 static void __exit brf6150_exit(void)
1026 brf6150_hci_close(exit_info->hdev);
1027 hci_free_dev(exit_info->hdev);
1028 omap_free_gpio(exit_info->btinfo->reset_gpio);
1029 omap_free_gpio(exit_info->btinfo->bt_wakeup_gpio);
1030 omap_free_gpio(exit_info->btinfo->host_wakeup_gpio);
1031 free_irq(exit_info->irq, (void *)exit_info);
1032 free_irq(OMAP_GPIO_IRQ(exit_info->btinfo->host_wakeup_gpio), (void *)exit_info);
1036 module_init(brf6150_init);
1037 module_exit(brf6150_exit);
1039 MODULE_DESCRIPTION("brf6150 hci driver");
1040 MODULE_LICENSE("GPL");
1041 MODULE_AUTHOR("Ville Tervo <ville.tervo@nokia.com>");