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>
37 #include <linux/gpio.h>
39 #include <mach/hardware.h>
40 #include <mach/board.h>
41 #include <mach/irqs.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 gpio_set_value(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 gpio_set_value(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);
235 err = hci_h4p_wait_for_cts(info, 1, 100);
239 hci_h4p_set_auto_ctsrts(info, 1, UART_EFR_CTS | UART_EFR_RTS);
241 err = hci_h4p_send_alive_packet(info);
245 dev_err(info->dev, "Could not negotiate hci_h4p settings\n");
254 info->init_error = err;
255 complete(&info->init_completion);
259 /* H4 packet handling functions */
260 static int hci_h4p_get_hdr_len(struct hci_h4p_info *info, u8 pkt_type)
266 retval = HCI_EVENT_HDR_SIZE;
269 retval = HCI_ACL_HDR_SIZE;
272 retval = HCI_SCO_HDR_SIZE;
281 dev_err(info->dev, "Unknown H4 packet type 0x%.2x\n", pkt_type);
289 static unsigned int hci_h4p_get_data_len(struct hci_h4p_info *info,
293 struct hci_event_hdr *evt_hdr;
294 struct hci_acl_hdr *acl_hdr;
295 struct hci_sco_hdr *sco_hdr;
297 switch (bt_cb(skb)->pkt_type) {
299 evt_hdr = (struct hci_event_hdr *)skb->data;
300 retval = evt_hdr->plen;
303 acl_hdr = (struct hci_acl_hdr *)skb->data;
304 retval = le16_to_cpu(acl_hdr->dlen);
307 sco_hdr = (struct hci_sco_hdr *)skb->data;
308 retval = sco_hdr->dlen;
321 static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
325 if (unlikely(!test_bit(HCI_RUNNING, &info->hdev->flags))) {
326 NBT_DBG("fw_event\n");
327 hci_h4p_parse_fw_event(info, skb);
330 NBT_DBG("Frame sent to upper layer\n");
334 static void hci_h4p_rx_tasklet(unsigned long data)
338 struct hci_h4p_info *info = (struct hci_h4p_info *)data;
340 NBT_DBG("tasklet woke up\n");
341 NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
343 while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
344 byte = hci_h4p_inb(info, UART_RX);
345 if (info->garbage_bytes) {
346 info->garbage_bytes--;
349 if (info->rx_skb == NULL) {
350 info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC | GFP_DMA);
352 dev_err(info->dev, "Can't allocate memory for new packet\n");
355 info->rx_state = WAIT_FOR_PKT_TYPE;
356 info->rx_skb->dev = (void *)info->hdev;
358 info->hdev->stat.byte_rx++;
359 NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
360 switch (info->rx_state) {
361 case WAIT_FOR_PKT_TYPE:
362 bt_cb(info->rx_skb)->pkt_type = byte;
363 info->rx_count = hci_h4p_get_hdr_len(info, byte);
364 if (info->rx_count < 0) {
365 info->hdev->stat.err_rx++;
366 kfree_skb(info->rx_skb);
369 info->rx_state = WAIT_FOR_HEADER;
372 case WAIT_FOR_HEADER:
374 *skb_put(info->rx_skb, 1) = byte;
375 if (info->rx_count == 0) {
376 info->rx_count = hci_h4p_get_data_len(info, info->rx_skb);
377 if (info->rx_count > skb_tailroom(info->rx_skb)) {
378 dev_err(info->dev, "Frame is %ld bytes too long.\n",
379 info->rx_count - skb_tailroom(info->rx_skb));
380 kfree_skb(info->rx_skb);
382 info->garbage_bytes = info->rx_count - skb_tailroom(info->rx_skb);
385 info->rx_state = WAIT_FOR_DATA;
387 if (bt_cb(info->rx_skb)->pkt_type == H4_NEG_PKT) {
388 hci_h4p_negotiation_packet(info, info->rx_skb);
390 info->rx_state = WAIT_FOR_PKT_TYPE;
393 if (bt_cb(info->rx_skb)->pkt_type == H4_ALIVE_PKT) {
394 hci_h4p_alive_packet(info, info->rx_skb);
396 info->rx_state = WAIT_FOR_PKT_TYPE;
403 *skb_put(info->rx_skb, 1) = byte;
404 if (info->rx_count == 0) {
405 /* H4+ devices should allways send word aligned packets */
406 if (!(info->rx_skb->len % 2)) {
407 info->garbage_bytes++;
409 hci_h4p_recv_frame(info, info->rx_skb);
420 spin_lock_irqsave(&info->lock, flags);
421 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_RDI);
422 spin_unlock_irqrestore(&info->lock, flags);
424 NBT_DBG_TRANSFER_NF("\n");
425 NBT_DBG("rx_ended\n");
428 static void hci_h4p_tx_tasklet(unsigned long data)
430 unsigned int sent = 0;
433 struct hci_h4p_info *info = (struct hci_h4p_info *)data;
435 NBT_DBG("tasklet woke up\n");
436 NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
438 skb = skb_dequeue(&info->txq);
440 /* No data in buffer */
441 NBT_DBG("skb ready\n");
442 hci_h4p_disable_tx(info);
446 /* Copy data to tx fifo */
447 while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
449 NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
450 hci_h4p_outb(info, UART_TX, skb->data[sent]);
454 info->hdev->stat.byte_tx += sent;
455 NBT_DBG_TRANSFER_NF("\n");
456 if (skb->len == sent) {
460 skb_queue_head(&info->txq, skb);
463 spin_lock_irqsave(&info->lock, flags);
464 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) | UART_IER_THRI);
465 spin_unlock_irqrestore(&info->lock, flags);
468 static irqreturn_t hci_h4p_interrupt(int irq, void *data)
470 struct hci_h4p_info *info = (struct hci_h4p_info *)data;
477 iir = hci_h4p_inb(info, UART_IIR);
478 if (iir & UART_IIR_NO_INT) {
479 dev_err(info->dev, "Interrupt but no reason irq 0x%.2x\n", iir);
483 NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
487 if (iir == UART_IIR_MSI) {
488 msr = hci_h4p_inb(info, UART_MSR);
491 if (iir == UART_IIR_RLSI) {
492 hci_h4p_inb(info, UART_RX);
493 hci_h4p_inb(info, UART_LSR);
497 if (iir == UART_IIR_RDI) {
498 spin_lock_irqsave(&info->lock, flags);
499 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_RDI);
500 spin_unlock_irqrestore(&info->lock, flags);
501 tasklet_schedule(&info->rx_task);
505 if (iir == UART_IIR_THRI) {
506 spin_lock_irqsave(&info->lock, flags);
507 hci_h4p_outb(info, UART_IER, hci_h4p_inb(info, UART_IER) & ~UART_IER_THRI);
508 spin_unlock_irqrestore(&info->lock, flags);
509 tasklet_schedule(&info->tx_task);
516 static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
518 struct hci_h4p_info *info = dev_inst;
520 struct hci_dev *hdev;
527 if (!test_bit(HCI_RUNNING, &hdev->flags))
530 should_wakeup = gpio_get_value(info->host_wakeup_gpio);
531 NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
533 hci_h4p_enable_rx(info);
535 hci_h4p_disable_rx(info);
541 static int hci_h4p_reset(struct hci_h4p_info *info)
545 hci_h4p_init_uart(info);
546 hci_h4p_set_rts(info, 0);
548 gpio_set_value(info->reset_gpio, 0);
550 gpio_set_value(info->bt_wakeup_gpio, 1);
551 gpio_set_value(info->reset_gpio, 1);
554 err = hci_h4p_wait_for_cts(info, 1, 10);
556 dev_err(info->dev, "No cts from bt chip\n");
560 hci_h4p_set_rts(info, 1);
565 /* hci callback functions */
566 static int hci_h4p_hci_flush(struct hci_dev *hdev)
568 struct hci_h4p_info *info;
569 info = hdev->driver_data;
571 skb_queue_purge(&info->txq);
576 static int hci_h4p_hci_open(struct hci_dev *hdev)
578 struct hci_h4p_info *info;
580 struct sk_buff *neg_cmd_skb;
581 struct sk_buff_head fw_queue;
583 info = hdev->driver_data;
585 if (test_bit(HCI_RUNNING, &hdev->flags))
588 skb_queue_head_init(&fw_queue);
589 err = hci_h4p_read_fw(info, &fw_queue);
591 dev_err(info->dev, "Cannot read firmware\n");
594 neg_cmd_skb = skb_dequeue(&fw_queue);
599 info->alive_cmd_skb = skb_dequeue(&fw_queue);
600 if (!info->alive_cmd_skb) {
605 hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
606 hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
608 tasklet_enable(&info->tx_task);
609 tasklet_enable(&info->rx_task);
610 info->rx_state = WAIT_FOR_PKT_TYPE;
612 info->garbage_bytes = 0;
614 info->pm_enabled = 0;
615 init_completion(&info->fw_completion);
617 err = hci_h4p_reset(info);
621 err = hci_h4p_send_negotiation(info, neg_cmd_skb);
626 err = hci_h4p_send_fw(info, &fw_queue);
628 dev_err(info->dev, "Sending firmware failed.\n");
632 kfree_skb(info->alive_cmd_skb);
633 info->alive_cmd_skb = NULL;
634 info->pm_enabled = 1;
635 info->tx_pm_enabled = 1;
636 info->rx_pm_enabled = 0;
637 set_bit(HCI_RUNNING, &hdev->flags);
639 NBT_DBG("hci up and running\n");
643 hci_h4p_hci_flush(hdev);
644 tasklet_disable(&info->tx_task);
645 tasklet_disable(&info->rx_task);
646 hci_h4p_reset_uart(info);
647 hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
648 hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
649 gpio_set_value(info->reset_gpio, 0);
650 gpio_set_value(info->bt_wakeup_gpio, 0);
651 skb_queue_purge(&fw_queue);
652 kfree_skb(neg_cmd_skb);
654 kfree_skb(info->alive_cmd_skb);
655 info->alive_cmd_skb = NULL;
656 kfree_skb(info->rx_skb);
661 static int hci_h4p_hci_close(struct hci_dev *hdev)
663 struct hci_h4p_info *info = hdev->driver_data;
665 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
668 hci_h4p_hci_flush(hdev);
669 del_timer_sync(&info->tx_pm_timer);
670 del_timer_sync(&info->rx_pm_timer);
671 tasklet_disable(&info->tx_task);
672 tasklet_disable(&info->rx_task);
673 hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
674 hci_h4p_set_clk(info, &info->rx_clocks_en, 1);
675 hci_h4p_reset_uart(info);
676 hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
677 hci_h4p_set_clk(info, &info->rx_clocks_en, 0);
678 gpio_set_value(info->reset_gpio, 0);
679 gpio_set_value(info->bt_wakeup_gpio, 0);
680 kfree_skb(info->rx_skb);
685 static void hci_h4p_hci_destruct(struct hci_dev *hdev)
689 static int hci_h4p_hci_send_frame(struct sk_buff *skb)
691 struct hci_h4p_info *info;
692 struct hci_dev *hdev = (struct hci_dev *)skb->dev;
696 printk(KERN_WARNING "hci_h4p: Frame for unknown device\n");
700 NBT_DBG("dev %p, skb %p\n", hdev, skb);
702 info = hdev->driver_data;
704 if (!test_bit(HCI_RUNNING, &hdev->flags)) {
705 dev_warn(info->dev, "Frame for non-running device\n");
709 switch (bt_cb(skb)->pkt_type) {
710 case HCI_COMMAND_PKT:
713 case HCI_ACLDATA_PKT:
716 case HCI_SCODATA_PKT:
721 /* Push frame type to skb */
722 *skb_push(skb, 1) = (bt_cb(skb)->pkt_type);
723 /* We should allways send word aligned data to h4+ devices */
725 err = skb_pad(skb, 1);
730 hci_h4p_enable_tx(info);
731 skb_queue_tail(&info->txq, skb);
732 tasklet_schedule(&info->tx_task);
737 static int hci_h4p_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
742 static int hci_h4p_register_hdev(struct hci_h4p_info *info)
744 struct hci_dev *hdev;
746 /* Initialize and register HCI device */
748 hdev = hci_alloc_dev();
750 dev_err(info->dev, "Can't allocate memory for device\n");
755 hdev->type = HCI_UART;
756 hdev->driver_data = info;
758 hdev->open = hci_h4p_hci_open;
759 hdev->close = hci_h4p_hci_close;
760 hdev->flush = hci_h4p_hci_flush;
761 hdev->send = hci_h4p_hci_send_frame;
762 hdev->destruct = hci_h4p_hci_destruct;
763 hdev->ioctl = hci_h4p_hci_ioctl;
765 hdev->owner = THIS_MODULE;
767 if (hci_register_dev(hdev) < 0) {
768 dev_err(info->dev, "hci_h4p: Can't register HCI device %s.\n", hdev->name);
775 static int hci_h4p_probe(struct platform_device *pdev)
777 struct omap_bluetooth_config *bt_config;
778 struct hci_h4p_info *info;
781 dev_info(&pdev->dev, "Registering HCI H4P device\n");
782 info = kzalloc(sizeof(struct hci_h4p_info), GFP_KERNEL);
786 info->dev = &pdev->dev;
787 info->pm_enabled = 0;
788 info->tx_pm_enabled = 0;
789 info->rx_pm_enabled = 0;
790 info->garbage_bytes = 0;
791 info->tx_clocks_en = 0;
792 info->rx_clocks_en = 0;
793 tasklet_init(&info->tx_task, hci_h4p_tx_tasklet, (unsigned long)info);
794 tasklet_init(&info->rx_task, hci_h4p_rx_tasklet, (unsigned long)info);
795 /* hci_h4p_hci_open assumes that tasklet is disabled in startup */
796 tasklet_disable(&info->tx_task);
797 tasklet_disable(&info->rx_task);
798 spin_lock_init(&info->lock);
799 spin_lock_init(&info->clocks_lock);
800 skb_queue_head_init(&info->txq);
801 init_timer(&info->tx_pm_timer);
802 info->tx_pm_timer.function = hci_h4p_tx_pm_timer;
803 info->tx_pm_timer.data = (unsigned long)info;
804 init_timer(&info->rx_pm_timer);
805 info->rx_pm_timer.function = hci_h4p_rx_pm_timer;
806 info->rx_pm_timer.data = (unsigned long)info;
808 if (pdev->dev.platform_data == NULL) {
809 dev_err(&pdev->dev, "Could not get Bluetooth config data\n");
813 bt_config = pdev->dev.platform_data;
814 info->chip_type = bt_config->chip_type;
815 info->bt_wakeup_gpio = bt_config->bt_wakeup_gpio;
816 info->host_wakeup_gpio = bt_config->host_wakeup_gpio;
817 info->reset_gpio = bt_config->reset_gpio;
818 info->bt_sysclk = bt_config->bt_sysclk;
820 NBT_DBG("RESET gpio: %d\n", info->reset_gpio);
821 NBT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
822 NBT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
823 NBT_DBG("Uart: %d\n", bt_config->bt_uart);
824 NBT_DBG("sysclk: %d\n", info->bt_sysclk);
826 err = gpio_request(info->reset_gpio, "BT reset");
828 dev_err(&pdev->dev, "Cannot get GPIO line %d\n",
834 err = gpio_request(info->bt_wakeup_gpio, "BT wakeup");
837 dev_err(info->dev, "Cannot get GPIO line 0x%d",
838 info->bt_wakeup_gpio);
839 gpio_free(info->reset_gpio);
844 err = gpio_request(info->host_wakeup_gpio, "BT host wakeup");
847 dev_err(info->dev, "Cannot get GPIO line %d",
848 info->host_wakeup_gpio);
849 gpio_free(info->reset_gpio);
850 gpio_free(info->bt_wakeup_gpio);
855 gpio_direction_output(info->reset_gpio, 0);
856 gpio_direction_output(info->bt_wakeup_gpio, 0);
857 gpio_direction_input(info->host_wakeup_gpio);
859 switch (bt_config->bt_uart) {
861 if (cpu_is_omap16xx()) {
863 info->uart_fclk = clk_get(NULL, "uart1_ck");
864 } else if (cpu_is_omap24xx()) {
865 irq = INT_24XX_UART1_IRQ;
866 info->uart_iclk = clk_get(NULL, "uart1_ick");
867 info->uart_fclk = clk_get(NULL, "uart1_fck");
869 /* FIXME: Use platform_get_resource for the port */
870 info->uart_base = ioremap(OMAP_UART1_BASE, 0x16);
871 if (!info->uart_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 /* FIXME: Use platform_get_resource for the port */
884 info->uart_base = ioremap(OMAP_UART2_BASE, 0x16);
885 if (!info->uart_base)
889 if (cpu_is_omap16xx()) {
891 info->uart_fclk = clk_get(NULL, "uart3_ck");
893 irq = INT_24XX_UART3_IRQ;
894 info->uart_iclk = clk_get(NULL, "uart3_ick");
895 info->uart_fclk = clk_get(NULL, "uart3_fck");
897 /* FIXME: Use platform_get_resource for the port */
898 info->uart_base = ioremap(OMAP_UART3_BASE, 0x16);
899 if (!info->uart_base)
903 dev_err(info->dev, "No uart defined\n");
908 err = request_irq(irq, hci_h4p_interrupt, 0, "hci_h4p", (void *)info);
910 dev_err(info->dev, "hci_h4p: unable to get IRQ %d\n", irq);
914 err = request_irq(gpio_to_irq(info->host_wakeup_gpio),
915 hci_h4p_wakeup_interrupt,
916 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
917 "hci_h4p_wkup", (void *)info);
919 dev_err(info->dev, "hci_h4p: unable to get wakeup IRQ %d\n",
920 gpio_to_irq(info->host_wakeup_gpio));
921 free_irq(irq, (void *)info);
925 hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
926 hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_CTS | UART_EFR_RTS);
927 err = hci_h4p_init_uart(info);
930 err = hci_h4p_reset(info);
933 err = hci_h4p_wait_for_cts(info, 1, 10);
936 hci_h4p_set_clk(info, &info->tx_clocks_en, 0);
938 platform_set_drvdata(pdev, info);
939 err = hci_h4p_sysfs_create_files(info->dev);
943 if (hci_h4p_register_hdev(info) < 0) {
944 dev_err(info->dev, "failed to register hci_h4p hci device\n");
947 gpio_set_value(info->reset_gpio, 0);
952 free_irq(irq, (void *)info);
953 free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *)info);
955 gpio_set_value(info->reset_gpio, 0);
956 gpio_free(info->reset_gpio);
957 gpio_free(info->bt_wakeup_gpio);
958 gpio_free(info->host_wakeup_gpio);
965 static int hci_h4p_remove(struct platform_device *dev)
967 struct hci_h4p_info *info;
969 info = platform_get_drvdata(dev);
971 hci_h4p_hci_close(info->hdev);
972 free_irq(gpio_to_irq(info->host_wakeup_gpio), (void *) info);
973 hci_free_dev(info->hdev);
974 gpio_free(info->reset_gpio);
975 gpio_free(info->bt_wakeup_gpio);
976 gpio_free(info->host_wakeup_gpio);
977 free_irq(info->irq, (void *) info);
983 static struct platform_driver hci_h4p_driver = {
984 .probe = hci_h4p_probe,
985 .remove = hci_h4p_remove,
991 static int __init hci_h4p_init(void)
995 /* Register the driver with LDM */
996 err = platform_driver_register(&hci_h4p_driver);
998 printk(KERN_WARNING "failed to register hci_h4p driver\n");
1003 static void __exit hci_h4p_exit(void)
1005 platform_driver_unregister(&hci_h4p_driver);
1008 module_init(hci_h4p_init);
1009 module_exit(hci_h4p_exit);
1011 MODULE_DESCRIPTION("h4 driver with nokia extensions");
1012 MODULE_LICENSE("GPL");
1013 MODULE_AUTHOR("Ville Tervo");