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(dev_link_t *);
97 static dev_link_t *dev_list = NULL;
100 /* Default baud rate: 57600, 115200, 230400 or 460800 */
101 #define DEFAULT_BAUD_RATE 230400
104 /* Hardware states */
106 #define CARD_HAS_PCCARD_ID 4
107 #define CARD_HAS_POWER_LED 5
108 #define CARD_HAS_ACTIVITY_LED 6
110 /* Transmit states */
111 #define XMIT_SENDING 1
112 #define XMIT_WAKEUP 2
113 #define XMIT_BUFFER_NUMBER 5 /* unset = buffer one, set = buffer two */
114 #define XMIT_BUF_ONE_READY 6
115 #define XMIT_BUF_TWO_READY 7
116 #define XMIT_SENDING_READY 8
118 /* Receiver states */
119 #define RECV_WAIT_PACKET_TYPE 0
120 #define RECV_WAIT_EVENT_HEADER 1
121 #define RECV_WAIT_ACL_HEADER 2
122 #define RECV_WAIT_SCO_HEADER 3
123 #define RECV_WAIT_DATA 4
125 /* Special packet types */
126 #define PKT_BAUD_RATE_57600 0x80
127 #define PKT_BAUD_RATE_115200 0x81
128 #define PKT_BAUD_RATE_230400 0x82
129 #define PKT_BAUD_RATE_460800 0x83
132 /* These are the register offsets */
133 #define REG_COMMAND 0x20
134 #define REG_INTERRUPT 0x21
135 #define REG_CONTROL 0x22
136 #define REG_RX_CONTROL 0x24
137 #define REG_CARD_RESET 0x30
138 #define REG_LED_CTRL 0x30
141 #define REG_COMMAND_TX_BUF_ONE 0x01
142 #define REG_COMMAND_TX_BUF_TWO 0x02
143 #define REG_COMMAND_RX_BUF_ONE 0x04
144 #define REG_COMMAND_RX_BUF_TWO 0x08
145 #define REG_COMMAND_RX_WIN_ONE 0x00
146 #define REG_COMMAND_RX_WIN_TWO 0x10
149 #define REG_CONTROL_BAUD_RATE_57600 0x00
150 #define REG_CONTROL_BAUD_RATE_115200 0x01
151 #define REG_CONTROL_BAUD_RATE_230400 0x02
152 #define REG_CONTROL_BAUD_RATE_460800 0x03
153 #define REG_CONTROL_RTS 0x04
154 #define REG_CONTROL_BT_ON 0x08
155 #define REG_CONTROL_BT_RESET 0x10
156 #define REG_CONTROL_BT_RES_PU 0x20
157 #define REG_CONTROL_INTERRUPT 0x40
158 #define REG_CONTROL_CARD_RESET 0x80
161 #define RTS_LEVEL_SHIFT_BITS 0x02
165 /* ======================== LED handling routines ======================== */
168 static void bluecard_activity_led_timeout(u_long arg)
170 bluecard_info_t *info = (bluecard_info_t *)arg;
171 unsigned int iobase = info->link.io.BasePort1;
173 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
176 if (test_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state))) {
177 /* Disable activity LED */
178 outb(0x08 | 0x20, iobase + 0x30);
180 /* Disable power LED */
181 outb(0x00, iobase + 0x30);
186 static void bluecard_enable_activity_led(bluecard_info_t *info)
188 unsigned int iobase = info->link.io.BasePort1;
190 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
193 if (test_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state))) {
194 /* Enable activity LED */
195 outb(0x10 | 0x40, iobase + 0x30);
197 /* Stop the LED after HZ/4 */
198 mod_timer(&(info->timer), jiffies + HZ / 4);
200 /* Enable power LED */
201 outb(0x08 | 0x20, iobase + 0x30);
203 /* Stop the LED after HZ/2 */
204 mod_timer(&(info->timer), jiffies + HZ / 2);
210 /* ======================== Interrupt handling ======================== */
213 static int bluecard_write(unsigned int iobase, unsigned int offset, __u8 *buf, int len)
217 actual = (len > 15) ? 15 : len;
219 outb_p(actual, iobase + offset);
221 for (i = 0; i < actual; i++)
222 outb_p(buf[i], iobase + offset + i + 1);
228 static void bluecard_write_wakeup(bluecard_info_t *info)
231 BT_ERR("Unknown device");
235 if (!test_bit(XMIT_SENDING_READY, &(info->tx_state)))
238 if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
239 set_bit(XMIT_WAKEUP, &(info->tx_state));
244 register unsigned int iobase = info->link.io.BasePort1;
245 register unsigned int offset;
246 register unsigned char command;
247 register unsigned long ready_bit;
248 register struct sk_buff *skb;
251 clear_bit(XMIT_WAKEUP, &(info->tx_state));
253 if (!(info->link.state & DEV_PRESENT))
256 if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) {
257 if (!test_bit(XMIT_BUF_TWO_READY, &(info->tx_state)))
260 command = REG_COMMAND_TX_BUF_TWO;
261 ready_bit = XMIT_BUF_TWO_READY;
263 if (!test_bit(XMIT_BUF_ONE_READY, &(info->tx_state)))
266 command = REG_COMMAND_TX_BUF_ONE;
267 ready_bit = XMIT_BUF_ONE_READY;
270 if (!(skb = skb_dequeue(&(info->txq))))
273 if (bt_cb(skb)->pkt_type & 0x80) {
275 info->ctrl_reg |= REG_CONTROL_RTS;
276 outb(info->ctrl_reg, iobase + REG_CONTROL);
280 bluecard_enable_activity_led(info);
283 len = bluecard_write(iobase, offset, skb->data, skb->len);
285 /* Tell the FPGA to send the data */
286 outb_p(command, iobase + REG_COMMAND);
288 /* Mark the buffer as dirty */
289 clear_bit(ready_bit, &(info->tx_state));
291 if (bt_cb(skb)->pkt_type & 0x80) {
292 DECLARE_WAIT_QUEUE_HEAD(wq);
295 unsigned char baud_reg;
297 switch (bt_cb(skb)->pkt_type) {
298 case PKT_BAUD_RATE_460800:
299 baud_reg = REG_CONTROL_BAUD_RATE_460800;
301 case PKT_BAUD_RATE_230400:
302 baud_reg = REG_CONTROL_BAUD_RATE_230400;
304 case PKT_BAUD_RATE_115200:
305 baud_reg = REG_CONTROL_BAUD_RATE_115200;
307 case PKT_BAUD_RATE_57600:
308 /* Fall through... */
310 baud_reg = REG_CONTROL_BAUD_RATE_57600;
314 /* Wait until the command reaches the baseband */
315 prepare_to_wait(&wq, &wait, TASK_INTERRUPTIBLE);
316 schedule_timeout(HZ/10);
317 finish_wait(&wq, &wait);
319 /* Set baud on baseband */
320 info->ctrl_reg &= ~0x03;
321 info->ctrl_reg |= baud_reg;
322 outb(info->ctrl_reg, iobase + REG_CONTROL);
325 info->ctrl_reg &= ~REG_CONTROL_RTS;
326 outb(info->ctrl_reg, iobase + REG_CONTROL);
328 /* Wait before the next HCI packet can be send */
329 prepare_to_wait(&wq, &wait, TASK_INTERRUPTIBLE);
330 schedule_timeout(HZ);
331 finish_wait(&wq, &wait);
334 if (len == skb->len) {
338 skb_queue_head(&(info->txq), skb);
341 info->hdev->stat.byte_tx += len;
344 change_bit(XMIT_BUFFER_NUMBER, &(info->tx_state));
346 } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
348 clear_bit(XMIT_SENDING, &(info->tx_state));
352 static int bluecard_read(unsigned int iobase, unsigned int offset, __u8 *buf, int size)
356 outb(REG_COMMAND_RX_WIN_ONE, iobase + REG_COMMAND);
358 len = inb(iobase + offset);
365 outb(REG_COMMAND_RX_WIN_TWO, iobase + REG_COMMAND);
369 buf[n] = inb(iobase + offset + i);
380 static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
383 unsigned char buf[31];
387 BT_ERR("Unknown device");
391 iobase = info->link.io.BasePort1;
393 if (test_bit(XMIT_SENDING_READY, &(info->tx_state)))
394 bluecard_enable_activity_led(info);
396 len = bluecard_read(iobase, offset, buf, sizeof(buf));
398 for (i = 0; i < len; i++) {
400 /* Allocate packet */
401 if (info->rx_skb == NULL) {
402 info->rx_state = RECV_WAIT_PACKET_TYPE;
404 if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
405 BT_ERR("Can't allocate mem for new packet");
410 if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
412 info->rx_skb->dev = (void *) info->hdev;
413 bt_cb(info->rx_skb)->pkt_type = buf[i];
415 switch (bt_cb(info->rx_skb)->pkt_type) {
419 if (offset != 0x00) {
420 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
421 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
422 set_bit(XMIT_SENDING_READY, &(info->tx_state));
423 bluecard_write_wakeup(info);
426 kfree_skb(info->rx_skb);
431 info->rx_state = RECV_WAIT_EVENT_HEADER;
432 info->rx_count = HCI_EVENT_HDR_SIZE;
435 case HCI_ACLDATA_PKT:
436 info->rx_state = RECV_WAIT_ACL_HEADER;
437 info->rx_count = HCI_ACL_HDR_SIZE;
440 case HCI_SCODATA_PKT:
441 info->rx_state = RECV_WAIT_SCO_HEADER;
442 info->rx_count = HCI_SCO_HDR_SIZE;
447 BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
448 info->hdev->stat.err_rx++;
450 kfree_skb(info->rx_skb);
458 *skb_put(info->rx_skb, 1) = buf[i];
461 if (info->rx_count == 0) {
464 struct hci_event_hdr *eh;
465 struct hci_acl_hdr *ah;
466 struct hci_sco_hdr *sh;
468 switch (info->rx_state) {
470 case RECV_WAIT_EVENT_HEADER:
471 eh = (struct hci_event_hdr *)(info->rx_skb->data);
472 info->rx_state = RECV_WAIT_DATA;
473 info->rx_count = eh->plen;
476 case RECV_WAIT_ACL_HEADER:
477 ah = (struct hci_acl_hdr *)(info->rx_skb->data);
478 dlen = __le16_to_cpu(ah->dlen);
479 info->rx_state = RECV_WAIT_DATA;
480 info->rx_count = dlen;
483 case RECV_WAIT_SCO_HEADER:
484 sh = (struct hci_sco_hdr *)(info->rx_skb->data);
485 info->rx_state = RECV_WAIT_DATA;
486 info->rx_count = sh->dlen;
490 hci_recv_frame(info->rx_skb);
503 info->hdev->stat.byte_rx += len;
507 static irqreturn_t bluecard_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
509 bluecard_info_t *info = dev_inst;
513 if (!info || !info->hdev) {
514 BT_ERR("Call of irq %d for unknown device", irq);
518 if (!test_bit(CARD_READY, &(info->hw_state)))
521 iobase = info->link.io.BasePort1;
523 spin_lock(&(info->lock));
525 /* Disable interrupt */
526 info->ctrl_reg &= ~REG_CONTROL_INTERRUPT;
527 outb(info->ctrl_reg, iobase + REG_CONTROL);
529 reg = inb(iobase + REG_INTERRUPT);
531 if ((reg != 0x00) && (reg != 0xff)) {
534 bluecard_receive(info, 0x00);
535 outb(0x04, iobase + REG_INTERRUPT);
536 outb(REG_COMMAND_RX_BUF_ONE, iobase + REG_COMMAND);
540 bluecard_receive(info, 0x10);
541 outb(0x08, iobase + REG_INTERRUPT);
542 outb(REG_COMMAND_RX_BUF_TWO, iobase + REG_COMMAND);
546 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
547 outb(0x01, iobase + REG_INTERRUPT);
548 bluecard_write_wakeup(info);
552 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
553 outb(0x02, iobase + REG_INTERRUPT);
554 bluecard_write_wakeup(info);
559 /* Enable interrupt */
560 info->ctrl_reg |= REG_CONTROL_INTERRUPT;
561 outb(info->ctrl_reg, iobase + REG_CONTROL);
563 spin_unlock(&(info->lock));
570 /* ======================== Device specific HCI commands ======================== */
573 static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud)
575 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
578 /* Ericsson baud rate command */
579 unsigned char cmd[] = { HCI_COMMAND_PKT, 0x09, 0xfc, 0x01, 0x03 };
581 if (!(skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
582 BT_ERR("Can't allocate mem for new packet");
589 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_460800;
593 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_230400;
597 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_115200;
600 /* Fall through... */
603 bt_cb(skb)->pkt_type = PKT_BAUD_RATE_57600;
607 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
609 skb_queue_tail(&(info->txq), skb);
611 bluecard_write_wakeup(info);
618 /* ======================== HCI interface ======================== */
621 static int bluecard_hci_flush(struct hci_dev *hdev)
623 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
626 skb_queue_purge(&(info->txq));
632 static int bluecard_hci_open(struct hci_dev *hdev)
634 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
635 unsigned int iobase = info->link.io.BasePort1;
637 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
638 bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE);
640 if (test_and_set_bit(HCI_RUNNING, &(hdev->flags)))
643 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) {
645 outb(0x08 | 0x20, iobase + 0x30);
652 static int bluecard_hci_close(struct hci_dev *hdev)
654 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
655 unsigned int iobase = info->link.io.BasePort1;
657 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
660 bluecard_hci_flush(hdev);
662 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) {
664 outb(0x00, iobase + 0x30);
671 static int bluecard_hci_send_frame(struct sk_buff *skb)
673 bluecard_info_t *info;
674 struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
677 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
681 info = (bluecard_info_t *)(hdev->driver_data);
683 switch (bt_cb(skb)->pkt_type) {
684 case HCI_COMMAND_PKT:
687 case HCI_ACLDATA_PKT:
690 case HCI_SCODATA_PKT:
695 /* Prepend skb with frame type */
696 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
697 skb_queue_tail(&(info->txq), skb);
699 bluecard_write_wakeup(info);
705 static void bluecard_hci_destruct(struct hci_dev *hdev)
710 static int bluecard_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
717 /* ======================== Card services HCI interaction ======================== */
720 static int bluecard_open(bluecard_info_t *info)
722 unsigned int iobase = info->link.io.BasePort1;
723 struct hci_dev *hdev;
726 spin_lock_init(&(info->lock));
728 init_timer(&(info->timer));
729 info->timer.function = &bluecard_activity_led_timeout;
730 info->timer.data = (u_long)info;
732 skb_queue_head_init(&(info->txq));
734 info->rx_state = RECV_WAIT_PACKET_TYPE;
738 /* Initialize HCI device */
739 hdev = hci_alloc_dev();
741 BT_ERR("Can't allocate HCI device");
747 hdev->type = HCI_PCCARD;
748 hdev->driver_data = info;
750 hdev->open = bluecard_hci_open;
751 hdev->close = bluecard_hci_close;
752 hdev->flush = bluecard_hci_flush;
753 hdev->send = bluecard_hci_send_frame;
754 hdev->destruct = bluecard_hci_destruct;
755 hdev->ioctl = bluecard_hci_ioctl;
757 hdev->owner = THIS_MODULE;
759 id = inb(iobase + 0x30);
761 if ((id & 0x0f) == 0x02)
762 set_bit(CARD_HAS_PCCARD_ID, &(info->hw_state));
765 set_bit(CARD_HAS_POWER_LED, &(info->hw_state));
768 set_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state));
771 info->ctrl_reg = REG_CONTROL_BT_RESET | REG_CONTROL_CARD_RESET;
772 outb(info->ctrl_reg, iobase + REG_CONTROL);
775 outb(0x80, iobase + 0x30);
781 outb(0x00, iobase + 0x30);
784 info->ctrl_reg = REG_CONTROL_BT_ON | REG_CONTROL_BT_RES_PU;
785 outb(info->ctrl_reg, iobase + REG_CONTROL);
787 /* Enable interrupt */
788 outb(0xff, iobase + REG_INTERRUPT);
789 info->ctrl_reg |= REG_CONTROL_INTERRUPT;
790 outb(info->ctrl_reg, iobase + REG_CONTROL);
792 if ((id & 0x0f) == 0x03) {
794 info->ctrl_reg |= REG_CONTROL_RTS;
795 outb(info->ctrl_reg, iobase + REG_CONTROL);
798 info->ctrl_reg |= 0x03;
799 outb(info->ctrl_reg, iobase + REG_CONTROL);
802 info->ctrl_reg &= ~REG_CONTROL_RTS;
803 outb(info->ctrl_reg, iobase + REG_CONTROL);
805 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
806 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
807 set_bit(XMIT_SENDING_READY, &(info->tx_state));
810 /* Start the RX buffers */
811 outb(REG_COMMAND_RX_BUF_ONE, iobase + REG_COMMAND);
812 outb(REG_COMMAND_RX_BUF_TWO, iobase + REG_COMMAND);
814 /* Signal that the hardware is ready */
815 set_bit(CARD_READY, &(info->hw_state));
818 skb_queue_purge(&(info->txq));
820 /* Control the point at which RTS is enabled */
821 outb((0x0f << RTS_LEVEL_SHIFT_BITS) | 1, iobase + REG_RX_CONTROL);
823 /* Timeout before it is safe to send the first HCI packet */
826 /* Register HCI device */
827 if (hci_register_dev(hdev) < 0) {
828 BT_ERR("Can't register HCI device");
838 static int bluecard_close(bluecard_info_t *info)
840 unsigned int iobase = info->link.io.BasePort1;
841 struct hci_dev *hdev = info->hdev;
846 bluecard_hci_close(hdev);
848 clear_bit(CARD_READY, &(info->hw_state));
851 info->ctrl_reg = REG_CONTROL_BT_RESET | REG_CONTROL_CARD_RESET;
852 outb(info->ctrl_reg, iobase + REG_CONTROL);
855 outb(0x80, iobase + 0x30);
857 if (hci_unregister_dev(hdev) < 0)
858 BT_ERR("Can't unregister HCI device %s", hdev->name);
865 static dev_link_t *bluecard_attach(void)
867 bluecard_info_t *info;
868 client_reg_t client_reg;
872 /* Create new info device */
873 info = kzalloc(sizeof(*info), GFP_KERNEL);
880 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
881 link->io.NumPorts1 = 8;
882 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
883 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
885 link->irq.Handler = bluecard_interrupt;
886 link->irq.Instance = info;
888 link->conf.Attributes = CONF_ENABLE_IRQ;
890 link->conf.IntType = INT_MEMORY_AND_IO;
892 /* Register with Card Services */
893 link->next = dev_list;
895 client_reg.dev_info = &dev_info;
896 client_reg.Version = 0x0210;
897 client_reg.event_callback_args.client_data = link;
899 ret = pcmcia_register_client(&link->handle, &client_reg);
900 if (ret != CS_SUCCESS) {
901 cs_error(link->handle, RegisterClient, ret);
902 bluecard_detach(link);
910 static void bluecard_detach(dev_link_t *link)
912 bluecard_info_t *info = link->priv;
916 /* Locate device structure */
917 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
924 if (link->state & DEV_CONFIG)
925 bluecard_release(link);
928 ret = pcmcia_deregister_client(link->handle);
929 if (ret != CS_SUCCESS)
930 cs_error(link->handle, DeregisterClient, ret);
933 /* Unlink device structure, free bits */
940 static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
944 i = pcmcia_get_first_tuple(handle, tuple);
946 return CS_NO_MORE_ITEMS;
948 i = pcmcia_get_tuple_data(handle, tuple);
952 return pcmcia_parse_tuple(handle, tuple, parse);
955 static void bluecard_config(dev_link_t *link)
957 client_handle_t handle = link->handle;
958 bluecard_info_t *info = link->priv;
962 config_info_t config;
963 int i, n, last_ret, last_fn;
965 tuple.TupleData = (cisdata_t *)buf;
966 tuple.TupleOffset = 0;
967 tuple.TupleDataMax = 255;
968 tuple.Attributes = 0;
970 /* Get configuration register information */
971 tuple.DesiredTuple = CISTPL_CONFIG;
972 last_ret = first_tuple(handle, &tuple, &parse);
973 if (last_ret != CS_SUCCESS) {
974 last_fn = ParseTuple;
977 link->conf.ConfigBase = parse.config.base;
978 link->conf.Present = parse.config.rmask[0];
981 link->state |= DEV_CONFIG;
982 i = pcmcia_get_configuration_info(handle, &config);
983 link->conf.Vcc = config.Vcc;
985 link->conf.ConfigIndex = 0x20;
986 link->io.NumPorts1 = 64;
987 link->io.IOAddrLines = 6;
989 for (n = 0; n < 0x400; n += 0x40) {
990 link->io.BasePort1 = n ^ 0x300;
991 i = pcmcia_request_io(link->handle, &link->io);
996 if (i != CS_SUCCESS) {
997 cs_error(link->handle, RequestIO, i);
1001 i = pcmcia_request_irq(link->handle, &link->irq);
1002 if (i != CS_SUCCESS) {
1003 cs_error(link->handle, RequestIRQ, i);
1004 link->irq.AssignedIRQ = 0;
1007 i = pcmcia_request_configuration(link->handle, &link->conf);
1008 if (i != CS_SUCCESS) {
1009 cs_error(link->handle, RequestConfiguration, i);
1013 if (bluecard_open(info) != 0)
1016 strcpy(info->node.dev_name, info->hdev->name);
1017 link->dev = &info->node;
1018 link->state &= ~DEV_CONFIG_PENDING;
1023 cs_error(link->handle, last_fn, last_ret);
1026 bluecard_release(link);
1030 static void bluecard_release(dev_link_t *link)
1032 bluecard_info_t *info = link->priv;
1034 if (link->state & DEV_PRESENT)
1035 bluecard_close(info);
1037 del_timer(&(info->timer));
1041 pcmcia_release_configuration(link->handle);
1042 pcmcia_release_io(link->handle, &link->io);
1043 pcmcia_release_irq(link->handle, &link->irq);
1045 link->state &= ~DEV_CONFIG;
1049 static int bluecard_event(event_t event, int priority, event_callback_args_t *args)
1051 dev_link_t *link = args->client_data;
1052 bluecard_info_t *info = link->priv;
1055 case CS_EVENT_CARD_REMOVAL:
1056 link->state &= ~DEV_PRESENT;
1057 if (link->state & DEV_CONFIG) {
1058 bluecard_close(info);
1059 bluecard_release(link);
1062 case CS_EVENT_CARD_INSERTION:
1063 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1064 bluecard_config(link);
1066 case CS_EVENT_PM_SUSPEND:
1067 link->state |= DEV_SUSPEND;
1068 /* Fall through... */
1069 case CS_EVENT_RESET_PHYSICAL:
1070 if (link->state & DEV_CONFIG)
1071 pcmcia_release_configuration(link->handle);
1073 case CS_EVENT_PM_RESUME:
1074 link->state &= ~DEV_SUSPEND;
1075 /* Fall through... */
1076 case CS_EVENT_CARD_RESET:
1078 pcmcia_request_configuration(link->handle, &link->conf);
1085 static struct pcmcia_device_id bluecard_ids[] = {
1086 PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e),
1087 PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c),
1088 PCMCIA_DEVICE_PROD_ID12("WSS", "LSE039", 0x0a0736ec, 0x24e6dfab),
1091 MODULE_DEVICE_TABLE(pcmcia, bluecard_ids);
1093 static struct pcmcia_driver bluecard_driver = {
1094 .owner = THIS_MODULE,
1096 .name = "bluecard_cs",
1098 .attach = bluecard_attach,
1099 .event = bluecard_event,
1100 .detach = bluecard_detach,
1101 .id_table = bluecard_ids,
1104 static int __init init_bluecard_cs(void)
1106 return pcmcia_register_driver(&bluecard_driver);
1110 static void __exit exit_bluecard_cs(void)
1112 pcmcia_unregister_driver(&bluecard_driver);
1113 BUG_ON(dev_list != NULL);
1116 module_init(init_bluecard_cs);
1117 module_exit(exit_bluecard_cs);