netfilter: xt_rateest: Better struct xt_rateest layout
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / bluetooth / bluecard_cs.c
blob6f907ebed2d50064a6c1058828097fca53192099
1 /*
3 * Bluetooth driver for the Anycom BlueCard (LSE039/LSE041)
5 * Copyright (C) 2001-2002 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
12 * Software distributed under the License is distributed on an "AS
13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The initial developer of the original code is David A. Hinds
18 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
19 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
23 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
29 #include <linux/sched.h>
30 #include <linux/delay.h>
31 #include <linux/timer.h>
32 #include <linux/errno.h>
33 #include <linux/ptrace.h>
34 #include <linux/ioport.h>
35 #include <linux/spinlock.h>
36 #include <linux/moduleparam.h>
37 #include <linux/wait.h>
39 #include <linux/skbuff.h>
40 #include <asm/io.h>
42 #include <pcmcia/cs_types.h>
43 #include <pcmcia/cs.h>
44 #include <pcmcia/cistpl.h>
45 #include <pcmcia/ciscode.h>
46 #include <pcmcia/ds.h>
47 #include <pcmcia/cisreg.h>
49 #include <net/bluetooth/bluetooth.h>
50 #include <net/bluetooth/hci_core.h>
54 /* ======================== Module parameters ======================== */
57 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
58 MODULE_DESCRIPTION("Bluetooth driver for the Anycom BlueCard (LSE039/LSE041)");
59 MODULE_LICENSE("GPL");
63 /* ======================== Local structures ======================== */
66 typedef struct bluecard_info_t {
67 struct pcmcia_device *p_dev;
69 struct hci_dev *hdev;
71 spinlock_t lock; /* For serializing operations */
72 struct timer_list timer; /* For LED control */
74 struct sk_buff_head txq;
75 unsigned long tx_state;
77 unsigned long rx_state;
78 unsigned long rx_count;
79 struct sk_buff *rx_skb;
81 unsigned char ctrl_reg;
82 unsigned long hw_state; /* Status of the hardware and LED control */
83 } bluecard_info_t;
86 static int bluecard_config(struct pcmcia_device *link);
87 static void bluecard_release(struct pcmcia_device *link);
89 static void bluecard_detach(struct pcmcia_device *p_dev);
92 /* Default baud rate: 57600, 115200, 230400 or 460800 */
93 #define DEFAULT_BAUD_RATE 230400
96 /* Hardware states */
97 #define CARD_READY 1
98 #define CARD_HAS_PCCARD_ID 4
99 #define CARD_HAS_POWER_LED 5
100 #define CARD_HAS_ACTIVITY_LED 6
102 /* Transmit states */
103 #define XMIT_SENDING 1
104 #define XMIT_WAKEUP 2
105 #define XMIT_BUFFER_NUMBER 5 /* unset = buffer one, set = buffer two */
106 #define XMIT_BUF_ONE_READY 6
107 #define XMIT_BUF_TWO_READY 7
108 #define XMIT_SENDING_READY 8
110 /* Receiver states */
111 #define RECV_WAIT_PACKET_TYPE 0
112 #define RECV_WAIT_EVENT_HEADER 1
113 #define RECV_WAIT_ACL_HEADER 2
114 #define RECV_WAIT_SCO_HEADER 3
115 #define RECV_WAIT_DATA 4
117 /* Special packet types */
118 #define PKT_BAUD_RATE_57600 0x80
119 #define PKT_BAUD_RATE_115200 0x81
120 #define PKT_BAUD_RATE_230400 0x82
121 #define PKT_BAUD_RATE_460800 0x83
124 /* These are the register offsets */
125 #define REG_COMMAND 0x20
126 #define REG_INTERRUPT 0x21
127 #define REG_CONTROL 0x22
128 #define REG_RX_CONTROL 0x24
129 #define REG_CARD_RESET 0x30
130 #define REG_LED_CTRL 0x30
132 /* REG_COMMAND */
133 #define REG_COMMAND_TX_BUF_ONE 0x01
134 #define REG_COMMAND_TX_BUF_TWO 0x02
135 #define REG_COMMAND_RX_BUF_ONE 0x04
136 #define REG_COMMAND_RX_BUF_TWO 0x08
137 #define REG_COMMAND_RX_WIN_ONE 0x00
138 #define REG_COMMAND_RX_WIN_TWO 0x10
140 /* REG_CONTROL */
141 #define REG_CONTROL_BAUD_RATE_57600 0x00
142 #define REG_CONTROL_BAUD_RATE_115200 0x01
143 #define REG_CONTROL_BAUD_RATE_230400 0x02
144 #define REG_CONTROL_BAUD_RATE_460800 0x03
145 #define REG_CONTROL_RTS 0x04
146 #define REG_CONTROL_BT_ON 0x08
147 #define REG_CONTROL_BT_RESET 0x10
148 #define REG_CONTROL_BT_RES_PU 0x20
149 #define REG_CONTROL_INTERRUPT 0x40
150 #define REG_CONTROL_CARD_RESET 0x80
152 /* REG_RX_CONTROL */
153 #define RTS_LEVEL_SHIFT_BITS 0x02
157 /* ======================== LED handling routines ======================== */
160 static void bluecard_activity_led_timeout(u_long arg)
162 bluecard_info_t *info = (bluecard_info_t *)arg;
163 unsigned int iobase = info->p_dev->io.BasePort1;
165 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
166 return;
168 if (test_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state))) {
169 /* Disable activity LED */
170 outb(0x08 | 0x20, iobase + 0x30);
171 } else {
172 /* Disable power LED */
173 outb(0x00, iobase + 0x30);
178 static void bluecard_enable_activity_led(bluecard_info_t *info)
180 unsigned int iobase = info->p_dev->io.BasePort1;
182 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
183 return;
185 if (test_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state))) {
186 /* Enable activity LED */
187 outb(0x10 | 0x40, iobase + 0x30);
189 /* Stop the LED after HZ/4 */
190 mod_timer(&(info->timer), jiffies + HZ / 4);
191 } else {
192 /* Enable power LED */
193 outb(0x08 | 0x20, iobase + 0x30);
195 /* Stop the LED after HZ/2 */
196 mod_timer(&(info->timer), jiffies + HZ / 2);
202 /* ======================== Interrupt handling ======================== */
205 static int bluecard_write(unsigned int iobase, unsigned int offset, __u8 *buf, int len)
207 int i, actual;
209 actual = (len > 15) ? 15 : len;
211 outb_p(actual, iobase + offset);
213 for (i = 0; i < actual; i++)
214 outb_p(buf[i], iobase + offset + i + 1);
216 return actual;
220 static void bluecard_write_wakeup(bluecard_info_t *info)
222 if (!info) {
223 BT_ERR("Unknown device");
224 return;
227 if (!test_bit(XMIT_SENDING_READY, &(info->tx_state)))
228 return;
230 if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
231 set_bit(XMIT_WAKEUP, &(info->tx_state));
232 return;
235 do {
236 register unsigned int iobase = info->p_dev->io.BasePort1;
237 register unsigned int offset;
238 register unsigned char command;
239 register unsigned long ready_bit;
240 register struct sk_buff *skb;
241 register int len;
243 clear_bit(XMIT_WAKEUP, &(info->tx_state));
245 if (!pcmcia_dev_present(info->p_dev))
246 return;
248 if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) {
249 if (!test_bit(XMIT_BUF_TWO_READY, &(info->tx_state)))
250 break;
251 offset = 0x10;
252 command = REG_COMMAND_TX_BUF_TWO;
253 ready_bit = XMIT_BUF_TWO_READY;
254 } else {
255 if (!test_bit(XMIT_BUF_ONE_READY, &(info->tx_state)))
256 break;
257 offset = 0x00;
258 command = REG_COMMAND_TX_BUF_ONE;
259 ready_bit = XMIT_BUF_ONE_READY;
262 if (!(skb = skb_dequeue(&(info->txq))))
263 break;
265 if (bt_cb(skb)->pkt_type & 0x80) {
266 /* Disable RTS */
267 info->ctrl_reg |= REG_CONTROL_RTS;
268 outb(info->ctrl_reg, iobase + REG_CONTROL);
271 /* Activate LED */
272 bluecard_enable_activity_led(info);
274 /* Send frame */
275 len = bluecard_write(iobase, offset, skb->data, skb->len);
277 /* Tell the FPGA to send the data */
278 outb_p(command, iobase + REG_COMMAND);
280 /* Mark the buffer as dirty */
281 clear_bit(ready_bit, &(info->tx_state));
283 if (bt_cb(skb)->pkt_type & 0x80) {
284 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
285 DEFINE_WAIT(wait);
287 unsigned char baud_reg;
289 switch (bt_cb(skb)->pkt_type) {
290 case PKT_BAUD_RATE_460800:
291 baud_reg = REG_CONTROL_BAUD_RATE_460800;
292 break;
293 case PKT_BAUD_RATE_230400:
294 baud_reg = REG_CONTROL_BAUD_RATE_230400;
295 break;
296 case PKT_BAUD_RATE_115200:
297 baud_reg = REG_CONTROL_BAUD_RATE_115200;
298 break;
299 case PKT_BAUD_RATE_57600:
300 /* Fall through... */
301 default:
302 baud_reg = REG_CONTROL_BAUD_RATE_57600;
303 break;
306 /* Wait until the command reaches the baseband */
307 prepare_to_wait(&wq, &wait, TASK_INTERRUPTIBLE);
308 schedule_timeout(HZ/10);
309 finish_wait(&wq, &wait);
311 /* Set baud on baseband */
312 info->ctrl_reg &= ~0x03;
313 info->ctrl_reg |= baud_reg;
314 outb(info->ctrl_reg, iobase + REG_CONTROL);
316 /* Enable RTS */
317 info->ctrl_reg &= ~REG_CONTROL_RTS;
318 outb(info->ctrl_reg, iobase + REG_CONTROL);
320 /* Wait before the next HCI packet can be send */
321 prepare_to_wait(&wq, &wait, TASK_INTERRUPTIBLE);
322 schedule_timeout(HZ);
323 finish_wait(&wq, &wait);
326 if (len == skb->len) {
327 kfree_skb(skb);
328 } else {
329 skb_pull(skb, len);
330 skb_queue_head(&(info->txq), skb);
333 info->hdev->stat.byte_tx += len;
335 /* Change buffer */
336 change_bit(XMIT_BUFFER_NUMBER, &(info->tx_state));
338 } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
340 clear_bit(XMIT_SENDING, &(info->tx_state));
344 static int bluecard_read(unsigned int iobase, unsigned int offset, __u8 *buf, int size)
346 int i, n, len;
348 outb(REG_COMMAND_RX_WIN_ONE, iobase + REG_COMMAND);
350 len = inb(iobase + offset);
351 n = 0;
352 i = 1;
354 while (n < len) {
356 if (i == 16) {
357 outb(REG_COMMAND_RX_WIN_TWO, iobase + REG_COMMAND);
358 i = 0;
361 buf[n] = inb(iobase + offset + i);
363 n++;
364 i++;
368 return len;
372 static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
374 unsigned int iobase;
375 unsigned char buf[31];
376 int i, len;
378 if (!info) {
379 BT_ERR("Unknown device");
380 return;
383 iobase = info->p_dev->io.BasePort1;
385 if (test_bit(XMIT_SENDING_READY, &(info->tx_state)))
386 bluecard_enable_activity_led(info);
388 len = bluecard_read(iobase, offset, buf, sizeof(buf));
390 for (i = 0; i < len; i++) {
392 /* Allocate packet */
393 if (info->rx_skb == NULL) {
394 info->rx_state = RECV_WAIT_PACKET_TYPE;
395 info->rx_count = 0;
396 if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
397 BT_ERR("Can't allocate mem for new packet");
398 return;
402 if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
404 info->rx_skb->dev = (void *) info->hdev;
405 bt_cb(info->rx_skb)->pkt_type = buf[i];
407 switch (bt_cb(info->rx_skb)->pkt_type) {
409 case 0x00:
410 /* init packet */
411 if (offset != 0x00) {
412 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
413 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
414 set_bit(XMIT_SENDING_READY, &(info->tx_state));
415 bluecard_write_wakeup(info);
418 kfree_skb(info->rx_skb);
419 info->rx_skb = NULL;
420 break;
422 case HCI_EVENT_PKT:
423 info->rx_state = RECV_WAIT_EVENT_HEADER;
424 info->rx_count = HCI_EVENT_HDR_SIZE;
425 break;
427 case HCI_ACLDATA_PKT:
428 info->rx_state = RECV_WAIT_ACL_HEADER;
429 info->rx_count = HCI_ACL_HDR_SIZE;
430 break;
432 case HCI_SCODATA_PKT:
433 info->rx_state = RECV_WAIT_SCO_HEADER;
434 info->rx_count = HCI_SCO_HDR_SIZE;
435 break;
437 default:
438 /* unknown packet */
439 BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
440 info->hdev->stat.err_rx++;
442 kfree_skb(info->rx_skb);
443 info->rx_skb = NULL;
444 break;
448 } else {
450 *skb_put(info->rx_skb, 1) = buf[i];
451 info->rx_count--;
453 if (info->rx_count == 0) {
455 int dlen;
456 struct hci_event_hdr *eh;
457 struct hci_acl_hdr *ah;
458 struct hci_sco_hdr *sh;
460 switch (info->rx_state) {
462 case RECV_WAIT_EVENT_HEADER:
463 eh = hci_event_hdr(info->rx_skb);
464 info->rx_state = RECV_WAIT_DATA;
465 info->rx_count = eh->plen;
466 break;
468 case RECV_WAIT_ACL_HEADER:
469 ah = hci_acl_hdr(info->rx_skb);
470 dlen = __le16_to_cpu(ah->dlen);
471 info->rx_state = RECV_WAIT_DATA;
472 info->rx_count = dlen;
473 break;
475 case RECV_WAIT_SCO_HEADER:
476 sh = hci_sco_hdr(info->rx_skb);
477 info->rx_state = RECV_WAIT_DATA;
478 info->rx_count = sh->dlen;
479 break;
481 case RECV_WAIT_DATA:
482 hci_recv_frame(info->rx_skb);
483 info->rx_skb = NULL;
484 break;
495 info->hdev->stat.byte_rx += len;
499 static irqreturn_t bluecard_interrupt(int irq, void *dev_inst)
501 bluecard_info_t *info = dev_inst;
502 unsigned int iobase;
503 unsigned char reg;
505 if (!info || !info->hdev)
506 /* our irq handler is shared */
507 return IRQ_NONE;
509 if (!test_bit(CARD_READY, &(info->hw_state)))
510 return IRQ_HANDLED;
512 iobase = info->p_dev->io.BasePort1;
514 spin_lock(&(info->lock));
516 /* Disable interrupt */
517 info->ctrl_reg &= ~REG_CONTROL_INTERRUPT;
518 outb(info->ctrl_reg, iobase + REG_CONTROL);
520 reg = inb(iobase + REG_INTERRUPT);
522 if ((reg != 0x00) && (reg != 0xff)) {
524 if (reg & 0x04) {
525 bluecard_receive(info, 0x00);
526 outb(0x04, iobase + REG_INTERRUPT);
527 outb(REG_COMMAND_RX_BUF_ONE, iobase + REG_COMMAND);
530 if (reg & 0x08) {
531 bluecard_receive(info, 0x10);
532 outb(0x08, iobase + REG_INTERRUPT);
533 outb(REG_COMMAND_RX_BUF_TWO, iobase + REG_COMMAND);
536 if (reg & 0x01) {
537 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
538 outb(0x01, iobase + REG_INTERRUPT);
539 bluecard_write_wakeup(info);
542 if (reg & 0x02) {
543 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
544 outb(0x02, iobase + REG_INTERRUPT);
545 bluecard_write_wakeup(info);
550 /* Enable interrupt */
551 info->ctrl_reg |= REG_CONTROL_INTERRUPT;
552 outb(info->ctrl_reg, iobase + REG_CONTROL);
554 spin_unlock(&(info->lock));
556 return IRQ_HANDLED;
561 /* ======================== Device specific HCI commands ======================== */
564 static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud)
566 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
567 struct sk_buff *skb;
569 /* Ericsson baud rate command */
570 unsigned char cmd[] = { HCI_COMMAND_PKT, 0x09, 0xfc, 0x01, 0x03 };
572 if (!(skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
573 BT_ERR("Can't allocate mem for new packet");
574 return -1;
577 switch (baud) {
578 case 460800:
579 cmd[4] = 0x00;
580 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_460800;
581 break;
582 case 230400:
583 cmd[4] = 0x01;
584 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_230400;
585 break;
586 case 115200:
587 cmd[4] = 0x02;
588 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_115200;
589 break;
590 case 57600:
591 /* Fall through... */
592 default:
593 cmd[4] = 0x03;
594 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_57600;
595 break;
598 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
600 skb_queue_tail(&(info->txq), skb);
602 bluecard_write_wakeup(info);
604 return 0;
609 /* ======================== HCI interface ======================== */
612 static int bluecard_hci_flush(struct hci_dev *hdev)
614 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
616 /* Drop TX queue */
617 skb_queue_purge(&(info->txq));
619 return 0;
623 static int bluecard_hci_open(struct hci_dev *hdev)
625 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
626 unsigned int iobase = info->p_dev->io.BasePort1;
628 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
629 bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE);
631 if (test_and_set_bit(HCI_RUNNING, &(hdev->flags)))
632 return 0;
634 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) {
635 /* Enable LED */
636 outb(0x08 | 0x20, iobase + 0x30);
639 return 0;
643 static int bluecard_hci_close(struct hci_dev *hdev)
645 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
646 unsigned int iobase = info->p_dev->io.BasePort1;
648 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
649 return 0;
651 bluecard_hci_flush(hdev);
653 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) {
654 /* Disable LED */
655 outb(0x00, iobase + 0x30);
658 return 0;
662 static int bluecard_hci_send_frame(struct sk_buff *skb)
664 bluecard_info_t *info;
665 struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
667 if (!hdev) {
668 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
669 return -ENODEV;
672 info = (bluecard_info_t *)(hdev->driver_data);
674 switch (bt_cb(skb)->pkt_type) {
675 case HCI_COMMAND_PKT:
676 hdev->stat.cmd_tx++;
677 break;
678 case HCI_ACLDATA_PKT:
679 hdev->stat.acl_tx++;
680 break;
681 case HCI_SCODATA_PKT:
682 hdev->stat.sco_tx++;
683 break;
686 /* Prepend skb with frame type */
687 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
688 skb_queue_tail(&(info->txq), skb);
690 bluecard_write_wakeup(info);
692 return 0;
696 static void bluecard_hci_destruct(struct hci_dev *hdev)
701 static int bluecard_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
703 return -ENOIOCTLCMD;
708 /* ======================== Card services HCI interaction ======================== */
711 static int bluecard_open(bluecard_info_t *info)
713 unsigned int iobase = info->p_dev->io.BasePort1;
714 struct hci_dev *hdev;
715 unsigned char id;
717 spin_lock_init(&(info->lock));
719 init_timer(&(info->timer));
720 info->timer.function = &bluecard_activity_led_timeout;
721 info->timer.data = (u_long)info;
723 skb_queue_head_init(&(info->txq));
725 info->rx_state = RECV_WAIT_PACKET_TYPE;
726 info->rx_count = 0;
727 info->rx_skb = NULL;
729 /* Initialize HCI device */
730 hdev = hci_alloc_dev();
731 if (!hdev) {
732 BT_ERR("Can't allocate HCI device");
733 return -ENOMEM;
736 info->hdev = hdev;
738 hdev->bus = HCI_PCCARD;
739 hdev->driver_data = info;
740 SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
742 hdev->open = bluecard_hci_open;
743 hdev->close = bluecard_hci_close;
744 hdev->flush = bluecard_hci_flush;
745 hdev->send = bluecard_hci_send_frame;
746 hdev->destruct = bluecard_hci_destruct;
747 hdev->ioctl = bluecard_hci_ioctl;
749 hdev->owner = THIS_MODULE;
751 id = inb(iobase + 0x30);
753 if ((id & 0x0f) == 0x02)
754 set_bit(CARD_HAS_PCCARD_ID, &(info->hw_state));
756 if (id & 0x10)
757 set_bit(CARD_HAS_POWER_LED, &(info->hw_state));
759 if (id & 0x20)
760 set_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state));
762 /* Reset card */
763 info->ctrl_reg = REG_CONTROL_BT_RESET | REG_CONTROL_CARD_RESET;
764 outb(info->ctrl_reg, iobase + REG_CONTROL);
766 /* Turn FPGA off */
767 outb(0x80, iobase + 0x30);
769 /* Wait some time */
770 msleep(10);
772 /* Turn FPGA on */
773 outb(0x00, iobase + 0x30);
775 /* Activate card */
776 info->ctrl_reg = REG_CONTROL_BT_ON | REG_CONTROL_BT_RES_PU;
777 outb(info->ctrl_reg, iobase + REG_CONTROL);
779 /* Enable interrupt */
780 outb(0xff, iobase + REG_INTERRUPT);
781 info->ctrl_reg |= REG_CONTROL_INTERRUPT;
782 outb(info->ctrl_reg, iobase + REG_CONTROL);
784 if ((id & 0x0f) == 0x03) {
785 /* Disable RTS */
786 info->ctrl_reg |= REG_CONTROL_RTS;
787 outb(info->ctrl_reg, iobase + REG_CONTROL);
789 /* Set baud rate */
790 info->ctrl_reg |= 0x03;
791 outb(info->ctrl_reg, iobase + REG_CONTROL);
793 /* Enable RTS */
794 info->ctrl_reg &= ~REG_CONTROL_RTS;
795 outb(info->ctrl_reg, iobase + REG_CONTROL);
797 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
798 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
799 set_bit(XMIT_SENDING_READY, &(info->tx_state));
802 /* Start the RX buffers */
803 outb(REG_COMMAND_RX_BUF_ONE, iobase + REG_COMMAND);
804 outb(REG_COMMAND_RX_BUF_TWO, iobase + REG_COMMAND);
806 /* Signal that the hardware is ready */
807 set_bit(CARD_READY, &(info->hw_state));
809 /* Drop TX queue */
810 skb_queue_purge(&(info->txq));
812 /* Control the point at which RTS is enabled */
813 outb((0x0f << RTS_LEVEL_SHIFT_BITS) | 1, iobase + REG_RX_CONTROL);
815 /* Timeout before it is safe to send the first HCI packet */
816 msleep(1250);
818 /* Register HCI device */
819 if (hci_register_dev(hdev) < 0) {
820 BT_ERR("Can't register HCI device");
821 info->hdev = NULL;
822 hci_free_dev(hdev);
823 return -ENODEV;
826 return 0;
830 static int bluecard_close(bluecard_info_t *info)
832 unsigned int iobase = info->p_dev->io.BasePort1;
833 struct hci_dev *hdev = info->hdev;
835 if (!hdev)
836 return -ENODEV;
838 bluecard_hci_close(hdev);
840 clear_bit(CARD_READY, &(info->hw_state));
842 /* Reset card */
843 info->ctrl_reg = REG_CONTROL_BT_RESET | REG_CONTROL_CARD_RESET;
844 outb(info->ctrl_reg, iobase + REG_CONTROL);
846 /* Turn FPGA off */
847 outb(0x80, iobase + 0x30);
849 if (hci_unregister_dev(hdev) < 0)
850 BT_ERR("Can't unregister HCI device %s", hdev->name);
852 hci_free_dev(hdev);
854 return 0;
857 static int bluecard_probe(struct pcmcia_device *link)
859 bluecard_info_t *info;
861 /* Create new info device */
862 info = kzalloc(sizeof(*info), GFP_KERNEL);
863 if (!info)
864 return -ENOMEM;
866 info->p_dev = link;
867 link->priv = info;
869 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
870 link->io.NumPorts1 = 8;
872 link->conf.Attributes = CONF_ENABLE_IRQ;
873 link->conf.IntType = INT_MEMORY_AND_IO;
875 return bluecard_config(link);
879 static void bluecard_detach(struct pcmcia_device *link)
881 bluecard_info_t *info = link->priv;
883 bluecard_release(link);
884 kfree(info);
888 static int bluecard_config(struct pcmcia_device *link)
890 bluecard_info_t *info = link->priv;
891 int i, n;
893 link->conf.ConfigIndex = 0x20;
894 link->io.NumPorts1 = 64;
895 link->io.IOAddrLines = 6;
897 for (n = 0; n < 0x400; n += 0x40) {
898 link->io.BasePort1 = n ^ 0x300;
899 i = pcmcia_request_io(link, &link->io);
900 if (i == 0)
901 break;
904 if (i != 0)
905 goto failed;
907 i = pcmcia_request_irq(link, bluecard_interrupt);
908 if (i != 0)
909 goto failed;
911 i = pcmcia_request_configuration(link, &link->conf);
912 if (i != 0)
913 goto failed;
915 if (bluecard_open(info) != 0)
916 goto failed;
918 return 0;
920 failed:
921 bluecard_release(link);
922 return -ENODEV;
926 static void bluecard_release(struct pcmcia_device *link)
928 bluecard_info_t *info = link->priv;
930 bluecard_close(info);
932 del_timer(&(info->timer));
934 pcmcia_disable_device(link);
937 static struct pcmcia_device_id bluecard_ids[] = {
938 PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e),
939 PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c),
940 PCMCIA_DEVICE_PROD_ID12("WSS", "LSE039", 0x0a0736ec, 0x24e6dfab),
941 PCMCIA_DEVICE_NULL
943 MODULE_DEVICE_TABLE(pcmcia, bluecard_ids);
945 static struct pcmcia_driver bluecard_driver = {
946 .owner = THIS_MODULE,
947 .drv = {
948 .name = "bluecard_cs",
950 .probe = bluecard_probe,
951 .remove = bluecard_detach,
952 .id_table = bluecard_ids,
955 static int __init init_bluecard_cs(void)
957 return pcmcia_register_driver(&bluecard_driver);
961 static void __exit exit_bluecard_cs(void)
963 pcmcia_unregister_driver(&bluecard_driver);
966 module_init(init_bluecard_cs);
967 module_exit(exit_bluecard_cs);