1 diff -Nur linux-orig/drivers/bluetooth/bt950_cs.c linux/drivers/bluetooth/bt950_cs.c
2 --- linux-orig/drivers/bluetooth/bt950_cs.c 1970-01-01 03:00:00.000000000 +0300
3 +++ linux/drivers/bluetooth/bt950_cs.c 2004-02-04 09:55:04.000000000 +0300
7 + * Driver for Bluetooth cards with OXCF950 UART interface
9 + * Copyright (C) 2001-2002 Marcel Holtmann <marcel@holtmann.org>
10 + * Albert Rybalkin <albertr@iral.com>
13 + * This program is free software; you can redistribute it and/or modify
14 + * it under the terms of the GNU General Public License version 2 as
15 + * published by the Free Software Foundation;
17 + * Software distributed under the License is distributed on an "AS
18 + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
19 + * implied. See the License for the specific language governing
20 + * rights and limitations under the License.
22 + * The initial developer of the original code is David A. Hinds
23 + * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
24 + * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
28 +#include <linux/config.h>
30 +#ifdef CONFIG_MODVERSIONS
34 +#include <linux/modversions.h>
37 +#include <linux/module.h>
38 +#include <linux/kernel.h>
39 +#include <linux/init.h>
40 +#include <linux/slab.h>
41 +#include <linux/types.h>
42 +#include <linux/sched.h>
43 +#include <linux/timer.h>
44 +#include <linux/errno.h>
45 +#include <linux/ptrace.h>
46 +#include <linux/ioport.h>
47 +#include <linux/spinlock.h>
48 +#include <linux/delay.h>
50 +#include <linux/skbuff.h>
51 +#include <linux/string.h>
52 +#include <linux/serial.h>
53 +#include <linux/serial_reg.h>
54 +#include <asm/system.h>
55 +#include <asm/bitops.h>
58 +#include <pcmcia/version.h>
59 +#include <pcmcia/cs_types.h>
60 +#include <pcmcia/cs.h>
61 +#include <pcmcia/cistpl.h>
62 +#include <pcmcia/ciscode.h>
63 +#include <pcmcia/ds.h>
64 +#include <pcmcia/cisreg.h>
66 +#include <net/bluetooth/bluetooth.h>
67 +#include <net/bluetooth/hci_core.h>
69 +/* Default baud rate: 57600, 115200, 230400 or 460800 */
70 +#define DEFAULT_BAUD_RATE 460800
73 +/* ======================== Module parameters ======================== */
76 +/* Bit map of interrupts to choose from */
77 +static u_int irq_mask = 0x86bc;
78 +static int irq_list[4] = { -1 };
79 +static long baud_rate = DEFAULT_BAUD_RATE;
81 +MODULE_PARM(irq_mask, "i");
82 +MODULE_PARM(irq_list, "1-4i");
83 +MODULE_PARM(baud_rate, "l");
85 +MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>, Albert Rybalkin <albertr@iral.com>");
86 +MODULE_DESCRIPTION("BlueZ driver for Bluetooth cards with OXCF950 UART interface");
87 +MODULE_LICENSE("GPL");
91 +/* ======================== Local structures ======================== */
94 +typedef struct bt950_info_t {
98 + struct hci_dev hdev;
100 + spinlock_t lock; /* For serializing operations */
102 + struct sk_buff_head txq;
103 + unsigned long tx_state;
105 + unsigned long rx_state;
106 + unsigned long rx_count;
107 + struct sk_buff *rx_skb;
111 +static void bt950_config(dev_link_t *link);
112 +static void bt950_release(u_long arg);
113 +static int bt950_event(event_t event, int priority, event_callback_args_t *args);
115 +static dev_info_t dev_info = "bt950_cs";
117 +static dev_link_t *bt950_attach(void);
118 +static void bt950_detach(dev_link_t *);
120 +static dev_link_t *dev_list = NULL;
122 +/* Transmit states */
123 +#define XMIT_SENDING 1
124 +#define XMIT_WAKEUP 2
125 +#define XMIT_WAITING 8
127 +/* Receiver states */
128 +#define RECV_WAIT_PACKET_TYPE 0
129 +#define RECV_WAIT_EVENT_HEADER 1
130 +#define RECV_WAIT_ACL_HEADER 2
131 +#define RECV_WAIT_SCO_HEADER 3
132 +#define RECV_WAIT_DATA 4
134 +/* Special packet types */
135 +#define PKT_BAUD_RATE_57600 0x80
136 +#define PKT_BAUD_RATE_115200 0x81
137 +#define PKT_BAUD_RATE_230400 0x82
138 +#define PKT_BAUD_RATE_460800 0x83
140 +/* 950-specific stuff */
141 +#define MAX_WAIT 0xFFFF
142 +#define FIFO_SIZE 128
144 +#define TR_TX_INT 0x10 /* TTL: TX interrupt trigger level (0-127) */
145 +#define TR_RX_INT 0x40 /* RTL: RX interrupt trigger level (1-127) */
146 +#define TR_CTL_LO 0x08 /* FCL: auto flow control LOWER trigger level (0-127) */
147 +#define TR_CTL_HI 0x60 /* FCH: auto flow control HIGH trigger level (1-127) */
149 +/* 950-specific registers and values we use. It should
150 + * eventually go to include/linux/serial_reg.h */
151 +#define UART_IER_CTS 0x80 /* enable CTS interrupt */
152 +#define UART_IER_RTS 0x40 /* enable RTS interrupt */
153 +#define UART_IER_SLP 0x10 /* enable sleep mode */
154 +#define UART_LCR_650 0xBF /* enable 650-compatible registers access */
155 +#define UART_LSR_DE 0x80 /* data error */
156 +#define UART_LSR_ERR (UART_LSR_OE|UART_LSR_PE|UART_LSR_FE|UART_LSR_BI|UART_LSR_DE)
157 +#define UART_IIR_RXTOUT 0x0C /* RX timeout interrupt */
158 +#define UART_IIR_CTSRTS 0x20 /* CTS or RTS change interrupt */
159 +#define UART_IIR_RTS 0x40
160 +#define UART_IIR_CTS 0x80
161 +#define UART_IIR_MASK 0x3E /* interrupt mask */
162 +#define UART_SRT 0x0D /* soft reset register */
166 +/* ======================== Interrupt handling ======================== */
169 +static int bt950_write(unsigned int iobase, int fifo_size, const unsigned char *buf, int len)
173 + /* Activate DTR and RTS */
174 + outb(UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2, iobase + UART_MCR);
176 + /* Wait for CTS flow control */
177 + for (i = MAX_WAIT; i; i--)
178 + if (inb(iobase + UART_MSR) & UART_MSR_CTS)
182 + printk(KERN_WARNING "bt950_cs: Timeout waiting for CTS on write.\n");
186 + /* The TX FIFO should be empty */
187 + for (i = MAX_WAIT; i; i--)
188 + if (inb(iobase + UART_LSR) & UART_LSR_THRE)
192 + printk(KERN_WARNING "bt950_cs: Timeout waiting for empty TX FIFO on write.\n");
196 + /* Fill FIFO with current frame */
197 + while ((fifo_size-- > 0) && (actual < len)) {
198 + /* Transmit next byte */
199 + outb(buf[actual], iobase + UART_TX);
207 +static void bt950_write_wakeup(bt950_info_t *info)
210 + unsigned int divisor;
213 + printk(KERN_WARNING "bt950_cs: Call of write_wakeup for unknown device.\n");
217 + if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
218 + set_bit(XMIT_WAKEUP, &(info->tx_state));
223 + register unsigned int iobase = info->link.io.BasePort1;
224 + register struct sk_buff *skb;
227 + clear_bit(XMIT_WAKEUP, &(info->tx_state));
229 + if (!(info->link.state & DEV_PRESENT))
232 + if (!(skb = skb_dequeue(&(info->txq))))
235 + if (skb->pkt_type & 0x80) {
237 + outb((inb(iobase + UART_MCR) & ~UART_MCR_RTS), iobase + UART_MCR);
241 + len = bt950_write(iobase, FIFO_SIZE, skb->data, skb->len);
243 + set_bit(XMIT_WAKEUP, &(info->tx_state));
245 + if (skb->pkt_type & 0x80) {
247 + wait_queue_head_t wait;
249 + switch (skb->pkt_type) {
251 + case PKT_BAUD_RATE_460800:
255 + case PKT_BAUD_RATE_230400:
259 + case PKT_BAUD_RATE_115200:
263 + case PKT_BAUD_RATE_57600:
264 + /* Fall through... */
271 + /* Wait until the command reaches the baseband */
272 + init_waitqueue_head(&wait);
273 + interruptible_sleep_on_timeout(&wait, HZ / 10);
275 + /* Set baud on baseband */
276 + /* Enable divisor latch access */
277 + lcr = inb(iobase + UART_LCR) & 0x3F;
278 + outb(lcr | UART_LCR_DLAB, iobase + UART_LCR);
280 + /* Setup divisor latch */
281 + outb(divisor & 0x00FF, iobase + UART_DLL); /* divisor latch LOW byte */
282 + outb((divisor & 0xFF00) >> 8, iobase + UART_DLM); /* divisor latch HI byte */
284 + /* Disable divisor latch access */
285 + outb(lcr, iobase + UART_LCR);
288 + outb((inb(iobase + UART_MCR) | UART_MCR_RTS), iobase + UART_MCR);
290 + /* Wait before the next HCI packet can be send */
291 + interruptible_sleep_on_timeout(&wait, HZ);
295 + if (len == skb->len) {
298 + skb_pull(skb, len);
299 + skb_queue_head(&(info->txq), skb);
302 + info->hdev.stat.byte_tx += len;
304 + } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
306 + clear_bit(XMIT_SENDING, &(info->tx_state));
310 +static inline void bt950_receive(bt950_info_t *info)
312 + unsigned int iobase;
313 + int boguscount = 0;
316 + printk(KERN_ERR "bt950_cs: Call of receive for unknown device.\n");
320 + iobase = info->link.io.BasePort1;
323 + inb(iobase + UART_MCR);
326 + info->hdev.stat.byte_rx++;
328 + /* Allocate packet */
329 + if (info->rx_skb == NULL) {
330 + info->rx_state = RECV_WAIT_PACKET_TYPE;
331 + info->rx_count = 0;
332 + if (!(info->rx_skb = bluez_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
333 + printk(KERN_ERR "bt950_cs: Can't allocate mem for new packet.\n");
338 + if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
340 + info->rx_skb->dev = (void *)&(info->hdev);
341 + info->rx_skb->pkt_type = inb(iobase + UART_RX);
343 + switch (info->rx_skb->pkt_type) {
345 + case HCI_EVENT_PKT:
346 + info->rx_state = RECV_WAIT_EVENT_HEADER;
347 + info->rx_count = HCI_EVENT_HDR_SIZE;
350 + case HCI_ACLDATA_PKT:
351 + info->rx_state = RECV_WAIT_ACL_HEADER;
352 + info->rx_count = HCI_ACL_HDR_SIZE;
355 + case HCI_SCODATA_PKT:
356 + info->rx_state = RECV_WAIT_SCO_HEADER;
357 + info->rx_count = HCI_SCO_HDR_SIZE;
361 + /* Unknown packet */
362 + printk(KERN_WARNING "bt950_cs: Unknown HCI packet with type 0x%02X received.\n", info->rx_skb->pkt_type);
363 + info->hdev.stat.err_rx++;
365 + kfree_skb(info->rx_skb);
366 + info->rx_skb = NULL;
373 + *skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
376 + if (info->rx_count == 0) {
384 + switch (info->rx_state) {
386 + case RECV_WAIT_EVENT_HEADER:
387 + eh = (hci_event_hdr *)(info->rx_skb->data);
388 + info->rx_state = RECV_WAIT_DATA;
389 + info->rx_count = eh->plen;
392 + case RECV_WAIT_ACL_HEADER:
393 + ah = (hci_acl_hdr *)(info->rx_skb->data);
394 + dlen = __le16_to_cpu(ah->dlen);
395 + info->rx_state = RECV_WAIT_DATA;
396 + info->rx_count = dlen;
399 + case RECV_WAIT_SCO_HEADER:
400 + sh = (hci_sco_hdr *)(info->rx_skb->data);
401 + info->rx_state = RECV_WAIT_DATA;
402 + info->rx_count = sh->dlen;
405 + case RECV_WAIT_DATA:
406 + hci_recv_frame(info->rx_skb);
407 + info->rx_skb = NULL;
416 + /* Make sure we don't stay here too long */
417 + if (boguscount++ > 16)
420 + } while (inb(iobase + UART_LSR) & UART_LSR_DR);
424 +static void bt950_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
426 + bt950_info_t *info = dev_inst;
427 + unsigned int iobase;
428 + int boguscount = 0;
432 + printk(KERN_ERR "bt950_cs: Call of irq %d for unknown device.\n", irq);
436 + iobase = info->link.io.BasePort1;
438 + spin_lock(&(info->lock));
440 + iir = inb(iobase + UART_IIR);
442 + while (!(iir & UART_IIR_NO_INT)) {
444 + switch (iir & UART_IIR_ID) {
445 + case UART_IIR_RLSI:
446 + /* Clear RLSI interrupt */
447 + lsr = inb(iobase + UART_LSR);
448 + printk(KERN_NOTICE "bt950_cs: RLSI interrupt, LSR=%#x\n", lsr);
449 + /* Fixme: we need to process errors ... */
452 + /* Receive interrupt */
453 + bt950_receive(info);
455 + case UART_IIR_THRI:
456 + /* Transmitter ready for data */
457 + bt950_write_wakeup(info);
460 + printk(KERN_NOTICE "bt950_cs: Unhandled IIR=%#x\n", iir);
464 + /* Make sure we don't stay here too long */
465 + if (boguscount++ > 100)
468 + iir = inb(iobase + UART_IIR);
472 + spin_unlock(&(info->lock));
475 +/* ======================== Device specific HCI commands ======================== */
478 +static int bt950_hci_set_baud_rate(struct hci_dev *hdev, int baud)
480 + bt950_info_t *info = (bt950_info_t *)(hdev->driver_data);
481 + struct sk_buff *skb;
483 + /* Ericsson baud rate command */
484 + unsigned char cmd[] = { HCI_COMMAND_PKT, 0x09, 0xfc, 0x01, 0x03 };
486 + if (!(skb = bluez_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
487 + printk(KERN_WARNING "bt950_cs: Can't allocate mem for new packet.\n");
494 + skb->pkt_type = PKT_BAUD_RATE_460800;
498 + skb->pkt_type = PKT_BAUD_RATE_230400;
502 + skb->pkt_type = PKT_BAUD_RATE_115200;
505 + /* Fall through... */
509 + skb->pkt_type = PKT_BAUD_RATE_57600;
513 + memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
515 + skb_queue_tail(&(info->txq), skb);
517 + printk(KERN_WARNING "bt950_cs: setting baud rate: %d.\n", baud);
519 + bt950_write_wakeup(info);
525 +/* ======================== HCI interface ======================== */
528 +static int bt950_hci_flush(struct hci_dev *hdev)
530 + bt950_info_t *info = (bt950_info_t *)(hdev->driver_data);
532 + /* Drop TX queue */
533 + skb_queue_purge(&(info->txq));
539 +static int bt950_hci_open(struct hci_dev *hdev)
541 + bt950_hci_set_baud_rate(hdev, baud_rate);
542 + set_bit(HCI_RUNNING, &(hdev->flags));
548 +static int bt950_hci_close(struct hci_dev *hdev)
550 + if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
553 + bt950_hci_flush(hdev);
559 +static int bt950_hci_send_frame(struct sk_buff *skb)
561 + bt950_info_t *info;
562 + struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
565 + printk(KERN_ERR "bt950_cs: Frame for unknown HCI device (hdev=NULL).");
569 + info = (bt950_info_t *)(hdev->driver_data);
571 + switch (skb->pkt_type) {
572 + case HCI_COMMAND_PKT:
573 + hdev->stat.cmd_tx++;
575 + case HCI_ACLDATA_PKT:
576 + hdev->stat.acl_tx++;
578 + case HCI_SCODATA_PKT:
579 + hdev->stat.sco_tx++;
583 + /* Prepend skb with frame type */
584 + memcpy(skb_push(skb, 1), &(skb->pkt_type), 1);
585 + skb_queue_tail(&(info->txq), skb);
587 + bt950_write_wakeup(info);
593 +static void bt950_hci_destruct(struct hci_dev *hdev)
598 +static int bt950_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
600 + return -ENOIOCTLCMD;
605 +/* ======================== Card services HCI interaction ======================== */
608 +static int bt950_setup_uart(bt950_info_t *info)
610 + unsigned long flags;
611 + unsigned int iobase = info->link.io.BasePort1;
612 + unsigned char lcr, ier = UART_IER_RDI | UART_IER_RLSI | UART_IER_SLP;
613 + unsigned int divisor = 8; /* Fixme: divisor == 0x0c ??? */
614 + unsigned char id1, id2, id3, rev;
617 + spin_lock_irqsave(&(info->lock), flags);
619 + /* Disable interrupts */
620 + outb(0, iobase + UART_IER);
622 + /* Activate RTS and OUT2 */
623 + /* Fixme: is OUT2 used to enable interrupts? */
624 + outb(UART_MCR_RTS | UART_MCR_OUT2, iobase + UART_MCR);
626 + /* Setup the FIFO's */
627 + outb(0, iobase + UART_FCR);
628 + inb(iobase + UART_RX);
629 + outb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
630 + UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_14, iobase + UART_FCR);
632 + /* Disable divisor latch access */
633 + lcr = inb(iobase + UART_LCR) & 0x3F; /* mask out UART_LCR_DLAB and UART_LCR_SBC */
634 + outb(lcr, iobase + UART_LCR);
636 + /* Read up to 4 bytes from RX FIFO */
637 + for (i = 0; i < 4; i++) {
638 + inb(iobase + UART_RX);
639 + if (!(inb(iobase + UART_LSR) & UART_LSR_DR))
643 + /* Wait if CTS/DSR/DCD changing */
644 + for (i = 1; i < 0x3E8; i++) {
645 + if (!(inb(iobase + UART_MSR) & UART_MSR_ANY_DELTA))
649 + /* Enable divisor latch access */
650 + outb(lcr | UART_LCR_DLAB, iobase + UART_LCR);
652 + /* Setup divisor latch */
653 + outb(divisor & 0x00FF, iobase + UART_DLL); /* divisor latch LOW byte */
654 + outb((divisor & 0xFF00) >> 8, iobase + UART_DLM); /* divisor latch HIGH byte */
656 + /* Disable divisor latch access */
657 + outb(lcr, iobase + UART_LCR);
659 + /* Setup interrupts, enable sleep mode */
660 + outb(ier, iobase + UART_IER); /* we don't want to handle TX interrupts */
662 + /* Skip pending interrupts */
663 + for (i = 0; i < 4; i++) {
664 + if (inb(iobase + UART_IIR) & UART_IIR_NO_INT)
669 + lcr = UART_LCR_WLEN8;
670 + outb(lcr, iobase + UART_LCR);
672 + /* Setup CTS/RTS flow control and 950 enhanced mode */
673 + outb(UART_LCR_650, iobase + UART_LCR);
674 + outb(UART_EFR_CTS | UART_EFR_RTS | UART_EFR_ECB,
675 + iobase + UART_EFR);
676 + outb(lcr, iobase + UART_LCR);
678 + /* Read core id and revision */
679 + outb(UART_ACR, iobase + UART_EMSR);
680 + outb(UART_ACR_ICRRD, iobase + UART_LSR); /* enable ICR read access, we don't need to save the old value of ACR */
682 + outb(UART_ID1, iobase + UART_EMSR);
683 + id1 = inb(iobase + UART_LSR);
685 + outb(UART_ID2, iobase + UART_EMSR);
686 + id2 = inb(iobase + UART_LSR);
688 + outb(UART_ID3, iobase + UART_EMSR);
689 + id3 = inb(iobase + UART_LSR);
691 + outb(UART_REV, iobase + UART_EMSR);
692 + rev = inb(iobase + UART_LSR);
694 + if (id1 != 0x16 || id2 != 0xC9 || id3 != 0x50) {
695 + printk(KERN_ERR "bt950_cs: Unknown UART core %02X%02X%02X found.\n", id1, id2, id3);
696 + spin_unlock_irqrestore(&(info->lock), flags);
701 + /* Init ICR registers */
702 + outb(UART_TTL, iobase + UART_EMSR);
703 + outb(TR_TX_INT, iobase + UART_LSR); /* TX interrupt trigger level (0-127) */
705 + outb(UART_RTL, iobase + UART_EMSR);
706 + outb(TR_RX_INT, iobase + UART_LSR); /* RX interrupt trigger level (1-127) */
708 + outb(UART_FCL, iobase + UART_EMSR);
709 + outb(TR_CTL_LO, iobase + UART_LSR); /* auto flow control LOWER trigger level (0-127) */
711 + outb(UART_FCH, iobase + UART_EMSR);
712 + outb(TR_CTL_HI, iobase + UART_LSR); /* auto flow control HIGH trigger level (1-127) */
714 + outb(UART_ACR, iobase + UART_EMSR);
715 + outb(UART_ACR_TLENB, iobase + UART_LSR); /* disable ICR read access, enable trigger levels */
717 + spin_unlock_irqrestore(&(info->lock), flags);
723 +static void bt950_stop_uart(bt950_info_t *info)
725 + unsigned long flags;
726 + unsigned int iobase = info->link.io.BasePort1;
728 + spin_lock_irqsave(&(info->lock), flags);
730 + /* Disable interrupts */
731 + outb(0, iobase + UART_IER);
733 + /* Set RTS and OUT2 low */
734 + outb(0, iobase + UART_MCR);
736 + spin_unlock_irqrestore(&(info->lock), flags);
740 +static int bt950_open(bt950_info_t *info)
742 + struct hci_dev *hdev;
745 + spin_lock_init(&(info->lock));
747 + skb_queue_head_init(&(info->txq));
749 + info->rx_state = RECV_WAIT_PACKET_TYPE;
750 + info->rx_count = 0;
751 + info->rx_skb = NULL;
753 + /* Setup hardware */
754 + if ((err = bt950_setup_uart(info)) < 0)
757 + /* Timeout before it is safe to send the first HCI packet */
758 + set_current_state(TASK_INTERRUPTIBLE);
759 + schedule_timeout(HZ);
762 + /* Initialize and register HCI device */
764 + hdev = &(info->hdev);
766 + hdev->type = HCI_PCCARD;
767 + hdev->driver_data = info;
769 + hdev->open = bt950_hci_open;
770 + hdev->close = bt950_hci_close;
771 + hdev->flush = bt950_hci_flush;
772 + hdev->send = bt950_hci_send_frame;
773 + hdev->destruct = bt950_hci_destruct;
774 + hdev->ioctl = bt950_hci_ioctl;
776 + if (hci_register_dev(hdev) < 0) {
777 + printk(KERN_ERR "bt950_cs: Can't register HCI device %s.\n", hdev->name);
785 +static int bt950_close(bt950_info_t *info)
787 + struct hci_dev *hdev = &(info->hdev);
789 + bt950_hci_close(hdev);
791 + /* Stop hardware */
792 + bt950_stop_uart(info);
794 + if (hci_unregister_dev(hdev) < 0)
795 + printk(KERN_ERR "bt950_cs: Can't unregister HCI device %s.\n", hdev->name);
802 +/* ======================== Card services ======================== */
805 +static void cs_error(client_handle_t handle, int func, int ret)
807 + error_info_t err = { func, ret };
809 + CardServices(ReportError, handle, &err);
813 +static dev_link_t *bt950_attach(void)
815 + bt950_info_t *info;
816 + client_reg_t client_reg;
820 + /* Create new info device */
821 + info = kmalloc(sizeof(*info), GFP_KERNEL);
824 + memset(info, 0, sizeof(*info));
826 + link = &info->link;
829 + link->release.function = &bt950_release;
830 + link->release.data = (u_long)link;
831 + link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
832 + link->io.NumPorts1 = 8;
833 + link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
834 + link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
836 + if (irq_list[0] == -1)
837 + link->irq.IRQInfo2 = irq_mask;
839 + for (i = 0; i < 4; i++)
840 + link->irq.IRQInfo2 |= 1 << irq_list[i];
842 + link->irq.Handler = bt950_interrupt;
843 + link->irq.Instance = info;
845 + link->conf.Attributes = CONF_ENABLE_IRQ;
846 + link->conf.IntType = INT_MEMORY_AND_IO;
847 + link->conf.Present =
848 + PRESENT_OPTION | PRESENT_STATUS | PRESENT_PIN_REPLACE |
851 + /* Register with Card Services */
852 + link->next = dev_list;
854 + client_reg.dev_info = &dev_info;
855 + client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
856 + client_reg.EventMask =
857 + CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
858 + CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
859 + CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
860 + client_reg.event_handler = &bt950_event;
861 + client_reg.Version = 0x0210;
862 + client_reg.event_callback_args.client_data = link;
864 + ret = CardServices(RegisterClient, &link->handle, &client_reg);
865 + if (ret != CS_SUCCESS) {
866 + cs_error(link->handle, RegisterClient, ret);
867 + bt950_detach(link);
875 +static void bt950_detach(dev_link_t *link)
877 + bt950_info_t *info = link->priv;
878 + dev_link_t **linkp;
881 + /* Locate device structure */
882 + for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
883 + if (*linkp == link)
886 + if (*linkp == NULL)
889 + del_timer(&link->release);
890 + if (link->state & DEV_CONFIG)
891 + bt950_release((u_long) link);
893 + if (link->handle) {
894 + ret = CardServices(DeregisterClient, link->handle);
895 + if (ret != CS_SUCCESS)
896 + cs_error(link->handle, DeregisterClient, ret);
899 + /* Unlink device structure, free bits */
900 + *linkp = link->next;
906 +static int get_tuple(int fn, client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
910 + i = CardServices(fn, handle, tuple);
911 + if (i != CS_SUCCESS)
912 + return CS_NO_MORE_ITEMS;
914 + i = CardServices(GetTupleData, handle, tuple);
915 + if (i != CS_SUCCESS)
918 + return CardServices(ParseTuple, handle, tuple, parse);
922 +#define first_tuple(a, b, c) get_tuple(GetFirstTuple, a, b, c)
923 +#define next_tuple(a, b, c) get_tuple(GetNextTuple, a, b, c)
925 +static void bt950_config(dev_link_t *link)
927 + static ioaddr_t base[4] = { 0x2f8, 0x3e8, 0x2e8, 0x0 };
928 + client_handle_t handle = link->handle;
929 + bt950_info_t *info = link->priv;
933 + cistpl_cftable_entry_t *cf = &parse.cftable_entry;
934 + config_info_t config;
935 + int i, j, try, last_ret, last_fn;
937 + tuple.TupleData = (cisdata_t *)buf;
938 + tuple.TupleOffset = 0;
939 + tuple.TupleDataMax = 255;
940 + tuple.Attributes = 0;
942 + /* Get configuration register information */
943 + tuple.DesiredTuple = CISTPL_CONFIG;
944 + last_ret = first_tuple(handle, &tuple, &parse);
945 + if (last_ret != CS_SUCCESS) {
946 + last_fn = ParseTuple;
949 + link->conf.ConfigBase = parse.config.base;
950 + link->conf.Present = parse.config.rmask[0];
952 + /* Configure card */
953 + link->state |= DEV_CONFIG;
954 + i = CardServices(GetConfigurationInfo, handle, &config);
955 + link->conf.Vcc = config.Vcc;
957 + /* First pass: look for a config entry that looks normal. */
958 + tuple.TupleData = (cisdata_t *) buf;
959 + tuple.TupleOffset = 0;
960 + tuple.TupleDataMax = 255;
961 + tuple.Attributes = 0;
962 + tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
963 + /* Two tries: without IO aliases, then with aliases */
964 + for (try = 0; try < 2; try++) {
965 + i = first_tuple(handle, &tuple, &parse);
966 + while (i != CS_NO_MORE_ITEMS) {
967 + if (i != CS_SUCCESS)
969 + if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
970 + link->conf.Vpp1 = link->conf.Vpp2 = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
971 + if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
972 + link->conf.ConfigIndex = cf->index;
973 + link->io.BasePort1 = cf->io.win[0].base;
974 + link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
975 + i = CardServices(RequestIO, link->handle, &link->io);
976 + if (i == CS_SUCCESS)
980 + i = next_tuple(handle, &tuple, &parse);
984 + /* Second pass: try to find an entry that isn't picky about
985 + its base address, then try to grab any standard serial port
986 + address, and finally try to get any free port. */
987 + i = first_tuple(handle, &tuple, &parse);
988 + while (i != CS_NO_MORE_ITEMS) {
989 + if ((i == CS_SUCCESS) && (cf->io.nwin > 0)
990 + && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
991 + link->conf.ConfigIndex = cf->index;
992 + for (j = 0; j < 5; j++) {
993 + link->io.BasePort1 = base[j];
994 + link->io.IOAddrLines = base[j] ? 16 : 3;
995 + i = CardServices(RequestIO, link->handle, &link->io);
996 + if (i == CS_SUCCESS)
1000 + i = next_tuple(handle, &tuple, &parse);
1004 + if (i != CS_SUCCESS) {
1005 + printk(KERN_ERR "bt950_cs: No usable port range found. Giving up.\n");
1006 + cs_error(link->handle, RequestIO, i);
1010 + i = CardServices(RequestIRQ, link->handle, &link->irq);
1011 + if (i != CS_SUCCESS) {
1012 + cs_error(link->handle, RequestIRQ, i);
1013 + link->irq.AssignedIRQ = 0;
1016 + i = CardServices(RequestConfiguration, link->handle, &link->conf);
1017 + if (i != CS_SUCCESS) {
1018 + cs_error(link->handle, RequestConfiguration, i);
1022 + MOD_INC_USE_COUNT;
1024 + if (bt950_open(info) != 0)
1027 + strcpy(info->node.dev_name, info->hdev.name);
1028 + link->dev = &info->node;
1029 + link->state &= ~DEV_CONFIG_PENDING;
1034 + cs_error(link->handle, last_fn, last_ret);
1037 + bt950_release((u_long)link);
1038 + link->state &= ~DEV_CONFIG_PENDING;
1042 +static void bt950_release(u_long arg)
1044 + dev_link_t *link = (dev_link_t *) arg;
1045 + bt950_info_t *info = link->priv;
1047 + if (link->state & DEV_PRESENT)
1048 + bt950_close(info);
1050 + MOD_DEC_USE_COUNT;
1054 + CardServices(ReleaseConfiguration, link->handle);
1055 + CardServices(ReleaseIO, link->handle, &link->io);
1056 + CardServices(ReleaseIRQ, link->handle, &link->irq);
1058 + link->state &= ~DEV_CONFIG;
1062 +static int bt950_event(event_t event, int priority, event_callback_args_t *args)
1064 + dev_link_t *link = args->client_data;
1065 + bt950_info_t *info = link->priv;
1068 + case CS_EVENT_CARD_REMOVAL:
1069 + link->state &= ~DEV_PRESENT;
1070 + if (link->state & DEV_CONFIG) {
1071 + bt950_close(info);
1072 + link->state |= DEV_RELEASE_PENDING;
1073 + mod_timer(&link->release, jiffies + HZ / 20);
1076 + case CS_EVENT_CARD_INSERTION:
1077 + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1078 + bt950_config(link);
1080 + case CS_EVENT_PM_SUSPEND:
1081 + link->state |= DEV_SUSPEND;
1082 + /* Fall through... */
1083 + case CS_EVENT_RESET_PHYSICAL:
1084 + if (link->state & DEV_CONFIG) {
1085 + bt950_stop_uart(info);
1086 + CardServices(ReleaseConfiguration, link->handle);
1089 + case CS_EVENT_PM_RESUME:
1090 + link->state &= ~DEV_SUSPEND;
1091 + /* Fall through... */
1092 + case CS_EVENT_CARD_RESET:
1093 + if (link->state & DEV_CONFIG) {
1094 + CardServices(RequestConfiguration, link->handle, &link->conf);
1095 + bt950_setup_uart(info);
1105 +/* ======================== Module initialization ======================== */
1108 +int __init init_bt950_cs(void)
1113 + CardServices(GetCardServicesInfo, &serv);
1114 + if (serv.Revision != CS_RELEASE_CODE) {
1115 + printk(KERN_NOTICE "bt950_cs: Card Services release does not match!\n");
1119 + err = register_pccard_driver(&dev_info, &bt950_attach, &bt950_detach);
1125 +void __exit exit_bt950_cs(void)
1127 + unregister_pccard_driver(&dev_info);
1129 + while (dev_list != NULL)
1130 + bt950_detach(dev_list);
1134 +module_init(init_bt950_cs);
1135 +module_exit(exit_bt950_cs);
1138 diff -Nur linux-orig/drivers/bluetooth/Config.in linux/drivers/bluetooth/Config.in
1139 --- linux-orig/drivers/bluetooth/Config.in 2004-02-16 08:45:33.000000000 +0300
1140 +++ linux/drivers/bluetooth/Config.in 2004-02-16 08:50:36.000000000 +0300
1143 dep_tristate 'HCI DTL1 (PC Card) driver' CONFIG_BLUEZ_HCIDTL1 $CONFIG_PCMCIA $CONFIG_BLUEZ
1145 -dep_tristate 'HCI BT3C (PC Card) driver' CONFIG_BLUEZ_HCIBT3C $CONFIG_PCMCIA $CONFIG_BLUEZ
1146 +# dep_tristate 'HCI BT3C (PC Card) driver' CONFIG_BLUEZ_HCIBT3C $CONFIG_PCMCIA $CONFIG_BLUEZ
1148 dep_tristate 'HCI BlueCard (PC Card) driver' CONFIG_BLUEZ_HCIBLUECARD $CONFIG_PCMCIA $CONFIG_BLUEZ
1152 dep_tristate 'HCI VHCI (Virtual HCI device) driver' CONFIG_BLUEZ_HCIVHCI $CONFIG_BLUEZ
1154 +dep_tristate 'HCI BT950 (BT950 device) driver' CONFIG_BLUEZ_BT950 $CONFIG_BLUEZ
1158 diff -Nur linux-orig/drivers/bluetooth/Makefile linux/drivers/bluetooth/Makefile
1159 --- linux-orig/drivers/bluetooth/Makefile 2004-02-16 08:45:33.000000000 +0300
1160 +++ linux/drivers/bluetooth/Makefile 2004-02-16 08:50:47.000000000 +0300
1162 obj-$(CONFIG_BLUEZ_HCIBFUSB) += bfusb.o
1164 obj-$(CONFIG_BLUEZ_HCIDTL1) += dtl1_cs.o
1165 -obj-$(CONFIG_BLUEZ_HCIBT3C) += bt3c_cs.o
1166 +# obj-$(CONFIG_BLUEZ_HCIBT3C) += bt3c_cs.o
1167 obj-$(CONFIG_BLUEZ_HCIBLUECARD) += bluecard_cs.o
1168 obj-$(CONFIG_BLUEZ_HCIBTUART) += btuart_cs.o
1170 +obj-$(CONFIG_BLUEZ_BT950) += bt950_cs.o
1172 include $(TOPDIR)/Rules.make
1174 hci_uart.o: $(uart-y)