[PATCH] Char: timers cleanup
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / char / pcmcia / cm4040_cs.c
blob0e82968c2f38ee74c30e6c0a779f365d2c5f5a52
1 /*
2 * A driver for the Omnikey PCMCIA smartcard reader CardMan 4040
4 * (c) 2000-2004 Omnikey AG (http://www.omnikey.com/)
6 * (C) 2005-2006 Harald Welte <laforge@gnumonks.org>
7 * - add support for poll()
8 * - driver cleanup
9 * - add waitqueues
10 * - adhere to linux kernel coding style and policies
11 * - support 2.6.13 "new style" pcmcia interface
12 * - add class interface for udev device creation
14 * The device basically is a USB CCID compliant device that has been
15 * attached to an I/O-Mapped FIFO.
17 * All rights reserved, Dual BSD/GPL Licensed.
20 /* #define PCMCIA_DEBUG 6 */
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/init.h>
26 #include <linux/fs.h>
27 #include <linux/delay.h>
28 #include <linux/poll.h>
29 #include <linux/wait.h>
30 #include <asm/uaccess.h>
31 #include <asm/io.h>
33 #include <pcmcia/cs_types.h>
34 #include <pcmcia/cs.h>
35 #include <pcmcia/cistpl.h>
36 #include <pcmcia/cisreg.h>
37 #include <pcmcia/ciscode.h>
38 #include <pcmcia/ds.h>
40 #include "cm4040_cs.h"
43 #ifdef PCMCIA_DEBUG
44 #define reader_to_dev(x) (&handle_to_dev(x->p_dev->handle))
45 static int pc_debug = PCMCIA_DEBUG;
46 module_param(pc_debug, int, 0600);
47 #define DEBUGP(n, rdr, x, args...) do { \
48 if (pc_debug >= (n)) \
49 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \
50 __FUNCTION__ , ##args); \
51 } while (0)
52 #else
53 #define DEBUGP(n, rdr, x, args...)
54 #endif
56 static char *version =
57 "OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte";
59 #define CCID_DRIVER_BULK_DEFAULT_TIMEOUT (150*HZ)
60 #define CCID_DRIVER_ASYNC_POWERUP_TIMEOUT (35*HZ)
61 #define CCID_DRIVER_MINIMUM_TIMEOUT (3*HZ)
62 #define READ_WRITE_BUFFER_SIZE 512
63 #define POLL_LOOP_COUNT 1000
65 /* how often to poll for fifo status change */
66 #define POLL_PERIOD msecs_to_jiffies(10)
68 static void reader_release(struct pcmcia_device *link);
70 static int major;
71 static struct class *cmx_class;
73 #define BS_READABLE 0x01
74 #define BS_WRITABLE 0x02
76 struct reader_dev {
77 struct pcmcia_device *p_dev;
78 dev_node_t node;
79 wait_queue_head_t devq;
80 wait_queue_head_t poll_wait;
81 wait_queue_head_t read_wait;
82 wait_queue_head_t write_wait;
83 unsigned long buffer_status;
84 unsigned long timeout;
85 unsigned char s_buf[READ_WRITE_BUFFER_SIZE];
86 unsigned char r_buf[READ_WRITE_BUFFER_SIZE];
87 struct timer_list poll_timer;
90 static struct pcmcia_device *dev_table[CM_MAX_DEV];
92 #ifndef PCMCIA_DEBUG
93 #define xoutb outb
94 #define xinb inb
95 #else
96 static inline void xoutb(unsigned char val, unsigned short port)
98 if (pc_debug >= 7)
99 printk(KERN_DEBUG "outb(val=%.2x,port=%.4x)\n", val, port);
100 outb(val, port);
103 static inline unsigned char xinb(unsigned short port)
105 unsigned char val;
107 val = inb(port);
108 if (pc_debug >= 7)
109 printk(KERN_DEBUG "%.2x=inb(%.4x)\n", val, port);
110 return val;
112 #endif
114 /* poll the device fifo status register. not to be confused with
115 * the poll syscall. */
116 static void cm4040_do_poll(unsigned long dummy)
118 struct reader_dev *dev = (struct reader_dev *) dummy;
119 unsigned int obs = xinb(dev->p_dev->io.BasePort1
120 + REG_OFFSET_BUFFER_STATUS);
122 if ((obs & BSR_BULK_IN_FULL)) {
123 set_bit(BS_READABLE, &dev->buffer_status);
124 DEBUGP(4, dev, "waking up read_wait\n");
125 wake_up_interruptible(&dev->read_wait);
126 } else
127 clear_bit(BS_READABLE, &dev->buffer_status);
129 if (!(obs & BSR_BULK_OUT_FULL)) {
130 set_bit(BS_WRITABLE, &dev->buffer_status);
131 DEBUGP(4, dev, "waking up write_wait\n");
132 wake_up_interruptible(&dev->write_wait);
133 } else
134 clear_bit(BS_WRITABLE, &dev->buffer_status);
136 if (dev->buffer_status)
137 wake_up_interruptible(&dev->poll_wait);
139 mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD);
142 static void cm4040_stop_poll(struct reader_dev *dev)
144 del_timer_sync(&dev->poll_timer);
147 static int wait_for_bulk_out_ready(struct reader_dev *dev)
149 int i, rc;
150 int iobase = dev->p_dev->io.BasePort1;
152 for (i = 0; i < POLL_LOOP_COUNT; i++) {
153 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
154 & BSR_BULK_OUT_FULL) == 0) {
155 DEBUGP(4, dev, "BulkOut empty (i=%d)\n", i);
156 return 1;
160 DEBUGP(4, dev, "wait_event_interruptible_timeout(timeout=%ld\n",
161 dev->timeout);
162 rc = wait_event_interruptible_timeout(dev->write_wait,
163 test_and_clear_bit(BS_WRITABLE,
164 &dev->buffer_status),
165 dev->timeout);
167 if (rc > 0)
168 DEBUGP(4, dev, "woke up: BulkOut empty\n");
169 else if (rc == 0)
170 DEBUGP(4, dev, "woke up: BulkOut full, returning 0 :(\n");
171 else if (rc < 0)
172 DEBUGP(4, dev, "woke up: signal arrived\n");
174 return rc;
177 /* Write to Sync Control Register */
178 static int write_sync_reg(unsigned char val, struct reader_dev *dev)
180 int iobase = dev->p_dev->io.BasePort1;
181 int rc;
183 rc = wait_for_bulk_out_ready(dev);
184 if (rc <= 0)
185 return rc;
187 xoutb(val, iobase + REG_OFFSET_SYNC_CONTROL);
188 rc = wait_for_bulk_out_ready(dev);
189 if (rc <= 0)
190 return rc;
192 return 1;
195 static int wait_for_bulk_in_ready(struct reader_dev *dev)
197 int i, rc;
198 int iobase = dev->p_dev->io.BasePort1;
200 for (i = 0; i < POLL_LOOP_COUNT; i++) {
201 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
202 & BSR_BULK_IN_FULL) == BSR_BULK_IN_FULL) {
203 DEBUGP(3, dev, "BulkIn full (i=%d)\n", i);
204 return 1;
208 DEBUGP(4, dev, "wait_event_interruptible_timeout(timeout=%ld\n",
209 dev->timeout);
210 rc = wait_event_interruptible_timeout(dev->read_wait,
211 test_and_clear_bit(BS_READABLE,
212 &dev->buffer_status),
213 dev->timeout);
214 if (rc > 0)
215 DEBUGP(4, dev, "woke up: BulkIn full\n");
216 else if (rc == 0)
217 DEBUGP(4, dev, "woke up: BulkIn not full, returning 0 :(\n");
218 else if (rc < 0)
219 DEBUGP(4, dev, "woke up: signal arrived\n");
221 return rc;
224 static ssize_t cm4040_read(struct file *filp, char __user *buf,
225 size_t count, loff_t *ppos)
227 struct reader_dev *dev = filp->private_data;
228 int iobase = dev->p_dev->io.BasePort1;
229 size_t bytes_to_read;
230 unsigned long i;
231 size_t min_bytes_to_read;
232 int rc;
233 unsigned char uc;
235 DEBUGP(2, dev, "-> cm4040_read(%s,%d)\n", current->comm, current->pid);
237 if (count == 0)
238 return 0;
240 if (count < 10)
241 return -EFAULT;
243 if (filp->f_flags & O_NONBLOCK) {
244 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
245 DEBUGP(2, dev, "<- cm4040_read (failure)\n");
246 return -EAGAIN;
249 if (!pcmcia_dev_present(dev->p_dev))
250 return -ENODEV;
252 for (i = 0; i < 5; i++) {
253 rc = wait_for_bulk_in_ready(dev);
254 if (rc <= 0) {
255 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
256 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
257 if (rc == -ERESTARTSYS)
258 return rc;
259 return -EIO;
261 dev->r_buf[i] = xinb(iobase + REG_OFFSET_BULK_IN);
262 #ifdef PCMCIA_DEBUG
263 if (pc_debug >= 6)
264 printk(KERN_DEBUG "%lu:%2x ", i, dev->r_buf[i]);
266 printk("\n");
267 #else
269 #endif
271 bytes_to_read = 5 + le32_to_cpu(*(__le32 *)&dev->r_buf[1]);
273 DEBUGP(6, dev, "BytesToRead=%lu\n", bytes_to_read);
275 min_bytes_to_read = min(count, bytes_to_read + 5);
277 DEBUGP(6, dev, "Min=%lu\n", min_bytes_to_read);
279 for (i = 0; i < (min_bytes_to_read-5); i++) {
280 rc = wait_for_bulk_in_ready(dev);
281 if (rc <= 0) {
282 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
283 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
284 if (rc == -ERESTARTSYS)
285 return rc;
286 return -EIO;
288 dev->r_buf[i+5] = xinb(iobase + REG_OFFSET_BULK_IN);
289 #ifdef PCMCIA_DEBUG
290 if (pc_debug >= 6)
291 printk(KERN_DEBUG "%lu:%2x ", i, dev->r_buf[i]);
293 printk("\n");
294 #else
296 #endif
298 *ppos = min_bytes_to_read;
299 if (copy_to_user(buf, dev->r_buf, min_bytes_to_read))
300 return -EFAULT;
302 rc = wait_for_bulk_in_ready(dev);
303 if (rc <= 0) {
304 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
305 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
306 if (rc == -ERESTARTSYS)
307 return rc;
308 return -EIO;
311 rc = write_sync_reg(SCR_READER_TO_HOST_DONE, dev);
312 if (rc <= 0) {
313 DEBUGP(5, dev, "write_sync_reg c=%.2x\n", rc);
314 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
315 if (rc == -ERESTARTSYS)
316 return rc;
317 else
318 return -EIO;
321 uc = xinb(iobase + REG_OFFSET_BULK_IN);
323 DEBUGP(2, dev, "<- cm4040_read (successfully)\n");
324 return min_bytes_to_read;
327 static ssize_t cm4040_write(struct file *filp, const char __user *buf,
328 size_t count, loff_t *ppos)
330 struct reader_dev *dev = filp->private_data;
331 int iobase = dev->p_dev->io.BasePort1;
332 ssize_t rc;
333 int i;
334 unsigned int bytes_to_write;
336 DEBUGP(2, dev, "-> cm4040_write(%s,%d)\n", current->comm, current->pid);
338 if (count == 0) {
339 DEBUGP(2, dev, "<- cm4040_write empty read (successfully)\n");
340 return 0;
343 if (count < 5) {
344 DEBUGP(2, dev, "<- cm4040_write buffersize=%Zd < 5\n", count);
345 return -EIO;
348 if (filp->f_flags & O_NONBLOCK) {
349 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
350 DEBUGP(4, dev, "<- cm4040_write (failure)\n");
351 return -EAGAIN;
354 if (!pcmcia_dev_present(dev->p_dev))
355 return -ENODEV;
357 bytes_to_write = count;
358 if (copy_from_user(dev->s_buf, buf, bytes_to_write))
359 return -EFAULT;
361 switch (dev->s_buf[0]) {
362 case CMD_PC_TO_RDR_XFRBLOCK:
363 case CMD_PC_TO_RDR_SECURE:
364 case CMD_PC_TO_RDR_TEST_SECURE:
365 case CMD_PC_TO_RDR_OK_SECURE:
366 dev->timeout = CCID_DRIVER_BULK_DEFAULT_TIMEOUT;
367 break;
369 case CMD_PC_TO_RDR_ICCPOWERON:
370 dev->timeout = CCID_DRIVER_ASYNC_POWERUP_TIMEOUT;
371 break;
373 case CMD_PC_TO_RDR_GETSLOTSTATUS:
374 case CMD_PC_TO_RDR_ICCPOWEROFF:
375 case CMD_PC_TO_RDR_GETPARAMETERS:
376 case CMD_PC_TO_RDR_RESETPARAMETERS:
377 case CMD_PC_TO_RDR_SETPARAMETERS:
378 case CMD_PC_TO_RDR_ESCAPE:
379 case CMD_PC_TO_RDR_ICCCLOCK:
380 default:
381 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
382 break;
385 rc = write_sync_reg(SCR_HOST_TO_READER_START, dev);
386 if (rc <= 0) {
387 DEBUGP(5, dev, "write_sync_reg c=%.2Zx\n", rc);
388 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
389 if (rc == -ERESTARTSYS)
390 return rc;
391 else
392 return -EIO;
395 DEBUGP(4, dev, "start \n");
397 for (i = 0; i < bytes_to_write; i++) {
398 rc = wait_for_bulk_out_ready(dev);
399 if (rc <= 0) {
400 DEBUGP(5, dev, "wait_for_bulk_out_ready rc=%.2Zx\n",
401 rc);
402 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
403 if (rc == -ERESTARTSYS)
404 return rc;
405 else
406 return -EIO;
409 xoutb(dev->s_buf[i],iobase + REG_OFFSET_BULK_OUT);
411 DEBUGP(4, dev, "end\n");
413 rc = write_sync_reg(SCR_HOST_TO_READER_DONE, dev);
415 if (rc <= 0) {
416 DEBUGP(5, dev, "write_sync_reg c=%.2Zx\n", rc);
417 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
418 if (rc == -ERESTARTSYS)
419 return rc;
420 else
421 return -EIO;
424 DEBUGP(2, dev, "<- cm4040_write (successfully)\n");
425 return count;
428 static unsigned int cm4040_poll(struct file *filp, poll_table *wait)
430 struct reader_dev *dev = filp->private_data;
431 unsigned int mask = 0;
433 poll_wait(filp, &dev->poll_wait, wait);
435 if (test_and_clear_bit(BS_READABLE, &dev->buffer_status))
436 mask |= POLLIN | POLLRDNORM;
437 if (test_and_clear_bit(BS_WRITABLE, &dev->buffer_status))
438 mask |= POLLOUT | POLLWRNORM;
440 DEBUGP(2, dev, "<- cm4040_poll(%u)\n", mask);
442 return mask;
445 static int cm4040_open(struct inode *inode, struct file *filp)
447 struct reader_dev *dev;
448 struct pcmcia_device *link;
449 int minor = iminor(inode);
451 if (minor >= CM_MAX_DEV)
452 return -ENODEV;
454 link = dev_table[minor];
455 if (link == NULL || !pcmcia_dev_present(link))
456 return -ENODEV;
458 if (link->open)
459 return -EBUSY;
461 dev = link->priv;
462 filp->private_data = dev;
464 if (filp->f_flags & O_NONBLOCK) {
465 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
466 return -EAGAIN;
469 link->open = 1;
471 dev->poll_timer.data = (unsigned long) dev;
472 mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD);
474 DEBUGP(2, dev, "<- cm4040_open (successfully)\n");
475 return nonseekable_open(inode, filp);
478 static int cm4040_close(struct inode *inode, struct file *filp)
480 struct reader_dev *dev = filp->private_data;
481 struct pcmcia_device *link;
482 int minor = iminor(inode);
484 DEBUGP(2, dev, "-> cm4040_close(maj/min=%d.%d)\n", imajor(inode),
485 iminor(inode));
487 if (minor >= CM_MAX_DEV)
488 return -ENODEV;
490 link = dev_table[minor];
491 if (link == NULL)
492 return -ENODEV;
494 cm4040_stop_poll(dev);
496 link->open = 0;
497 wake_up(&dev->devq);
499 DEBUGP(2, dev, "<- cm4040_close\n");
500 return 0;
503 static void cm4040_reader_release(struct pcmcia_device *link)
505 struct reader_dev *dev = link->priv;
507 DEBUGP(3, dev, "-> cm4040_reader_release\n");
508 while (link->open) {
509 DEBUGP(3, dev, KERN_INFO MODULE_NAME ": delaying release "
510 "until process has terminated\n");
511 wait_event(dev->devq, (link->open == 0));
513 DEBUGP(3, dev, "<- cm4040_reader_release\n");
514 return;
517 static int reader_config(struct pcmcia_device *link, int devno)
519 struct reader_dev *dev;
520 tuple_t tuple;
521 cisparse_t parse;
522 u_char buf[64];
523 int fail_fn, fail_rc;
524 int rc;
526 tuple.Attributes = 0;
527 tuple.TupleData = buf;
528 tuple.TupleDataMax = sizeof(buf);
529 tuple.TupleOffset = 0;
531 link->io.BasePort2 = 0;
532 link->io.NumPorts2 = 0;
533 link->io.Attributes2 = 0;
534 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
535 for (rc = pcmcia_get_first_tuple(link, &tuple);
536 rc == CS_SUCCESS;
537 rc = pcmcia_get_next_tuple(link, &tuple)) {
538 rc = pcmcia_get_tuple_data(link, &tuple);
539 if (rc != CS_SUCCESS)
540 continue;
541 rc = pcmcia_parse_tuple(link, &tuple, &parse);
542 if (rc != CS_SUCCESS)
543 continue;
545 link->conf.ConfigIndex = parse.cftable_entry.index;
547 if (!parse.cftable_entry.io.nwin)
548 continue;
550 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
551 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
552 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
553 if (!(parse.cftable_entry.io.flags & CISTPL_IO_8BIT))
554 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
555 if (!(parse.cftable_entry.io.flags & CISTPL_IO_16BIT))
556 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
557 link->io.IOAddrLines = parse.cftable_entry.io.flags
558 & CISTPL_IO_LINES_MASK;
559 rc = pcmcia_request_io(link, &link->io);
561 dev_printk(KERN_INFO, &handle_to_dev(link), "foo");
562 if (rc == CS_SUCCESS)
563 break;
564 else
565 dev_printk(KERN_INFO, &handle_to_dev(link),
566 "pcmcia_request_io failed 0x%x\n", rc);
568 if (rc != CS_SUCCESS)
569 goto cs_release;
571 link->conf.IntType = 00000002;
573 if ((fail_rc = pcmcia_request_configuration(link,&link->conf))
574 !=CS_SUCCESS) {
575 fail_fn = RequestConfiguration;
576 dev_printk(KERN_INFO, &handle_to_dev(link),
577 "pcmcia_request_configuration failed 0x%x\n",
578 fail_rc);
579 goto cs_release;
582 dev = link->priv;
583 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
584 dev->node.major = major;
585 dev->node.minor = devno;
586 dev->node.next = &dev->node;
588 DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno,
589 link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1);
590 DEBUGP(2, dev, "<- reader_config (succ)\n");
592 return 0;
594 cs_release:
595 reader_release(link);
596 return -ENODEV;
599 static void reader_release(struct pcmcia_device *link)
601 cm4040_reader_release(link->priv);
602 pcmcia_disable_device(link);
605 static int reader_probe(struct pcmcia_device *link)
607 struct reader_dev *dev;
608 int i, ret;
610 for (i = 0; i < CM_MAX_DEV; i++) {
611 if (dev_table[i] == NULL)
612 break;
615 if (i == CM_MAX_DEV)
616 return -ENODEV;
618 dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL);
619 if (dev == NULL)
620 return -ENOMEM;
622 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
623 dev->buffer_status = 0;
625 link->priv = dev;
626 dev->p_dev = link;
628 link->conf.IntType = INT_MEMORY_AND_IO;
629 dev_table[i] = link;
631 init_waitqueue_head(&dev->devq);
632 init_waitqueue_head(&dev->poll_wait);
633 init_waitqueue_head(&dev->read_wait);
634 init_waitqueue_head(&dev->write_wait);
635 setup_timer(&dev->poll_timer, cm4040_do_poll, 0);
637 ret = reader_config(link, i);
638 if (ret)
639 return ret;
641 class_device_create(cmx_class, NULL, MKDEV(major, i), NULL,
642 "cmx%d", i);
644 return 0;
647 static void reader_detach(struct pcmcia_device *link)
649 struct reader_dev *dev = link->priv;
650 int devno;
652 /* find device */
653 for (devno = 0; devno < CM_MAX_DEV; devno++) {
654 if (dev_table[devno] == link)
655 break;
657 if (devno == CM_MAX_DEV)
658 return;
660 reader_release(link);
662 dev_table[devno] = NULL;
663 kfree(dev);
665 class_device_destroy(cmx_class, MKDEV(major, devno));
667 return;
670 static const struct file_operations reader_fops = {
671 .owner = THIS_MODULE,
672 .read = cm4040_read,
673 .write = cm4040_write,
674 .open = cm4040_open,
675 .release = cm4040_close,
676 .poll = cm4040_poll,
679 static struct pcmcia_device_id cm4040_ids[] = {
680 PCMCIA_DEVICE_MANF_CARD(0x0223, 0x0200),
681 PCMCIA_DEVICE_PROD_ID12("OMNIKEY", "CardMan 4040",
682 0xE32CDD8C, 0x8F23318B),
683 PCMCIA_DEVICE_NULL,
685 MODULE_DEVICE_TABLE(pcmcia, cm4040_ids);
687 static struct pcmcia_driver reader_driver = {
688 .owner = THIS_MODULE,
689 .drv = {
690 .name = "cm4040_cs",
692 .probe = reader_probe,
693 .remove = reader_detach,
694 .id_table = cm4040_ids,
697 static int __init cm4040_init(void)
699 int rc;
701 printk(KERN_INFO "%s\n", version);
702 cmx_class = class_create(THIS_MODULE, "cardman_4040");
703 if (IS_ERR(cmx_class))
704 return PTR_ERR(cmx_class);
706 major = register_chrdev(0, DEVICE_NAME, &reader_fops);
707 if (major < 0) {
708 printk(KERN_WARNING MODULE_NAME
709 ": could not get major number\n");
710 return major;
713 rc = pcmcia_register_driver(&reader_driver);
714 if (rc < 0) {
715 unregister_chrdev(major, DEVICE_NAME);
716 return rc;
719 return 0;
722 static void __exit cm4040_exit(void)
724 printk(KERN_INFO MODULE_NAME ": unloading\n");
725 pcmcia_unregister_driver(&reader_driver);
726 unregister_chrdev(major, DEVICE_NAME);
727 class_destroy(cmx_class);
730 module_init(cm4040_init);
731 module_exit(cm4040_exit);
732 MODULE_LICENSE("Dual BSD/GPL");