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>
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
;
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 */
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
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
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
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
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
)))
168 if (test_bit(CARD_HAS_ACTIVITY_LED
, &(info
->hw_state
))) {
169 /* Disable activity LED */
170 outb(0x08 | 0x20, iobase
+ 0x30);
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
)))
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);
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
)
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);
220 static void bluecard_write_wakeup(bluecard_info_t
*info
)
223 BT_ERR("Unknown device");
227 if (!test_bit(XMIT_SENDING_READY
, &(info
->tx_state
)))
230 if (test_and_set_bit(XMIT_SENDING
, &(info
->tx_state
))) {
231 set_bit(XMIT_WAKEUP
, &(info
->tx_state
));
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
;
243 clear_bit(XMIT_WAKEUP
, &(info
->tx_state
));
245 if (!pcmcia_dev_present(info
->p_dev
))
248 if (test_bit(XMIT_BUFFER_NUMBER
, &(info
->tx_state
))) {
249 if (!test_bit(XMIT_BUF_TWO_READY
, &(info
->tx_state
)))
252 command
= REG_COMMAND_TX_BUF_TWO
;
253 ready_bit
= XMIT_BUF_TWO_READY
;
255 if (!test_bit(XMIT_BUF_ONE_READY
, &(info
->tx_state
)))
258 command
= REG_COMMAND_TX_BUF_ONE
;
259 ready_bit
= XMIT_BUF_ONE_READY
;
262 if (!(skb
= skb_dequeue(&(info
->txq
))))
265 if (bt_cb(skb
)->pkt_type
& 0x80) {
267 info
->ctrl_reg
|= REG_CONTROL_RTS
;
268 outb(info
->ctrl_reg
, iobase
+ REG_CONTROL
);
272 bluecard_enable_activity_led(info
);
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
);
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
;
293 case PKT_BAUD_RATE_230400
:
294 baud_reg
= REG_CONTROL_BAUD_RATE_230400
;
296 case PKT_BAUD_RATE_115200
:
297 baud_reg
= REG_CONTROL_BAUD_RATE_115200
;
299 case PKT_BAUD_RATE_57600
:
300 /* Fall through... */
302 baud_reg
= REG_CONTROL_BAUD_RATE_57600
;
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
);
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
) {
330 skb_queue_head(&(info
->txq
), skb
);
333 info
->hdev
->stat
.byte_tx
+= len
;
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
)
348 outb(REG_COMMAND_RX_WIN_ONE
, iobase
+ REG_COMMAND
);
350 len
= inb(iobase
+ offset
);
357 outb(REG_COMMAND_RX_WIN_TWO
, iobase
+ REG_COMMAND
);
361 buf
[n
] = inb(iobase
+ offset
+ i
);
372 static void bluecard_receive(bluecard_info_t
*info
, unsigned int offset
)
375 unsigned char buf
[31];
379 BT_ERR("Unknown device");
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
;
396 if (!(info
->rx_skb
= bt_skb_alloc(HCI_MAX_FRAME_SIZE
, GFP_ATOMIC
))) {
397 BT_ERR("Can't allocate mem for new packet");
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
) {
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
);
423 info
->rx_state
= RECV_WAIT_EVENT_HEADER
;
424 info
->rx_count
= HCI_EVENT_HDR_SIZE
;
427 case HCI_ACLDATA_PKT
:
428 info
->rx_state
= RECV_WAIT_ACL_HEADER
;
429 info
->rx_count
= HCI_ACL_HDR_SIZE
;
432 case HCI_SCODATA_PKT
:
433 info
->rx_state
= RECV_WAIT_SCO_HEADER
;
434 info
->rx_count
= HCI_SCO_HDR_SIZE
;
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
);
450 *skb_put(info
->rx_skb
, 1) = buf
[i
];
453 if (info
->rx_count
== 0) {
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
;
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
;
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
;
482 hci_recv_frame(info
->rx_skb
);
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
;
505 if (!info
|| !info
->hdev
)
506 /* our irq handler is shared */
509 if (!test_bit(CARD_READY
, &(info
->hw_state
)))
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)) {
525 bluecard_receive(info
, 0x00);
526 outb(0x04, iobase
+ REG_INTERRUPT
);
527 outb(REG_COMMAND_RX_BUF_ONE
, iobase
+ REG_COMMAND
);
531 bluecard_receive(info
, 0x10);
532 outb(0x08, iobase
+ REG_INTERRUPT
);
533 outb(REG_COMMAND_RX_BUF_TWO
, iobase
+ REG_COMMAND
);
537 set_bit(XMIT_BUF_ONE_READY
, &(info
->tx_state
));
538 outb(0x01, iobase
+ REG_INTERRUPT
);
539 bluecard_write_wakeup(info
);
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
));
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
);
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");
580 bt_cb(skb
)->pkt_type
= PKT_BAUD_RATE_460800
;
584 bt_cb(skb
)->pkt_type
= PKT_BAUD_RATE_230400
;
588 bt_cb(skb
)->pkt_type
= PKT_BAUD_RATE_115200
;
591 /* Fall through... */
594 bt_cb(skb
)->pkt_type
= PKT_BAUD_RATE_57600
;
598 memcpy(skb_put(skb
, sizeof(cmd
)), cmd
, sizeof(cmd
));
600 skb_queue_tail(&(info
->txq
), skb
);
602 bluecard_write_wakeup(info
);
609 /* ======================== HCI interface ======================== */
612 static int bluecard_hci_flush(struct hci_dev
*hdev
)
614 bluecard_info_t
*info
= (bluecard_info_t
*)(hdev
->driver_data
);
617 skb_queue_purge(&(info
->txq
));
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
)))
634 if (test_bit(CARD_HAS_PCCARD_ID
, &(info
->hw_state
))) {
636 outb(0x08 | 0x20, iobase
+ 0x30);
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
)))
651 bluecard_hci_flush(hdev
);
653 if (test_bit(CARD_HAS_PCCARD_ID
, &(info
->hw_state
))) {
655 outb(0x00, iobase
+ 0x30);
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
);
668 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
672 info
= (bluecard_info_t
*)(hdev
->driver_data
);
674 switch (bt_cb(skb
)->pkt_type
) {
675 case HCI_COMMAND_PKT
:
678 case HCI_ACLDATA_PKT
:
681 case HCI_SCODATA_PKT
:
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
);
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
)
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
;
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
;
729 /* Initialize HCI device */
730 hdev
= hci_alloc_dev();
732 BT_ERR("Can't allocate HCI device");
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
));
757 set_bit(CARD_HAS_POWER_LED
, &(info
->hw_state
));
760 set_bit(CARD_HAS_ACTIVITY_LED
, &(info
->hw_state
));
763 info
->ctrl_reg
= REG_CONTROL_BT_RESET
| REG_CONTROL_CARD_RESET
;
764 outb(info
->ctrl_reg
, iobase
+ REG_CONTROL
);
767 outb(0x80, iobase
+ 0x30);
773 outb(0x00, iobase
+ 0x30);
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) {
786 info
->ctrl_reg
|= REG_CONTROL_RTS
;
787 outb(info
->ctrl_reg
, iobase
+ REG_CONTROL
);
790 info
->ctrl_reg
|= 0x03;
791 outb(info
->ctrl_reg
, iobase
+ REG_CONTROL
);
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
));
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 */
818 /* Register HCI device */
819 if (hci_register_dev(hdev
) < 0) {
820 BT_ERR("Can't register HCI device");
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
;
838 bluecard_hci_close(hdev
);
840 clear_bit(CARD_READY
, &(info
->hw_state
));
843 info
->ctrl_reg
= REG_CONTROL_BT_RESET
| REG_CONTROL_CARD_RESET
;
844 outb(info
->ctrl_reg
, iobase
+ REG_CONTROL
);
847 outb(0x80, iobase
+ 0x30);
849 if (hci_unregister_dev(hdev
) < 0)
850 BT_ERR("Can't unregister HCI device %s", hdev
->name
);
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
);
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
);
888 static int bluecard_config(struct pcmcia_device
*link
)
890 bluecard_info_t
*info
= link
->priv
;
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
);
907 i
= pcmcia_request_irq(link
, bluecard_interrupt
);
911 i
= pcmcia_request_configuration(link
, &link
->conf
);
915 if (bluecard_open(info
) != 0)
921 bluecard_release(link
);
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),
943 MODULE_DEVICE_TABLE(pcmcia
, bluecard_ids
);
945 static struct pcmcia_driver bluecard_driver
= {
946 .owner
= THIS_MODULE
,
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
);