24 #include <linux/module.h>
26 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/types.h>
31 #include <linux/errno.h>
32 #include <linux/ptrace.h>
38 #include <linux/string.h>
39 #include <linux/serial.h>
41 #include <linux/bitops.h>
44 #include <linux/device.h>
86 static int bt3c_config(
struct pcmcia_device *
link);
87 static void bt3c_release(
struct pcmcia_device *
link);
89 static void bt3c_detach(
struct pcmcia_device *p_dev);
93 #define XMIT_SENDING 1
95 #define XMIT_WAITING 8
98 #define RECV_WAIT_PACKET_TYPE 0
99 #define RECV_WAIT_EVENT_HEADER 1
100 #define RECV_WAIT_ACL_HEADER 2
101 #define RECV_WAIT_SCO_HEADER 3
102 #define RECV_WAIT_DATA 4
116 static inline void bt3c_address(
unsigned int iobase,
unsigned short addr)
123 static inline void bt3c_put(
unsigned int iobase,
unsigned short value)
130 static inline void bt3c_io_write(
unsigned int iobase,
unsigned short addr,
unsigned short value)
132 bt3c_address(iobase, addr);
133 bt3c_put(iobase, value);
137 static inline unsigned short bt3c_get(
unsigned int iobase)
139 unsigned short value =
inb(iobase +
DATA_L);
147 static inline unsigned short bt3c_read(
unsigned int iobase,
unsigned short addr)
149 bt3c_address(iobase, addr);
151 return bt3c_get(iobase);
163 bt3c_address(iobase, 0x7080);
166 while (actual < len) {
168 bt3c_put(iobase, buf[actual]);
172 bt3c_io_write(iobase, 0x7005, actual);
189 unsigned int iobase = info->
p_dev->resource[0]->start;
203 len = bt3c_write(iobase, 256, skb->
data, skb->
len);
205 if (len != skb->
len) {
211 info->
hdev->stat.byte_tx +=
len;
227 iobase = info->
p_dev->resource[0]->start;
229 avail = bt3c_read(iobase, 0x7006);
232 bt3c_address(iobase, 0x7480);
233 while (size <
avail) {
235 info->
hdev->stat.byte_rx++;
242 BT_ERR(
"Can't allocate mem for new packet");
274 BT_ERR(
"Unknown HCI packet with type 0x%02x received",
bt_cb(info->
rx_skb)->pkt_type);
275 info->
hdev->stat.err_rx++;
333 bt3c_io_write(iobase, 0x7006, 0x0000);
337 static irqreturn_t bt3c_interrupt(
int irq,
void *dev_inst)
344 if (!info || !info->
hdev)
348 iobase = info->
p_dev->resource[0]->start;
350 spin_lock(&(info->
lock));
354 int stat = bt3c_read(iobase, 0x7001);
356 if ((stat & 0xff) == 0x7f) {
357 BT_ERR(
"Very strange (stat=0x%04x)", stat);
358 }
else if ((stat & 0xff) != 0xff) {
360 int status = bt3c_read(iobase, 0x7002) & 0x10;
362 status ?
"out" :
"in");
369 bt3c_write_wakeup(info);
372 bt3c_io_write(iobase, 0x7001, 0x0000);
379 spin_unlock(&(info->
lock));
389 static int bt3c_hci_flush(
struct hci_dev *hdev)
400 static int bt3c_hci_open(
struct hci_dev *hdev)
408 static int bt3c_hci_close(
struct hci_dev *hdev)
413 bt3c_hci_flush(hdev);
419 static int bt3c_hci_send_frame(
struct sk_buff *skb)
426 BT_ERR(
"Frame for unknown HCI device (hdev=NULL)");
430 info = hci_get_drvdata(hdev);
450 bt3c_write_wakeup(info);
452 spin_unlock_irqrestore(&(info->
lock), flags);
458 static int bt3c_hci_ioctl(
struct hci_dev *hdev,
unsigned int cmd,
unsigned long arg)
471 char *
ptr = (
char *) firmware;
476 iobase = info->
p_dev->resource[0]->start;
479 bt3c_io_write(iobase, 0x8040, 0x0404);
480 bt3c_io_write(iobase, 0x8040, 0x0400);
484 bt3c_io_write(iobase, 0x8040, 0x0404);
491 BT_ERR(
"Bad address in firmware");
505 memcpy(b, ptr + (size * 2) + 2, 2);
509 for (tmp = 0, i = 0; i <
size; i++) {
510 memcpy(b, ptr + (i * 2) + 2, 2);
514 if (((tmp + fcs) & 0xff) != 0xff) {
515 BT_ERR(
"Checksum error in firmware");
521 bt3c_address(iobase, addr);
524 for (i = 0; i < (size - 4) / 2; i++) {
525 memcpy(b, ptr + (i * 4) + 12, 4);
527 bt3c_put(iobase, tmp);
531 ptr += (size * 2) + 6;
532 count -= (size * 2) + 6;
538 bt3c_address(iobase, 0x3000);
545 bt3c_io_write(iobase, 0x7006, 0x0000);
546 bt3c_io_write(iobase, 0x7005, 0x0000);
547 bt3c_io_write(iobase, 0x7001, 0x0000);
555 const struct firmware *firmware;
561 skb_queue_head_init(&(info->
txq));
570 BT_ERR(
"Can't allocate HCI device");
577 hci_set_drvdata(hdev, info);
580 hdev->
open = bt3c_hci_open;
581 hdev->
close = bt3c_hci_close;
582 hdev->
flush = bt3c_hci_flush;
583 hdev->
send = bt3c_hci_send_frame;
584 hdev->
ioctl = bt3c_hci_ioctl;
589 BT_ERR(
"Firmware request failed");
593 err = bt3c_load_firmware(info, firmware->
data, firmware->
size);
598 BT_ERR(
"Firmware loading failed");
608 BT_ERR(
"Can't register HCI device");
628 bt3c_hci_close(hdev);
636 static int bt3c_probe(
struct pcmcia_device *
link)
648 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
651 return bt3c_config(link);
655 static void bt3c_detach(
struct pcmcia_device *link)
660 static int bt3c_check_config(
struct pcmcia_device *p_dev,
void *priv_data)
662 int *
try = priv_data;
665 p_dev->io_lines = 16;
667 if ((p_dev->resource[0]->end != 8) || (p_dev->resource[0]->start == 0))
670 p_dev->resource[0]->end = 8;
671 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
672 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
677 static int bt3c_check_config_notpicky(
struct pcmcia_device *p_dev,
680 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
683 if (p_dev->io_lines > 3)
686 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
687 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
688 p_dev->resource[0]->end = 8;
690 for (j = 0; j < 5; j++) {
691 p_dev->resource[0]->start = base[
j];
692 p_dev->io_lines = base[
j] ? 16 : 3;
699 static int bt3c_config(
struct pcmcia_device *link)
707 for (
try = 0;
try < 2;
try++)
708 if (!pcmcia_loop_config(link, bt3c_check_config, (
void *)
try))
714 if (!pcmcia_loop_config(link, bt3c_check_config_notpicky,
NULL))
717 BT_ERR(
"No usable port range found");
729 if (bt3c_open(info) != 0)
740 static void bt3c_release(
struct pcmcia_device *link)
751 PCMCIA_DEVICE_PROD_ID13(
"3COM",
"Bluetooth PC Card", 0xefce0a31, 0xd4ce9b02),
756 static struct pcmcia_driver bt3c_driver = {
760 .remove = bt3c_detach,
761 .id_table = bt3c_ids,
764 static int __init init_bt3c_cs(
void)
770 static void __exit exit_bt3c_cs(
void)