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/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/timer.h>
33 #include <linux/errno.h>
34 #include <linux/ptrace.h>
35 #include <linux/ioport.h>
36 #include <linux/spinlock.h>
37 #include <linux/moduleparam.h>
38 #include <linux/wait.h>
40 #include <linux/skbuff.h>
43 #include <pcmcia/cs_types.h>
44 #include <pcmcia/cs.h>
45 #include <pcmcia/cistpl.h>
46 #include <pcmcia/ciscode.h>
47 #include <pcmcia/ds.h>
48 #include <pcmcia/cisreg.h>
50 #include <net/bluetooth/bluetooth.h>
51 #include <net/bluetooth/hci_core.h>
55 /* ======================== Module parameters ======================== */
58 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
59 MODULE_DESCRIPTION("Bluetooth driver for the Anycom BlueCard (LSE039/LSE041)");
60 MODULE_LICENSE("GPL");
64 /* ======================== Local structures ======================== */
67 typedef struct bluecard_info_t {
73 spinlock_t lock; /* For serializing operations */
74 struct timer_list timer; /* For LED control */
76 struct sk_buff_head txq;
77 unsigned long tx_state;
79 unsigned long rx_state;
80 unsigned long rx_count;
81 struct sk_buff *rx_skb;
83 unsigned char ctrl_reg;
84 unsigned long hw_state; /* Status of the hardware and LED control */
88 static void bluecard_config(dev_link_t *link);
89 static void bluecard_release(dev_link_t *link);
90 static int bluecard_event(event_t event, int priority, event_callback_args_t *args);
92 static dev_info_t dev_info = "bluecard_cs";
94 static dev_link_t *bluecard_attach(void);
95 static void bluecard_detach(struct pcmcia_device *p_dev);
98 /* Default baud rate: 57600, 115200, 230400 or 460800 */
99 #define DEFAULT_BAUD_RATE 230400
102 /* Hardware states */
104 #define CARD_HAS_PCCARD_ID 4
105 #define CARD_HAS_POWER_LED 5
106 #define CARD_HAS_ACTIVITY_LED 6
108 /* Transmit states */
109 #define XMIT_SENDING 1
110 #define XMIT_WAKEUP 2
111 #define XMIT_BUFFER_NUMBER 5 /* unset = buffer one, set = buffer two */
112 #define XMIT_BUF_ONE_READY 6
113 #define XMIT_BUF_TWO_READY 7
114 #define XMIT_SENDING_READY 8
116 /* Receiver states */
117 #define RECV_WAIT_PACKET_TYPE 0
118 #define RECV_WAIT_EVENT_HEADER 1
119 #define RECV_WAIT_ACL_HEADER 2
120 #define RECV_WAIT_SCO_HEADER 3
121 #define RECV_WAIT_DATA 4
123 /* Special packet types */
124 #define PKT_BAUD_RATE_57600 0x80
125 #define PKT_BAUD_RATE_115200 0x81
126 #define PKT_BAUD_RATE_230400 0x82
127 #define PKT_BAUD_RATE_460800 0x83
130 /* These are the register offsets */
131 #define REG_COMMAND 0x20
132 #define REG_INTERRUPT 0x21
133 #define REG_CONTROL 0x22
134 #define REG_RX_CONTROL 0x24
135 #define REG_CARD_RESET 0x30
136 #define REG_LED_CTRL 0x30
139 #define REG_COMMAND_TX_BUF_ONE 0x01
140 #define REG_COMMAND_TX_BUF_TWO 0x02
141 #define REG_COMMAND_RX_BUF_ONE 0x04
142 #define REG_COMMAND_RX_BUF_TWO 0x08
143 #define REG_COMMAND_RX_WIN_ONE 0x00
144 #define REG_COMMAND_RX_WIN_TWO 0x10
147 #define REG_CONTROL_BAUD_RATE_57600 0x00
148 #define REG_CONTROL_BAUD_RATE_115200 0x01
149 #define REG_CONTROL_BAUD_RATE_230400 0x02
150 #define REG_CONTROL_BAUD_RATE_460800 0x03
151 #define REG_CONTROL_RTS 0x04
152 #define REG_CONTROL_BT_ON 0x08
153 #define REG_CONTROL_BT_RESET 0x10
154 #define REG_CONTROL_BT_RES_PU 0x20
155 #define REG_CONTROL_INTERRUPT 0x40
156 #define REG_CONTROL_CARD_RESET 0x80
159 #define RTS_LEVEL_SHIFT_BITS 0x02
163 /* ======================== LED handling routines ======================== */
166 static void bluecard_activity_led_timeout(u_long arg)
168 bluecard_info_t *info = (bluecard_info_t *)arg;
169 unsigned int iobase = info->link.io.BasePort1;
171 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
174 if (test_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state))) {
175 /* Disable activity LED */
176 outb(0x08 | 0x20, iobase + 0x30);
178 /* Disable power LED */
179 outb(0x00, iobase + 0x30);
184 static void bluecard_enable_activity_led(bluecard_info_t *info)
186 unsigned int iobase = info->link.io.BasePort1;
188 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
191 if (test_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state))) {
192 /* Enable activity LED */
193 outb(0x10 | 0x40, iobase + 0x30);
195 /* Stop the LED after HZ/4 */
196 mod_timer(&(info->timer), jiffies + HZ / 4);
198 /* Enable power LED */
199 outb(0x08 | 0x20, iobase + 0x30);
201 /* Stop the LED after HZ/2 */
202 mod_timer(&(info->timer), jiffies + HZ / 2);
208 /* ======================== Interrupt handling ======================== */
211 static int bluecard_write(unsigned int iobase, unsigned int offset, __u8 *buf, int len)
215 actual = (len > 15) ? 15 : len;
217 outb_p(actual, iobase + offset);
219 for (i = 0; i < actual; i++)
220 outb_p(buf[i], iobase + offset + i + 1);
226 static void bluecard_write_wakeup(bluecard_info_t *info)
229 BT_ERR("Unknown device");
233 if (!test_bit(XMIT_SENDING_READY, &(info->tx_state)))
236 if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
237 set_bit(XMIT_WAKEUP, &(info->tx_state));
242 register unsigned int iobase = info->link.io.BasePort1;
243 register unsigned int offset;
244 register unsigned char command;
245 register unsigned long ready_bit;
246 register struct sk_buff *skb;
249 clear_bit(XMIT_WAKEUP, &(info->tx_state));
251 if (!(info->link.state & DEV_PRESENT))
254 if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) {
255 if (!test_bit(XMIT_BUF_TWO_READY, &(info->tx_state)))
258 command = REG_COMMAND_TX_BUF_TWO;
259 ready_bit = XMIT_BUF_TWO_READY;
261 if (!test_bit(XMIT_BUF_ONE_READY, &(info->tx_state)))
264 command = REG_COMMAND_TX_BUF_ONE;
265 ready_bit = XMIT_BUF_ONE_READY;
268 if (!(skb = skb_dequeue(&(info->txq))))
271 if (bt_cb(skb)->pkt_type & 0x80) {
273 info->ctrl_reg |= REG_CONTROL_RTS;
274 outb(info->ctrl_reg, iobase + REG_CONTROL);
278 bluecard_enable_activity_led(info);
281 len = bluecard_write(iobase, offset, skb->data, skb->len);
283 /* Tell the FPGA to send the data */
284 outb_p(command, iobase + REG_COMMAND);
286 /* Mark the buffer as dirty */
287 clear_bit(ready_bit, &(info->tx_state));
289 if (bt_cb(skb)->pkt_type & 0x80) {
290 DECLARE_WAIT_QUEUE_HEAD(wq);
293 unsigned char baud_reg;
295 switch (bt_cb(skb)->pkt_type) {
296 case PKT_BAUD_RATE_460800:
297 baud_reg = REG_CONTROL_BAUD_RATE_460800;
299 case PKT_BAUD_RATE_230400:
300 baud_reg = REG_CONTROL_BAUD_RATE_230400;
302 case PKT_BAUD_RATE_115200:
303 baud_reg = REG_CONTROL_BAUD_RATE_115200;
305 case PKT_BAUD_RATE_57600:
306 /* Fall through... */
308 baud_reg = REG_CONTROL_BAUD_RATE_57600;
312 /* Wait until the command reaches the baseband */
313 prepare_to_wait(&wq, &wait, TASK_INTERRUPTIBLE);
314 schedule_timeout(HZ/10);
315 finish_wait(&wq, &wait);
317 /* Set baud on baseband */
318 info->ctrl_reg &= ~0x03;
319 info->ctrl_reg |= baud_reg;
320 outb(info->ctrl_reg, iobase + REG_CONTROL);
323 info->ctrl_reg &= ~REG_CONTROL_RTS;
324 outb(info->ctrl_reg, iobase + REG_CONTROL);
326 /* Wait before the next HCI packet can be send */
327 prepare_to_wait(&wq, &wait, TASK_INTERRUPTIBLE);
328 schedule_timeout(HZ);
329 finish_wait(&wq, &wait);
332 if (len == skb->len) {
336 skb_queue_head(&(info->txq), skb);
339 info->hdev->stat.byte_tx += len;
342 change_bit(XMIT_BUFFER_NUMBER, &(info->tx_state));
344 } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
346 clear_bit(XMIT_SENDING, &(info->tx_state));
350 static int bluecard_read(unsigned int iobase, unsigned int offset, __u8 *buf, int size)
354 outb(REG_COMMAND_RX_WIN_ONE, iobase + REG_COMMAND);
356 len = inb(iobase + offset);
363 outb(REG_COMMAND_RX_WIN_TWO, iobase + REG_COMMAND);
367 buf[n] = inb(iobase + offset + i);
378 static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
381 unsigned char buf[31];
385 BT_ERR("Unknown device");
389 iobase = info->link.io.BasePort1;
391 if (test_bit(XMIT_SENDING_READY, &(info->tx_state)))
392 bluecard_enable_activity_led(info);
394 len = bluecard_read(iobase, offset, buf, sizeof(buf));
396 for (i = 0; i < len; i++) {
398 /* Allocate packet */
399 if (info->rx_skb == NULL) {
400 info->rx_state = RECV_WAIT_PACKET_TYPE;
402 if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
403 BT_ERR("Can't allocate mem for new packet");
408 if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
410 info->rx_skb->dev = (void *) info->hdev;
411 bt_cb(info->rx_skb)->pkt_type = buf[i];
413 switch (bt_cb(info->rx_skb)->pkt_type) {
417 if (offset != 0x00) {
418 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
419 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
420 set_bit(XMIT_SENDING_READY, &(info->tx_state));
421 bluecard_write_wakeup(info);
424 kfree_skb(info->rx_skb);
429 info->rx_state = RECV_WAIT_EVENT_HEADER;
430 info->rx_count = HCI_EVENT_HDR_SIZE;
433 case HCI_ACLDATA_PKT:
434 info->rx_state = RECV_WAIT_ACL_HEADER;
435 info->rx_count = HCI_ACL_HDR_SIZE;
438 case HCI_SCODATA_PKT:
439 info->rx_state = RECV_WAIT_SCO_HEADER;
440 info->rx_count = HCI_SCO_HDR_SIZE;
445 BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
446 info->hdev->stat.err_rx++;
448 kfree_skb(info->rx_skb);
456 *skb_put(info->rx_skb, 1) = buf[i];
459 if (info->rx_count == 0) {
462 struct hci_event_hdr *eh;
463 struct hci_acl_hdr *ah;
464 struct hci_sco_hdr *sh;
466 switch (info->rx_state) {
468 case RECV_WAIT_EVENT_HEADER:
469 eh = (struct hci_event_hdr *)(info->rx_skb->data);
470 info->rx_state = RECV_WAIT_DATA;
471 info->rx_count = eh->plen;
474 case RECV_WAIT_ACL_HEADER:
475 ah = (struct hci_acl_hdr *)(info->rx_skb->data);
476 dlen = __le16_to_cpu(ah->dlen);
477 info->rx_state = RECV_WAIT_DATA;
478 info->rx_count = dlen;
481 case RECV_WAIT_SCO_HEADER:
482 sh = (struct hci_sco_hdr *)(info->rx_skb->data);
483 info->rx_state = RECV_WAIT_DATA;
484 info->rx_count = sh->dlen;
488 hci_recv_frame(info->rx_skb);
501 info->hdev->stat.byte_rx += len;
505 static irqreturn_t bluecard_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
507 bluecard_info_t *info = dev_inst;
511 if (!info || !info->hdev) {
512 BT_ERR("Call of irq %d for unknown device", irq);
516 if (!test_bit(CARD_READY, &(info->hw_state)))
519 iobase = info->link.io.BasePort1;
521 spin_lock(&(info->lock));
523 /* Disable interrupt */
524 info->ctrl_reg &= ~REG_CONTROL_INTERRUPT;
525 outb(info->ctrl_reg, iobase + REG_CONTROL);
527 reg = inb(iobase + REG_INTERRUPT);
529 if ((reg != 0x00) && (reg != 0xff)) {
532 bluecard_receive(info, 0x00);
533 outb(0x04, iobase + REG_INTERRUPT);
534 outb(REG_COMMAND_RX_BUF_ONE, iobase + REG_COMMAND);
538 bluecard_receive(info, 0x10);
539 outb(0x08, iobase + REG_INTERRUPT);
540 outb(REG_COMMAND_RX_BUF_TWO, iobase + REG_COMMAND);
544 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
545 outb(0x01, iobase + REG_INTERRUPT);
546 bluecard_write_wakeup(info);
550 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
551 outb(0x02, iobase + REG_INTERRUPT);
552 bluecard_write_wakeup(info);
557 /* Enable interrupt */
558 info->ctrl_reg |= REG_CONTROL_INTERRUPT;
559 outb(info->ctrl_reg, iobase + REG_CONTROL);
561 spin_unlock(&(info->lock));
568 /* ======================== Device specific HCI commands ======================== */
571 static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud)
573 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
576 /* Ericsson baud rate command */
577 unsigned char cmd[] = { HCI_COMMAND_PKT, 0x09, 0xfc, 0x01, 0x03 };
579 if (!(skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
580 BT_ERR("Can't allocate mem for new packet");
587 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_460800;
591 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_230400;
595 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_115200;
598 /* Fall through... */
601 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_57600;
605 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
607 skb_queue_tail(&(info->txq), skb);
609 bluecard_write_wakeup(info);
616 /* ======================== HCI interface ======================== */
619 static int bluecard_hci_flush(struct hci_dev *hdev)
621 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
624 skb_queue_purge(&(info->txq));
630 static int bluecard_hci_open(struct hci_dev *hdev)
632 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
633 unsigned int iobase = info->link.io.BasePort1;
635 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
636 bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE);
638 if (test_and_set_bit(HCI_RUNNING, &(hdev->flags)))
641 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) {
643 outb(0x08 | 0x20, iobase + 0x30);
650 static int bluecard_hci_close(struct hci_dev *hdev)
652 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
653 unsigned int iobase = info->link.io.BasePort1;
655 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
658 bluecard_hci_flush(hdev);
660 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) {
662 outb(0x00, iobase + 0x30);
669 static int bluecard_hci_send_frame(struct sk_buff *skb)
671 bluecard_info_t *info;
672 struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
675 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
679 info = (bluecard_info_t *)(hdev->driver_data);
681 switch (bt_cb(skb)->pkt_type) {
682 case HCI_COMMAND_PKT:
685 case HCI_ACLDATA_PKT:
688 case HCI_SCODATA_PKT:
693 /* Prepend skb with frame type */
694 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
695 skb_queue_tail(&(info->txq), skb);
697 bluecard_write_wakeup(info);
703 static void bluecard_hci_destruct(struct hci_dev *hdev)
708 static int bluecard_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
715 /* ======================== Card services HCI interaction ======================== */
718 static int bluecard_open(bluecard_info_t *info)
720 unsigned int iobase = info->link.io.BasePort1;
721 struct hci_dev *hdev;
724 spin_lock_init(&(info->lock));
726 init_timer(&(info->timer));
727 info->timer.function = &bluecard_activity_led_timeout;
728 info->timer.data = (u_long)info;
730 skb_queue_head_init(&(info->txq));
732 info->rx_state = RECV_WAIT_PACKET_TYPE;
736 /* Initialize HCI device */
737 hdev = hci_alloc_dev();
739 BT_ERR("Can't allocate HCI device");
745 hdev->type = HCI_PCCARD;
746 hdev->driver_data = info;
748 hdev->open = bluecard_hci_open;
749 hdev->close = bluecard_hci_close;
750 hdev->flush = bluecard_hci_flush;
751 hdev->send = bluecard_hci_send_frame;
752 hdev->destruct = bluecard_hci_destruct;
753 hdev->ioctl = bluecard_hci_ioctl;
755 hdev->owner = THIS_MODULE;
757 id = inb(iobase + 0x30);
759 if ((id & 0x0f) == 0x02)
760 set_bit(CARD_HAS_PCCARD_ID, &(info->hw_state));
763 set_bit(CARD_HAS_POWER_LED, &(info->hw_state));
766 set_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state));
769 info->ctrl_reg = REG_CONTROL_BT_RESET | REG_CONTROL_CARD_RESET;
770 outb(info->ctrl_reg, iobase + REG_CONTROL);
773 outb(0x80, iobase + 0x30);
779 outb(0x00, iobase + 0x30);
782 info->ctrl_reg = REG_CONTROL_BT_ON | REG_CONTROL_BT_RES_PU;
783 outb(info->ctrl_reg, iobase + REG_CONTROL);
785 /* Enable interrupt */
786 outb(0xff, iobase + REG_INTERRUPT);
787 info->ctrl_reg |= REG_CONTROL_INTERRUPT;
788 outb(info->ctrl_reg, iobase + REG_CONTROL);
790 if ((id & 0x0f) == 0x03) {
792 info->ctrl_reg |= REG_CONTROL_RTS;
793 outb(info->ctrl_reg, iobase + REG_CONTROL);
796 info->ctrl_reg |= 0x03;
797 outb(info->ctrl_reg, iobase + REG_CONTROL);
800 info->ctrl_reg &= ~REG_CONTROL_RTS;
801 outb(info->ctrl_reg, iobase + REG_CONTROL);
803 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
804 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
805 set_bit(XMIT_SENDING_READY, &(info->tx_state));
808 /* Start the RX buffers */
809 outb(REG_COMMAND_RX_BUF_ONE, iobase + REG_COMMAND);
810 outb(REG_COMMAND_RX_BUF_TWO, iobase + REG_COMMAND);
812 /* Signal that the hardware is ready */
813 set_bit(CARD_READY, &(info->hw_state));
816 skb_queue_purge(&(info->txq));
818 /* Control the point at which RTS is enabled */
819 outb((0x0f << RTS_LEVEL_SHIFT_BITS) | 1, iobase + REG_RX_CONTROL);
821 /* Timeout before it is safe to send the first HCI packet */
824 /* Register HCI device */
825 if (hci_register_dev(hdev) < 0) {
826 BT_ERR("Can't register HCI device");
836 static int bluecard_close(bluecard_info_t *info)
838 unsigned int iobase = info->link.io.BasePort1;
839 struct hci_dev *hdev = info->hdev;
844 bluecard_hci_close(hdev);
846 clear_bit(CARD_READY, &(info->hw_state));
849 info->ctrl_reg = REG_CONTROL_BT_RESET | REG_CONTROL_CARD_RESET;
850 outb(info->ctrl_reg, iobase + REG_CONTROL);
853 outb(0x80, iobase + 0x30);
855 if (hci_unregister_dev(hdev) < 0)
856 BT_ERR("Can't unregister HCI device %s", hdev->name);
863 static dev_link_t *bluecard_attach(void)
865 bluecard_info_t *info;
866 client_reg_t client_reg;
870 /* Create new info device */
871 info = kzalloc(sizeof(*info), GFP_KERNEL);
878 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
879 link->io.NumPorts1 = 8;
880 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
881 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
883 link->irq.Handler = bluecard_interrupt;
884 link->irq.Instance = info;
886 link->conf.Attributes = CONF_ENABLE_IRQ;
888 link->conf.IntType = INT_MEMORY_AND_IO;
890 /* Register with Card Services */
892 client_reg.dev_info = &dev_info;
893 client_reg.Version = 0x0210;
894 client_reg.event_callback_args.client_data = link;
896 ret = pcmcia_register_client(&link->handle, &client_reg);
897 if (ret != CS_SUCCESS) {
898 cs_error(link->handle, RegisterClient, ret);
899 bluecard_detach(link->handle);
907 static void bluecard_detach(struct pcmcia_device *p_dev)
909 dev_link_t *link = dev_to_instance(p_dev);
910 bluecard_info_t *info = link->priv;
912 if (link->state & DEV_CONFIG)
913 bluecard_release(link);
919 static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
923 i = pcmcia_get_first_tuple(handle, tuple);
925 return CS_NO_MORE_ITEMS;
927 i = pcmcia_get_tuple_data(handle, tuple);
931 return pcmcia_parse_tuple(handle, tuple, parse);
934 static void bluecard_config(dev_link_t *link)
936 client_handle_t handle = link->handle;
937 bluecard_info_t *info = link->priv;
941 config_info_t config;
942 int i, n, last_ret, last_fn;
944 tuple.TupleData = (cisdata_t *)buf;
945 tuple.TupleOffset = 0;
946 tuple.TupleDataMax = 255;
947 tuple.Attributes = 0;
949 /* Get configuration register information */
950 tuple.DesiredTuple = CISTPL_CONFIG;
951 last_ret = first_tuple(handle, &tuple, &parse);
952 if (last_ret != CS_SUCCESS) {
953 last_fn = ParseTuple;
956 link->conf.ConfigBase = parse.config.base;
957 link->conf.Present = parse.config.rmask[0];
960 link->state |= DEV_CONFIG;
961 i = pcmcia_get_configuration_info(handle, &config);
962 link->conf.Vcc = config.Vcc;
964 link->conf.ConfigIndex = 0x20;
965 link->io.NumPorts1 = 64;
966 link->io.IOAddrLines = 6;
968 for (n = 0; n < 0x400; n += 0x40) {
969 link->io.BasePort1 = n ^ 0x300;
970 i = pcmcia_request_io(link->handle, &link->io);
975 if (i != CS_SUCCESS) {
976 cs_error(link->handle, RequestIO, i);
980 i = pcmcia_request_irq(link->handle, &link->irq);
981 if (i != CS_SUCCESS) {
982 cs_error(link->handle, RequestIRQ, i);
983 link->irq.AssignedIRQ = 0;
986 i = pcmcia_request_configuration(link->handle, &link->conf);
987 if (i != CS_SUCCESS) {
988 cs_error(link->handle, RequestConfiguration, i);
992 if (bluecard_open(info) != 0)
995 strcpy(info->node.dev_name, info->hdev->name);
996 link->dev = &info->node;
997 link->state &= ~DEV_CONFIG_PENDING;
1002 cs_error(link->handle, last_fn, last_ret);
1005 bluecard_release(link);
1009 static void bluecard_release(dev_link_t *link)
1011 bluecard_info_t *info = link->priv;
1013 if (link->state & DEV_PRESENT)
1014 bluecard_close(info);
1016 del_timer(&(info->timer));
1020 pcmcia_release_configuration(link->handle);
1021 pcmcia_release_io(link->handle, &link->io);
1022 pcmcia_release_irq(link->handle, &link->irq);
1024 link->state &= ~DEV_CONFIG;
1027 static int bluecard_suspend(struct pcmcia_device *dev)
1029 dev_link_t *link = dev_to_instance(dev);
1031 link->state |= DEV_SUSPEND;
1032 if (link->state & DEV_CONFIG)
1033 pcmcia_release_configuration(link->handle);
1038 static int bluecard_resume(struct pcmcia_device *dev)
1040 dev_link_t *link = dev_to_instance(dev);
1042 link->state &= ~DEV_SUSPEND;
1044 pcmcia_request_configuration(link->handle, &link->conf);
1049 static int bluecard_event(event_t event, int priority, event_callback_args_t *args)
1051 dev_link_t *link = args->client_data;
1054 case CS_EVENT_CARD_INSERTION:
1055 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1056 bluecard_config(link);
1063 static struct pcmcia_device_id bluecard_ids[] = {
1064 PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e),
1065 PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c),
1066 PCMCIA_DEVICE_PROD_ID12("WSS", "LSE039", 0x0a0736ec, 0x24e6dfab),
1069 MODULE_DEVICE_TABLE(pcmcia, bluecard_ids);
1071 static struct pcmcia_driver bluecard_driver = {
1072 .owner = THIS_MODULE,
1074 .name = "bluecard_cs",
1076 .attach = bluecard_attach,
1077 .event = bluecard_event,
1078 .remove = bluecard_detach,
1079 .id_table = bluecard_ids,
1080 .suspend = bluecard_suspend,
1081 .resume = bluecard_resume,
1084 static int __init init_bluecard_cs(void)
1086 return pcmcia_register_driver(&bluecard_driver);
1090 static void __exit exit_bluecard_cs(void)
1092 pcmcia_unregister_driver(&bluecard_driver);
1095 module_init(init_bluecard_cs);
1096 module_exit(exit_bluecard_cs);