Linux Kernel iMX6
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

861 lines
18 KiB

  1. /*
  2. *
  3. * Driver for the 3Com Bluetooth PCMCIA card
  4. *
  5. * Copyright (C) 2001-2002 Marcel Holtmann <marcel@holtmann.org>
  6. * Jose Orlando Pereira <jop@di.uminho.pt>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation;
  12. *
  13. * Software distributed under the License is distributed on an "AS
  14. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  15. * implied. See the License for the specific language governing
  16. * rights and limitations under the License.
  17. *
  18. * The initial developer of the original code is David A. Hinds
  19. * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  20. * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  21. *
  22. */
  23. #include <linux/config.h>
  24. #include <linux/module.h>
  25. #include <linux/kernel.h>
  26. #include <linux/init.h>
  27. #include <linux/slab.h>
  28. #include <linux/types.h>
  29. #include <linux/sched.h>
  30. #include <linux/delay.h>
  31. #include <linux/errno.h>
  32. #include <linux/ptrace.h>
  33. #include <linux/ioport.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/moduleparam.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/string.h>
  38. #include <linux/serial.h>
  39. #include <linux/serial_reg.h>
  40. #include <linux/bitops.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <linux/device.h>
  44. #include <linux/firmware.h>
  45. #include <pcmcia/cs_types.h>
  46. #include <pcmcia/cs.h>
  47. #include <pcmcia/cistpl.h>
  48. #include <pcmcia/ciscode.h>
  49. #include <pcmcia/ds.h>
  50. #include <pcmcia/cisreg.h>
  51. #include <net/bluetooth/bluetooth.h>
  52. #include <net/bluetooth/hci_core.h>
  53. /* ======================== Module parameters ======================== */
  54. MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>, Jose Orlando Pereira <jop@di.uminho.pt>");
  55. MODULE_DESCRIPTION("Bluetooth driver for the 3Com Bluetooth PCMCIA card");
  56. MODULE_LICENSE("GPL");
  57. /* ======================== Local structures ======================== */
  58. typedef struct bt3c_info_t {
  59. struct pcmcia_device *p_dev;
  60. dev_node_t node;
  61. struct hci_dev *hdev;
  62. spinlock_t lock; /* For serializing operations */
  63. struct sk_buff_head txq;
  64. unsigned long tx_state;
  65. unsigned long rx_state;
  66. unsigned long rx_count;
  67. struct sk_buff *rx_skb;
  68. } bt3c_info_t;
  69. static void bt3c_config(struct pcmcia_device *link);
  70. static void bt3c_release(struct pcmcia_device *link);
  71. static void bt3c_detach(struct pcmcia_device *p_dev);
  72. /* Transmit states */
  73. #define XMIT_SENDING 1
  74. #define XMIT_WAKEUP 2
  75. #define XMIT_WAITING 8
  76. /* Receiver states */
  77. #define RECV_WAIT_PACKET_TYPE 0
  78. #define RECV_WAIT_EVENT_HEADER 1
  79. #define RECV_WAIT_ACL_HEADER 2
  80. #define RECV_WAIT_SCO_HEADER 3
  81. #define RECV_WAIT_DATA 4
  82. /* ======================== Special I/O functions ======================== */
  83. #define DATA_L 0
  84. #define DATA_H 1
  85. #define ADDR_L 2
  86. #define ADDR_H 3
  87. #define CONTROL 4
  88. static inline void bt3c_address(unsigned int iobase, unsigned short addr)
  89. {
  90. outb(addr & 0xff, iobase + ADDR_L);
  91. outb((addr >> 8) & 0xff, iobase + ADDR_H);
  92. }
  93. static inline void bt3c_put(unsigned int iobase, unsigned short value)
  94. {
  95. outb(value & 0xff, iobase + DATA_L);
  96. outb((value >> 8) & 0xff, iobase + DATA_H);
  97. }
  98. static inline void bt3c_io_write(unsigned int iobase, unsigned short addr, unsigned short value)
  99. {
  100. bt3c_address(iobase, addr);
  101. bt3c_put(iobase, value);
  102. }
  103. static inline unsigned short bt3c_get(unsigned int iobase)
  104. {
  105. unsigned short value = inb(iobase + DATA_L);
  106. value |= inb(iobase + DATA_H) << 8;
  107. return value;
  108. }
  109. static inline unsigned short bt3c_read(unsigned int iobase, unsigned short addr)
  110. {
  111. bt3c_address(iobase, addr);
  112. return bt3c_get(iobase);
  113. }
  114. /* ======================== Interrupt handling ======================== */
  115. static int bt3c_write(unsigned int iobase, int fifo_size, __u8 *buf, int len)
  116. {
  117. int actual = 0;
  118. bt3c_address(iobase, 0x7080);
  119. /* Fill FIFO with current frame */
  120. while (actual < len) {
  121. /* Transmit next byte */
  122. bt3c_put(iobase, buf[actual]);
  123. actual++;
  124. }
  125. bt3c_io_write(iobase, 0x7005, actual);
  126. return actual;
  127. }
  128. static void bt3c_write_wakeup(bt3c_info_t *info)
  129. {
  130. if (!info) {
  131. BT_ERR("Unknown device");
  132. return;
  133. }
  134. if (test_and_set_bit(XMIT_SENDING, &(info->tx_state)))
  135. return;
  136. do {
  137. register unsigned int iobase = info->p_dev->io.BasePort1;
  138. register struct sk_buff *skb;
  139. register int len;
  140. if (!(info->p_dev->state & DEV_PRESENT))
  141. break;
  142. if (!(skb = skb_dequeue(&(info->txq)))) {
  143. clear_bit(XMIT_SENDING, &(info->tx_state));
  144. break;
  145. }
  146. /* Send frame */
  147. len = bt3c_write(iobase, 256, skb->data, skb->len);
  148. if (len != skb->len) {
  149. BT_ERR("Very strange");
  150. }
  151. kfree_skb(skb);
  152. info->hdev->stat.byte_tx += len;
  153. } while (0);
  154. }
  155. static void bt3c_receive(bt3c_info_t *info)
  156. {
  157. unsigned int iobase;
  158. int size = 0, avail;
  159. if (!info) {
  160. BT_ERR("Unknown device");
  161. return;
  162. }
  163. iobase = info->p_dev->io.BasePort1;
  164. avail = bt3c_read(iobase, 0x7006);
  165. //printk("bt3c_cs: receiving %d bytes\n", avail);
  166. bt3c_address(iobase, 0x7480);
  167. while (size < avail) {
  168. size++;
  169. info->hdev->stat.byte_rx++;
  170. /* Allocate packet */
  171. if (info->rx_skb == NULL) {
  172. info->rx_state = RECV_WAIT_PACKET_TYPE;
  173. info->rx_count = 0;
  174. if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
  175. BT_ERR("Can't allocate mem for new packet");
  176. return;
  177. }
  178. }
  179. if (info->rx_state == RECV_WAIT_PACKET_TYPE) {
  180. info->rx_skb->dev = (void *) info->hdev;
  181. bt_cb(info->rx_skb)->pkt_type = inb(iobase + DATA_L);
  182. inb(iobase + DATA_H);
  183. //printk("bt3c: PACKET_TYPE=%02x\n", bt_cb(info->rx_skb)->pkt_type);
  184. switch (bt_cb(info->rx_skb)->pkt_type) {
  185. case HCI_EVENT_PKT:
  186. info->rx_state = RECV_WAIT_EVENT_HEADER;
  187. info->rx_count = HCI_EVENT_HDR_SIZE;
  188. break;
  189. case HCI_ACLDATA_PKT:
  190. info->rx_state = RECV_WAIT_ACL_HEADER;
  191. info->rx_count = HCI_ACL_HDR_SIZE;
  192. break;
  193. case HCI_SCODATA_PKT:
  194. info->rx_state = RECV_WAIT_SCO_HEADER;
  195. info->rx_count = HCI_SCO_HDR_SIZE;
  196. break;
  197. default:
  198. /* Unknown packet */
  199. BT_ERR("Unknown HCI packet with type 0x%02x received", bt_cb(info->rx_skb)->pkt_type);
  200. info->hdev->stat.err_rx++;
  201. clear_bit(HCI_RUNNING, &(info->hdev->flags));
  202. kfree_skb(info->rx_skb);
  203. info->rx_skb = NULL;
  204. break;
  205. }
  206. } else {
  207. __u8 x = inb(iobase + DATA_L);
  208. *skb_put(info->rx_skb, 1) = x;
  209. inb(iobase + DATA_H);
  210. info->rx_count--;
  211. if (info->rx_count == 0) {
  212. int dlen;
  213. struct hci_event_hdr *eh;
  214. struct hci_acl_hdr *ah;
  215. struct hci_sco_hdr *sh;
  216. switch (info->rx_state) {
  217. case RECV_WAIT_EVENT_HEADER:
  218. eh = (struct hci_event_hdr *)(info->rx_skb->data);
  219. info->rx_state = RECV_WAIT_DATA;
  220. info->rx_count = eh->plen;
  221. break;
  222. case RECV_WAIT_ACL_HEADER:
  223. ah = (struct hci_acl_hdr *)(info->rx_skb->data);
  224. dlen = __le16_to_cpu(ah->dlen);
  225. info->rx_state = RECV_WAIT_DATA;
  226. info->rx_count = dlen;
  227. break;
  228. case RECV_WAIT_SCO_HEADER:
  229. sh = (struct hci_sco_hdr *)(info->rx_skb->data);
  230. info->rx_state = RECV_WAIT_DATA;
  231. info->rx_count = sh->dlen;
  232. break;
  233. case RECV_WAIT_DATA:
  234. hci_recv_frame(info->rx_skb);
  235. info->rx_skb = NULL;
  236. break;
  237. }
  238. }
  239. }
  240. }
  241. bt3c_io_write(iobase, 0x7006, 0x0000);
  242. }
  243. static irqreturn_t bt3c_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
  244. {
  245. bt3c_info_t *info = dev_inst;
  246. unsigned int iobase;
  247. int iir;
  248. if (!info || !info->hdev) {
  249. BT_ERR("Call of irq %d for unknown device", irq);
  250. return IRQ_NONE;
  251. }
  252. iobase = info->p_dev->io.BasePort1;
  253. spin_lock(&(info->lock));
  254. iir = inb(iobase + CONTROL);
  255. if (iir & 0x80) {
  256. int stat = bt3c_read(iobase, 0x7001);
  257. if ((stat & 0xff) == 0x7f) {
  258. BT_ERR("Very strange (stat=0x%04x)", stat);
  259. } else if ((stat & 0xff) != 0xff) {
  260. if (stat & 0x0020) {
  261. int stat = bt3c_read(iobase, 0x7002) & 0x10;
  262. BT_INFO("%s: Antenna %s", info->hdev->name,
  263. stat ? "out" : "in");
  264. }
  265. if (stat & 0x0001)
  266. bt3c_receive(info);
  267. if (stat & 0x0002) {
  268. //BT_ERR("Ack (stat=0x%04x)", stat);
  269. clear_bit(XMIT_SENDING, &(info->tx_state));
  270. bt3c_write_wakeup(info);
  271. }
  272. bt3c_io_write(iobase, 0x7001, 0x0000);
  273. outb(iir, iobase + CONTROL);
  274. }
  275. }
  276. spin_unlock(&(info->lock));
  277. return IRQ_HANDLED;
  278. }
  279. /* ======================== HCI interface ======================== */
  280. static int bt3c_hci_flush(struct hci_dev *hdev)
  281. {
  282. bt3c_info_t *info = (bt3c_info_t *)(hdev->driver_data);
  283. /* Drop TX queue */
  284. skb_queue_purge(&(info->txq));
  285. return 0;
  286. }
  287. static int bt3c_hci_open(struct hci_dev *hdev)
  288. {
  289. set_bit(HCI_RUNNING, &(hdev->flags));
  290. return 0;
  291. }
  292. static int bt3c_hci_close(struct hci_dev *hdev)
  293. {
  294. if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
  295. return 0;
  296. bt3c_hci_flush(hdev);
  297. return 0;
  298. }
  299. static int bt3c_hci_send_frame(struct sk_buff *skb)
  300. {
  301. bt3c_info_t *info;
  302. struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
  303. unsigned long flags;
  304. if (!hdev) {
  305. BT_ERR("Frame for unknown HCI device (hdev=NULL)");
  306. return -ENODEV;
  307. }
  308. info = (bt3c_info_t *) (hdev->driver_data);
  309. switch (bt_cb(skb)->pkt_type) {
  310. case HCI_COMMAND_PKT:
  311. hdev->stat.cmd_tx++;
  312. break;
  313. case HCI_ACLDATA_PKT:
  314. hdev->stat.acl_tx++;
  315. break;
  316. case HCI_SCODATA_PKT:
  317. hdev->stat.sco_tx++;
  318. break;
  319. };
  320. /* Prepend skb with frame type */
  321. memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
  322. skb_queue_tail(&(info->txq), skb);
  323. spin_lock_irqsave(&(info->lock), flags);
  324. bt3c_write_wakeup(info);
  325. spin_unlock_irqrestore(&(info->lock), flags);
  326. return 0;
  327. }
  328. static void bt3c_hci_destruct(struct hci_dev *hdev)
  329. {
  330. }
  331. static int bt3c_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
  332. {
  333. return -ENOIOCTLCMD;
  334. }
  335. /* ======================== Card services HCI interaction ======================== */
  336. static int bt3c_load_firmware(bt3c_info_t *info, unsigned char *firmware, int count)
  337. {
  338. char *ptr = (char *) firmware;
  339. char b[9];
  340. unsigned int iobase, size, addr, fcs, tmp;
  341. int i, err = 0;
  342. iobase = info->p_dev->io.BasePort1;
  343. /* Reset */
  344. bt3c_io_write(iobase, 0x8040, 0x0404);
  345. bt3c_io_write(iobase, 0x8040, 0x0400);
  346. udelay(1);
  347. bt3c_io_write(iobase, 0x8040, 0x0404);
  348. udelay(17);
  349. /* Load */
  350. while (count) {
  351. if (ptr[0] != 'S') {
  352. BT_ERR("Bad address in firmware");
  353. err = -EFAULT;
  354. goto error;
  355. }
  356. memset(b, 0, sizeof(b));
  357. memcpy(b, ptr + 2, 2);
  358. size = simple_strtol(b, NULL, 16);
  359. memset(b, 0, sizeof(b));
  360. memcpy(b, ptr + 4, 8);
  361. addr = simple_strtol(b, NULL, 16);
  362. memset(b, 0, sizeof(b));
  363. memcpy(b, ptr + (size * 2) + 2, 2);
  364. fcs = simple_strtol(b, NULL, 16);
  365. memset(b, 0, sizeof(b));
  366. for (tmp = 0, i = 0; i < size; i++) {
  367. memcpy(b, ptr + (i * 2) + 2, 2);
  368. tmp += simple_strtol(b, NULL, 16);
  369. }
  370. if (((tmp + fcs) & 0xff) != 0xff) {
  371. BT_ERR("Checksum error in firmware");
  372. err = -EILSEQ;
  373. goto error;
  374. }
  375. if (ptr[1] == '3') {
  376. bt3c_address(iobase, addr);
  377. memset(b, 0, sizeof(b));
  378. for (i = 0; i < (size - 4) / 2; i++) {
  379. memcpy(b, ptr + (i * 4) + 12, 4);
  380. tmp = simple_strtol(b, NULL, 16);
  381. bt3c_put(iobase, tmp);
  382. }
  383. }
  384. ptr += (size * 2) + 6;
  385. count -= (size * 2) + 6;
  386. }
  387. udelay(17);
  388. /* Boot */
  389. bt3c_address(iobase, 0x3000);
  390. outb(inb(iobase + CONTROL) | 0x40, iobase + CONTROL);
  391. error:
  392. udelay(17);
  393. /* Clear */
  394. bt3c_io_write(iobase, 0x7006, 0x0000);
  395. bt3c_io_write(iobase, 0x7005, 0x0000);
  396. bt3c_io_write(iobase, 0x7001, 0x0000);
  397. return err;
  398. }
  399. static int bt3c_open(bt3c_info_t *info)
  400. {
  401. const struct firmware *firmware;
  402. struct hci_dev *hdev;
  403. int err;
  404. spin_lock_init(&(info->lock));
  405. skb_queue_head_init(&(info->txq));
  406. info->rx_state = RECV_WAIT_PACKET_TYPE;
  407. info->rx_count = 0;
  408. info->rx_skb = NULL;
  409. /* Initialize HCI device */
  410. hdev = hci_alloc_dev();
  411. if (!hdev) {
  412. BT_ERR("Can't allocate HCI device");
  413. return -ENOMEM;
  414. }
  415. info->hdev = hdev;
  416. hdev->type = HCI_PCCARD;
  417. hdev->driver_data = info;
  418. hdev->open = bt3c_hci_open;
  419. hdev->close = bt3c_hci_close;
  420. hdev->flush = bt3c_hci_flush;
  421. hdev->send = bt3c_hci_send_frame;
  422. hdev->destruct = bt3c_hci_destruct;
  423. hdev->ioctl = bt3c_hci_ioctl;
  424. hdev->owner = THIS_MODULE;
  425. /* Load firmware */
  426. err = request_firmware(&firmware, "BT3CPCC.bin", &info->p_dev->dev);
  427. if (err < 0) {
  428. BT_ERR("Firmware request failed");
  429. goto error;
  430. }
  431. err = bt3c_load_firmware(info, firmware->data, firmware->size);
  432. release_firmware(firmware);
  433. if (err < 0) {
  434. BT_ERR("Firmware loading failed");
  435. goto error;
  436. }
  437. /* Timeout before it is safe to send the first HCI packet */
  438. msleep(1000);
  439. /* Register HCI device */
  440. err = hci_register_dev(hdev);
  441. if (err < 0) {
  442. BT_ERR("Can't register HCI device");
  443. goto error;
  444. }
  445. return 0;
  446. error:
  447. info->hdev = NULL;
  448. hci_free_dev(hdev);
  449. return err;
  450. }
  451. static int bt3c_close(bt3c_info_t *info)
  452. {
  453. struct hci_dev *hdev = info->hdev;
  454. if (!hdev)
  455. return -ENODEV;
  456. bt3c_hci_close(hdev);
  457. if (hci_unregister_dev(hdev) < 0)
  458. BT_ERR("Can't unregister HCI device %s", hdev->name);
  459. hci_free_dev(hdev);
  460. return 0;
  461. }
  462. static int bt3c_attach(struct pcmcia_device *link)
  463. {
  464. bt3c_info_t *info;
  465. /* Create new info device */
  466. info = kzalloc(sizeof(*info), GFP_KERNEL);
  467. if (!info)
  468. return -ENOMEM;
  469. info->p_dev = link;
  470. link->priv = info;
  471. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  472. link->io.NumPorts1 = 8;
  473. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  474. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  475. link->irq.Handler = bt3c_interrupt;
  476. link->irq.Instance = info;
  477. link->conf.Attributes = CONF_ENABLE_IRQ;
  478. link->conf.IntType = INT_MEMORY_AND_IO;
  479. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  480. bt3c_config(link);
  481. return 0;
  482. }
  483. static void bt3c_detach(struct pcmcia_device *link)
  484. {
  485. bt3c_info_t *info = link->priv;
  486. if (link->state & DEV_CONFIG)
  487. bt3c_release(link);
  488. kfree(info);
  489. }
  490. static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
  491. {
  492. int i;
  493. i = pcmcia_get_tuple_data(handle, tuple);
  494. if (i != CS_SUCCESS)
  495. return i;
  496. return pcmcia_parse_tuple(handle, tuple, parse);
  497. }
  498. static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
  499. {
  500. if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
  501. return CS_NO_MORE_ITEMS;
  502. return get_tuple(handle, tuple, parse);
  503. }
  504. static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
  505. {
  506. if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
  507. return CS_NO_MORE_ITEMS;
  508. return get_tuple(handle, tuple, parse);
  509. }
  510. static void bt3c_config(struct pcmcia_device *link)
  511. {
  512. static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
  513. bt3c_info_t *info = link->priv;
  514. tuple_t tuple;
  515. u_short buf[256];
  516. cisparse_t parse;
  517. cistpl_cftable_entry_t *cf = &parse.cftable_entry;
  518. int i, j, try, last_ret, last_fn;
  519. tuple.TupleData = (cisdata_t *)buf;
  520. tuple.TupleOffset = 0;
  521. tuple.TupleDataMax = 255;
  522. tuple.Attributes = 0;
  523. /* Get configuration register information */
  524. tuple.DesiredTuple = CISTPL_CONFIG;
  525. last_ret = first_tuple(link, &tuple, &parse);
  526. if (last_ret != CS_SUCCESS) {
  527. last_fn = ParseTuple;
  528. goto cs_failed;
  529. }
  530. link->conf.ConfigBase = parse.config.base;
  531. link->conf.Present = parse.config.rmask[0];
  532. /* Configure card */
  533. link->state |= DEV_CONFIG;
  534. /* First pass: look for a config entry that looks normal. */
  535. tuple.TupleData = (cisdata_t *)buf;
  536. tuple.TupleOffset = 0;
  537. tuple.TupleDataMax = 255;
  538. tuple.Attributes = 0;
  539. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  540. /* Two tries: without IO aliases, then with aliases */
  541. for (try = 0; try < 2; try++) {
  542. i = first_tuple(link, &tuple, &parse);
  543. while (i != CS_NO_MORE_ITEMS) {
  544. if (i != CS_SUCCESS)
  545. goto next_entry;
  546. if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
  547. link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
  548. if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
  549. link->conf.ConfigIndex = cf->index;
  550. link->io.BasePort1 = cf->io.win[0].base;
  551. link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
  552. i = pcmcia_request_io(link, &link->io);
  553. if (i == CS_SUCCESS)
  554. goto found_port;
  555. }
  556. next_entry:
  557. i = next_tuple(link, &tuple, &parse);
  558. }
  559. }
  560. /* Second pass: try to find an entry that isn't picky about
  561. its base address, then try to grab any standard serial port
  562. address, and finally try to get any free port. */
  563. i = first_tuple(link, &tuple, &parse);
  564. while (i != CS_NO_MORE_ITEMS) {
  565. if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
  566. link->conf.ConfigIndex = cf->index;
  567. for (j = 0; j < 5; j++) {
  568. link->io.BasePort1 = base[j];
  569. link->io.IOAddrLines = base[j] ? 16 : 3;
  570. i = pcmcia_request_io(link, &link->io);
  571. if (i == CS_SUCCESS)
  572. goto found_port;
  573. }
  574. }
  575. i = next_tuple(link, &tuple, &parse);
  576. }
  577. found_port:
  578. if (i != CS_SUCCESS) {
  579. BT_ERR("No usable port range found");
  580. cs_error(link, RequestIO, i);
  581. goto failed;
  582. }
  583. i = pcmcia_request_irq(link, &link->irq);
  584. if (i != CS_SUCCESS) {
  585. cs_error(link, RequestIRQ, i);
  586. link->irq.AssignedIRQ = 0;
  587. }
  588. i = pcmcia_request_configuration(link, &link->conf);
  589. if (i != CS_SUCCESS) {
  590. cs_error(link, RequestConfiguration, i);
  591. goto failed;
  592. }
  593. if (bt3c_open(info) != 0)
  594. goto failed;
  595. strcpy(info->node.dev_name, info->hdev->name);
  596. link->dev_node = &info->node;
  597. link->state &= ~DEV_CONFIG_PENDING;
  598. return;
  599. cs_failed:
  600. cs_error(link, last_fn, last_ret);
  601. failed:
  602. bt3c_release(link);
  603. }
  604. static void bt3c_release(struct pcmcia_device *link)
  605. {
  606. bt3c_info_t *info = link->priv;
  607. if (link->state & DEV_PRESENT)
  608. bt3c_close(info);
  609. pcmcia_disable_device(link);
  610. }
  611. static struct pcmcia_device_id bt3c_ids[] = {
  612. PCMCIA_DEVICE_PROD_ID13("3COM", "Bluetooth PC Card", 0xefce0a31, 0xd4ce9b02),
  613. PCMCIA_DEVICE_NULL
  614. };
  615. MODULE_DEVICE_TABLE(pcmcia, bt3c_ids);
  616. static struct pcmcia_driver bt3c_driver = {
  617. .owner = THIS_MODULE,
  618. .drv = {
  619. .name = "bt3c_cs",
  620. },
  621. .probe = bt3c_attach,
  622. .remove = bt3c_detach,
  623. .id_table = bt3c_ids,
  624. };
  625. static int __init init_bt3c_cs(void)
  626. {
  627. return pcmcia_register_driver(&bt3c_driver);
  628. }
  629. static void __exit exit_bt3c_cs(void)
  630. {
  631. pcmcia_unregister_driver(&bt3c_driver);
  632. }
  633. module_init(init_bt3c_cs);
  634. module_exit(exit_bt3c_cs);