• source navigation • diff markup • identifier search • freetext search •
Version: 2.6.24 2.6.25 2.6.26 2.6.27 2.6.28 2.6.29 2.6.30 2.6.31 2.6.32 2.6.33 2.6.34-rc1
Architecture: x86 arm avr32 blackfin m68k m68knommu microblaze mips powerpc sh
1 /* 2 * A driver for the Omnikey PCMCIA smartcard reader CardMan 4040 3 * 4 * (c) 2000-2004 Omnikey AG (http://www.omnikey.com/) 5 * 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 13 * 14 * The device basically is a USB CCID compliant device that has been 15 * attached to an I/O-Mapped FIFO. 16 * 17 * All rights reserved, Dual BSD/GPL Licensed. 18 */ 19 20 #include <linux/kernel.h> 21 #include <linux/module.h> 22 #include <linux/slab.h> 23 #include <linux/init.h> 24 #include <linux/fs.h> 25 #include <linux/delay.h> 26 #include <linux/poll.h> 27 #include <linux/smp_lock.h> 28 #include <linux/wait.h> 29 #include <asm/uaccess.h> 30 #include <asm/io.h> 31 32 #include <pcmcia/cs_types.h> 33 #include <pcmcia/cs.h> 34 #include <pcmcia/cistpl.h> 35 #include <pcmcia/cisreg.h> 36 #include <pcmcia/ciscode.h> 37 #include <pcmcia/ds.h> 38 39 #include "cm4040_cs.h" 40 41 42 #define reader_to_dev(x) (&x->p_dev->dev) 43 44 /* n (debug level) is ignored */ 45 /* additional debug output may be enabled by re-compiling with 46 * CM4040_DEBUG set */ 47 /* #define CM4040_DEBUG */ 48 #define DEBUGP(n, rdr, x, args...) do { \ 49 dev_dbg(reader_to_dev(rdr), "%s:" x, \ 50 __func__ , ## args); \ 51 } while (0) 52 53 static char *version = 54 "OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte"; 55 56 #define CCID_DRIVER_BULK_DEFAULT_TIMEOUT (150*HZ) 57 #define CCID_DRIVER_ASYNC_POWERUP_TIMEOUT (35*HZ) 58 #define CCID_DRIVER_MINIMUM_TIMEOUT (3*HZ) 59 #define READ_WRITE_BUFFER_SIZE 512 60 #define POLL_LOOP_COUNT 1000 61 62 /* how often to poll for fifo status change */ 63 #define POLL_PERIOD msecs_to_jiffies(10) 64 65 static void reader_release(struct pcmcia_device *link); 66 67 static int major; 68 static struct class *cmx_class; 69 70 #define BS_READABLE 0x01 71 #define BS_WRITABLE 0x02 72 73 struct reader_dev { 74 struct pcmcia_device *p_dev; 75 dev_node_t node; 76 wait_queue_head_t devq; 77 wait_queue_head_t poll_wait; 78 wait_queue_head_t read_wait; 79 wait_queue_head_t write_wait; 80 unsigned long buffer_status; 81 unsigned long timeout; 82 unsigned char s_buf[READ_WRITE_BUFFER_SIZE]; 83 unsigned char r_buf[READ_WRITE_BUFFER_SIZE]; 84 struct timer_list poll_timer; 85 }; 86 87 static struct pcmcia_device *dev_table[CM_MAX_DEV]; 88 89 #ifndef CM4040_DEBUG 90 #define xoutb outb 91 #define xinb inb 92 #else 93 static inline void xoutb(unsigned char val, unsigned short port) 94 { 95 pr_debug("outb(val=%.2x,port=%.4x)\n", val, port); 96 outb(val, port); 97 } 98 99 static inline unsigned char xinb(unsigned short port) 100 { 101 unsigned char val; 102 103 val = inb(port); 104 pr_debug("%.2x=inb(%.4x)\n", val, port); 105 return val; 106 } 107 #endif 108 109 /* poll the device fifo status register. not to be confused with 110 * the poll syscall. */ 111 static void cm4040_do_poll(unsigned long dummy) 112 { 113 struct reader_dev *dev = (struct reader_dev *) dummy; 114 unsigned int obs = xinb(dev->p_dev->io.BasePort1 115 + REG_OFFSET_BUFFER_STATUS); 116 117 if ((obs & BSR_BULK_IN_FULL)) { 118 set_bit(BS_READABLE, &dev->buffer_status); 119 DEBUGP(4, dev, "waking up read_wait\n"); 120 wake_up_interruptible(&dev->read_wait); 121 } else 122 clear_bit(BS_READABLE, &dev->buffer_status); 123 124 if (!(obs & BSR_BULK_OUT_FULL)) { 125 set_bit(BS_WRITABLE, &dev->buffer_status); 126 DEBUGP(4, dev, "waking up write_wait\n"); 127 wake_up_interruptible(&dev->write_wait); 128 } else 129 clear_bit(BS_WRITABLE, &dev->buffer_status); 130 131 if (dev->buffer_status) 132 wake_up_interruptible(&dev->poll_wait); 133 134 mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD); 135 } 136 137 static void cm4040_stop_poll(struct reader_dev *dev) 138 { 139 del_timer_sync(&dev->poll_timer); 140 } 141 142 static int wait_for_bulk_out_ready(struct reader_dev *dev) 143 { 144 int i, rc; 145 int iobase = dev->p_dev->io.BasePort1; 146 147 for (i = 0; i < POLL_LOOP_COUNT; i++) { 148 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS) 149 & BSR_BULK_OUT_FULL) == 0) { 150 DEBUGP(4, dev, "BulkOut empty (i=%d)\n", i); 151 return 1; 152 } 153 } 154 155 DEBUGP(4, dev, "wait_event_interruptible_timeout(timeout=%ld\n", 156 dev->timeout); 157 rc = wait_event_interruptible_timeout(dev->write_wait, 158 test_and_clear_bit(BS_WRITABLE, 159 &dev->buffer_status), 160 dev->timeout); 161 162 if (rc > 0) 163 DEBUGP(4, dev, "woke up: BulkOut empty\n"); 164 else if (rc == 0) 165 DEBUGP(4, dev, "woke up: BulkOut full, returning 0 :(\n"); 166 else if (rc < 0) 167 DEBUGP(4, dev, "woke up: signal arrived\n"); 168 169 return rc; 170 } 171 172 /* Write to Sync Control Register */ 173 static int write_sync_reg(unsigned char val, struct reader_dev *dev) 174 { 175 int iobase = dev->p_dev->io.BasePort1; 176 int rc; 177 178 rc = wait_for_bulk_out_ready(dev); 179 if (rc <= 0) 180 return rc; 181 182 xoutb(val, iobase + REG_OFFSET_SYNC_CONTROL); 183 rc = wait_for_bulk_out_ready(dev); 184 if (rc <= 0) 185 return rc; 186 187 return 1; 188 } 189 190 static int wait_for_bulk_in_ready(struct reader_dev *dev) 191 { 192 int i, rc; 193 int iobase = dev->p_dev->io.BasePort1; 194 195 for (i = 0; i < POLL_LOOP_COUNT; i++) { 196 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS) 197 & BSR_BULK_IN_FULL) == BSR_BULK_IN_FULL) { 198 DEBUGP(3, dev, "BulkIn full (i=%d)\n", i); 199 return 1; 200 } 201 } 202 203 DEBUGP(4, dev, "wait_event_interruptible_timeout(timeout=%ld\n", 204 dev->timeout); 205 rc = wait_event_interruptible_timeout(dev->read_wait, 206 test_and_clear_bit(BS_READABLE, 207 &dev->buffer_status), 208 dev->timeout); 209 if (rc > 0) 210 DEBUGP(4, dev, "woke up: BulkIn full\n"); 211 else if (rc == 0) 212 DEBUGP(4, dev, "woke up: BulkIn not full, returning 0 :(\n"); 213 else if (rc < 0) 214 DEBUGP(4, dev, "woke up: signal arrived\n"); 215 216 return rc; 217 } 218 219 static ssize_t cm4040_read(struct file *filp, char __user *buf, 220 size_t count, loff_t *ppos) 221 { 222 struct reader_dev *dev = filp->private_data; 223 int iobase = dev->p_dev->io.BasePort1; 224 size_t bytes_to_read; 225 unsigned long i; 226 size_t min_bytes_to_read; 227 int rc; 228 unsigned char uc; 229 230 DEBUGP(2, dev, "-> cm4040_read(%s,%d)\n", current->comm, current->pid); 231 232 if (count == 0) 233 return 0; 234 235 if (count < 10) 236 return -EFAULT; 237 238 if (filp->f_flags & O_NONBLOCK) { 239 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n"); 240 DEBUGP(2, dev, "<- cm4040_read (failure)\n"); 241 return -EAGAIN; 242 } 243 244 if (!pcmcia_dev_present(dev->p_dev)) 245 return -ENODEV; 246 247 for (i = 0; i < 5; i++) { 248 rc = wait_for_bulk_in_ready(dev); 249 if (rc <= 0) { 250 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc); 251 DEBUGP(2, dev, "<- cm4040_read (failed)\n"); 252 if (rc == -ERESTARTSYS) 253 return rc; 254 return -EIO; 255 } 256 dev->r_buf[i] = xinb(iobase + REG_OFFSET_BULK_IN); 257 #ifdef CM4040_DEBUG 258 pr_debug("%lu:%2x ", i, dev->r_buf[i]); 259 } 260 pr_debug("\n"); 261 #else 262 } 263 #endif 264 265 bytes_to_read = 5 + le32_to_cpu(*(__le32 *)&dev->r_buf[1]); 266 267 DEBUGP(6, dev, "BytesToRead=%zu\n", bytes_to_read); 268 269 min_bytes_to_read = min(count, bytes_to_read + 5); 270 min_bytes_to_read = min_t(size_t, min_bytes_to_read, READ_WRITE_BUFFER_SIZE); 271 272 DEBUGP(6, dev, "Min=%zu\n", min_bytes_to_read); 273 274 for (i = 0; i < (min_bytes_to_read-5); i++) { 275 rc = wait_for_bulk_in_ready(dev); 276 if (rc <= 0) { 277 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc); 278 DEBUGP(2, dev, "<- cm4040_read (failed)\n"); 279 if (rc == -ERESTARTSYS) 280 return rc; 281 return -EIO; 282 } 283 dev->r_buf[i+5] = xinb(iobase + REG_OFFSET_BULK_IN); 284 #ifdef CM4040_DEBUG 285 pr_debug("%lu:%2x ", i, dev->r_buf[i]); 286 } 287 pr_debug("\n"); 288 #else 289 } 290 #endif 291 292 *ppos = min_bytes_to_read; 293 if (copy_to_user(buf, dev->r_buf, min_bytes_to_read)) 294 return -EFAULT; 295 296 rc = wait_for_bulk_in_ready(dev); 297 if (rc <= 0) { 298 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc); 299 DEBUGP(2, dev, "<- cm4040_read (failed)\n"); 300 if (rc == -ERESTARTSYS) 301 return rc; 302 return -EIO; 303 } 304 305 rc = write_sync_reg(SCR_READER_TO_HOST_DONE, dev); 306 if (rc <= 0) { 307 DEBUGP(5, dev, "write_sync_reg c=%.2x\n", rc); 308 DEBUGP(2, dev, "<- cm4040_read (failed)\n"); 309 if (rc == -ERESTARTSYS) 310 return rc; 311 else 312 return -EIO; 313 } 314 315 uc = xinb(iobase + REG_OFFSET_BULK_IN); 316 317 DEBUGP(2, dev, "<- cm4040_read (successfully)\n"); 318 return min_bytes_to_read; 319 } 320 321 static ssize_t cm4040_write(struct file *filp, const char __user *buf, 322 size_t count, loff_t *ppos) 323 { 324 struct reader_dev *dev = filp->private_data; 325 int iobase = dev->p_dev->io.BasePort1; 326 ssize_t rc; 327 int i; 328 unsigned int bytes_to_write; 329 330 DEBUGP(2, dev, "-> cm4040_write(%s,%d)\n", current->comm, current->pid); 331 332 if (count == 0) { 333 DEBUGP(2, dev, "<- cm4040_write empty read (successfully)\n"); 334 return 0; 335 } 336 337 if ((count < 5) || (count > READ_WRITE_BUFFER_SIZE)) { 338 DEBUGP(2, dev, "<- cm4040_write buffersize=%Zd < 5\n", count); 339 return -EIO; 340 } 341 342 if (filp->f_flags & O_NONBLOCK) { 343 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n"); 344 DEBUGP(4, dev, "<- cm4040_write (failure)\n"); 345 return -EAGAIN; 346 } 347 348 if (!pcmcia_dev_present(dev->p_dev)) 349 return -ENODEV; 350 351 bytes_to_write = count; 352 if (copy_from_user(dev->s_buf, buf, bytes_to_write)) 353 return -EFAULT; 354 355 switch (dev->s_buf[0]) { 356 case CMD_PC_TO_RDR_XFRBLOCK: 357 case CMD_PC_TO_RDR_SECURE: 358 case CMD_PC_TO_RDR_TEST_SECURE: 359 case CMD_PC_TO_RDR_OK_SECURE: 360 dev->timeout = CCID_DRIVER_BULK_DEFAULT_TIMEOUT; 361 break; 362 363 case CMD_PC_TO_RDR_ICCPOWERON: 364 dev->timeout = CCID_DRIVER_ASYNC_POWERUP_TIMEOUT; 365 break; 366 367 case CMD_PC_TO_RDR_GETSLOTSTATUS: 368 case CMD_PC_TO_RDR_ICCPOWEROFF: 369 case CMD_PC_TO_RDR_GETPARAMETERS: 370 case CMD_PC_TO_RDR_RESETPARAMETERS: 371 case CMD_PC_TO_RDR_SETPARAMETERS: 372 case CMD_PC_TO_RDR_ESCAPE: 373 case CMD_PC_TO_RDR_ICCCLOCK: 374 default: 375 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT; 376 break; 377 } 378 379 rc = write_sync_reg(SCR_HOST_TO_READER_START, dev); 380 if (rc <= 0) { 381 DEBUGP(5, dev, "write_sync_reg c=%.2Zx\n", rc); 382 DEBUGP(2, dev, "<- cm4040_write (failed)\n"); 383 if (rc == -ERESTARTSYS) 384 return rc; 385 else 386 return -EIO; 387 } 388 389 DEBUGP(4, dev, "start \n"); 390 391 for (i = 0; i < bytes_to_write; i++) { 392 rc = wait_for_bulk_out_ready(dev); 393 if (rc <= 0) { 394 DEBUGP(5, dev, "wait_for_bulk_out_ready rc=%.2Zx\n", 395 rc); 396 DEBUGP(2, dev, "<- cm4040_write (failed)\n"); 397 if (rc == -ERESTARTSYS) 398 return rc; 399 else 400 return -EIO; 401 } 402 403 xoutb(dev->s_buf[i],iobase + REG_OFFSET_BULK_OUT); 404 } 405 DEBUGP(4, dev, "end\n"); 406 407 rc = write_sync_reg(SCR_HOST_TO_READER_DONE, dev); 408 409 if (rc <= 0) { 410 DEBUGP(5, dev, "write_sync_reg c=%.2Zx\n", rc); 411 DEBUGP(2, dev, "<- cm4040_write (failed)\n"); 412 if (rc == -ERESTARTSYS) 413 return rc; 414 else 415 return -EIO; 416 } 417 418 DEBUGP(2, dev, "<- cm4040_write (successfully)\n"); 419 return count; 420 } 421 422 static unsigned int cm4040_poll(struct file *filp, poll_table *wait) 423 { 424 struct reader_dev *dev = filp->private_data; 425 unsigned int mask = 0; 426 427 poll_wait(filp, &dev->poll_wait, wait); 428 429 if (test_and_clear_bit(BS_READABLE, &dev->buffer_status)) 430 mask |= POLLIN | POLLRDNORM; 431 if (test_and_clear_bit(BS_WRITABLE, &dev->buffer_status)) 432 mask |= POLLOUT | POLLWRNORM; 433 434 DEBUGP(2, dev, "<- cm4040_poll(%u)\n", mask); 435 436 return mask; 437 } 438 439 static int cm4040_open(struct inode *inode, struct file *filp) 440 { 441 struct reader_dev *dev; 442 struct pcmcia_device *link; 443 int minor = iminor(inode); 444 int ret; 445 446 if (minor >= CM_MAX_DEV) 447 return -ENODEV; 448 449 lock_kernel(); 450 link = dev_table[minor]; 451 if (link == NULL || !pcmcia_dev_present(link)) { 452 ret = -ENODEV; 453 goto out; 454 } 455 456 if (link->open) { 457 ret = -EBUSY; 458 goto out; 459 } 460 461 dev = link->priv; 462 filp->private_data = dev; 463 464 if (filp->f_flags & O_NONBLOCK) { 465 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n"); 466 ret = -EAGAIN; 467 goto out; 468 } 469 470 link->open = 1; 471 472 dev->poll_timer.data = (unsigned long) dev; 473 mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD); 474 475 DEBUGP(2, dev, "<- cm4040_open (successfully)\n"); 476 ret = nonseekable_open(inode, filp); 477 out: 478 unlock_kernel(); 479 return ret; 480 } 481 482 static int cm4040_close(struct inode *inode, struct file *filp) 483 { 484 struct reader_dev *dev = filp->private_data; 485 struct pcmcia_device *link; 486 int minor = iminor(inode); 487 488 DEBUGP(2, dev, "-> cm4040_close(maj/min=%d.%d)\n", imajor(inode), 489 iminor(inode)); 490 491 if (minor >= CM_MAX_DEV) 492 return -ENODEV; 493 494 link = dev_table[minor]; 495 if (link == NULL) 496 return -ENODEV; 497 498 cm4040_stop_poll(dev); 499 500 link->open = 0; 501 wake_up(&dev->devq); 502 503 DEBUGP(2, dev, "<- cm4040_close\n"); 504 return 0; 505 } 506 507 static void cm4040_reader_release(struct pcmcia_device *link) 508 { 509 struct reader_dev *dev = link->priv; 510 511 DEBUGP(3, dev, "-> cm4040_reader_release\n"); 512 while (link->open) { 513 DEBUGP(3, dev, KERN_INFO MODULE_NAME ": delaying release " 514 "until process has terminated\n"); 515 wait_event(dev->devq, (link->open == 0)); 516 } 517 DEBUGP(3, dev, "<- cm4040_reader_release\n"); 518 return; 519 } 520 521 static int cm4040_config_check(struct pcmcia_device *p_dev, 522 cistpl_cftable_entry_t *cfg, 523 cistpl_cftable_entry_t *dflt, 524 unsigned int vcc, 525 void *priv_data) 526 { 527 int rc; 528 if (!cfg->io.nwin) 529 return -ENODEV; 530 531 /* Get the IOaddr */ 532 p_dev->io.BasePort1 = cfg->io.win[0].base; 533 p_dev->io.NumPorts1 = cfg->io.win[0].len; 534 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 535 if (!(cfg->io.flags & CISTPL_IO_8BIT)) 536 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 537 if (!(cfg->io.flags & CISTPL_IO_16BIT)) 538 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 539 p_dev->io.IOAddrLines = cfg->io.flags & CISTPL_IO_LINES_MASK; 540 541 rc = pcmcia_request_io(p_dev, &p_dev->io); 542 dev_printk(KERN_INFO, &p_dev->dev, 543 "pcmcia_request_io returned 0x%x\n", rc); 544 return rc; 545 } 546 547 548 static int reader_config(struct pcmcia_device *link, int devno) 549 { 550 struct reader_dev *dev; 551 int fail_rc; 552 553 link->io.BasePort2 = 0; 554 link->io.NumPorts2 = 0; 555 link->io.Attributes2 = 0; 556 557 if (pcmcia_loop_config(link, cm4040_config_check, NULL)) 558 goto cs_release; 559 560 link->conf.IntType = 00000002; 561 562 fail_rc = pcmcia_request_configuration(link, &link->conf); 563 if (fail_rc != 0) { 564 dev_printk(KERN_INFO, &link->dev, 565 "pcmcia_request_configuration failed 0x%x\n", 566 fail_rc); 567 goto cs_release; 568 } 569 570 dev = link->priv; 571 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno); 572 dev->node.major = major; 573 dev->node.minor = devno; 574 dev->node.next = &dev->node; 575 576 DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno, 577 link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1); 578 DEBUGP(2, dev, "<- reader_config (succ)\n"); 579 580 return 0; 581 582 cs_release: 583 reader_release(link); 584 return -ENODEV; 585 } 586 587 static void reader_release(struct pcmcia_device *link) 588 { 589 cm4040_reader_release(link); 590 pcmcia_disable_device(link); 591 } 592 593 static int reader_probe(struct pcmcia_device *link) 594 { 595 struct reader_dev *dev; 596 int i, ret; 597 598 for (i = 0; i < CM_MAX_DEV; i++) { 599 if (dev_table[i] == NULL) 600 break; 601 } 602 603 if (i == CM_MAX_DEV) 604 return -ENODEV; 605 606 dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL); 607 if (dev == NULL) 608 return -ENOMEM; 609 610 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT; 611 dev->buffer_status = 0; 612 613 link->priv = dev; 614 dev->p_dev = link; 615 616 link->conf.IntType = INT_MEMORY_AND_IO; 617 dev_table[i] = link; 618 619 init_waitqueue_head(&dev->devq); 620 init_waitqueue_head(&dev->poll_wait); 621 init_waitqueue_head(&dev->read_wait); 622 init_waitqueue_head(&dev->write_wait); 623 setup_timer(&dev->poll_timer, cm4040_do_poll, 0); 624 625 ret = reader_config(link, i); 626 if (ret) { 627 dev_table[i] = NULL; 628 kfree(dev); 629 return ret; 630 } 631 632 device_create(cmx_class, NULL, MKDEV(major, i), NULL, "cmx%d", i); 633 634 return 0; 635 } 636 637 static void reader_detach(struct pcmcia_device *link) 638 { 639 struct reader_dev *dev = link->priv; 640 int devno; 641 642 /* find device */ 643 for (devno = 0; devno < CM_MAX_DEV; devno++) { 644 if (dev_table[devno] == link) 645 break; 646 } 647 if (devno == CM_MAX_DEV) 648 return; 649 650 reader_release(link); 651 652 dev_table[devno] = NULL; 653 kfree(dev); 654 655 device_destroy(cmx_class, MKDEV(major, devno)); 656 657 return; 658 } 659 660 static const struct file_operations reader_fops = { 661 .owner = THIS_MODULE, 662 .read = cm4040_read, 663 .write = cm4040_write, 664 .open = cm4040_open, 665 .release = cm4040_close, 666 .poll = cm4040_poll, 667 }; 668 669 static struct pcmcia_device_id cm4040_ids[] = { 670 PCMCIA_DEVICE_MANF_CARD(0x0223, 0x0200), 671 PCMCIA_DEVICE_PROD_ID12("OMNIKEY", "CardMan 4040", 672 0xE32CDD8C, 0x8F23318B), 673 PCMCIA_DEVICE_NULL, 674 }; 675 MODULE_DEVICE_TABLE(pcmcia, cm4040_ids); 676 677 static struct pcmcia_driver reader_driver = { 678 .owner = THIS_MODULE, 679 .drv = { 680 .name = "cm4040_cs", 681 }, 682 .probe = reader_probe, 683 .remove = reader_detach, 684 .id_table = cm4040_ids, 685 }; 686 687 static int __init cm4040_init(void) 688 { 689 int rc; 690 691 printk(KERN_INFO "%s\n", version); 692 cmx_class = class_create(THIS_MODULE, "cardman_4040"); 693 if (IS_ERR(cmx_class)) 694 return PTR_ERR(cmx_class); 695 696 major = register_chrdev(0, DEVICE_NAME, &reader_fops); 697 if (major < 0) { 698 printk(KERN_WARNING MODULE_NAME 699 ": could not get major number\n"); 700 class_destroy(cmx_class); 701 return major; 702 } 703 704 rc = pcmcia_register_driver(&reader_driver); 705 if (rc < 0) { 706 unregister_chrdev(major, DEVICE_NAME); 707 class_destroy(cmx_class); 708 return rc; 709 } 710 711 return 0; 712 } 713 714 static void __exit cm4040_exit(void) 715 { 716 printk(KERN_INFO MODULE_NAME ": unloading\n"); 717 pcmcia_unregister_driver(&reader_driver); 718 unregister_chrdev(major, DEVICE_NAME); 719 class_destroy(cmx_class); 720 } 721 722 module_init(cm4040_init); 723 module_exit(cm4040_exit); 724 MODULE_LICENSE("Dual BSD/GPL"); 725
This page was automatically generated by LXR 0.3.1. • Linux is a registered trademark of Linus Torvalds