23 #include <linux/module.h>
25 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
29 #include <linux/sched.h>
32 #include <linux/errno.h>
33 #include <linux/ptrace.h>
37 #include <linux/wait.h>
84 static int bluecard_config(
struct pcmcia_device *
link);
85 static void bluecard_release(
struct pcmcia_device *
link);
87 static void bluecard_detach(
struct pcmcia_device *p_dev);
91 #define DEFAULT_BAUD_RATE 230400
96 #define CARD_HAS_PCCARD_ID 4
97 #define CARD_HAS_POWER_LED 5
98 #define CARD_HAS_ACTIVITY_LED 6
101 #define XMIT_SENDING 1
102 #define XMIT_WAKEUP 2
103 #define XMIT_BUFFER_NUMBER 5
104 #define XMIT_BUF_ONE_READY 6
105 #define XMIT_BUF_TWO_READY 7
106 #define XMIT_SENDING_READY 8
109 #define RECV_WAIT_PACKET_TYPE 0
110 #define RECV_WAIT_EVENT_HEADER 1
111 #define RECV_WAIT_ACL_HEADER 2
112 #define RECV_WAIT_SCO_HEADER 3
113 #define RECV_WAIT_DATA 4
116 #define PKT_BAUD_RATE_57600 0x80
117 #define PKT_BAUD_RATE_115200 0x81
118 #define PKT_BAUD_RATE_230400 0x82
119 #define PKT_BAUD_RATE_460800 0x83
123 #define REG_COMMAND 0x20
124 #define REG_INTERRUPT 0x21
125 #define REG_CONTROL 0x22
126 #define REG_RX_CONTROL 0x24
127 #define REG_CARD_RESET 0x30
128 #define REG_LED_CTRL 0x30
131 #define REG_COMMAND_TX_BUF_ONE 0x01
132 #define REG_COMMAND_TX_BUF_TWO 0x02
133 #define REG_COMMAND_RX_BUF_ONE 0x04
134 #define REG_COMMAND_RX_BUF_TWO 0x08
135 #define REG_COMMAND_RX_WIN_ONE 0x00
136 #define REG_COMMAND_RX_WIN_TWO 0x10
139 #define REG_CONTROL_BAUD_RATE_57600 0x00
140 #define REG_CONTROL_BAUD_RATE_115200 0x01
141 #define REG_CONTROL_BAUD_RATE_230400 0x02
142 #define REG_CONTROL_BAUD_RATE_460800 0x03
143 #define REG_CONTROL_RTS 0x04
144 #define REG_CONTROL_BT_ON 0x08
145 #define REG_CONTROL_BT_RESET 0x10
146 #define REG_CONTROL_BT_RES_PU 0x20
147 #define REG_CONTROL_INTERRUPT 0x40
148 #define REG_CONTROL_CARD_RESET 0x80
151 #define RTS_LEVEL_SHIFT_BITS 0x02
158 static void bluecard_activity_led_timeout(
u_long arg)
161 unsigned int iobase = info->
p_dev->resource[0]->start;
168 outb(0x08 | 0x20, iobase + 0x30);
171 outb(0x00, iobase + 0x30);
178 unsigned int iobase = info->
p_dev->resource[0]->start;
185 outb(0x10 | 0x40, iobase + 0x30);
191 outb(0x08 | 0x20, iobase + 0x30);
203 static int bluecard_write(
unsigned int iobase,
unsigned int offset,
__u8 *
buf,
int len)
207 actual = (len > 15) ? 15 : len;
209 outb_p(actual, iobase + offset);
211 for (i = 0; i < actual; i++)
212 outb_p(buf[i], iobase + offset + i + 1);
234 unsigned int iobase = info->
p_dev->resource[0]->start;
237 unsigned long ready_bit;
270 bluecard_enable_activity_led(info);
273 len = bluecard_write(iobase, offset, skb->
data, skb->
len);
285 unsigned char baud_reg;
324 if (len == skb->
len) {
331 info->
hdev->stat.byte_tx +=
len;
342 static int bluecard_read(
unsigned int iobase,
unsigned int offset,
__u8 *buf,
int size)
348 len =
inb(iobase + offset);
359 buf[
n] =
inb(iobase + offset + i);
370 static void bluecard_receive(
bluecard_info_t *info,
unsigned int offset)
373 unsigned char buf[31];
381 iobase = info->
p_dev->resource[0]->start;
384 bluecard_enable_activity_led(info);
386 len = bluecard_read(iobase, offset, buf,
sizeof(buf));
388 for (i = 0; i <
len; i++) {
395 BT_ERR(
"Can't allocate mem for new packet");
409 if (offset != 0x00) {
413 bluecard_write_wakeup(info);
437 BT_ERR(
"Unknown HCI packet with type 0x%02x received",
bt_cb(info->
rx_skb)->pkt_type);
438 info->
hdev->stat.err_rx++;
493 info->
hdev->stat.byte_rx += len;
497 static irqreturn_t bluecard_interrupt(
int irq,
void *dev_inst)
503 if (!info || !info->
hdev)
510 iobase = info->
p_dev->resource[0]->start;
512 spin_lock(&(info->
lock));
520 if ((reg != 0x00) && (reg != 0xff)) {
523 bluecard_receive(info, 0x00);
529 bluecard_receive(info, 0x10);
537 bluecard_write_wakeup(info);
543 bluecard_write_wakeup(info);
552 spin_unlock(&(info->
lock));
562 static int bluecard_hci_set_baud_rate(
struct hci_dev *hdev,
int baud)
571 BT_ERR(
"Can't allocate mem for new packet");
600 bluecard_write_wakeup(info);
610 static int bluecard_hci_flush(
struct hci_dev *hdev)
621 static int bluecard_hci_open(
struct hci_dev *hdev)
632 unsigned int iobase = info->
p_dev->resource[0]->start;
635 outb(0x08 | 0x20, iobase + 0x30);
642 static int bluecard_hci_close(
struct hci_dev *hdev)
649 bluecard_hci_flush(hdev);
652 unsigned int iobase = info->
p_dev->resource[0]->start;
655 outb(0x00, iobase + 0x30);
662 static int bluecard_hci_send_frame(
struct sk_buff *skb)
668 BT_ERR(
"Frame for unknown HCI device (hdev=NULL)");
672 info = hci_get_drvdata(hdev);
690 bluecard_write_wakeup(info);
696 static int bluecard_hci_ioctl(
struct hci_dev *hdev,
unsigned int cmd,
unsigned long arg)
708 unsigned int iobase = info->
p_dev->resource[0]->start;
715 info->
timer.function = &bluecard_activity_led_timeout;
718 skb_queue_head_init(&(info->
txq));
727 BT_ERR(
"Can't allocate HCI device");
734 hci_set_drvdata(hdev, info);
737 hdev->
open = bluecard_hci_open;
738 hdev->
close = bluecard_hci_close;
739 hdev->
flush = bluecard_hci_flush;
740 hdev->
send = bluecard_hci_send_frame;
741 hdev->
ioctl = bluecard_hci_ioctl;
743 id =
inb(iobase + 0x30);
745 if ((
id & 0x0f) == 0x02)
759 outb(0x80, iobase + 0x30);
765 outb(0x00, iobase + 0x30);
776 if ((
id & 0x0f) == 0x03) {
812 BT_ERR(
"Can't register HCI device");
824 unsigned int iobase = info->
p_dev->resource[0]->start;
830 bluecard_hci_close(hdev);
839 outb(0x80, iobase + 0x30);
847 static int bluecard_probe(
struct pcmcia_device *
link)
859 link->config_flags |= CONF_ENABLE_IRQ;
861 return bluecard_config(link);
865 static void bluecard_detach(
struct pcmcia_device *link)
867 bluecard_release(link);
871 static int bluecard_config(
struct pcmcia_device *link)
876 link->config_index = 0x20;
878 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
879 link->resource[0]->end = 64;
882 for (n = 0; n < 0x400; n += 0x40) {
883 link->resource[0]->start = n ^ 0x300;
900 if (bluecard_open(info) != 0)
906 bluecard_release(link);
911 static void bluecard_release(
struct pcmcia_device *link)
915 bluecard_close(info);
923 PCMCIA_DEVICE_PROD_ID12(
"BlueCard",
"LSE041", 0xbaf16fbf, 0x657cc15e),
924 PCMCIA_DEVICE_PROD_ID12(
"BTCFCARD",
"LSE139", 0xe3987764, 0x2524b59c),
925 PCMCIA_DEVICE_PROD_ID12(
"WSS",
"LSE039", 0x0a0736ec, 0x24e6dfab),
930 static struct pcmcia_driver bluecard_driver = {
932 .name =
"bluecard_cs",
933 .probe = bluecard_probe,
934 .remove = bluecard_detach,
935 .id_table = bluecard_ids,
938 static int __init init_bluecard_cs(
void)
944 static void __exit exit_bluecard_cs(
void)