2 * This file is part of hci_h4p bluetooth driver
4 * Copyright (C) 2005, 2006 Nokia Corporation.
6 * Contact: Ville Tervo <ville.tervo@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * 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., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/errno.h>
29 #include <linux/delay.h>
30 #include <linux/spinlock.h>
31 #include <linux/serial_reg.h>
32 #include <linux/skbuff.h>
33 #include <linux/timer.h>
34 #include <linux/device.h>
35 #include <linux/platform_device.h>
36 #include <linux/clk.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>
42 #include <asm/arch/pm.h>
44 #include <net/bluetooth/bluetooth.h>
45 #include <net/bluetooth/hci_core.h>
46 #include <net/bluetooth/hci.h>
50 #define PM_TIMEOUT 200
52 /* This should be used in function that cannot release clocks */
53 static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
57 spin_lock_irqsave(&info->clocks_lock, flags);
58 if (enable && !*clock) {
59 NBT_DBG_POWER("Enabling %p\n", clock);
60 clk_enable(info->uart_fclk);
61 #ifdef CONFIG_ARCH_OMAP2
62 if (cpu_is_omap24xx()) {
63 clk_enable(info->uart_iclk);
68 if (!enable && *clock) {
69 NBT_DBG_POWER("Disabling %p\n", clock);
70 clk_disable(info->uart_fclk);
71 #ifdef CONFIG_ARCH_OMAP2
72 if (cpu_is_omap24xx()) {
73 clk_disable(info->uart_iclk);
80 spin_unlock_irqrestore(&info->clocks_lock, flags);
83 /* Power management functions */
84 static void hci_h4p_disable_tx(struct hci_h4p_info *info)
88 if (!info->pm_enabled)
91 mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
94 static void hci_h4p_enable_tx(struct hci_h4p_info *info)
98 if (!info->pm_enabled)
101 del_timer_sync(&info->tx_pm_timer);
102 if (info->tx_pm_enabled) {
103 info->tx_pm_enabled = 0;
104 hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
105 omap_set_gpio_dataout(info->bt_wakeup_gpio, 1);
109 static void hci_h4p_tx_pm_timer(unsigned long data)
111 struct hci_h4p_info *info;
115 info = (struct hci_h4p_info *)data;
117 if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
118 omap_set_gpio_dataout(info->bt_wakeup_gpio, 0);
119 hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
120 info->tx_pm_enabled = 1;
123 mod_timer(&info->tx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
127 static void hci_h4p_disable_rx(struct hci_h4p_info *info)
129 if (!info->pm_enabled)
132 mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
135 static void hci_h4p_enable_rx(struct hci_h4p_info *info)
139 if (!info->pm_enabled)
142 del_timer_sync(&info->rx_pm_timer);
143 spin_lock_irqsave(&info->lock, flags);
144 if (info->rx_pm_enabled) {
145 hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
146 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
147 hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_RTS);
148 info->rx_pm_enabled = 0;
150 spin_unlock_irqrestore(&info->lock, flags);
153 static void hci_h4p_rx_pm_timer(unsigned long data)
156 struct hci_h4p_info *info = (struct hci_h4p_info *)data;
158 spin_lock_irqsave(&info->lock, flags);
159 if (!(hci_h4p_inb(info, UART_LSR) & UART_LSR_DR)) {
160 hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
161 hci_h4p_set_rts(info, 0);
162 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
163 hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
164 info->rx_pm_enabled = 1;
167 mod_timer(&info->rx_pm_timer, jiffies + msecs_to_jiffies(PM_TIMEOUT));
169 spin_unlock_irqrestore(&info->lock, flags);
172 /* Negotiation functions */
173 int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
175 NBT_DBG("Sending alive packet\n");
177 if (!info->alive_cmd_skb)
180 /* Keep reference to buffer so we can reuse it */
181 info->alive_cmd_skb = skb_get(info->alive_cmd_skb);
183 skb_queue_tail(&info->txq, info->alive_cmd_skb);
184 tasklet_schedule(&info->tx_task);
186 NBT_DBG("Alive packet sent\n");
191 static void hci_h4p_alive_packet(struct hci_h4p_info *info, struct sk_buff *skb)
193 NBT_DBG("Received alive packet\n");
194 if (skb->data[1] == 0xCC) {
195 complete(&info->init_completion);
201 static int hci_h4p_send_negotiation(struct hci_h4p_info *info, struct sk_buff *skb)
203 NBT_DBG("Sending negotiation..\n");
205 hci_h4p_change_speed(info, INIT_SPEED);
207 info->init_error = 0;
208 init_completion(&info->init_completion);
209 skb_queue_tail(&info->txq, skb);
210 tasklet_schedule(&info->tx_task);
212 if (!wait_for_completion_interruptible_timeout(&info->init_completion,
213 msecs_to_jiffies(1000)))
216 NBT_DBG("Negotiation sent\n");
217 return info->init_error;
220 static void hci_h4p_negotiation_packet(struct hci_h4p_info *info,
225 if (skb->data[1] == 0x20) {
226 /* Change to operational settings */
227 hci_h4p_set_rts(info, 0);
229 err = hci_h4p_wait_for_cts(info, 0, 100);
233 hci_h4p_change_speed(info, MAX_BAUD_RATE);
234 hci_h4p_set_rts(info, 1);
236 err = hci_h4p_wait_for_cts(info, 1, 100);
240 hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
242 err = hci_h4p_send_alive_packet(info);
246 dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
255 complete(&info->init_completion);
256 info->init_error = err;
260 /* H4 packet handling functions */
261 static int hci_h4p_get_hdr_len(struct hci_h4p_info *info, u8 pkt_type)
267 retval = HCI_EVENT_HDR_SIZE;
270 retval = HCI_ACL_HDR_SIZE;
273 retval = HCI_SCO_HDR_SIZE;
282 dev_err(info->dev, "Unknown H4 packet type 0x%.2x\n", pkt_type);
290 static unsigned int hci_h4p_get_data_len(struct hci_h4p_info *info,
294 struct hci_event_hdr *evt_hdr;
295 struct hci_acl_hdr *acl_hdr;
296 struct hci_sco_hdr *sco_hdr;
298 switch (bt_cb(skb)->pkt_type) {
300 evt_hdr = (struct hci_event_hdr *)skb->data;
301 retval = evt_hdr->plen;
304 acl_hdr = (struct hci_acl_hdr *)skb->data;
305 retval = le16_to_cpu(acl_hdr->dlen);
308 sco_hdr = (struct hci_sco_hdr *)skb->data;
309 retval = sco_hdr->dlen;
322 static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
326 if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
327 NBT_DBG("fw_event\n");
328 hci_h4p_parse_fw_event(info, skb);
331 NBT_DBG("Frame sent to upper layer\n");
335 static void hci_h4p_rx_tasklet(unsigned long data)
339 struct hci_h4p_info *info = (struct hci_h4p_info *)data;
341 NBT_DBG("tasklet woke up\n");
342 NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
344 while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
345 byte = hci_h4p_inb(info, UART_RX);
346 if (info->garbage_bytes) {
347 info->garbage_bytes--;
350 if (info->rx_skb == NULL) {
351 info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC | GFP_DMA);
353 dev_err(info->dev, "Can't allocate memory for new packet\n");
356 info->rx_state = WAIT_FOR_PKT_TYPE;
357 info->rx_skb->dev = (void *)info->hdev;
359 info->hdev->stat.byte_rx++;
360 NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
361 switch (info->rx_state) {
362 case WAIT_FOR_PKT_TYPE:
363 bt_cb(info->rx_skb)->pkt_type = byte;
364 info->rx_count = hci_h4p_get_hdr_len(info, byte);
365 if (info->rx_count < 0) {
366 info->hdev->stat.err_rx++;
367 kfree_skb(info->rx_skb);
370 info->rx_state = WAIT_FOR_HEADER;
373 case WAIT_FOR_HEADER:
375 *skb_put(info->rx_skb, 1) = byte;
376 if (info->rx_count == 0) {
377 info->rx_count = hci_h4p_get_data_len(info, info->rx_skb);
378 if (info->rx_count > skb_tailroom(info->rx_skb)) {
379 dev_err(info->dev, "Frame is %ld bytes too long.\n",
380 info->rx_count - skb_tailroom(info->rx_skb));
381 kfree_skb(info->rx_skb);
383 info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
386 info->rx_state = WAIT_FOR_DATA;
388 if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
389 hci_h4p_negotiation_packet(info, info->rx_skb);
391 info->rx_state = WAIT_FOR_PKT_TYPE;
394 if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
395 hci_h4p_alive_packet(info, info->rx_skb);
397 info->rx_state = WAIT_FOR_PKT_TYPE;
404 *skb_put(info->rx_skb, 1) = byte;
405 if (info->rx_count == 0) {
406 /* H4+ devices should allways send word aligned packets */
407 if (!(info->rx_skb->len % 2)) {
408 info->garbage_bytes++;
410 hci_h4p_recv_frame(info, info->rx_skb);
421 spin_lock_irqsave(&info->lock, flags);
422 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
423 spin_unlock_irqrestore(&info->lock, flags);
425 NBT_DBG_TRANSFER_NF("\n");
426 NBT_DBG("rx_ended\n");
429 static void hci_h4p_tx_tasklet(unsigned long data)
431 unsigned int sent = 0;
434 struct hci_h4p_info *info = (struct hci_h4p_info *)data;
436 NBT_DBG("tasklet woke up\n");
437 NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
439 skb = skb_dequeue(&info->txq);
441 /* No data in buffer */
442 NBT_DBG("skb ready\n");
443 hci_h4p_disable_tx(info);
447 /* Copy data to tx fifo */
448 while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
450 NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
451 hci_h4p_outb(info, UART_TX, skb->data[sent]);
455 info->hdev->stat.byte_tx += sent;
456 NBT_DBG_TRANSFER_NF("\n");
457 if (skb->len == sent) {
461 skb_queue_head(&info->txq, skb);
464 spin_lock_irqsave(&info->lock, flags);
465 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_THRI);
466 spin_unlock_irqrestore(&info->lock, flags);
469 static irqreturn_t hci_h4p_interrupt(int irq, void *data)
471 struct hci_h4p_info *info = (struct hci_h4p_info *)data;
478 iir = hci_h4p_inb(info, UART_IIR);
479 if (iir & UART_IIR_NO_INT) {
480 dev_err(info->dev, "Interrupt but no reason irq 0x%.2x\n", iir);
484 NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
488 if (iir == UART_IIR_MSI) {
489 msr = hci_h4p_inb(info, UART_MSR);
492 if (iir == UART_IIR_RLSI) {
493 hci_h4p_inb(info, UART_RX);
494 hci_h4p_inb(info, UART_LSR);
498 if (iir == UART_IIR_RDI) {
499 spin_lock_irqsave(&info->lock, flags);
500 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
501 spin_unlock_irqrestore(&info->lock, flags);
502 tasklet_schedule(&info->rx_task);
506 if (iir == UART_IIR_THRI) {
507 spin_lock_irqsave(&info->lock, flags);
508 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_THRI);
509 spin_unlock_irqrestore(&info->lock, flags);
510 tasklet_schedule(&info->tx_task);
518 static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
520 struct hci_h4p_info *info = dev_inst;
522 struct hci_dev *hdev;
529 if (!test_bit(HCI_RUNNING, &hdev->flags))
532 should_wakeup = omap_get_gpio_datain(info->host_wakeup_gpio);
533 NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
535 hci_h4p_enable_rx(info);
537 hci_h4p_disable_rx(info);
543 static int hci_h4p_reset(struct hci_h4p_info *info)
547 hci_h4p_init_uart(info);
548 hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
549 hci_h4p_set_rts(info, 0);
551 omap_set_gpio_dataout(info->reset_gpio, 0);
553 omap_set_gpio_dataout(info->bt_wakeup_gpio, 1);
554 omap_set_gpio_dataout(info->reset_gpio, 1);
557 err = hci_h4p_wait_for_cts(info, 1, 10);
559 dev_err(info->dev, "No cts from bt chip\n");
563 hci_h4p_set_rts(info, 1);
568 /* hci callback functions */
569 static int hci_h4p_hci_flush(struct hci_dev *hdev)
571 struct hci_h4p_info *info;
572 info = hdev->driver_data;
574 skb_queue_purge(&info->txq);
579 static int hci_h4p_hci_open(struct hci_dev *hdev)
581 struct hci_h4p_info *info;
583 struct sk_buff *neg_cmd_skb;
584 struct sk_buff_head fw_queue;
586 info = hdev->driver_data;
588 if (test_bit(HCI_RUNNING, &hdev->flags))
591 skb_queue_head_init(&fw_queue);
592 err = hci_h4p_read_fw(info, &fw_queue);
594 dev_err(info->dev, "Cannot read firmware\n");
597 neg_cmd_skb = skb_dequeue(&fw_queue);
602 info->alive_cmd_skb = skb_dequeue(&fw_queue);
603 if (!info->alive_cmd_skb) {
608 hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
609 hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
611 tasklet_enable(&info->tx_task);
612 tasklet_enable(&info->rx_task);
613 info->rx_state = WAIT_FOR_PKT_TYPE;
615 info->garbage_bytes = 0;
617 info->pm_enabled = 0;
618 init_completion(&info->fw_completion);
620 err = hci_h4p_reset(info);
624 err = hci_h4p_send_negotiation(info, neg_cmd_skb);
629 hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
631 err = hci_h4p_send_fw(info, &fw_queue);
633 dev_err(info->dev, "Sending firmware failed.\n");
637 kfree_skb(info->alive_cmd_skb);
638 info->alive_cmd_skb = NULL;
639 info->pm_enabled = 1;
640 info->tx_pm_enabled = 1;
641 info->rx_pm_enabled = 0;
642 set_bit(HCI_RUNNING, &hdev->flags);
644 NBT_DBG("hci up and running\n");
648 hci_h4p_hci_flush(hdev);
649 tasklet_disable(&info->tx_task);
650 tasklet_disable(&info->rx_task);
651 hci_h4p_reset_uart(info);
652 hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
653 hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
654 omap_set_gpio_dataout(info->reset_gpio, 0);
655 omap_set_gpio_dataout(info->bt_wakeup_gpio, 0);
656 skb_queue_purge(&fw_queue);
657 kfree_skb(neg_cmd_skb);
659 kfree_skb(info->alive_cmd_skb);
660 info->alive_cmd_skb = NULL;
661 kfree_skb(info->rx_skb);
666 static int hci_h4p_hci_close(struct hci_dev *hdev)
668 struct hci_h4p_info *info = hdev->driver_data;
670 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
673 hci_h4p_hci_flush(hdev);
674 del_timer_sync(&info->tx_pm_timer);
675 del_timer_sync(&info->rx_pm_timer);
676 tasklet_disable(&info->tx_task);
677 tasklet_disable(&info->rx_task);
678 hci_h4p_reset_uart(info);
679 hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
680 hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
681 omap_set_gpio_dataout(info->reset_gpio, 0);
682 omap_set_gpio_dataout(info->bt_wakeup_gpio, 0);
683 kfree_skb(info->rx_skb);
688 static void hci_h4p_hci_destruct(struct hci_dev *hdev)
692 static int hci_h4p_hci_send_frame(struct sk_buff *skb)
694 struct hci_h4p_info *info;
695 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
699 printk(KERN_WARNING "hci_h4p: Frame for unknown device\n");
703 NBT_DBG("dev %p, skb %p\n", hdev, skb);
705 info = hdev->driver_data;
707 if (!test_bit(HCI_RUNNING, &hdev->flags)) {
708 dev_warn(info->dev, "Frame for non-running device\n");
712 switch (bt_cb(skb)->pkt_type) {
713 case HCI_COMMAND_PKT:
716 case HCI_ACLDATA_PKT:
719 case HCI_SCODATA_PKT:
724 /* Push frame type to skb */
725 *skb_push(skb, 1) = (bt_cb(skb)->pkt_type);
726 /* We should allways send word aligned data to h4+ devices */
728 err = skb_pad(skb, 1);
733 hci_h4p_enable_tx(info);
734 skb_queue_tail(&info->txq, skb);
735 tasklet_schedule(&info->tx_task);
740 static int hci_h4p_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
745 static int hci_h4p_register_hdev(struct hci_h4p_info *info)
747 struct hci_dev *hdev;
749 /* Initialize and register HCI device */
751 hdev = hci_alloc_dev();
753 dev_err(info->dev, "Can't allocate memory for device\n");
758 hdev->type = HCI_UART;
759 hdev->driver_data = info;
761 hdev->open = hci_h4p_hci_open;
762 hdev->close = hci_h4p_hci_close;
763 hdev->flush = hci_h4p_hci_flush;
764 hdev->send = hci_h4p_hci_send_frame;
765 hdev->destruct = hci_h4p_hci_destruct;
766 hdev->ioctl = hci_h4p_hci_ioctl;
768 hdev->owner = THIS_MODULE;
770 if (hci_register_dev(hdev) < 0) {
771 dev_err(info->dev, "hci_h4p: Can't register HCI device %s.\n", hdev->name);
778 static int hci_h4p_probe(struct platform_device *pdev)
780 struct omap_bluetooth_config *bt_config;
781 struct hci_h4p_info *info;
784 dev_info(&pdev->dev, "Registering HCI H4P device\n");
785 info = kzalloc(sizeof(struct hci_h4p_info), GFP_KERNEL);
789 info->dev = &pdev->dev;
790 info->pm_enabled = 0;
791 info->tx_pm_enabled = 0;
792 info->rx_pm_enabled = 0;
793 info->garbage_bytes = 0;
794 info->tx_clocks_en = 0;
795 info->rx_clocks_en = 0;
796 tasklet_init(&info->tx_task, hci_h4p_tx_tasklet, (unsigned long)info);
797 tasklet_init(&info->rx_task, hci_h4p_rx_tasklet, (unsigned long)info);
798 /* hci_h4p_hci_open assumes that tasklet is disabled in startup */
799 tasklet_disable(&info->tx_task);
800 tasklet_disable(&info->rx_task);
801 spin_lock_init(&info->lock);
802 spin_lock_init(&info->clocks_lock);
803 skb_queue_head_init(&info->txq);
804 init_timer(&info->tx_pm_timer);
805 info->tx_pm_timer.function = hci_h4p_tx_pm_timer;
806 info->tx_pm_timer.data = (unsigned long)info;
807 init_timer(&info->rx_pm_timer);
808 info->rx_pm_timer.function = hci_h4p_rx_pm_timer;
809 info->rx_pm_timer.data = (unsigned long)info;
811 if (pdev->dev.platform_data == NULL) {
812 dev_err(&pdev->dev, "Could not get Bluetooth config data\n");
816 bt_config = pdev->dev.platform_data;
817 info->chip_type = bt_config->chip_type;
818 info->bt_wakeup_gpio = bt_config->bt_wakeup_gpio;
819 info->host_wakeup_gpio = bt_config->host_wakeup_gpio;
820 info->reset_gpio = bt_config->reset_gpio;
821 info->bt_sysclk = bt_config->bt_sysclk;
823 NBT_DBG("RESET gpio: %d\n", info->reset_gpio);
824 NBT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
825 NBT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
826 NBT_DBG("Uart: %d\n", bt_config->bt_uart);
827 NBT_DBG("sysclk: %d\n", info->bt_sysclk);
829 err = omap_request_gpio(info->reset_gpio);
831 dev_err(&pdev->dev, "Cannot get GPIO line %d\n",
837 err = omap_request_gpio(info->bt_wakeup_gpio);
840 dev_err(info->dev, "Cannot get GPIO line 0x%d",
841 info->bt_wakeup_gpio);
842 omap_free_gpio(info->reset_gpio);
847 err = omap_request_gpio(info->host_wakeup_gpio);
850 dev_err(info->dev, "Cannot get GPIO line %d",
851 info->host_wakeup_gpio);
852 omap_free_gpio(info->reset_gpio);
853 omap_free_gpio(info->bt_wakeup_gpio);
858 omap_set_gpio_direction(info->reset_gpio, 0);
859 omap_set_gpio_direction(info->bt_wakeup_gpio, 0);
860 omap_set_gpio_direction(info->host_wakeup_gpio, 1);
862 switch (bt_config->bt_uart) {
864 if (cpu_is_omap16xx()) {
866 info->uart_fclk = clk_get(NULL, "uart1_ck");
867 } else if (cpu_is_omap24xx()) {
868 irq = INT_24XX_UART1_IRQ;
869 info->uart_iclk = clk_get(NULL, "uart1_ick");
870 info->uart_fclk = clk_get(NULL, "uart1_fck");
872 info->uart_base = (void *)io_p2v(OMAP_UART1_BASE);
875 if (cpu_is_omap16xx()) {
877 info->uart_fclk = clk_get(NULL, "uart2_ck");
879 irq = INT_24XX_UART2_IRQ;
880 info->uart_iclk = clk_get(NULL, "uart2_ick");
881 info->uart_fclk = clk_get(NULL, "uart2_fck");
883 info->uart_base = (void *)io_p2v(OMAP_UART2_BASE);
886 if (cpu_is_omap16xx()) {
888 info->uart_fclk = clk_get(NULL, "uart3_ck");
890 irq = INT_24XX_UART3_IRQ;
891 info->uart_iclk = clk_get(NULL, "uart3_ick");
892 info->uart_fclk = clk_get(NULL, "uart3_fck");
894 info->uart_base = (void *)io_p2v(OMAP_UART3_BASE);
897 dev_err(info->dev, "No uart defined\n");
902 err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
904 dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
908 err = request_irq(OMAP_GPIO_IRQ(info->host_wakeup_gpio),
909 hci_h4p_wakeup_interrupt, SA_TRIGGER_FALLING | SA_TRIGGER_RISING,
910 "hci_h4p_wkup", (void *)info);
912 dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
913 OMAP_GPIO_IRQ(info->host_wakeup_gpio));
914 free_irq(irq, (void *)info);
918 hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
919 err = hci_h4p_init_uart(info);
922 hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
923 hci_h4p_set_rts(info, 0);
924 err = hci_h4p_reset(info);
927 err = hci_h4p_wait_for_cts(info, 1, 10);
930 hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
932 platform_set_drvdata(pdev, info);
933 err = hci_h4p_sysfs_create_files(info->dev);
937 if (hci_h4p_register_hdev(info) < 0) {
938 dev_err(info->dev, "failed to register hci_h4p hci device\n");
941 omap_set_gpio_dataout(info->reset_gpio, 0);
946 free_irq(irq, (void *)info);
947 free_irq(OMAP_GPIO_IRQ(info->host_wakeup_gpio), (void *)info);
949 omap_set_gpio_dataout(info->reset_gpio, 0);
950 omap_free_gpio(info->reset_gpio);
951 omap_free_gpio(info->bt_wakeup_gpio);
952 omap_free_gpio(info->host_wakeup_gpio);
959 static int hci_h4p_remove(struct platform_device *dev)
961 struct hci_h4p_info *info;
963 info = platform_get_drvdata(dev);
965 hci_h4p_hci_close(info->hdev);
966 free_irq(OMAP_GPIO_IRQ(info->host_wakeup_gpio), (void *) info);
967 hci_free_dev(info->hdev);
968 omap_free_gpio(info->reset_gpio);
969 omap_free_gpio(info->bt_wakeup_gpio);
970 omap_free_gpio(info->host_wakeup_gpio);
971 free_irq(info->irq, (void *) info);
977 static struct platform_driver hci_h4p_driver = {
978 .probe = hci_h4p_probe,
979 .remove = hci_h4p_remove,
985 static int __init hci_h4p_init(void)
989 /* Register the driver with LDM */
990 err = platform_driver_register(&hci_h4p_driver);
992 printk(KERN_WARNING "failed to register hci_h4p driver\n");
997 static void __exit hci_h4p_exit(void)
999 platform_driver_unregister(&hci_h4p_driver);
1002 module_init(hci_h4p_init);
1003 module_exit(hci_h4p_exit);
1005 MODULE_DESCRIPTION("h4 driver with nokia extensions");
1006 MODULE_LICENSE("GPL");
1007 MODULE_AUTHOR("Ville Tervo");