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/config.h>
23 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/errno.h>
28 #include <linux/delay.h>
29 #include <linux/spinlock.h>
30 #include <linux/serial_reg.h>
31 #include <linux/skbuff.h>
32 #include <linux/firmware.h>
33 #include <linux/irq.h>
34 #include <linux/timer.h>
35 #include <linux/clk.h>
36 #include <linux/platform_device.h>
38 #include <asm/arch/hardware.h>
39 #include <asm/arch/gpio.h>
40 #include <asm/arch/board.h>
41 #include <asm/arch/irqs.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 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 1);
187 if (omap_get_gpio_datain(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 omap_set_gpio_dataout(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, struct pt_regs *regs)
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,
622 struct pt_regs *regs)
624 struct brf6150_info *info = dev_inst;
628 spin_lock_irqsave(&info->lock, flags);
629 should_wakeup = omap_get_gpio_datain(info->btinfo->host_wakeup_gpio);
630 NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
632 clk_enable(info->uart_ck);
633 brf6150_set_auto_ctsrts(info, 1);
635 tasklet_schedule(&info->tx_task);
637 brf6150_set_auto_ctsrts(info, 0);
638 brf6150_set_rts(info, 0);
639 clk_disable(info->uart_ck);
642 spin_unlock_irqrestore(&info->lock, flags);
646 static int brf6150_init_uart(struct brf6150_info *info)
651 brf6150_outb(info, UART_OMAP_SYSC, UART_SYSC_OMAP_RESET);
652 while (!(brf6150_inb(info, UART_OMAP_SYSS) & UART_SYSS_RESETDONE)) {
654 printk(KERN_ERR "brf6150: UART reset timeout\n");
660 /* Enable and setup FIFO */
661 brf6150_outb(info, UART_LCR, UART_LCR_WLEN8);
662 brf6150_outb(info, UART_OMAP_MDR1, 0x00); /* Make sure UART mode is enabled */
663 brf6150_outb(info, UART_OMAP_SCR, 0x00);
664 brf6150_outb(info, UART_EFR, brf6150_inb(info, UART_EFR) | UART_EFR_ECB);
665 brf6150_outb(info, UART_MCR, brf6150_inb(info, UART_MCR) | UART_MCR_TCRTLR);
666 brf6150_outb(info, UART_TI752_TLR, 0xff);
667 brf6150_outb(info, UART_TI752_TCR, 0x1f);
668 brf6150_outb(info, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
669 brf6150_outb(info, UART_IER, UART_IER_RDI);
674 static int brf6150_reset(struct brf6150_info *info)
676 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 0);
677 omap_set_gpio_dataout(info->btinfo->reset_gpio, 0);
678 current->state = TASK_UNINTERRUPTIBLE;
679 schedule_timeout(msecs_to_jiffies(10));
680 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 1);
681 current->state = TASK_UNINTERRUPTIBLE;
682 schedule_timeout(msecs_to_jiffies(100));
683 omap_set_gpio_dataout(info->btinfo->reset_gpio, 1);
684 current->state = TASK_UNINTERRUPTIBLE;
685 schedule_timeout(msecs_to_jiffies(100));
690 static int brf6150_send_firmware(struct brf6150_info *info)
694 init_completion(&info->fw_completion);
697 while ((skb = brf6150_read_fw_cmd(info, GFP_KERNEL)) != NULL) {
698 clk_enable(info->uart_ck);
699 skb_queue_tail(&info->txq, skb);
700 tasklet_schedule(&info->tx_task);
702 if (!wait_for_completion_timeout(&info->fw_completion, HZ)) {
706 if (info->fw_error) {
710 NBT_DBG_FW("Firmware sent\n");
716 /* hci callback functions */
717 static int brf6150_hci_flush(struct hci_dev *hdev)
719 struct brf6150_info *info;
720 info = hdev->driver_data;
722 skb_queue_purge(&info->txq);
727 static int brf6150_hci_open(struct hci_dev *hdev)
729 struct brf6150_info *info;
732 info = hdev->driver_data;
734 if (test_bit(HCI_RUNNING, &hdev->flags))
737 if (brf6150_open_firmware(info) < 0) {
738 printk("Cannot open firmware\n");
742 info->rx_state = WAIT_FOR_PKT_TYPE;
744 info->garbage_bytes = 0;
746 info->pm_enabled = 0;
747 set_irq_type(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), IRQT_NOEDGE);
748 init_completion(&info->fw_completion);
750 clk_enable(info->uart_ck);
752 brf6150_init_uart(info);
753 brf6150_set_auto_ctsrts(info, 0);
754 brf6150_set_rts(info, 0);
756 brf6150_wait_for_cts(info, 1, 10);
757 brf6150_set_rts(info, 1);
758 if (brf6150_send_negotiation(info)) {
759 brf6150_close_firmware(info);
763 if (!wait_for_completion_interruptible_timeout(&info->init_completion, HZ)) {
764 brf6150_close_firmware(info);
765 clk_disable(info->uart_ck);
766 clear_bit(HCI_RUNNING, &hdev->flags);
769 brf6150_set_auto_ctsrts(info, 1);
771 err = brf6150_send_firmware(info);
772 brf6150_close_firmware(info);
774 printk(KERN_ERR "brf6150: Sending firmware failed. Bluetooth won't work properly\n");
776 set_irq_type(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), IRQT_BOTHEDGE);
777 info->pm_enabled = 1;
778 set_bit(HCI_RUNNING, &hdev->flags);
782 static int brf6150_hci_close(struct hci_dev *hdev)
784 struct brf6150_info *info = hdev->driver_data;
785 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
788 brf6150_hci_flush(hdev);
789 clk_disable(info->uart_ck);
790 del_timer_sync(&info->pm_timer);
791 omap_set_gpio_dataout(info->btinfo->bt_wakeup_gpio, 0);
792 set_irq_type(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), IRQT_NOEDGE);
797 static void brf6150_hci_destruct(struct hci_dev *hdev)
801 static int brf6150_hci_send_frame(struct sk_buff *skb)
803 struct brf6150_info *info;
804 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
807 printk(KERN_WARNING "brf6150: Frame for unknown device\n");
811 if (!test_bit(HCI_RUNNING, &hdev->flags)) {
812 printk(KERN_WARNING "brf6150: Frame for non-running device\n");
816 info = hdev->driver_data;
818 switch (bt_cb(skb)->pkt_type) {
819 case HCI_COMMAND_PKT:
822 case HCI_ACLDATA_PKT:
825 case HCI_SCODATA_PKT:
830 /* Push frame type to skb */
831 clk_enable(info->uart_ck);
832 *skb_push(skb, 1) = bt_cb(skb)->pkt_type;
833 skb_queue_tail(&info->txq, skb);
835 brf6150_disable_pm_tx(info);
840 static int brf6150_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
845 static void brf6150_device_release(struct device *dev)
849 static int brf6150_register_hdev(struct brf6150_info *info)
851 struct hci_dev *hdev;
853 /* Initialize and register HCI device */
855 hdev = hci_alloc_dev();
857 printk(KERN_WARNING "brf6150: Can't allocate memory for device\n");
862 hdev->type = HCI_UART;
863 hdev->driver_data = info;
865 hdev->open = brf6150_hci_open;
866 hdev->close = brf6150_hci_close;
867 hdev->destruct = brf6150_hci_destruct;
868 hdev->flush = brf6150_hci_flush;
869 hdev->send = brf6150_hci_send_frame;
870 hdev->destruct = brf6150_hci_destruct;
871 hdev->ioctl = brf6150_hci_ioctl;
873 hdev->owner = THIS_MODULE;
875 if (hci_register_dev(hdev) < 0) {
876 printk(KERN_WARNING "brf6150: Can't register HCI device %s.\n", hdev->name);
883 static int __init brf6150_init(void)
885 struct brf6150_info *info;
888 info = kmalloc(sizeof(struct brf6150_info), GFP_KERNEL);
891 memset(info, 0, sizeof(struct brf6150_info));
893 brf6150_device.dev.driver_data = info;
894 init_completion(&info->init_completion);
895 init_completion(&info->fw_completion);
896 info->pm_enabled = 0;
897 info->rx_pm_enabled = 0;
898 info->tx_pm_enabled = 0;
899 info->garbage_bytes = 0;
900 tasklet_init(&info->tx_task, brf6150_tx_tasklet, (unsigned long)info);
901 spin_lock_init(&info->lock);
902 skb_queue_head_init(&info->txq);
903 init_timer(&info->pm_timer);
904 info->pm_timer.function = brf6150_pm_timer;
905 info->pm_timer.data = (unsigned long)info;
908 info->btinfo = omap_get_config(OMAP_TAG_NOKIA_BT, struct omap_bluetooth_config);
909 if (info->btinfo == NULL)
912 NBT_DBG("RESET gpio: %d\n", info->btinfo->reset_gpio);
913 NBT_DBG("BTWU gpio: %d\n", info->btinfo->bt_wakeup_gpio);
914 NBT_DBG("HOSTWU gpio: %d\n", info->btinfo->host_wakeup_gpio);
915 NBT_DBG("Uart: %d\n", info->btinfo->bt_uart);
916 NBT_DBG("sysclk: %d\n", info->btinfo->bt_sysclk);
918 err = omap_request_gpio(info->btinfo->reset_gpio);
921 printk(KERN_WARNING "Cannot get GPIO line %d",
922 info->btinfo->reset_gpio);
927 err = omap_request_gpio(info->btinfo->bt_wakeup_gpio);
930 printk(KERN_WARNING "Cannot get GPIO line 0x%d",
931 info->btinfo->bt_wakeup_gpio);
932 omap_free_gpio(info->btinfo->reset_gpio);
937 err = omap_request_gpio(info->btinfo->host_wakeup_gpio);
940 printk(KERN_WARNING "Cannot get GPIO line %d",
941 info->btinfo->host_wakeup_gpio);
942 omap_free_gpio(info->btinfo->reset_gpio);
943 omap_free_gpio(info->btinfo->bt_wakeup_gpio);
948 omap_set_gpio_direction(info->btinfo->reset_gpio, 0);
949 omap_set_gpio_direction(info->btinfo->bt_wakeup_gpio, 0);
950 omap_set_gpio_direction(info->btinfo->host_wakeup_gpio, 1);
951 set_irq_type(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), IRQT_NOEDGE);
953 switch (info->btinfo->bt_uart) {
956 info->uart_ck = clk_get(NULL, "uart1_ck");
957 info->uart_base = io_p2v((unsigned long)OMAP_UART1_BASE);
961 info->uart_ck = clk_get(NULL, "uart2_ck");
962 info->uart_base = io_p2v((unsigned long)OMAP_UART2_BASE);
966 info->uart_ck = clk_get(NULL, "uart3_ck");
967 info->uart_base = io_p2v((unsigned long)OMAP_UART3_BASE);
970 printk(KERN_ERR "No uart defined\n");
975 err = request_irq(irq, brf6150_interrupt, 0, "brf6150", (void *)info);
977 printk(KERN_ERR "brf6150: unable to get IRQ %d\n", irq);
981 err = request_irq(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio),
982 brf6150_wakeup_interrupt, 0, "brf6150_wkup", (void *)info);
984 printk(KERN_ERR "brf6150: unable to get wakeup IRQ %d\n",
985 OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio));
986 free_irq(irq, (void *)info);
990 /* Register with LDM */
991 if (platform_device_register(&brf6150_device)) {
992 printk(KERN_ERR "failed to register brf6150 device\n");
996 /* Register the driver with LDM */
997 if (driver_register(&brf6150_driver)) {
998 printk(KERN_WARNING "failed to register brf6150 driver\n");
999 platform_device_unregister(&brf6150_device);
1004 if (brf6150_register_hdev(info) < 0) {
1005 printk(KERN_WARNING "failed to register brf6150 hci device\n");
1006 platform_device_unregister(&brf6150_device);
1007 driver_unregister(&brf6150_driver);
1015 free_irq(irq, (void *)info);
1016 free_irq(OMAP_GPIO_IRQ(info->btinfo->host_wakeup_gpio), (void *)info);
1018 omap_free_gpio(info->btinfo->reset_gpio);
1019 omap_free_gpio(info->btinfo->bt_wakeup_gpio);
1020 omap_free_gpio(info->btinfo->host_wakeup_gpio);
1026 static void __exit brf6150_exit(void)
1028 brf6150_hci_close(exit_info->hdev);
1029 hci_free_dev(exit_info->hdev);
1030 omap_free_gpio(exit_info->btinfo->reset_gpio);
1031 omap_free_gpio(exit_info->btinfo->bt_wakeup_gpio);
1032 omap_free_gpio(exit_info->btinfo->host_wakeup_gpio);
1033 free_irq(exit_info->irq, (void *)exit_info);
1034 free_irq(OMAP_GPIO_IRQ(exit_info->btinfo->host_wakeup_gpio), (void *)exit_info);
1038 module_init(brf6150_init);
1039 module_exit(brf6150_exit);
1041 MODULE_DESCRIPTION("brf6150 hci driver");
1042 MODULE_LICENSE("GPL");
1043 MODULE_AUTHOR("Ville Tervo <ville.tervo@nokia.com>");