bt3c_cs.c 17 KB

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