23 #include <linux/module.h>
25 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
30 #include <linux/errno.h>
31 #include <linux/ptrace.h>
37 #include <linux/string.h>
38 #include <linux/serial.h>
40 #include <linux/bitops.h>
57 MODULE_DESCRIPTION(
"Bluetooth driver for Bluetooth PCMCIA cards with HCI UART interface");
81 static int btuart_config(
struct pcmcia_device *
link);
82 static void btuart_release(
struct pcmcia_device *
link);
84 static void btuart_detach(
struct pcmcia_device *p_dev);
88 #define SPEED_MAX 115200
91 #define DEFAULT_BAUD_RATE 115200
95 #define XMIT_SENDING 1
97 #define XMIT_WAITING 8
100 #define RECV_WAIT_PACKET_TYPE 0
101 #define RECV_WAIT_EVENT_HEADER 1
102 #define RECV_WAIT_ACL_HEADER 2
103 #define RECV_WAIT_SCO_HEADER 3
104 #define RECV_WAIT_DATA 4
120 while ((fifo_size-- > 0) && (actual < len)) {
143 unsigned int iobase = info->
p_dev->resource[0]->start;
156 len = btuart_write(iobase, 16, skb->
data, skb->
len);
159 if (len == skb->
len) {
166 info->
hdev->stat.byte_tx +=
len;
184 iobase = info->
p_dev->resource[0]->start;
187 info->
hdev->stat.byte_rx++;
194 BT_ERR(
"Can't allocate mem for new packet");
223 BT_ERR(
"Unknown HCI packet with type 0x%02x received",
bt_cb(info->
rx_skb)->pkt_type);
224 info->
hdev->stat.err_rx++;
279 if (boguscount++ > 16)
286 static irqreturn_t btuart_interrupt(
int irq,
void *dev_inst)
294 if (!info || !info->
hdev)
298 iobase = info->
p_dev->resource[0]->start;
300 spin_lock(&(info->
lock));
315 btuart_receive(info);
320 btuart_write_wakeup(info);
324 BT_ERR(
"Unhandled IIR=%#x", iir);
329 if (boguscount++ > 100)
336 spin_unlock(&(info->
lock));
342 static void btuart_change_speed(
btuart_info_t *info,
unsigned int speed)
355 iobase = info->
p_dev->resource[0]->start;
389 spin_unlock_irqrestore(&(info->
lock), flags);
397 static int btuart_hci_flush(
struct hci_dev *hdev)
408 static int btuart_hci_open(
struct hci_dev *hdev)
416 static int btuart_hci_close(
struct hci_dev *hdev)
421 btuart_hci_flush(hdev);
427 static int btuart_hci_send_frame(
struct sk_buff *skb)
433 BT_ERR(
"Frame for unknown HCI device (hdev=NULL)");
437 info = hci_get_drvdata(hdev);
455 btuart_write_wakeup(info);
461 static int btuart_hci_ioctl(
struct hci_dev *hdev,
unsigned int cmd,
unsigned long arg)
474 unsigned int iobase = info->
p_dev->resource[0]->start;
479 skb_queue_head_init(&(info->
txq));
488 BT_ERR(
"Can't allocate HCI device");
495 hci_set_drvdata(hdev, info);
498 hdev->
open = btuart_hci_open;
499 hdev->
close = btuart_hci_close;
500 hdev->
flush = btuart_hci_flush;
501 hdev->
send = btuart_hci_send_frame;
502 hdev->
ioctl = btuart_hci_ioctl;
519 spin_unlock_irqrestore(&(info->
lock), flags);
528 BT_ERR(
"Can't register HCI device");
541 unsigned int iobase = info->
p_dev->resource[0]->start;
547 btuart_hci_close(hdev);
557 spin_unlock_irqrestore(&(info->
lock), flags);
565 static int btuart_probe(
struct pcmcia_device *
link)
577 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
580 return btuart_config(link);
584 static void btuart_detach(
struct pcmcia_device *link)
586 btuart_release(link);
589 static int btuart_check_config(
struct pcmcia_device *p_dev,
void *priv_data)
591 int *
try = priv_data;
594 p_dev->io_lines = 16;
596 if ((p_dev->resource[0]->end != 8) || (p_dev->resource[0]->start == 0))
599 p_dev->resource[0]->end = 8;
600 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
601 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
606 static int btuart_check_config_notpicky(
struct pcmcia_device *p_dev,
609 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
612 if (p_dev->io_lines > 3)
615 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
616 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
617 p_dev->resource[0]->end = 8;
619 for (j = 0; j < 5; j++) {
620 p_dev->resource[0]->start = base[
j];
621 p_dev->io_lines = base[
j] ? 16 : 3;
628 static int btuart_config(
struct pcmcia_device *link)
636 for (
try = 0;
try < 2;
try++)
637 if (!pcmcia_loop_config(link, btuart_check_config, &
try))
643 if (!pcmcia_loop_config(link, btuart_check_config_notpicky,
NULL))
646 BT_ERR(
"No usable port range found");
658 if (btuart_open(info) != 0)
664 btuart_release(link);
669 static void btuart_release(
struct pcmcia_device *link)
684 static struct pcmcia_driver btuart_driver = {
687 .probe = btuart_probe,
688 .remove = btuart_detach,
689 .id_table = btuart_ids,
692 static int __init init_btuart_cs(
void)
698 static void __exit exit_btuart_cs(
void)