device create: char: convert device_create to device_create_drvdata
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / char / pcmcia / cm4040_cs.c
blob0b5934bef7a4301049f19c8d82393544742f4a84
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/smp_lock.h>
30 #include <linux/wait.h>
31 #include <asm/uaccess.h>
32 #include <asm/io.h>
34 #include <pcmcia/cs_types.h>
35 #include <pcmcia/cs.h>
36 #include <pcmcia/cistpl.h>
37 #include <pcmcia/cisreg.h>
38 #include <pcmcia/ciscode.h>
39 #include <pcmcia/ds.h>
41 #include "cm4040_cs.h"
44 #ifdef PCMCIA_DEBUG
45 #define reader_to_dev(x) (&handle_to_dev(x->p_dev))
46 static int pc_debug = PCMCIA_DEBUG;
47 module_param(pc_debug, int, 0600);
48 #define DEBUGP(n, rdr, x, args...) do { \
49 if (pc_debug >= (n)) \
50 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \
51 __func__ , ##args); \
52 } while (0)
53 #else
54 #define DEBUGP(n, rdr, x, args...)
55 #endif
57 static char *version =
58 "OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte";
60 #define CCID_DRIVER_BULK_DEFAULT_TIMEOUT (150*HZ)
61 #define CCID_DRIVER_ASYNC_POWERUP_TIMEOUT (35*HZ)
62 #define CCID_DRIVER_MINIMUM_TIMEOUT (3*HZ)
63 #define READ_WRITE_BUFFER_SIZE 512
64 #define POLL_LOOP_COUNT 1000
66 /* how often to poll for fifo status change */
67 #define POLL_PERIOD msecs_to_jiffies(10)
69 static void reader_release(struct pcmcia_device *link);
71 static int major;
72 static struct class *cmx_class;
74 #define BS_READABLE 0x01
75 #define BS_WRITABLE 0x02
77 struct reader_dev {
78 struct pcmcia_device *p_dev;
79 dev_node_t node;
80 wait_queue_head_t devq;
81 wait_queue_head_t poll_wait;
82 wait_queue_head_t read_wait;
83 wait_queue_head_t write_wait;
84 unsigned long buffer_status;
85 unsigned long timeout;
86 unsigned char s_buf[READ_WRITE_BUFFER_SIZE];
87 unsigned char r_buf[READ_WRITE_BUFFER_SIZE];
88 struct timer_list poll_timer;
91 static struct pcmcia_device *dev_table[CM_MAX_DEV];
93 #ifndef PCMCIA_DEBUG
94 #define xoutb outb
95 #define xinb inb
96 #else
97 static inline void xoutb(unsigned char val, unsigned short port)
99 if (pc_debug >= 7)
100 printk(KERN_DEBUG "outb(val=%.2x,port=%.4x)\n", val, port);
101 outb(val, port);
104 static inline unsigned char xinb(unsigned short port)
106 unsigned char val;
108 val = inb(port);
109 if (pc_debug >= 7)
110 printk(KERN_DEBUG "%.2x=inb(%.4x)\n", val, port);
111 return val;
113 #endif
115 /* poll the device fifo status register. not to be confused with
116 * the poll syscall. */
117 static void cm4040_do_poll(unsigned long dummy)
119 struct reader_dev *dev = (struct reader_dev *) dummy;
120 unsigned int obs = xinb(dev->p_dev->io.BasePort1
121 + REG_OFFSET_BUFFER_STATUS);
123 if ((obs & BSR_BULK_IN_FULL)) {
124 set_bit(BS_READABLE, &dev->buffer_status);
125 DEBUGP(4, dev, "waking up read_wait\n");
126 wake_up_interruptible(&dev->read_wait);
127 } else
128 clear_bit(BS_READABLE, &dev->buffer_status);
130 if (!(obs & BSR_BULK_OUT_FULL)) {
131 set_bit(BS_WRITABLE, &dev->buffer_status);
132 DEBUGP(4, dev, "waking up write_wait\n");
133 wake_up_interruptible(&dev->write_wait);
134 } else
135 clear_bit(BS_WRITABLE, &dev->buffer_status);
137 if (dev->buffer_status)
138 wake_up_interruptible(&dev->poll_wait);
140 mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD);
143 static void cm4040_stop_poll(struct reader_dev *dev)
145 del_timer_sync(&dev->poll_timer);
148 static int wait_for_bulk_out_ready(struct reader_dev *dev)
150 int i, rc;
151 int iobase = dev->p_dev->io.BasePort1;
153 for (i = 0; i < POLL_LOOP_COUNT; i++) {
154 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
155 & BSR_BULK_OUT_FULL) == 0) {
156 DEBUGP(4, dev, "BulkOut empty (i=%d)\n", i);
157 return 1;
161 DEBUGP(4, dev, "wait_event_interruptible_timeout(timeout=%ld\n",
162 dev->timeout);
163 rc = wait_event_interruptible_timeout(dev->write_wait,
164 test_and_clear_bit(BS_WRITABLE,
165 &dev->buffer_status),
166 dev->timeout);
168 if (rc > 0)
169 DEBUGP(4, dev, "woke up: BulkOut empty\n");
170 else if (rc == 0)
171 DEBUGP(4, dev, "woke up: BulkOut full, returning 0 :(\n");
172 else if (rc < 0)
173 DEBUGP(4, dev, "woke up: signal arrived\n");
175 return rc;
178 /* Write to Sync Control Register */
179 static int write_sync_reg(unsigned char val, struct reader_dev *dev)
181 int iobase = dev->p_dev->io.BasePort1;
182 int rc;
184 rc = wait_for_bulk_out_ready(dev);
185 if (rc <= 0)
186 return rc;
188 xoutb(val, iobase + REG_OFFSET_SYNC_CONTROL);
189 rc = wait_for_bulk_out_ready(dev);
190 if (rc <= 0)
191 return rc;
193 return 1;
196 static int wait_for_bulk_in_ready(struct reader_dev *dev)
198 int i, rc;
199 int iobase = dev->p_dev->io.BasePort1;
201 for (i = 0; i < POLL_LOOP_COUNT; i++) {
202 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
203 & BSR_BULK_IN_FULL) == BSR_BULK_IN_FULL) {
204 DEBUGP(3, dev, "BulkIn full (i=%d)\n", i);
205 return 1;
209 DEBUGP(4, dev, "wait_event_interruptible_timeout(timeout=%ld\n",
210 dev->timeout);
211 rc = wait_event_interruptible_timeout(dev->read_wait,
212 test_and_clear_bit(BS_READABLE,
213 &dev->buffer_status),
214 dev->timeout);
215 if (rc > 0)
216 DEBUGP(4, dev, "woke up: BulkIn full\n");
217 else if (rc == 0)
218 DEBUGP(4, dev, "woke up: BulkIn not full, returning 0 :(\n");
219 else if (rc < 0)
220 DEBUGP(4, dev, "woke up: signal arrived\n");
222 return rc;
225 static ssize_t cm4040_read(struct file *filp, char __user *buf,
226 size_t count, loff_t *ppos)
228 struct reader_dev *dev = filp->private_data;
229 int iobase = dev->p_dev->io.BasePort1;
230 size_t bytes_to_read;
231 unsigned long i;
232 size_t min_bytes_to_read;
233 int rc;
234 unsigned char uc;
236 DEBUGP(2, dev, "-> cm4040_read(%s,%d)\n", current->comm, current->pid);
238 if (count == 0)
239 return 0;
241 if (count < 10)
242 return -EFAULT;
244 if (filp->f_flags & O_NONBLOCK) {
245 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
246 DEBUGP(2, dev, "<- cm4040_read (failure)\n");
247 return -EAGAIN;
250 if (!pcmcia_dev_present(dev->p_dev))
251 return -ENODEV;
253 for (i = 0; i < 5; i++) {
254 rc = wait_for_bulk_in_ready(dev);
255 if (rc <= 0) {
256 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
257 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
258 if (rc == -ERESTARTSYS)
259 return rc;
260 return -EIO;
262 dev->r_buf[i] = xinb(iobase + REG_OFFSET_BULK_IN);
263 #ifdef PCMCIA_DEBUG
264 if (pc_debug >= 6)
265 printk(KERN_DEBUG "%lu:%2x ", i, dev->r_buf[i]);
267 printk("\n");
268 #else
270 #endif
272 bytes_to_read = 5 + le32_to_cpu(*(__le32 *)&dev->r_buf[1]);
274 DEBUGP(6, dev, "BytesToRead=%lu\n", bytes_to_read);
276 min_bytes_to_read = min(count, bytes_to_read + 5);
277 min_bytes_to_read = min_t(size_t, min_bytes_to_read, READ_WRITE_BUFFER_SIZE);
279 DEBUGP(6, dev, "Min=%lu\n", min_bytes_to_read);
281 for (i = 0; i < (min_bytes_to_read-5); i++) {
282 rc = wait_for_bulk_in_ready(dev);
283 if (rc <= 0) {
284 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
285 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
286 if (rc == -ERESTARTSYS)
287 return rc;
288 return -EIO;
290 dev->r_buf[i+5] = xinb(iobase + REG_OFFSET_BULK_IN);
291 #ifdef PCMCIA_DEBUG
292 if (pc_debug >= 6)
293 printk(KERN_DEBUG "%lu:%2x ", i, dev->r_buf[i]);
295 printk("\n");
296 #else
298 #endif
300 *ppos = min_bytes_to_read;
301 if (copy_to_user(buf, dev->r_buf, min_bytes_to_read))
302 return -EFAULT;
304 rc = wait_for_bulk_in_ready(dev);
305 if (rc <= 0) {
306 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
307 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
308 if (rc == -ERESTARTSYS)
309 return rc;
310 return -EIO;
313 rc = write_sync_reg(SCR_READER_TO_HOST_DONE, dev);
314 if (rc <= 0) {
315 DEBUGP(5, dev, "write_sync_reg c=%.2x\n", rc);
316 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
317 if (rc == -ERESTARTSYS)
318 return rc;
319 else
320 return -EIO;
323 uc = xinb(iobase + REG_OFFSET_BULK_IN);
325 DEBUGP(2, dev, "<- cm4040_read (successfully)\n");
326 return min_bytes_to_read;
329 static ssize_t cm4040_write(struct file *filp, const char __user *buf,
330 size_t count, loff_t *ppos)
332 struct reader_dev *dev = filp->private_data;
333 int iobase = dev->p_dev->io.BasePort1;
334 ssize_t rc;
335 int i;
336 unsigned int bytes_to_write;
338 DEBUGP(2, dev, "-> cm4040_write(%s,%d)\n", current->comm, current->pid);
340 if (count == 0) {
341 DEBUGP(2, dev, "<- cm4040_write empty read (successfully)\n");
342 return 0;
345 if ((count < 5) || (count > READ_WRITE_BUFFER_SIZE)) {
346 DEBUGP(2, dev, "<- cm4040_write buffersize=%Zd < 5\n", count);
347 return -EIO;
350 if (filp->f_flags & O_NONBLOCK) {
351 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
352 DEBUGP(4, dev, "<- cm4040_write (failure)\n");
353 return -EAGAIN;
356 if (!pcmcia_dev_present(dev->p_dev))
357 return -ENODEV;
359 bytes_to_write = count;
360 if (copy_from_user(dev->s_buf, buf, bytes_to_write))
361 return -EFAULT;
363 switch (dev->s_buf[0]) {
364 case CMD_PC_TO_RDR_XFRBLOCK:
365 case CMD_PC_TO_RDR_SECURE:
366 case CMD_PC_TO_RDR_TEST_SECURE:
367 case CMD_PC_TO_RDR_OK_SECURE:
368 dev->timeout = CCID_DRIVER_BULK_DEFAULT_TIMEOUT;
369 break;
371 case CMD_PC_TO_RDR_ICCPOWERON:
372 dev->timeout = CCID_DRIVER_ASYNC_POWERUP_TIMEOUT;
373 break;
375 case CMD_PC_TO_RDR_GETSLOTSTATUS:
376 case CMD_PC_TO_RDR_ICCPOWEROFF:
377 case CMD_PC_TO_RDR_GETPARAMETERS:
378 case CMD_PC_TO_RDR_RESETPARAMETERS:
379 case CMD_PC_TO_RDR_SETPARAMETERS:
380 case CMD_PC_TO_RDR_ESCAPE:
381 case CMD_PC_TO_RDR_ICCCLOCK:
382 default:
383 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
384 break;
387 rc = write_sync_reg(SCR_HOST_TO_READER_START, dev);
388 if (rc <= 0) {
389 DEBUGP(5, dev, "write_sync_reg c=%.2Zx\n", rc);
390 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
391 if (rc == -ERESTARTSYS)
392 return rc;
393 else
394 return -EIO;
397 DEBUGP(4, dev, "start \n");
399 for (i = 0; i < bytes_to_write; i++) {
400 rc = wait_for_bulk_out_ready(dev);
401 if (rc <= 0) {
402 DEBUGP(5, dev, "wait_for_bulk_out_ready rc=%.2Zx\n",
403 rc);
404 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
405 if (rc == -ERESTARTSYS)
406 return rc;
407 else
408 return -EIO;
411 xoutb(dev->s_buf[i],iobase + REG_OFFSET_BULK_OUT);
413 DEBUGP(4, dev, "end\n");
415 rc = write_sync_reg(SCR_HOST_TO_READER_DONE, dev);
417 if (rc <= 0) {
418 DEBUGP(5, dev, "write_sync_reg c=%.2Zx\n", rc);
419 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
420 if (rc == -ERESTARTSYS)
421 return rc;
422 else
423 return -EIO;
426 DEBUGP(2, dev, "<- cm4040_write (successfully)\n");
427 return count;
430 static unsigned int cm4040_poll(struct file *filp, poll_table *wait)
432 struct reader_dev *dev = filp->private_data;
433 unsigned int mask = 0;
435 poll_wait(filp, &dev->poll_wait, wait);
437 if (test_and_clear_bit(BS_READABLE, &dev->buffer_status))
438 mask |= POLLIN | POLLRDNORM;
439 if (test_and_clear_bit(BS_WRITABLE, &dev->buffer_status))
440 mask |= POLLOUT | POLLWRNORM;
442 DEBUGP(2, dev, "<- cm4040_poll(%u)\n", mask);
444 return mask;
447 static int cm4040_open(struct inode *inode, struct file *filp)
449 struct reader_dev *dev;
450 struct pcmcia_device *link;
451 int minor = iminor(inode);
452 int ret;
454 if (minor >= CM_MAX_DEV)
455 return -ENODEV;
457 lock_kernel();
458 link = dev_table[minor];
459 if (link == NULL || !pcmcia_dev_present(link)) {
460 ret = -ENODEV;
461 goto out;
464 if (link->open) {
465 ret = -EBUSY;
466 goto out;
469 dev = link->priv;
470 filp->private_data = dev;
472 if (filp->f_flags & O_NONBLOCK) {
473 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
474 ret = -EAGAIN;
475 goto out;
478 link->open = 1;
480 dev->poll_timer.data = (unsigned long) dev;
481 mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD);
483 DEBUGP(2, dev, "<- cm4040_open (successfully)\n");
484 ret = nonseekable_open(inode, filp);
485 out:
486 unlock_kernel();
487 return ret;
490 static int cm4040_close(struct inode *inode, struct file *filp)
492 struct reader_dev *dev = filp->private_data;
493 struct pcmcia_device *link;
494 int minor = iminor(inode);
496 DEBUGP(2, dev, "-> cm4040_close(maj/min=%d.%d)\n", imajor(inode),
497 iminor(inode));
499 if (minor >= CM_MAX_DEV)
500 return -ENODEV;
502 link = dev_table[minor];
503 if (link == NULL)
504 return -ENODEV;
506 cm4040_stop_poll(dev);
508 link->open = 0;
509 wake_up(&dev->devq);
511 DEBUGP(2, dev, "<- cm4040_close\n");
512 return 0;
515 static void cm4040_reader_release(struct pcmcia_device *link)
517 struct reader_dev *dev = link->priv;
519 DEBUGP(3, dev, "-> cm4040_reader_release\n");
520 while (link->open) {
521 DEBUGP(3, dev, KERN_INFO MODULE_NAME ": delaying release "
522 "until process has terminated\n");
523 wait_event(dev->devq, (link->open == 0));
525 DEBUGP(3, dev, "<- cm4040_reader_release\n");
526 return;
529 static int reader_config(struct pcmcia_device *link, int devno)
531 struct reader_dev *dev;
532 tuple_t tuple;
533 cisparse_t parse;
534 u_char buf[64];
535 int fail_fn, fail_rc;
536 int rc;
538 tuple.Attributes = 0;
539 tuple.TupleData = buf;
540 tuple.TupleDataMax = sizeof(buf);
541 tuple.TupleOffset = 0;
543 link->io.BasePort2 = 0;
544 link->io.NumPorts2 = 0;
545 link->io.Attributes2 = 0;
546 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
547 for (rc = pcmcia_get_first_tuple(link, &tuple);
548 rc == CS_SUCCESS;
549 rc = pcmcia_get_next_tuple(link, &tuple)) {
550 rc = pcmcia_get_tuple_data(link, &tuple);
551 if (rc != CS_SUCCESS)
552 continue;
553 rc = pcmcia_parse_tuple(link, &tuple, &parse);
554 if (rc != CS_SUCCESS)
555 continue;
557 link->conf.ConfigIndex = parse.cftable_entry.index;
559 if (!parse.cftable_entry.io.nwin)
560 continue;
562 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
563 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
564 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
565 if (!(parse.cftable_entry.io.flags & CISTPL_IO_8BIT))
566 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
567 if (!(parse.cftable_entry.io.flags & CISTPL_IO_16BIT))
568 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
569 link->io.IOAddrLines = parse.cftable_entry.io.flags
570 & CISTPL_IO_LINES_MASK;
571 rc = pcmcia_request_io(link, &link->io);
573 dev_printk(KERN_INFO, &handle_to_dev(link), "foo");
574 if (rc == CS_SUCCESS)
575 break;
576 else
577 dev_printk(KERN_INFO, &handle_to_dev(link),
578 "pcmcia_request_io failed 0x%x\n", rc);
580 if (rc != CS_SUCCESS)
581 goto cs_release;
583 link->conf.IntType = 00000002;
585 if ((fail_rc = pcmcia_request_configuration(link,&link->conf))
586 !=CS_SUCCESS) {
587 fail_fn = RequestConfiguration;
588 dev_printk(KERN_INFO, &handle_to_dev(link),
589 "pcmcia_request_configuration failed 0x%x\n",
590 fail_rc);
591 goto cs_release;
594 dev = link->priv;
595 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
596 dev->node.major = major;
597 dev->node.minor = devno;
598 dev->node.next = &dev->node;
600 DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno,
601 link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1);
602 DEBUGP(2, dev, "<- reader_config (succ)\n");
604 return 0;
606 cs_release:
607 reader_release(link);
608 return -ENODEV;
611 static void reader_release(struct pcmcia_device *link)
613 cm4040_reader_release(link);
614 pcmcia_disable_device(link);
617 static int reader_probe(struct pcmcia_device *link)
619 struct reader_dev *dev;
620 int i, ret;
622 for (i = 0; i < CM_MAX_DEV; i++) {
623 if (dev_table[i] == NULL)
624 break;
627 if (i == CM_MAX_DEV)
628 return -ENODEV;
630 dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL);
631 if (dev == NULL)
632 return -ENOMEM;
634 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
635 dev->buffer_status = 0;
637 link->priv = dev;
638 dev->p_dev = link;
640 link->conf.IntType = INT_MEMORY_AND_IO;
641 dev_table[i] = link;
643 init_waitqueue_head(&dev->devq);
644 init_waitqueue_head(&dev->poll_wait);
645 init_waitqueue_head(&dev->read_wait);
646 init_waitqueue_head(&dev->write_wait);
647 setup_timer(&dev->poll_timer, cm4040_do_poll, 0);
649 ret = reader_config(link, i);
650 if (ret) {
651 dev_table[i] = NULL;
652 kfree(dev);
653 return ret;
656 device_create_drvdata(cmx_class, NULL, MKDEV(major, i), NULL,
657 "cmx%d", i);
659 return 0;
662 static void reader_detach(struct pcmcia_device *link)
664 struct reader_dev *dev = link->priv;
665 int devno;
667 /* find device */
668 for (devno = 0; devno < CM_MAX_DEV; devno++) {
669 if (dev_table[devno] == link)
670 break;
672 if (devno == CM_MAX_DEV)
673 return;
675 reader_release(link);
677 dev_table[devno] = NULL;
678 kfree(dev);
680 device_destroy(cmx_class, MKDEV(major, devno));
682 return;
685 static const struct file_operations reader_fops = {
686 .owner = THIS_MODULE,
687 .read = cm4040_read,
688 .write = cm4040_write,
689 .open = cm4040_open,
690 .release = cm4040_close,
691 .poll = cm4040_poll,
694 static struct pcmcia_device_id cm4040_ids[] = {
695 PCMCIA_DEVICE_MANF_CARD(0x0223, 0x0200),
696 PCMCIA_DEVICE_PROD_ID12("OMNIKEY", "CardMan 4040",
697 0xE32CDD8C, 0x8F23318B),
698 PCMCIA_DEVICE_NULL,
700 MODULE_DEVICE_TABLE(pcmcia, cm4040_ids);
702 static struct pcmcia_driver reader_driver = {
703 .owner = THIS_MODULE,
704 .drv = {
705 .name = "cm4040_cs",
707 .probe = reader_probe,
708 .remove = reader_detach,
709 .id_table = cm4040_ids,
712 static int __init cm4040_init(void)
714 int rc;
716 printk(KERN_INFO "%s\n", version);
717 cmx_class = class_create(THIS_MODULE, "cardman_4040");
718 if (IS_ERR(cmx_class))
719 return PTR_ERR(cmx_class);
721 major = register_chrdev(0, DEVICE_NAME, &reader_fops);
722 if (major < 0) {
723 printk(KERN_WARNING MODULE_NAME
724 ": could not get major number\n");
725 class_destroy(cmx_class);
726 return major;
729 rc = pcmcia_register_driver(&reader_driver);
730 if (rc < 0) {
731 unregister_chrdev(major, DEVICE_NAME);
732 class_destroy(cmx_class);
733 return rc;
736 return 0;
739 static void __exit cm4040_exit(void)
741 printk(KERN_INFO MODULE_NAME ": unloading\n");
742 pcmcia_unregister_driver(&reader_driver);
743 unregister_chrdev(major, DEVICE_NAME);
744 class_destroy(cmx_class);
747 module_init(cm4040_init);
748 module_exit(cm4040_exit);
749 MODULE_LICENSE("Dual BSD/GPL");