dtl1_cs.c 17 KB

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