Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / bluetooth / btuart_cs.c
blobad8d972444a522e682776e97ffbb1fe758df5a06
1 /*
3 * Driver for Bluetooth PCMCIA cards with HCI UART interface
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/config.h>
24 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/types.h>
30 #include <linux/sched.h>
31 #include <linux/delay.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>
38 #include <linux/skbuff.h>
39 #include <linux/string.h>
40 #include <linux/serial.h>
41 #include <linux/serial_reg.h>
42 #include <linux/bitops.h>
43 #include <asm/system.h>
44 #include <asm/io.h>
46 #include <pcmcia/version.h>
47 #include <pcmcia/cs_types.h>
48 #include <pcmcia/cs.h>
49 #include <pcmcia/cistpl.h>
50 #include <pcmcia/ciscode.h>
51 #include <pcmcia/ds.h>
52 #include <pcmcia/cisreg.h>
54 #include <net/bluetooth/bluetooth.h>
55 #include <net/bluetooth/hci_core.h>
59 /* ======================== Module parameters ======================== */
62 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
63 MODULE_DESCRIPTION("Bluetooth driver for Bluetooth PCMCIA cards with HCI UART interface");
64 MODULE_LICENSE("GPL");
68 /* ======================== Local structures ======================== */
71 typedef struct btuart_info_t {
72 dev_link_t link;
73 dev_node_t node;
75 struct hci_dev *hdev;
77 spinlock_t lock; /* For serializing operations */
79 struct sk_buff_head txq;
80 unsigned long tx_state;
82 unsigned long rx_state;
83 unsigned long rx_count;
84 struct sk_buff *rx_skb;
85 } btuart_info_t;
88 static void btuart_config(dev_link_t *link);
89 static void btuart_release(dev_link_t *link);
90 static int btuart_event(event_t event, int priority, event_callback_args_t *args);
92 static dev_info_t dev_info = "btuart_cs";
94 static dev_link_t *btuart_attach(void);
95 static void btuart_detach(dev_link_t *);
97 static dev_link_t *dev_list = NULL;
100 /* Maximum baud rate */
101 #define SPEED_MAX 115200
103 /* Default baud rate: 57600, 115200, 230400 or 460800 */
104 #define DEFAULT_BAUD_RATE 115200
107 /* Transmit states */
108 #define XMIT_SENDING 1
109 #define XMIT_WAKEUP 2
110 #define XMIT_WAITING 8
112 /* Receiver states */
113 #define RECV_WAIT_PACKET_TYPE 0
114 #define RECV_WAIT_EVENT_HEADER 1
115 #define RECV_WAIT_ACL_HEADER 2
116 #define RECV_WAIT_SCO_HEADER 3
117 #define RECV_WAIT_DATA 4
121 /* ======================== Interrupt handling ======================== */
124 static int btuart_write(unsigned int iobase, int fifo_size, __u8 *buf, int len)
126 int actual = 0;
128 /* Tx FIFO should be empty */
129 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE))
130 return 0;
132 /* Fill FIFO with current frame */
133 while ((fifo_size-- > 0) && (actual < len)) {
134 /* Transmit next byte */
135 outb(buf[actual], iobase + UART_TX);
136 actual++;
139 return actual;
143 static void btuart_write_wakeup(btuart_info_t *info)
145 if (!info) {
146 BT_ERR("Unknown device");
147 return;
150 if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
151 set_bit(XMIT_WAKEUP, &(info->tx_state));
152 return;
155 do {
156 register unsigned int iobase = info->link.io.BasePort1;
157 register struct sk_buff *skb;
158 register int len;
160 clear_bit(XMIT_WAKEUP, &(info->tx_state));
162 if (!(info->link.state & DEV_PRESENT))
163 return;
165 if (!(skb = skb_dequeue(&(info->txq))))
166 break;
168 /* Send frame */
169 len = btuart_write(iobase, 16, skb->data, skb->len);
170 set_bit(XMIT_WAKEUP, &(info->tx_state));
172 if (len == skb->len) {
173 kfree_skb(skb);
174 } else {
175 skb_pull(skb, len);
176 skb_queue_head(&(info->txq), skb);
179 info->hdev->stat.byte_tx += len;
181 } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
183 clear_bit(XMIT_SENDING, &(info->tx_state));
187 static void btuart_receive(btuart_info_t *info)
189 unsigned int iobase;
190 int boguscount = 0;
192 if (!info) {
193 BT_ERR("Unknown device");
194 return;
197 iobase = info->link.io.BasePort1;
199 do {
200 info->hdev->stat.byte_rx++;
202 /* Allocate packet */
203 if (info->rx_skb == NULL) {
204 info->rx_state = RECV_WAIT_PACKET_TYPE;
205 info->rx_count = 0;
206 if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
207 BT_ERR("Can't allocate mem for new packet");
208 return;
212 if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
214 info->rx_skb->dev = (void *) info->hdev;
215 info->rx_skb->pkt_type = inb(iobase + UART_RX);
217 switch (info->rx_skb->pkt_type) {
219 case HCI_EVENT_PKT:
220 info->rx_state = RECV_WAIT_EVENT_HEADER;
221 info->rx_count = HCI_EVENT_HDR_SIZE;
222 break;
224 case HCI_ACLDATA_PKT:
225 info->rx_state = RECV_WAIT_ACL_HEADER;
226 info->rx_count = HCI_ACL_HDR_SIZE;
227 break;
229 case HCI_SCODATA_PKT:
230 info->rx_state = RECV_WAIT_SCO_HEADER;
231 info->rx_count = HCI_SCO_HDR_SIZE;
232 break;
234 default:
235 /* Unknown packet */
236 BT_ERR("Unknown HCI packet with type 0x%02x received", info->rx_skb->pkt_type);
237 info->hdev->stat.err_rx++;
238 clear_bit(HCI_RUNNING, &(info->hdev->flags));
240 kfree_skb(info->rx_skb);
241 info->rx_skb = NULL;
242 break;
246 } else {
248 *skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
249 info->rx_count--;
251 if (info->rx_count == 0) {
253 int dlen;
254 struct hci_event_hdr *eh;
255 struct hci_acl_hdr *ah;
256 struct hci_sco_hdr *sh;
259 switch (info->rx_state) {
261 case RECV_WAIT_EVENT_HEADER:
262 eh = (struct hci_event_hdr *)(info->rx_skb->data);
263 info->rx_state = RECV_WAIT_DATA;
264 info->rx_count = eh->plen;
265 break;
267 case RECV_WAIT_ACL_HEADER:
268 ah = (struct hci_acl_hdr *)(info->rx_skb->data);
269 dlen = __le16_to_cpu(ah->dlen);
270 info->rx_state = RECV_WAIT_DATA;
271 info->rx_count = dlen;
272 break;
274 case RECV_WAIT_SCO_HEADER:
275 sh = (struct hci_sco_hdr *)(info->rx_skb->data);
276 info->rx_state = RECV_WAIT_DATA;
277 info->rx_count = sh->dlen;
278 break;
280 case RECV_WAIT_DATA:
281 hci_recv_frame(info->rx_skb);
282 info->rx_skb = NULL;
283 break;
291 /* Make sure we don't stay here too long */
292 if (boguscount++ > 16)
293 break;
295 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
299 static irqreturn_t btuart_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
301 btuart_info_t *info = dev_inst;
302 unsigned int iobase;
303 int boguscount = 0;
304 int iir, lsr;
306 if (!info || !info->hdev) {
307 BT_ERR("Call of irq %d for unknown device", irq);
308 return IRQ_NONE;
311 iobase = info->link.io.BasePort1;
313 spin_lock(&(info->lock));
315 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
316 while (iir) {
318 /* Clear interrupt */
319 lsr = inb(iobase + UART_LSR);
321 switch (iir) {
322 case UART_IIR_RLSI:
323 BT_ERR("RLSI");
324 break;
325 case UART_IIR_RDI:
326 /* Receive interrupt */
327 btuart_receive(info);
328 break;
329 case UART_IIR_THRI:
330 if (lsr & UART_LSR_THRE) {
331 /* Transmitter ready for data */
332 btuart_write_wakeup(info);
334 break;
335 default:
336 BT_ERR("Unhandled IIR=%#x", iir);
337 break;
340 /* Make sure we don't stay here too long */
341 if (boguscount++ > 100)
342 break;
344 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
348 spin_unlock(&(info->lock));
350 return IRQ_HANDLED;
354 static void btuart_change_speed(btuart_info_t *info, unsigned int speed)
356 unsigned long flags;
357 unsigned int iobase;
358 int fcr; /* FIFO control reg */
359 int lcr; /* Line control reg */
360 int divisor;
362 if (!info) {
363 BT_ERR("Unknown device");
364 return;
367 iobase = info->link.io.BasePort1;
369 spin_lock_irqsave(&(info->lock), flags);
371 /* Turn off interrupts */
372 outb(0, iobase + UART_IER);
374 divisor = SPEED_MAX / speed;
376 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT;
379 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
380 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
381 * about this timeout since it will always be fast enough.
384 if (speed < 38400)
385 fcr |= UART_FCR_TRIGGER_1;
386 else
387 fcr |= UART_FCR_TRIGGER_14;
389 /* Bluetooth cards use 8N1 */
390 lcr = UART_LCR_WLEN8;
392 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
393 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
394 outb(divisor >> 8, iobase + UART_DLM);
395 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
396 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
398 /* Turn on interrups */
399 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
401 spin_unlock_irqrestore(&(info->lock), flags);
406 /* ======================== HCI interface ======================== */
409 static int btuart_hci_flush(struct hci_dev *hdev)
411 btuart_info_t *info = (btuart_info_t *)(hdev->driver_data);
413 /* Drop TX queue */
414 skb_queue_purge(&(info->txq));
416 return 0;
420 static int btuart_hci_open(struct hci_dev *hdev)
422 set_bit(HCI_RUNNING, &(hdev->flags));
424 return 0;
428 static int btuart_hci_close(struct hci_dev *hdev)
430 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
431 return 0;
433 btuart_hci_flush(hdev);
435 return 0;
439 static int btuart_hci_send_frame(struct sk_buff *skb)
441 btuart_info_t *info;
442 struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
444 if (!hdev) {
445 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
446 return -ENODEV;
449 info = (btuart_info_t *)(hdev->driver_data);
451 switch (skb->pkt_type) {
452 case HCI_COMMAND_PKT:
453 hdev->stat.cmd_tx++;
454 break;
455 case HCI_ACLDATA_PKT:
456 hdev->stat.acl_tx++;
457 break;
458 case HCI_SCODATA_PKT:
459 hdev->stat.sco_tx++;
460 break;
463 /* Prepend skb with frame type */
464 memcpy(skb_push(skb, 1), &(skb->pkt_type), 1);
465 skb_queue_tail(&(info->txq), skb);
467 btuart_write_wakeup(info);
469 return 0;
473 static void btuart_hci_destruct(struct hci_dev *hdev)
478 static int btuart_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
480 return -ENOIOCTLCMD;
485 /* ======================== Card services HCI interaction ======================== */
488 static int btuart_open(btuart_info_t *info)
490 unsigned long flags;
491 unsigned int iobase = info->link.io.BasePort1;
492 struct hci_dev *hdev;
494 spin_lock_init(&(info->lock));
496 skb_queue_head_init(&(info->txq));
498 info->rx_state = RECV_WAIT_PACKET_TYPE;
499 info->rx_count = 0;
500 info->rx_skb = NULL;
502 /* Initialize HCI device */
503 hdev = hci_alloc_dev();
504 if (!hdev) {
505 BT_ERR("Can't allocate HCI device");
506 return -ENOMEM;
509 info->hdev = hdev;
511 hdev->type = HCI_PCCARD;
512 hdev->driver_data = info;
514 hdev->open = btuart_hci_open;
515 hdev->close = btuart_hci_close;
516 hdev->flush = btuart_hci_flush;
517 hdev->send = btuart_hci_send_frame;
518 hdev->destruct = btuart_hci_destruct;
519 hdev->ioctl = btuart_hci_ioctl;
521 hdev->owner = THIS_MODULE;
523 spin_lock_irqsave(&(info->lock), flags);
525 /* Reset UART */
526 outb(0, iobase + UART_MCR);
528 /* Turn off interrupts */
529 outb(0, iobase + UART_IER);
531 /* Initialize UART */
532 outb(UART_LCR_WLEN8, iobase + UART_LCR); /* Reset DLAB */
533 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR);
535 /* Turn on interrupts */
536 // outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
538 spin_unlock_irqrestore(&(info->lock), flags);
540 btuart_change_speed(info, DEFAULT_BAUD_RATE);
542 /* Timeout before it is safe to send the first HCI packet */
543 msleep(1000);
545 /* Register HCI device */
546 if (hci_register_dev(hdev) < 0) {
547 BT_ERR("Can't register HCI device");
548 info->hdev = NULL;
549 hci_free_dev(hdev);
550 return -ENODEV;
553 return 0;
557 static int btuart_close(btuart_info_t *info)
559 unsigned long flags;
560 unsigned int iobase = info->link.io.BasePort1;
561 struct hci_dev *hdev = info->hdev;
563 if (!hdev)
564 return -ENODEV;
566 btuart_hci_close(hdev);
568 spin_lock_irqsave(&(info->lock), flags);
570 /* Reset UART */
571 outb(0, iobase + UART_MCR);
573 /* Turn off interrupts */
574 outb(0, iobase + UART_IER);
576 spin_unlock_irqrestore(&(info->lock), flags);
578 if (hci_unregister_dev(hdev) < 0)
579 BT_ERR("Can't unregister HCI device %s", hdev->name);
581 hci_free_dev(hdev);
583 return 0;
586 static dev_link_t *btuart_attach(void)
588 btuart_info_t *info;
589 client_reg_t client_reg;
590 dev_link_t *link;
591 int ret;
593 /* Create new info device */
594 info = kmalloc(sizeof(*info), GFP_KERNEL);
595 if (!info)
596 return NULL;
597 memset(info, 0, sizeof(*info));
599 link = &info->link;
600 link->priv = info;
602 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
603 link->io.NumPorts1 = 8;
604 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
605 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
607 link->irq.Handler = btuart_interrupt;
608 link->irq.Instance = info;
610 link->conf.Attributes = CONF_ENABLE_IRQ;
611 link->conf.Vcc = 50;
612 link->conf.IntType = INT_MEMORY_AND_IO;
614 /* Register with Card Services */
615 link->next = dev_list;
616 dev_list = link;
617 client_reg.dev_info = &dev_info;
618 client_reg.EventMask =
619 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
620 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
621 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
622 client_reg.event_handler = &btuart_event;
623 client_reg.Version = 0x0210;
624 client_reg.event_callback_args.client_data = link;
626 ret = pcmcia_register_client(&link->handle, &client_reg);
627 if (ret != CS_SUCCESS) {
628 cs_error(link->handle, RegisterClient, ret);
629 btuart_detach(link);
630 return NULL;
633 return link;
637 static void btuart_detach(dev_link_t *link)
639 btuart_info_t *info = link->priv;
640 dev_link_t **linkp;
641 int ret;
643 /* Locate device structure */
644 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
645 if (*linkp == link)
646 break;
648 if (*linkp == NULL)
649 return;
651 if (link->state & DEV_CONFIG)
652 btuart_release(link);
654 if (link->handle) {
655 ret = pcmcia_deregister_client(link->handle);
656 if (ret != CS_SUCCESS)
657 cs_error(link->handle, DeregisterClient, ret);
660 /* Unlink device structure, free bits */
661 *linkp = link->next;
663 kfree(info);
666 static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
668 int i;
670 i = pcmcia_get_tuple_data(handle, tuple);
671 if (i != CS_SUCCESS)
672 return i;
674 return pcmcia_parse_tuple(handle, tuple, parse);
677 static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
679 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
680 return CS_NO_MORE_ITEMS;
681 return get_tuple(handle, tuple, parse);
684 static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
686 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
687 return CS_NO_MORE_ITEMS;
688 return get_tuple(handle, tuple, parse);
691 static void btuart_config(dev_link_t *link)
693 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
694 client_handle_t handle = link->handle;
695 btuart_info_t *info = link->priv;
696 tuple_t tuple;
697 u_short buf[256];
698 cisparse_t parse;
699 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
700 config_info_t config;
701 int i, j, try, last_ret, last_fn;
703 tuple.TupleData = (cisdata_t *)buf;
704 tuple.TupleOffset = 0;
705 tuple.TupleDataMax = 255;
706 tuple.Attributes = 0;
708 /* Get configuration register information */
709 tuple.DesiredTuple = CISTPL_CONFIG;
710 last_ret = first_tuple(handle, &tuple, &parse);
711 if (last_ret != CS_SUCCESS) {
712 last_fn = ParseTuple;
713 goto cs_failed;
715 link->conf.ConfigBase = parse.config.base;
716 link->conf.Present = parse.config.rmask[0];
718 /* Configure card */
719 link->state |= DEV_CONFIG;
720 i = pcmcia_get_configuration_info(handle, &config);
721 link->conf.Vcc = config.Vcc;
723 /* First pass: look for a config entry that looks normal. */
724 tuple.TupleData = (cisdata_t *) buf;
725 tuple.TupleOffset = 0;
726 tuple.TupleDataMax = 255;
727 tuple.Attributes = 0;
728 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
729 /* Two tries: without IO aliases, then with aliases */
730 for (try = 0; try < 2; try++) {
731 i = first_tuple(handle, &tuple, &parse);
732 while (i != CS_NO_MORE_ITEMS) {
733 if (i != CS_SUCCESS)
734 goto next_entry;
735 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
736 link->conf.Vpp1 = link->conf.Vpp2 = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
737 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
738 link->conf.ConfigIndex = cf->index;
739 link->io.BasePort1 = cf->io.win[0].base;
740 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
741 i = pcmcia_request_io(link->handle, &link->io);
742 if (i == CS_SUCCESS)
743 goto found_port;
745 next_entry:
746 i = next_tuple(handle, &tuple, &parse);
750 /* Second pass: try to find an entry that isn't picky about
751 its base address, then try to grab any standard serial port
752 address, and finally try to get any free port. */
753 i = first_tuple(handle, &tuple, &parse);
754 while (i != CS_NO_MORE_ITEMS) {
755 if ((i == CS_SUCCESS) && (cf->io.nwin > 0)
756 && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
757 link->conf.ConfigIndex = cf->index;
758 for (j = 0; j < 5; j++) {
759 link->io.BasePort1 = base[j];
760 link->io.IOAddrLines = base[j] ? 16 : 3;
761 i = pcmcia_request_io(link->handle, &link->io);
762 if (i == CS_SUCCESS)
763 goto found_port;
766 i = next_tuple(handle, &tuple, &parse);
769 found_port:
770 if (i != CS_SUCCESS) {
771 BT_ERR("No usable port range found");
772 cs_error(link->handle, RequestIO, i);
773 goto failed;
776 i = pcmcia_request_irq(link->handle, &link->irq);
777 if (i != CS_SUCCESS) {
778 cs_error(link->handle, RequestIRQ, i);
779 link->irq.AssignedIRQ = 0;
782 i = pcmcia_request_configuration(link->handle, &link->conf);
783 if (i != CS_SUCCESS) {
784 cs_error(link->handle, RequestConfiguration, i);
785 goto failed;
788 if (btuart_open(info) != 0)
789 goto failed;
791 strcpy(info->node.dev_name, info->hdev->name);
792 link->dev = &info->node;
793 link->state &= ~DEV_CONFIG_PENDING;
795 return;
797 cs_failed:
798 cs_error(link->handle, last_fn, last_ret);
800 failed:
801 btuart_release(link);
805 static void btuart_release(dev_link_t *link)
807 btuart_info_t *info = link->priv;
809 if (link->state & DEV_PRESENT)
810 btuart_close(info);
812 link->dev = NULL;
814 pcmcia_release_configuration(link->handle);
815 pcmcia_release_io(link->handle, &link->io);
816 pcmcia_release_irq(link->handle, &link->irq);
818 link->state &= ~DEV_CONFIG;
822 static int btuart_event(event_t event, int priority, event_callback_args_t *args)
824 dev_link_t *link = args->client_data;
825 btuart_info_t *info = link->priv;
827 switch (event) {
828 case CS_EVENT_CARD_REMOVAL:
829 link->state &= ~DEV_PRESENT;
830 if (link->state & DEV_CONFIG) {
831 btuart_close(info);
832 btuart_release(link);
834 break;
835 case CS_EVENT_CARD_INSERTION:
836 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
837 btuart_config(link);
838 break;
839 case CS_EVENT_PM_SUSPEND:
840 link->state |= DEV_SUSPEND;
841 /* Fall through... */
842 case CS_EVENT_RESET_PHYSICAL:
843 if (link->state & DEV_CONFIG)
844 pcmcia_release_configuration(link->handle);
845 break;
846 case CS_EVENT_PM_RESUME:
847 link->state &= ~DEV_SUSPEND;
848 /* Fall through... */
849 case CS_EVENT_CARD_RESET:
850 if (DEV_OK(link))
851 pcmcia_request_configuration(link->handle, &link->conf);
852 break;
855 return 0;
858 static struct pcmcia_driver btuart_driver = {
859 .owner = THIS_MODULE,
860 .drv = {
861 .name = "btuart_cs",
863 .attach = btuart_attach,
864 .detach = btuart_detach,
867 static int __init init_btuart_cs(void)
869 return pcmcia_register_driver(&btuart_driver);
873 static void __exit exit_btuart_cs(void)
875 pcmcia_unregister_driver(&btuart_driver);
876 BUG_ON(dev_list != NULL);
879 module_init(init_btuart_cs);
880 module_exit(exit_btuart_cs);