Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * A driver for the Omnikey PCMCIA smartcard reader CardMan 4040 |
| 3 | * |
| 4 | * (c) 2000-2004 Omnikey AG (http://www.omnikey.com/) |
| 5 | * |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 6 | * (C) 2005-2006 Harald Welte <laforge@gnumonks.org> |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 12 | * - add class interface for udev device creation |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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> |
Jonathan Corbet | 8b5332f | 2008-06-19 14:34:41 -0600 | [diff] [blame] | 27 | #include <linux/smp_lock.h> |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Dominik Brodowski | dd2e5a1 | 2009-11-03 10:27:34 +0100 | [diff] [blame^] | 42 | #define reader_to_dev(x) (&x->p_dev->dev) |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 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); \ |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 51 | } while (0) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 52 | |
| 53 | static char *version = |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 54 | "OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte"; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 65 | static void reader_release(struct pcmcia_device *link); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 66 | |
| 67 | static int major; |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 68 | static struct class *cmx_class; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 69 | |
| 70 | #define BS_READABLE 0x01 |
| 71 | #define BS_WRITABLE 0x02 |
| 72 | |
| 73 | struct reader_dev { |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 74 | struct pcmcia_device *p_dev; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 87 | static struct pcmcia_device *dev_table[CM_MAX_DEV]; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 88 | |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 89 | #ifndef CM4040_DEBUG |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 90 | #define xoutb outb |
| 91 | #define xinb inb |
| 92 | #else |
| 93 | static inline void xoutb(unsigned char val, unsigned short port) |
| 94 | { |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 95 | pr_debug("outb(val=%.2x,port=%.4x)\n", val, port); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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); |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 104 | pr_debug("%.2x=inb(%.4x)\n", val, port); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 114 | unsigned int obs = xinb(dev->p_dev->io.BasePort1 |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 145 | int iobase = dev->p_dev->io.BasePort1; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | { |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 175 | int iobase = dev->p_dev->io.BasePort1; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 193 | int iobase = dev->p_dev->io.BasePort1; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 223 | int iobase = dev->p_dev->io.BasePort1; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 244 | if (!pcmcia_dev_present(dev->p_dev)) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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); |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 257 | #ifdef CM4040_DEBUG |
| 258 | pr_debug("%lu:%2x ", i, dev->r_buf[i]); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 259 | } |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 260 | pr_debug("\n"); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 261 | #else |
| 262 | } |
| 263 | #endif |
| 264 | |
| 265 | bytes_to_read = 5 + le32_to_cpu(*(__le32 *)&dev->r_buf[1]); |
| 266 | |
Randy Dunlap | e657ea1 | 2009-11-11 09:31:07 -0800 | [diff] [blame] | 267 | DEBUGP(6, dev, "BytesToRead=%zu\n", bytes_to_read); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 268 | |
| 269 | min_bytes_to_read = min(count, bytes_to_read + 5); |
Marcel Holtmann | 059819a | 2007-03-06 22:12:00 +0100 | [diff] [blame] | 270 | min_bytes_to_read = min_t(size_t, min_bytes_to_read, READ_WRITE_BUFFER_SIZE); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 271 | |
Randy Dunlap | e657ea1 | 2009-11-11 09:31:07 -0800 | [diff] [blame] | 272 | DEBUGP(6, dev, "Min=%zu\n", min_bytes_to_read); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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); |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 284 | #ifdef CM4040_DEBUG |
| 285 | pr_debug("%lu:%2x ", i, dev->r_buf[i]); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 286 | } |
Dominik Brodowski | cbf624f | 2009-10-24 15:47:29 +0200 | [diff] [blame] | 287 | pr_debug("\n"); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 325 | int iobase = dev->p_dev->io.BasePort1; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Marcel Holtmann | 059819a | 2007-03-06 22:12:00 +0100 | [diff] [blame] | 337 | if ((count < 5) || (count > READ_WRITE_BUFFER_SIZE)) { |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 348 | if (!pcmcia_dev_present(dev->p_dev)) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 442 | struct pcmcia_device *link; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 443 | int minor = iminor(inode); |
Jonathan Corbet | 8b5332f | 2008-06-19 14:34:41 -0600 | [diff] [blame] | 444 | int ret; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 445 | |
| 446 | if (minor >= CM_MAX_DEV) |
| 447 | return -ENODEV; |
| 448 | |
Jonathan Corbet | 8b5332f | 2008-06-19 14:34:41 -0600 | [diff] [blame] | 449 | lock_kernel(); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 450 | link = dev_table[minor]; |
Jonathan Corbet | 8b5332f | 2008-06-19 14:34:41 -0600 | [diff] [blame] | 451 | if (link == NULL || !pcmcia_dev_present(link)) { |
| 452 | ret = -ENODEV; |
| 453 | goto out; |
| 454 | } |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 455 | |
Jonathan Corbet | 8b5332f | 2008-06-19 14:34:41 -0600 | [diff] [blame] | 456 | if (link->open) { |
| 457 | ret = -EBUSY; |
| 458 | goto out; |
| 459 | } |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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"); |
Jonathan Corbet | 8b5332f | 2008-06-19 14:34:41 -0600 | [diff] [blame] | 466 | ret = -EAGAIN; |
| 467 | goto out; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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"); |
Jonathan Corbet | 8b5332f | 2008-06-19 14:34:41 -0600 | [diff] [blame] | 476 | ret = nonseekable_open(inode, filp); |
| 477 | out: |
| 478 | unlock_kernel(); |
| 479 | return ret; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static int cm4040_close(struct inode *inode, struct file *filp) |
| 483 | { |
| 484 | struct reader_dev *dev = filp->private_data; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 485 | struct pcmcia_device *link; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 507 | static void cm4040_reader_release(struct pcmcia_device *link) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 521 | static int cm4040_config_check(struct pcmcia_device *p_dev, |
| 522 | cistpl_cftable_entry_t *cfg, |
Dominik Brodowski | 8e2fc39 | 2008-08-02 15:30:31 +0200 | [diff] [blame] | 523 | cistpl_cftable_entry_t *dflt, |
Dominik Brodowski | ad913c1 | 2008-08-02 16:12:00 +0200 | [diff] [blame] | 524 | unsigned int vcc, |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 525 | void *priv_data) |
| 526 | { |
| 527 | int rc; |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 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); |
Dominik Brodowski | dd2e5a1 | 2009-11-03 10:27:34 +0100 | [diff] [blame^] | 542 | dev_printk(KERN_INFO, &p_dev->dev, |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 543 | "pcmcia_request_io returned 0x%x\n", rc); |
| 544 | return rc; |
| 545 | } |
| 546 | |
| 547 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 548 | static int reader_config(struct pcmcia_device *link, int devno) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 549 | { |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 550 | struct reader_dev *dev; |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 551 | int fail_rc; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 552 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 553 | link->io.BasePort2 = 0; |
| 554 | link->io.NumPorts2 = 0; |
| 555 | link->io.Attributes2 = 0; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 556 | |
Dominik Brodowski | 84e2d34 | 2008-07-29 08:38:55 +0200 | [diff] [blame] | 557 | if (pcmcia_loop_config(link, cm4040_config_check, NULL)) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 558 | goto cs_release; |
| 559 | |
| 560 | link->conf.IntType = 00000002; |
| 561 | |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 562 | fail_rc = pcmcia_request_configuration(link, &link->conf); |
| 563 | if (fail_rc != 0) { |
Dominik Brodowski | dd2e5a1 | 2009-11-03 10:27:34 +0100 | [diff] [blame^] | 564 | dev_printk(KERN_INFO, &link->dev, |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 574 | dev->node.next = &dev->node; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 580 | return 0; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 581 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 582 | cs_release: |
| 583 | reader_release(link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 584 | return -ENODEV; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 587 | static void reader_release(struct pcmcia_device *link) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 588 | { |
Daniel Ritz | 925796e | 2007-08-10 13:00:58 -0700 | [diff] [blame] | 589 | cm4040_reader_release(link); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 590 | pcmcia_disable_device(link); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 593 | static int reader_probe(struct pcmcia_device *link) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 594 | { |
| 595 | struct reader_dev *dev; |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 596 | int i, ret; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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) |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 604 | return -ENODEV; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 605 | |
| 606 | dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL); |
| 607 | if (dev == NULL) |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 608 | return -ENOMEM; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 609 | |
| 610 | dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT; |
| 611 | dev->buffer_status = 0; |
| 612 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 613 | link->priv = dev; |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 614 | dev->p_dev = link; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 615 | |
| 616 | link->conf.IntType = INT_MEMORY_AND_IO; |
| 617 | dev_table[i] = link; |
| 618 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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); |
Jiri Slaby | 40565f1 | 2007-02-12 00:52:31 -0800 | [diff] [blame] | 623 | setup_timer(&dev->poll_timer, cm4040_do_poll, 0); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 624 | |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 625 | ret = reader_config(link, i); |
Akinobu Mita | 54493c1 | 2007-05-09 02:33:31 -0700 | [diff] [blame] | 626 | if (ret) { |
| 627 | dev_table[i] = NULL; |
| 628 | kfree(dev); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 629 | return ret; |
Akinobu Mita | 54493c1 | 2007-05-09 02:33:31 -0700 | [diff] [blame] | 630 | } |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 631 | |
Greg Kroah-Hartman | 03457cd | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 632 | device_create(cmx_class, NULL, MKDEV(major, i), NULL, "cmx%d", i); |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 633 | |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 634 | return 0; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 637 | static void reader_detach(struct pcmcia_device *link) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 638 | { |
| 639 | struct reader_dev *dev = link->priv; |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 640 | int devno; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 641 | |
| 642 | /* find device */ |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 643 | for (devno = 0; devno < CM_MAX_DEV; devno++) { |
| 644 | if (dev_table[devno] == link) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 645 | break; |
| 646 | } |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 647 | if (devno == CM_MAX_DEV) |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 648 | return; |
| 649 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 650 | reader_release(link); |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 651 | |
| 652 | dev_table[devno] = NULL; |
| 653 | kfree(dev); |
| 654 | |
tonyj@suse.de | 07c015e | 2007-08-07 22:28:44 -0700 | [diff] [blame] | 655 | device_destroy(cmx_class, MKDEV(major, devno)); |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 656 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 657 | return; |
| 658 | } |
| 659 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 660 | static const struct file_operations reader_fops = { |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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 | }, |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 682 | .probe = reader_probe, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 683 | .remove = reader_detach, |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 684 | .id_table = cm4040_ids, |
| 685 | }; |
| 686 | |
| 687 | static int __init cm4040_init(void) |
| 688 | { |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 689 | int rc; |
| 690 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 691 | printk(KERN_INFO "%s\n", version); |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 692 | cmx_class = class_create(THIS_MODULE, "cardman_4040"); |
Akinobu Mita | 5eb5fc9 | 2006-10-17 15:25:59 +0900 | [diff] [blame] | 693 | if (IS_ERR(cmx_class)) |
| 694 | return PTR_ERR(cmx_class); |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 695 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 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"); |
Akinobu Mita | 54493c1 | 2007-05-09 02:33:31 -0700 | [diff] [blame] | 700 | class_destroy(cmx_class); |
Akinobu Mita | 5eb5fc9 | 2006-10-17 15:25:59 +0900 | [diff] [blame] | 701 | return major; |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 702 | } |
Harald Welte | 7fc5b1e | 2006-05-10 13:28:52 +0200 | [diff] [blame] | 703 | |
| 704 | rc = pcmcia_register_driver(&reader_driver); |
| 705 | if (rc < 0) { |
| 706 | unregister_chrdev(major, DEVICE_NAME); |
Akinobu Mita | 54493c1 | 2007-05-09 02:33:31 -0700 | [diff] [blame] | 707 | class_destroy(cmx_class); |
Harald Welte | 7fc5b1e | 2006-05-10 13:28:52 +0200 | [diff] [blame] | 708 | return rc; |
| 709 | } |
| 710 | |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static void __exit cm4040_exit(void) |
| 715 | { |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 716 | printk(KERN_INFO MODULE_NAME ": unloading\n"); |
| 717 | pcmcia_unregister_driver(&reader_driver); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 718 | unregister_chrdev(major, DEVICE_NAME); |
Harald Welte | 67bc620 | 2006-02-14 09:21:26 +0100 | [diff] [blame] | 719 | class_destroy(cmx_class); |
Harald Welte | 77c44ab | 2005-11-13 16:06:26 -0800 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | module_init(cm4040_init); |
| 723 | module_exit(cm4040_exit); |
| 724 | MODULE_LICENSE("Dual BSD/GPL"); |