dtl1_cs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /*
  2. *
  3. * A driver for Nokia Connectivity Card DTL-1 devices
  4. *
  5. * Copyright (C) 2001-2002 Marcel Holtmann <marcel@holtmann.org>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation;
  11. *
  12. * Software distributed under the License is distributed on an "AS
  13. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  14. * implied. See the License for the specific language governing
  15. * rights and limitations under the License.
  16. *
  17. * The initial developer of the original code is David A. Hinds
  18. * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  19. * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  20. *
  21. */
  22. #include <linux/config.h>
  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/sched.h>
  29. #include <linux/delay.h>
  30. #include <linux/errno.h>
  31. #include <linux/ptrace.h>
  32. #include <linux/ioport.h>
  33. #include <linux/spinlock.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/string.h>
  37. #include <linux/serial.h>
  38. #include <linux/serial_reg.h>
  39. #include <linux/bitops.h>
  40. #include <asm/system.h>
  41. #include <asm/io.h>
  42. #include <pcmcia/version.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>");
  53. MODULE_DESCRIPTION("Bluetooth driver for Nokia Connectivity Card DTL-1");
  54. MODULE_LICENSE("GPL");
  55. /* ======================== Local structures ======================== */
  56. typedef struct dtl1_info_t {
  57. dev_link_t link;
  58. dev_node_t node;
  59. struct hci_dev *hdev;
  60. spinlock_t lock; /* For serializing operations */
  61. unsigned long flowmask; /* HCI flow mask */
  62. int ri_latch;
  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. } dtl1_info_t;
  69. static void dtl1_config(dev_link_t *link);
  70. static void dtl1_release(dev_link_t *link);
  71. static int dtl1_event(event_t event, int priority, event_callback_args_t *args);
  72. static dev_info_t dev_info = "dtl1_cs";
  73. static dev_link_t *dtl1_attach(void);
  74. static void dtl1_detach(dev_link_t *);
  75. static dev_link_t *dev_list = NULL;
  76. /* Transmit states */
  77. #define XMIT_SENDING 1
  78. #define XMIT_WAKEUP 2
  79. #define XMIT_WAITING 8
  80. /* Receiver States */
  81. #define RECV_WAIT_NSH 0
  82. #define RECV_WAIT_DATA 1
  83. typedef struct {
  84. u8 type;
  85. u8 zero;
  86. u16 len;
  87. } __attribute__ ((packed)) nsh_t; /* Nokia Specific Header */
  88. #define NSHL 4 /* Nokia Specific Header Length */
  89. /* ======================== Interrupt handling ======================== */
  90. static int dtl1_write(unsigned int iobase, int fifo_size, __u8 *buf, int len)
  91. {
  92. int actual = 0;
  93. /* Tx FIFO should be empty */
  94. if (!(inb(iobase + UART_LSR) & UART_LSR_THRE))
  95. return 0;
  96. /* Fill FIFO with current frame */
  97. while ((fifo_size-- > 0) && (actual < len)) {
  98. /* Transmit next byte */
  99. outb(buf[actual], iobase + UART_TX);
  100. actual++;
  101. }
  102. return actual;
  103. }
  104. static void dtl1_write_wakeup(dtl1_info_t *info)
  105. {
  106. if (!info) {
  107. BT_ERR("Unknown device");
  108. return;
  109. }
  110. if (test_bit(XMIT_WAITING, &(info->tx_state))) {
  111. set_bit(XMIT_WAKEUP, &(info->tx_state));
  112. return;
  113. }
  114. if (test_and_set_bit(XMIT_SENDING, &(info->tx_state))) {
  115. set_bit(XMIT_WAKEUP, &(info->tx_state));
  116. return;
  117. }
  118. do {
  119. register unsigned int iobase = info->link.io.BasePort1;
  120. register struct sk_buff *skb;
  121. register int len;
  122. clear_bit(XMIT_WAKEUP, &(info->tx_state));
  123. if (!(info->link.state & DEV_PRESENT))
  124. return;
  125. if (!(skb = skb_dequeue(&(info->txq))))
  126. break;
  127. /* Send frame */
  128. len = dtl1_write(iobase, 32, skb->data, skb->len);
  129. if (len == skb->len) {
  130. set_bit(XMIT_WAITING, &(info->tx_state));
  131. kfree_skb(skb);
  132. } else {
  133. skb_pull(skb, len);
  134. skb_queue_head(&(info->txq), skb);
  135. }
  136. info->hdev->stat.byte_tx += len;
  137. } while (test_bit(XMIT_WAKEUP, &(info->tx_state)));
  138. clear_bit(XMIT_SENDING, &(info->tx_state));
  139. }
  140. static void dtl1_control(dtl1_info_t *info, struct sk_buff *skb)
  141. {
  142. u8 flowmask = *(u8 *)skb->data;
  143. int i;
  144. printk(KERN_INFO "Bluetooth: Nokia control data =");
  145. for (i = 0; i < skb->len; i++) {
  146. printk(" %02x", skb->data[i]);
  147. }
  148. printk("\n");
  149. /* transition to active state */
  150. if (((info->flowmask & 0x07) == 0) && ((flowmask & 0x07) != 0)) {
  151. clear_bit(XMIT_WAITING, &(info->tx_state));
  152. dtl1_write_wakeup(info);
  153. }
  154. info->flowmask = flowmask;
  155. kfree_skb(skb);
  156. }
  157. static void dtl1_receive(dtl1_info_t *info)
  158. {
  159. unsigned int iobase;
  160. nsh_t *nsh;
  161. int boguscount = 0;
  162. if (!info) {
  163. BT_ERR("Unknown device");
  164. return;
  165. }
  166. iobase = info->link.io.BasePort1;
  167. do {
  168. info->hdev->stat.byte_rx++;
  169. /* Allocate packet */
  170. if (info->rx_skb == NULL)
  171. if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
  172. BT_ERR("Can't allocate mem for new packet");
  173. info->rx_state = RECV_WAIT_NSH;
  174. info->rx_count = NSHL;
  175. return;
  176. }
  177. *skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
  178. nsh = (nsh_t *)info->rx_skb->data;
  179. info->rx_count--;
  180. if (info->rx_count == 0) {
  181. switch (info->rx_state) {
  182. case RECV_WAIT_NSH:
  183. info->rx_state = RECV_WAIT_DATA;
  184. info->rx_count = nsh->len + (nsh->len & 0x0001);
  185. break;
  186. case RECV_WAIT_DATA:
  187. info->rx_skb->pkt_type = nsh->type;
  188. /* remove PAD byte if it exists */
  189. if (nsh->len & 0x0001) {
  190. info->rx_skb->tail--;
  191. info->rx_skb->len--;
  192. }
  193. /* remove NSH */
  194. skb_pull(info->rx_skb, NSHL);
  195. switch (info->rx_skb->pkt_type) {
  196. case 0x80:
  197. /* control data for the Nokia Card */
  198. dtl1_control(info, info->rx_skb);
  199. break;
  200. case 0x82:
  201. case 0x83:
  202. case 0x84:
  203. /* send frame to the HCI layer */
  204. info->rx_skb->dev = (void *) info->hdev;
  205. info->rx_skb->pkt_type &= 0x0f;
  206. hci_recv_frame(info->rx_skb);
  207. break;
  208. default:
  209. /* unknown packet */
  210. BT_ERR("Unknown HCI packet with type 0x%02x received", info->rx_skb->pkt_type);
  211. kfree_skb(info->rx_skb);
  212. break;
  213. }
  214. info->rx_state = RECV_WAIT_NSH;
  215. info->rx_count = NSHL;
  216. info->rx_skb = NULL;
  217. break;
  218. }
  219. }
  220. /* Make sure we don't stay here too long */
  221. if (boguscount++ > 32)
  222. break;
  223. } while (inb(iobase + UART_LSR) & UART_LSR_DR);
  224. }
  225. static irqreturn_t dtl1_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
  226. {
  227. dtl1_info_t *info = dev_inst;
  228. unsigned int iobase;
  229. unsigned char msr;
  230. int boguscount = 0;
  231. int iir, lsr;
  232. if (!info || !info->hdev) {
  233. BT_ERR("Call of irq %d for unknown device", irq);
  234. return IRQ_NONE;
  235. }
  236. iobase = info->link.io.BasePort1;
  237. spin_lock(&(info->lock));
  238. iir = inb(iobase + UART_IIR) & UART_IIR_ID;
  239. while (iir) {
  240. /* Clear interrupt */
  241. lsr = inb(iobase + UART_LSR);
  242. switch (iir) {
  243. case UART_IIR_RLSI:
  244. BT_ERR("RLSI");
  245. break;
  246. case UART_IIR_RDI:
  247. /* Receive interrupt */
  248. dtl1_receive(info);
  249. break;
  250. case UART_IIR_THRI:
  251. if (lsr & UART_LSR_THRE) {
  252. /* Transmitter ready for data */
  253. dtl1_write_wakeup(info);
  254. }
  255. break;
  256. default:
  257. BT_ERR("Unhandled IIR=%#x", iir);
  258. break;
  259. }
  260. /* Make sure we don't stay here too long */
  261. if (boguscount++ > 100)
  262. break;
  263. iir = inb(iobase + UART_IIR) & UART_IIR_ID;
  264. }
  265. msr = inb(iobase + UART_MSR);
  266. if (info->ri_latch ^ (msr & UART_MSR_RI)) {
  267. info->ri_latch = msr & UART_MSR_RI;
  268. clear_bit(XMIT_WAITING, &(info->tx_state));
  269. dtl1_write_wakeup(info);
  270. }
  271. spin_unlock(&(info->lock));
  272. return IRQ_HANDLED;
  273. }
  274. /* ======================== HCI interface ======================== */
  275. static int dtl1_hci_open(struct hci_dev *hdev)
  276. {
  277. set_bit(HCI_RUNNING, &(hdev->flags));
  278. return 0;
  279. }
  280. static int dtl1_hci_flush(struct hci_dev *hdev)
  281. {
  282. dtl1_info_t *info = (dtl1_info_t *)(hdev->driver_data);
  283. /* Drop TX queue */
  284. skb_queue_purge(&(info->txq));
  285. return 0;
  286. }
  287. static int dtl1_hci_close(struct hci_dev *hdev)
  288. {
  289. if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
  290. return 0;
  291. dtl1_hci_flush(hdev);
  292. return 0;
  293. }
  294. static int dtl1_hci_send_frame(struct sk_buff *skb)
  295. {
  296. dtl1_info_t *info;
  297. struct hci_dev *hdev = (struct hci_dev *)(skb->dev);
  298. struct sk_buff *s;
  299. nsh_t nsh;
  300. if (!hdev) {
  301. BT_ERR("Frame for unknown HCI device (hdev=NULL)");
  302. return -ENODEV;
  303. }
  304. info = (dtl1_info_t *)(hdev->driver_data);
  305. switch (skb->pkt_type) {
  306. case HCI_COMMAND_PKT:
  307. hdev->stat.cmd_tx++;
  308. nsh.type = 0x81;
  309. break;
  310. case HCI_ACLDATA_PKT:
  311. hdev->stat.acl_tx++;
  312. nsh.type = 0x82;
  313. break;
  314. case HCI_SCODATA_PKT:
  315. hdev->stat.sco_tx++;
  316. nsh.type = 0x83;
  317. break;
  318. };
  319. nsh.zero = 0;
  320. nsh.len = skb->len;
  321. s = bt_skb_alloc(NSHL + skb->len + 1, GFP_ATOMIC);
  322. skb_reserve(s, NSHL);
  323. memcpy(skb_put(s, skb->len), skb->data, skb->len);
  324. if (skb->len & 0x0001)
  325. *skb_put(s, 1) = 0; /* PAD */
  326. /* Prepend skb with Nokia frame header and queue */
  327. memcpy(skb_push(s, NSHL), &nsh, NSHL);
  328. skb_queue_tail(&(info->txq), s);
  329. dtl1_write_wakeup(info);
  330. kfree_skb(skb);
  331. return 0;
  332. }
  333. static void dtl1_hci_destruct(struct hci_dev *hdev)
  334. {
  335. }
  336. static int dtl1_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
  337. {
  338. return -ENOIOCTLCMD;
  339. }
  340. /* ======================== Card services HCI interaction ======================== */
  341. static int dtl1_open(dtl1_info_t *info)
  342. {
  343. unsigned long flags;
  344. unsigned int iobase = info->link.io.BasePort1;
  345. struct hci_dev *hdev;
  346. spin_lock_init(&(info->lock));
  347. skb_queue_head_init(&(info->txq));
  348. info->rx_state = RECV_WAIT_NSH;
  349. info->rx_count = NSHL;
  350. info->rx_skb = NULL;
  351. set_bit(XMIT_WAITING, &(info->tx_state));
  352. /* Initialize HCI device */
  353. hdev = hci_alloc_dev();
  354. if (!hdev) {
  355. BT_ERR("Can't allocate HCI device");
  356. return -ENOMEM;
  357. }
  358. info->hdev = hdev;
  359. hdev->type = HCI_PCCARD;
  360. hdev->driver_data = info;
  361. hdev->open = dtl1_hci_open;
  362. hdev->close = dtl1_hci_close;
  363. hdev->flush = dtl1_hci_flush;
  364. hdev->send = dtl1_hci_send_frame;
  365. hdev->destruct = dtl1_hci_destruct;
  366. hdev->ioctl = dtl1_hci_ioctl;
  367. hdev->owner = THIS_MODULE;
  368. spin_lock_irqsave(&(info->lock), flags);
  369. /* Reset UART */
  370. outb(0, iobase + UART_MCR);
  371. /* Turn off interrupts */
  372. outb(0, iobase + UART_IER);
  373. /* Initialize UART */
  374. outb(UART_LCR_WLEN8, iobase + UART_LCR); /* Reset DLAB */
  375. outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR);
  376. info->ri_latch = inb(info->link.io.BasePort1 + UART_MSR) & UART_MSR_RI;
  377. /* Turn on interrupts */
  378. outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
  379. spin_unlock_irqrestore(&(info->lock), flags);
  380. /* Timeout before it is safe to send the first HCI packet */
  381. msleep(2000);
  382. /* Register HCI device */
  383. if (hci_register_dev(hdev) < 0) {
  384. BT_ERR("Can't register HCI device");
  385. info->hdev = NULL;
  386. hci_free_dev(hdev);
  387. return -ENODEV;
  388. }
  389. return 0;
  390. }
  391. static int dtl1_close(dtl1_info_t *info)
  392. {
  393. unsigned long flags;
  394. unsigned int iobase = info->link.io.BasePort1;
  395. struct hci_dev *hdev = info->hdev;
  396. if (!hdev)
  397. return -ENODEV;
  398. dtl1_hci_close(hdev);
  399. spin_lock_irqsave(&(info->lock), flags);
  400. /* Reset UART */
  401. outb(0, iobase + UART_MCR);
  402. /* Turn off interrupts */
  403. outb(0, iobase + UART_IER);
  404. spin_unlock_irqrestore(&(info->lock), flags);
  405. if (hci_unregister_dev(hdev) < 0)
  406. BT_ERR("Can't unregister HCI device %s", hdev->name);
  407. hci_free_dev(hdev);
  408. return 0;
  409. }
  410. static dev_link_t *dtl1_attach(void)
  411. {
  412. dtl1_info_t *info;
  413. client_reg_t client_reg;
  414. dev_link_t *link;
  415. int ret;
  416. /* Create new info device */
  417. info = kmalloc(sizeof(*info), GFP_KERNEL);
  418. if (!info)
  419. return NULL;
  420. memset(info, 0, sizeof(*info));
  421. link = &info->link;
  422. link->priv = info;
  423. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  424. link->io.NumPorts1 = 8;
  425. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  426. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  427. link->irq.Handler = dtl1_interrupt;
  428. link->irq.Instance = info;
  429. link->conf.Attributes = CONF_ENABLE_IRQ;
  430. link->conf.Vcc = 50;
  431. link->conf.IntType = INT_MEMORY_AND_IO;
  432. /* Register with Card Services */
  433. link->next = dev_list;
  434. dev_list = link;
  435. client_reg.dev_info = &dev_info;
  436. client_reg.EventMask =
  437. CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
  438. CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
  439. CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
  440. client_reg.event_handler = &dtl1_event;
  441. client_reg.Version = 0x0210;
  442. client_reg.event_callback_args.client_data = link;
  443. ret = pcmcia_register_client(&link->handle, &client_reg);
  444. if (ret != CS_SUCCESS) {
  445. cs_error(link->handle, RegisterClient, ret);
  446. dtl1_detach(link);
  447. return NULL;
  448. }
  449. return link;
  450. }
  451. static void dtl1_detach(dev_link_t *link)
  452. {
  453. dtl1_info_t *info = link->priv;
  454. dev_link_t **linkp;
  455. int ret;
  456. /* Locate device structure */
  457. for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
  458. if (*linkp == link)
  459. break;
  460. if (*linkp == NULL)
  461. return;
  462. if (link->state & DEV_CONFIG)
  463. dtl1_release(link);
  464. if (link->handle) {
  465. ret = pcmcia_deregister_client(link->handle);
  466. if (ret != CS_SUCCESS)
  467. cs_error(link->handle, DeregisterClient, ret);
  468. }
  469. /* Unlink device structure, free bits */
  470. *linkp = link->next;
  471. kfree(info);
  472. }
  473. static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
  474. {
  475. int i;
  476. i = pcmcia_get_tuple_data(handle, tuple);
  477. if (i != CS_SUCCESS)
  478. return i;
  479. return pcmcia_parse_tuple(handle, tuple, parse);
  480. }
  481. static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
  482. {
  483. if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
  484. return CS_NO_MORE_ITEMS;
  485. return get_tuple(handle, tuple, parse);
  486. }
  487. static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
  488. {
  489. if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
  490. return CS_NO_MORE_ITEMS;
  491. return get_tuple(handle, tuple, parse);
  492. }
  493. static void dtl1_config(dev_link_t *link)
  494. {
  495. client_handle_t handle = link->handle;
  496. dtl1_info_t *info = link->priv;
  497. tuple_t tuple;
  498. u_short buf[256];
  499. cisparse_t parse;
  500. cistpl_cftable_entry_t *cf = &parse.cftable_entry;
  501. config_info_t config;
  502. int i, last_ret, last_fn;
  503. tuple.TupleData = (cisdata_t *)buf;
  504. tuple.TupleOffset = 0;
  505. tuple.TupleDataMax = 255;
  506. tuple.Attributes = 0;
  507. /* Get configuration register information */
  508. tuple.DesiredTuple = CISTPL_CONFIG;
  509. last_ret = first_tuple(handle, &tuple, &parse);
  510. if (last_ret != CS_SUCCESS) {
  511. last_fn = ParseTuple;
  512. goto cs_failed;
  513. }
  514. link->conf.ConfigBase = parse.config.base;
  515. link->conf.Present = parse.config.rmask[0];
  516. /* Configure card */
  517. link->state |= DEV_CONFIG;
  518. i = pcmcia_get_configuration_info(handle, &config);
  519. link->conf.Vcc = config.Vcc;
  520. tuple.TupleData = (cisdata_t *)buf;
  521. tuple.TupleOffset = 0;
  522. tuple.TupleDataMax = 255;
  523. tuple.Attributes = 0;
  524. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  525. /* Look for a generic full-sized window */
  526. link->io.NumPorts1 = 8;
  527. i = first_tuple(handle, &tuple, &parse);
  528. while (i != CS_NO_MORE_ITEMS) {
  529. if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
  530. link->conf.ConfigIndex = cf->index;
  531. link->io.BasePort1 = cf->io.win[0].base;
  532. link->io.NumPorts1 = cf->io.win[0].len; /*yo */
  533. link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
  534. i = pcmcia_request_io(link->handle, &link->io);
  535. if (i == CS_SUCCESS)
  536. break;
  537. }
  538. i = next_tuple(handle, &tuple, &parse);
  539. }
  540. if (i != CS_SUCCESS) {
  541. cs_error(link->handle, RequestIO, i);
  542. goto failed;
  543. }
  544. i = pcmcia_request_irq(link->handle, &link->irq);
  545. if (i != CS_SUCCESS) {
  546. cs_error(link->handle, RequestIRQ, i);
  547. link->irq.AssignedIRQ = 0;
  548. }
  549. i = pcmcia_request_configuration(link->handle, &link->conf);
  550. if (i != CS_SUCCESS) {
  551. cs_error(link->handle, RequestConfiguration, i);
  552. goto failed;
  553. }
  554. if (dtl1_open(info) != 0)
  555. goto failed;
  556. strcpy(info->node.dev_name, info->hdev->name);
  557. link->dev = &info->node;
  558. link->state &= ~DEV_CONFIG_PENDING;
  559. return;
  560. cs_failed:
  561. cs_error(link->handle, last_fn, last_ret);
  562. failed:
  563. dtl1_release(link);
  564. }
  565. static void dtl1_release(dev_link_t *link)
  566. {
  567. dtl1_info_t *info = link->priv;
  568. if (link->state & DEV_PRESENT)
  569. dtl1_close(info);
  570. link->dev = NULL;
  571. pcmcia_release_configuration(link->handle);
  572. pcmcia_release_io(link->handle, &link->io);
  573. pcmcia_release_irq(link->handle, &link->irq);
  574. link->state &= ~DEV_CONFIG;
  575. }
  576. static int dtl1_event(event_t event, int priority, event_callback_args_t *args)
  577. {
  578. dev_link_t *link = args->client_data;
  579. dtl1_info_t *info = link->priv;
  580. switch (event) {
  581. case CS_EVENT_CARD_REMOVAL:
  582. link->state &= ~DEV_PRESENT;
  583. if (link->state & DEV_CONFIG) {
  584. dtl1_close(info);
  585. dtl1_release(link);
  586. }
  587. break;
  588. case CS_EVENT_CARD_INSERTION:
  589. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  590. dtl1_config(link);
  591. break;
  592. case CS_EVENT_PM_SUSPEND:
  593. link->state |= DEV_SUSPEND;
  594. /* Fall through... */
  595. case CS_EVENT_RESET_PHYSICAL:
  596. if (link->state & DEV_CONFIG)
  597. pcmcia_release_configuration(link->handle);
  598. break;
  599. case CS_EVENT_PM_RESUME:
  600. link->state &= ~DEV_SUSPEND;
  601. /* Fall through... */
  602. case CS_EVENT_CARD_RESET:
  603. if (DEV_OK(link))
  604. pcmcia_request_configuration(link->handle, &link->conf);
  605. break;
  606. }
  607. return 0;
  608. }
  609. static struct pcmcia_device_id dtl1_ids[] = {
  610. PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d),
  611. PCMCIA_DEVICE_PROD_ID12("Socket", "CF", 0xb38bcc2e, 0x44ebf863),
  612. PCMCIA_DEVICE_NULL
  613. };
  614. MODULE_DEVICE_TABLE(pcmcia, dtl1_ids);
  615. static struct pcmcia_driver dtl1_driver = {
  616. .owner = THIS_MODULE,
  617. .drv = {
  618. .name = "dtl1_cs",
  619. },
  620. .attach = dtl1_attach,
  621. .detach = dtl1_detach,
  622. .id_table = dtl1_ids,
  623. };
  624. static int __init init_dtl1_cs(void)
  625. {
  626. return pcmcia_register_driver(&dtl1_driver);
  627. }
  628. static void __exit exit_dtl1_cs(void)
  629. {
  630. pcmcia_unregister_driver(&dtl1_driver);
  631. BUG_ON(dev_list != NULL);
  632. }
  633. module_init(init_dtl1_cs);
  634. module_exit(exit_dtl1_cs);