0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include <linux/module.h>
0024
0025 #include <linux/kernel.h>
0026 #include <linux/init.h>
0027 #include <linux/slab.h>
0028 #include <linux/types.h>
0029 #include <linux/sched.h>
0030 #include <linux/delay.h>
0031 #include <linux/timer.h>
0032 #include <linux/errno.h>
0033 #include <linux/ptrace.h>
0034 #include <linux/ioport.h>
0035 #include <linux/spinlock.h>
0036 #include <linux/moduleparam.h>
0037 #include <linux/wait.h>
0038
0039 #include <linux/skbuff.h>
0040 #include <linux/io.h>
0041
0042 #include <pcmcia/cistpl.h>
0043 #include <pcmcia/ciscode.h>
0044 #include <pcmcia/ds.h>
0045 #include <pcmcia/cisreg.h>
0046
0047 #include <net/bluetooth/bluetooth.h>
0048 #include <net/bluetooth/hci_core.h>
0049
0050
0051
0052
0053
0054
0055 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
0056 MODULE_DESCRIPTION("Bluetooth driver for the Anycom BlueCard (LSE039/LSE041)");
0057 MODULE_LICENSE("GPL");
0058
0059
0060
0061
0062
0063
0064 struct bluecard_info {
0065 struct pcmcia_device *p_dev;
0066
0067 struct hci_dev *hdev;
0068
0069 spinlock_t lock;
0070 struct timer_list timer;
0071
0072 struct sk_buff_head txq;
0073 unsigned long tx_state;
0074
0075 unsigned long rx_state;
0076 unsigned long rx_count;
0077 struct sk_buff *rx_skb;
0078
0079 unsigned char ctrl_reg;
0080 unsigned long hw_state;
0081 };
0082
0083
0084 static int bluecard_config(struct pcmcia_device *link);
0085 static void bluecard_release(struct pcmcia_device *link);
0086
0087 static void bluecard_detach(struct pcmcia_device *p_dev);
0088
0089
0090
0091 #define DEFAULT_BAUD_RATE 230400
0092
0093
0094
0095 #define CARD_READY 1
0096 #define CARD_ACTIVITY 2
0097 #define CARD_HAS_PCCARD_ID 4
0098 #define CARD_HAS_POWER_LED 5
0099 #define CARD_HAS_ACTIVITY_LED 6
0100
0101
0102 #define XMIT_SENDING 1
0103 #define XMIT_WAKEUP 2
0104 #define XMIT_BUFFER_NUMBER 5
0105 #define XMIT_BUF_ONE_READY 6
0106 #define XMIT_BUF_TWO_READY 7
0107 #define XMIT_SENDING_READY 8
0108
0109
0110 #define RECV_WAIT_PACKET_TYPE 0
0111 #define RECV_WAIT_EVENT_HEADER 1
0112 #define RECV_WAIT_ACL_HEADER 2
0113 #define RECV_WAIT_SCO_HEADER 3
0114 #define RECV_WAIT_DATA 4
0115
0116
0117 #define PKT_BAUD_RATE_57600 0x80
0118 #define PKT_BAUD_RATE_115200 0x81
0119 #define PKT_BAUD_RATE_230400 0x82
0120 #define PKT_BAUD_RATE_460800 0x83
0121
0122
0123
0124 #define REG_COMMAND 0x20
0125 #define REG_INTERRUPT 0x21
0126 #define REG_CONTROL 0x22
0127 #define REG_RX_CONTROL 0x24
0128 #define REG_CARD_RESET 0x30
0129 #define REG_LED_CTRL 0x30
0130
0131
0132 #define REG_COMMAND_TX_BUF_ONE 0x01
0133 #define REG_COMMAND_TX_BUF_TWO 0x02
0134 #define REG_COMMAND_RX_BUF_ONE 0x04
0135 #define REG_COMMAND_RX_BUF_TWO 0x08
0136 #define REG_COMMAND_RX_WIN_ONE 0x00
0137 #define REG_COMMAND_RX_WIN_TWO 0x10
0138
0139
0140 #define REG_CONTROL_BAUD_RATE_57600 0x00
0141 #define REG_CONTROL_BAUD_RATE_115200 0x01
0142 #define REG_CONTROL_BAUD_RATE_230400 0x02
0143 #define REG_CONTROL_BAUD_RATE_460800 0x03
0144 #define REG_CONTROL_RTS 0x04
0145 #define REG_CONTROL_BT_ON 0x08
0146 #define REG_CONTROL_BT_RESET 0x10
0147 #define REG_CONTROL_BT_RES_PU 0x20
0148 #define REG_CONTROL_INTERRUPT 0x40
0149 #define REG_CONTROL_CARD_RESET 0x80
0150
0151
0152 #define RTS_LEVEL_SHIFT_BITS 0x02
0153
0154
0155
0156
0157
0158
0159 static void bluecard_activity_led_timeout(struct timer_list *t)
0160 {
0161 struct bluecard_info *info = from_timer(info, t, timer);
0162 unsigned int iobase = info->p_dev->resource[0]->start;
0163
0164 if (test_bit(CARD_ACTIVITY, &(info->hw_state))) {
0165
0166 clear_bit(CARD_ACTIVITY, &(info->hw_state));
0167 mod_timer(&(info->timer), jiffies + HZ / 10);
0168 }
0169
0170
0171 outb(0x08 | 0x20, iobase + 0x30);
0172 }
0173
0174
0175 static void bluecard_enable_activity_led(struct bluecard_info *info)
0176 {
0177 unsigned int iobase = info->p_dev->resource[0]->start;
0178
0179
0180 if (timer_pending(&(info->timer)))
0181 return;
0182
0183 set_bit(CARD_ACTIVITY, &(info->hw_state));
0184
0185 if (test_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state))) {
0186
0187 outb(0x18 | 0x60, iobase + 0x30);
0188 } else {
0189
0190 outb(0x00, iobase + 0x30);
0191 }
0192
0193
0194 mod_timer(&(info->timer), jiffies + HZ / 10);
0195 }
0196
0197
0198
0199
0200
0201
0202 static int bluecard_write(unsigned int iobase, unsigned int offset, __u8 *buf, int len)
0203 {
0204 int i, actual;
0205
0206 actual = (len > 15) ? 15 : len;
0207
0208 outb_p(actual, iobase + offset);
0209
0210 for (i = 0; i < actual; i++)
0211 outb_p(buf[i], iobase + offset + i + 1);
0212
0213 return actual;
0214 }
0215
0216
0217 static void bluecard_write_wakeup(struct bluecard_info *info)
0218 {
0219 if (!info) {
0220 BT_ERR("Unknown device");
0221 return;
0222 }
0223
0224 if (!test_bit(XMIT_SENDING_READY, &(info->tx_state)))
0225 return;
0226
0227 if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
0228 set_bit(XMIT_WAKEUP, &(info->tx_state));
0229 return;
0230 }
0231
0232 do {
0233 unsigned int iobase = info->p_dev->resource[0]->start;
0234 unsigned int offset;
0235 unsigned char command;
0236 unsigned long ready_bit;
0237 register struct sk_buff *skb;
0238 int len;
0239
0240 clear_bit(XMIT_WAKEUP, &(info->tx_state));
0241
0242 if (!pcmcia_dev_present(info->p_dev))
0243 return;
0244
0245 if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) {
0246 if (!test_bit(XMIT_BUF_TWO_READY, &(info->tx_state)))
0247 break;
0248 offset = 0x10;
0249 command = REG_COMMAND_TX_BUF_TWO;
0250 ready_bit = XMIT_BUF_TWO_READY;
0251 } else {
0252 if (!test_bit(XMIT_BUF_ONE_READY, &(info->tx_state)))
0253 break;
0254 offset = 0x00;
0255 command = REG_COMMAND_TX_BUF_ONE;
0256 ready_bit = XMIT_BUF_ONE_READY;
0257 }
0258
0259 skb = skb_dequeue(&(info->txq));
0260 if (!skb)
0261 break;
0262
0263 if (hci_skb_pkt_type(skb) & 0x80) {
0264
0265 info->ctrl_reg |= REG_CONTROL_RTS;
0266 outb(info->ctrl_reg, iobase + REG_CONTROL);
0267 }
0268
0269
0270 bluecard_enable_activity_led(info);
0271
0272
0273 len = bluecard_write(iobase, offset, skb->data, skb->len);
0274
0275
0276 outb_p(command, iobase + REG_COMMAND);
0277
0278
0279 clear_bit(ready_bit, &(info->tx_state));
0280
0281 if (hci_skb_pkt_type(skb) & 0x80) {
0282 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
0283 DEFINE_WAIT(wait);
0284
0285 unsigned char baud_reg;
0286
0287 switch (hci_skb_pkt_type(skb)) {
0288 case PKT_BAUD_RATE_460800:
0289 baud_reg = REG_CONTROL_BAUD_RATE_460800;
0290 break;
0291 case PKT_BAUD_RATE_230400:
0292 baud_reg = REG_CONTROL_BAUD_RATE_230400;
0293 break;
0294 case PKT_BAUD_RATE_115200:
0295 baud_reg = REG_CONTROL_BAUD_RATE_115200;
0296 break;
0297 case PKT_BAUD_RATE_57600:
0298 default:
0299 baud_reg = REG_CONTROL_BAUD_RATE_57600;
0300 break;
0301 }
0302
0303
0304 mdelay(100);
0305
0306
0307 info->ctrl_reg &= ~0x03;
0308 info->ctrl_reg |= baud_reg;
0309 outb(info->ctrl_reg, iobase + REG_CONTROL);
0310
0311
0312 info->ctrl_reg &= ~REG_CONTROL_RTS;
0313 outb(info->ctrl_reg, iobase + REG_CONTROL);
0314
0315
0316 mdelay(1000);
0317 }
0318
0319 if (len == skb->len) {
0320 kfree_skb(skb);
0321 } else {
0322 skb_pull(skb, len);
0323 skb_queue_head(&(info->txq), skb);
0324 }
0325
0326 info->hdev->stat.byte_tx += len;
0327
0328
0329 change_bit(XMIT_BUFFER_NUMBER, &(info->tx_state));
0330
0331 } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
0332
0333 clear_bit(XMIT_SENDING, &(info->tx_state));
0334 }
0335
0336
0337 static int bluecard_read(unsigned int iobase, unsigned int offset, __u8 *buf, int size)
0338 {
0339 int i, n, len;
0340
0341 outb(REG_COMMAND_RX_WIN_ONE, iobase + REG_COMMAND);
0342
0343 len = inb(iobase + offset);
0344 n = 0;
0345 i = 1;
0346
0347 while (n < len) {
0348
0349 if (i == 16) {
0350 outb(REG_COMMAND_RX_WIN_TWO, iobase + REG_COMMAND);
0351 i = 0;
0352 }
0353
0354 buf[n] = inb(iobase + offset + i);
0355
0356 n++;
0357 i++;
0358
0359 }
0360
0361 return len;
0362 }
0363
0364
0365 static void bluecard_receive(struct bluecard_info *info,
0366 unsigned int offset)
0367 {
0368 unsigned int iobase;
0369 unsigned char buf[31];
0370 int i, len;
0371
0372 if (!info) {
0373 BT_ERR("Unknown device");
0374 return;
0375 }
0376
0377 iobase = info->p_dev->resource[0]->start;
0378
0379 if (test_bit(XMIT_SENDING_READY, &(info->tx_state)))
0380 bluecard_enable_activity_led(info);
0381
0382 len = bluecard_read(iobase, offset, buf, sizeof(buf));
0383
0384 for (i = 0; i < len; i++) {
0385
0386
0387 if (!info->rx_skb) {
0388 info->rx_state = RECV_WAIT_PACKET_TYPE;
0389 info->rx_count = 0;
0390 info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
0391 if (!info->rx_skb) {
0392 BT_ERR("Can't allocate mem for new packet");
0393 return;
0394 }
0395 }
0396
0397 if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
0398
0399 hci_skb_pkt_type(info->rx_skb) = buf[i];
0400
0401 switch (hci_skb_pkt_type(info->rx_skb)) {
0402
0403 case 0x00:
0404
0405 if (offset != 0x00) {
0406 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
0407 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
0408 set_bit(XMIT_SENDING_READY, &(info->tx_state));
0409 bluecard_write_wakeup(info);
0410 }
0411
0412 kfree_skb(info->rx_skb);
0413 info->rx_skb = NULL;
0414 break;
0415
0416 case HCI_EVENT_PKT:
0417 info->rx_state = RECV_WAIT_EVENT_HEADER;
0418 info->rx_count = HCI_EVENT_HDR_SIZE;
0419 break;
0420
0421 case HCI_ACLDATA_PKT:
0422 info->rx_state = RECV_WAIT_ACL_HEADER;
0423 info->rx_count = HCI_ACL_HDR_SIZE;
0424 break;
0425
0426 case HCI_SCODATA_PKT:
0427 info->rx_state = RECV_WAIT_SCO_HEADER;
0428 info->rx_count = HCI_SCO_HDR_SIZE;
0429 break;
0430
0431 default:
0432
0433 BT_ERR("Unknown HCI packet with type 0x%02x received",
0434 hci_skb_pkt_type(info->rx_skb));
0435 info->hdev->stat.err_rx++;
0436
0437 kfree_skb(info->rx_skb);
0438 info->rx_skb = NULL;
0439 break;
0440
0441 }
0442
0443 } else {
0444
0445 skb_put_u8(info->rx_skb, buf[i]);
0446 info->rx_count--;
0447
0448 if (info->rx_count == 0) {
0449
0450 int dlen;
0451 struct hci_event_hdr *eh;
0452 struct hci_acl_hdr *ah;
0453 struct hci_sco_hdr *sh;
0454
0455 switch (info->rx_state) {
0456
0457 case RECV_WAIT_EVENT_HEADER:
0458 eh = hci_event_hdr(info->rx_skb);
0459 info->rx_state = RECV_WAIT_DATA;
0460 info->rx_count = eh->plen;
0461 break;
0462
0463 case RECV_WAIT_ACL_HEADER:
0464 ah = hci_acl_hdr(info->rx_skb);
0465 dlen = __le16_to_cpu(ah->dlen);
0466 info->rx_state = RECV_WAIT_DATA;
0467 info->rx_count = dlen;
0468 break;
0469
0470 case RECV_WAIT_SCO_HEADER:
0471 sh = hci_sco_hdr(info->rx_skb);
0472 info->rx_state = RECV_WAIT_DATA;
0473 info->rx_count = sh->dlen;
0474 break;
0475
0476 case RECV_WAIT_DATA:
0477 hci_recv_frame(info->hdev, info->rx_skb);
0478 info->rx_skb = NULL;
0479 break;
0480
0481 }
0482
0483 }
0484
0485 }
0486
0487
0488 }
0489
0490 info->hdev->stat.byte_rx += len;
0491 }
0492
0493
0494 static irqreturn_t bluecard_interrupt(int irq, void *dev_inst)
0495 {
0496 struct bluecard_info *info = dev_inst;
0497 unsigned int iobase;
0498 unsigned char reg;
0499
0500 if (!info || !info->hdev)
0501
0502 return IRQ_NONE;
0503
0504 if (!test_bit(CARD_READY, &(info->hw_state)))
0505 return IRQ_HANDLED;
0506
0507 iobase = info->p_dev->resource[0]->start;
0508
0509 spin_lock(&(info->lock));
0510
0511
0512 info->ctrl_reg &= ~REG_CONTROL_INTERRUPT;
0513 outb(info->ctrl_reg, iobase + REG_CONTROL);
0514
0515 reg = inb(iobase + REG_INTERRUPT);
0516
0517 if ((reg != 0x00) && (reg != 0xff)) {
0518
0519 if (reg & 0x04) {
0520 bluecard_receive(info, 0x00);
0521 outb(0x04, iobase + REG_INTERRUPT);
0522 outb(REG_COMMAND_RX_BUF_ONE, iobase + REG_COMMAND);
0523 }
0524
0525 if (reg & 0x08) {
0526 bluecard_receive(info, 0x10);
0527 outb(0x08, iobase + REG_INTERRUPT);
0528 outb(REG_COMMAND_RX_BUF_TWO, iobase + REG_COMMAND);
0529 }
0530
0531 if (reg & 0x01) {
0532 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
0533 outb(0x01, iobase + REG_INTERRUPT);
0534 bluecard_write_wakeup(info);
0535 }
0536
0537 if (reg & 0x02) {
0538 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
0539 outb(0x02, iobase + REG_INTERRUPT);
0540 bluecard_write_wakeup(info);
0541 }
0542
0543 }
0544
0545
0546 info->ctrl_reg |= REG_CONTROL_INTERRUPT;
0547 outb(info->ctrl_reg, iobase + REG_CONTROL);
0548
0549 spin_unlock(&(info->lock));
0550
0551 return IRQ_HANDLED;
0552 }
0553
0554
0555
0556
0557
0558
0559 static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud)
0560 {
0561 struct bluecard_info *info = hci_get_drvdata(hdev);
0562 struct sk_buff *skb;
0563
0564
0565 unsigned char cmd[] = { HCI_COMMAND_PKT, 0x09, 0xfc, 0x01, 0x03 };
0566
0567 skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_KERNEL);
0568 if (!skb) {
0569 BT_ERR("Can't allocate mem for new packet");
0570 return -1;
0571 }
0572
0573 switch (baud) {
0574 case 460800:
0575 cmd[4] = 0x00;
0576 hci_skb_pkt_type(skb) = PKT_BAUD_RATE_460800;
0577 break;
0578 case 230400:
0579 cmd[4] = 0x01;
0580 hci_skb_pkt_type(skb) = PKT_BAUD_RATE_230400;
0581 break;
0582 case 115200:
0583 cmd[4] = 0x02;
0584 hci_skb_pkt_type(skb) = PKT_BAUD_RATE_115200;
0585 break;
0586 case 57600:
0587 default:
0588 cmd[4] = 0x03;
0589 hci_skb_pkt_type(skb) = PKT_BAUD_RATE_57600;
0590 break;
0591 }
0592
0593 skb_put_data(skb, cmd, sizeof(cmd));
0594
0595 skb_queue_tail(&(info->txq), skb);
0596
0597 bluecard_write_wakeup(info);
0598
0599 return 0;
0600 }
0601
0602
0603
0604
0605
0606
0607 static int bluecard_hci_flush(struct hci_dev *hdev)
0608 {
0609 struct bluecard_info *info = hci_get_drvdata(hdev);
0610
0611
0612 skb_queue_purge(&(info->txq));
0613
0614 return 0;
0615 }
0616
0617
0618 static int bluecard_hci_open(struct hci_dev *hdev)
0619 {
0620 struct bluecard_info *info = hci_get_drvdata(hdev);
0621 unsigned int iobase = info->p_dev->resource[0]->start;
0622
0623 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
0624 bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE);
0625
0626
0627 outb(0x08 | 0x20, iobase + 0x30);
0628
0629 return 0;
0630 }
0631
0632
0633 static int bluecard_hci_close(struct hci_dev *hdev)
0634 {
0635 struct bluecard_info *info = hci_get_drvdata(hdev);
0636 unsigned int iobase = info->p_dev->resource[0]->start;
0637
0638 bluecard_hci_flush(hdev);
0639
0640
0641 del_timer_sync(&(info->timer));
0642
0643
0644 outb(0x00, iobase + 0x30);
0645
0646 return 0;
0647 }
0648
0649
0650 static int bluecard_hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
0651 {
0652 struct bluecard_info *info = hci_get_drvdata(hdev);
0653
0654 switch (hci_skb_pkt_type(skb)) {
0655 case HCI_COMMAND_PKT:
0656 hdev->stat.cmd_tx++;
0657 break;
0658 case HCI_ACLDATA_PKT:
0659 hdev->stat.acl_tx++;
0660 break;
0661 case HCI_SCODATA_PKT:
0662 hdev->stat.sco_tx++;
0663 break;
0664 }
0665
0666
0667 memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
0668 skb_queue_tail(&(info->txq), skb);
0669
0670 bluecard_write_wakeup(info);
0671
0672 return 0;
0673 }
0674
0675
0676
0677
0678
0679
0680 static int bluecard_open(struct bluecard_info *info)
0681 {
0682 unsigned int iobase = info->p_dev->resource[0]->start;
0683 struct hci_dev *hdev;
0684 unsigned char id;
0685
0686 spin_lock_init(&(info->lock));
0687
0688 timer_setup(&info->timer, bluecard_activity_led_timeout, 0);
0689
0690 skb_queue_head_init(&(info->txq));
0691
0692 info->rx_state = RECV_WAIT_PACKET_TYPE;
0693 info->rx_count = 0;
0694 info->rx_skb = NULL;
0695
0696
0697 hdev = hci_alloc_dev();
0698 if (!hdev) {
0699 BT_ERR("Can't allocate HCI device");
0700 return -ENOMEM;
0701 }
0702
0703 info->hdev = hdev;
0704
0705 hdev->bus = HCI_PCCARD;
0706 hci_set_drvdata(hdev, info);
0707 SET_HCIDEV_DEV(hdev, &info->p_dev->dev);
0708
0709 hdev->open = bluecard_hci_open;
0710 hdev->close = bluecard_hci_close;
0711 hdev->flush = bluecard_hci_flush;
0712 hdev->send = bluecard_hci_send_frame;
0713
0714 id = inb(iobase + 0x30);
0715
0716 if ((id & 0x0f) == 0x02)
0717 set_bit(CARD_HAS_PCCARD_ID, &(info->hw_state));
0718
0719 if (id & 0x10)
0720 set_bit(CARD_HAS_POWER_LED, &(info->hw_state));
0721
0722 if (id & 0x20)
0723 set_bit(CARD_HAS_ACTIVITY_LED, &(info->hw_state));
0724
0725
0726 info->ctrl_reg = REG_CONTROL_BT_RESET | REG_CONTROL_CARD_RESET;
0727 outb(info->ctrl_reg, iobase + REG_CONTROL);
0728
0729
0730 outb(0x80, iobase + 0x30);
0731
0732
0733 msleep(10);
0734
0735
0736 outb(0x00, iobase + 0x30);
0737
0738
0739 info->ctrl_reg = REG_CONTROL_BT_ON | REG_CONTROL_BT_RES_PU;
0740 outb(info->ctrl_reg, iobase + REG_CONTROL);
0741
0742
0743 outb(0xff, iobase + REG_INTERRUPT);
0744 info->ctrl_reg |= REG_CONTROL_INTERRUPT;
0745 outb(info->ctrl_reg, iobase + REG_CONTROL);
0746
0747 if ((id & 0x0f) == 0x03) {
0748
0749 info->ctrl_reg |= REG_CONTROL_RTS;
0750 outb(info->ctrl_reg, iobase + REG_CONTROL);
0751
0752
0753 info->ctrl_reg |= 0x03;
0754 outb(info->ctrl_reg, iobase + REG_CONTROL);
0755
0756
0757 info->ctrl_reg &= ~REG_CONTROL_RTS;
0758 outb(info->ctrl_reg, iobase + REG_CONTROL);
0759
0760 set_bit(XMIT_BUF_ONE_READY, &(info->tx_state));
0761 set_bit(XMIT_BUF_TWO_READY, &(info->tx_state));
0762 set_bit(XMIT_SENDING_READY, &(info->tx_state));
0763 }
0764
0765
0766 outb(REG_COMMAND_RX_BUF_ONE, iobase + REG_COMMAND);
0767 outb(REG_COMMAND_RX_BUF_TWO, iobase + REG_COMMAND);
0768
0769
0770 set_bit(CARD_READY, &(info->hw_state));
0771
0772
0773 skb_queue_purge(&(info->txq));
0774
0775
0776 outb((0x0f << RTS_LEVEL_SHIFT_BITS) | 1, iobase + REG_RX_CONTROL);
0777
0778
0779 msleep(1250);
0780
0781
0782 if (hci_register_dev(hdev) < 0) {
0783 BT_ERR("Can't register HCI device");
0784 info->hdev = NULL;
0785 hci_free_dev(hdev);
0786 return -ENODEV;
0787 }
0788
0789 return 0;
0790 }
0791
0792
0793 static int bluecard_close(struct bluecard_info *info)
0794 {
0795 unsigned int iobase = info->p_dev->resource[0]->start;
0796 struct hci_dev *hdev = info->hdev;
0797
0798 if (!hdev)
0799 return -ENODEV;
0800
0801 bluecard_hci_close(hdev);
0802
0803 clear_bit(CARD_READY, &(info->hw_state));
0804
0805
0806 info->ctrl_reg = REG_CONTROL_BT_RESET | REG_CONTROL_CARD_RESET;
0807 outb(info->ctrl_reg, iobase + REG_CONTROL);
0808
0809
0810 outb(0x80, iobase + 0x30);
0811
0812 hci_unregister_dev(hdev);
0813 hci_free_dev(hdev);
0814
0815 return 0;
0816 }
0817
0818 static int bluecard_probe(struct pcmcia_device *link)
0819 {
0820 struct bluecard_info *info;
0821
0822
0823 info = devm_kzalloc(&link->dev, sizeof(*info), GFP_KERNEL);
0824 if (!info)
0825 return -ENOMEM;
0826
0827 info->p_dev = link;
0828 link->priv = info;
0829
0830 link->config_flags |= CONF_ENABLE_IRQ;
0831
0832 return bluecard_config(link);
0833 }
0834
0835
0836 static void bluecard_detach(struct pcmcia_device *link)
0837 {
0838 bluecard_release(link);
0839 }
0840
0841
0842 static int bluecard_config(struct pcmcia_device *link)
0843 {
0844 struct bluecard_info *info = link->priv;
0845 int i, n;
0846
0847 link->config_index = 0x20;
0848
0849 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
0850 link->resource[0]->end = 64;
0851 link->io_lines = 6;
0852
0853 for (n = 0; n < 0x400; n += 0x40) {
0854 link->resource[0]->start = n ^ 0x300;
0855 i = pcmcia_request_io(link);
0856 if (i == 0)
0857 break;
0858 }
0859
0860 if (i != 0)
0861 goto failed;
0862
0863 i = pcmcia_request_irq(link, bluecard_interrupt);
0864 if (i != 0)
0865 goto failed;
0866
0867 i = pcmcia_enable_device(link);
0868 if (i != 0)
0869 goto failed;
0870
0871 if (bluecard_open(info) != 0)
0872 goto failed;
0873
0874 return 0;
0875
0876 failed:
0877 bluecard_release(link);
0878 return -ENODEV;
0879 }
0880
0881
0882 static void bluecard_release(struct pcmcia_device *link)
0883 {
0884 struct bluecard_info *info = link->priv;
0885
0886 bluecard_close(info);
0887
0888 del_timer_sync(&(info->timer));
0889
0890 pcmcia_disable_device(link);
0891 }
0892
0893 static const struct pcmcia_device_id bluecard_ids[] = {
0894 PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e),
0895 PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c),
0896 PCMCIA_DEVICE_PROD_ID12("WSS", "LSE039", 0x0a0736ec, 0x24e6dfab),
0897 PCMCIA_DEVICE_NULL
0898 };
0899 MODULE_DEVICE_TABLE(pcmcia, bluecard_ids);
0900
0901 static struct pcmcia_driver bluecard_driver = {
0902 .owner = THIS_MODULE,
0903 .name = "bluecard_cs",
0904 .probe = bluecard_probe,
0905 .remove = bluecard_detach,
0906 .id_table = bluecard_ids,
0907 };
0908 module_pcmcia_driver(bluecard_driver);