Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cdc-wdm.c |
| 3 | * |
| 4 | * This driver supports USB CDC WCM Device Management. |
| 5 | * |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 6 | * Copyright (c) 2007-2009 Oliver Neukum |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 7 | * |
| 8 | * Some code taken from cdc-acm.c |
| 9 | * |
| 10 | * Released under the GPLv2. |
| 11 | * |
| 12 | * Many thanks to Carl Nordbeck |
| 13 | */ |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/module.h> |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 18 | #include <linux/mutex.h> |
| 19 | #include <linux/uaccess.h> |
| 20 | #include <linux/bitops.h> |
| 21 | #include <linux/poll.h> |
| 22 | #include <linux/usb.h> |
| 23 | #include <linux/usb/cdc.h> |
| 24 | #include <asm/byteorder.h> |
| 25 | #include <asm/unaligned.h> |
| 26 | |
| 27 | /* |
| 28 | * Version Information |
| 29 | */ |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 30 | #define DRIVER_VERSION "v0.03" |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 31 | #define DRIVER_AUTHOR "Oliver Neukum" |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 32 | #define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management" |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 33 | |
| 34 | static struct usb_device_id wdm_ids[] = { |
| 35 | { |
| 36 | .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS | |
| 37 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, |
| 38 | .bInterfaceClass = USB_CLASS_COMM, |
| 39 | .bInterfaceSubClass = USB_CDC_SUBCLASS_DMM |
| 40 | }, |
| 41 | { } |
| 42 | }; |
| 43 | |
Oliver Neukum | aa5380b | 2008-10-13 14:05:20 +0200 | [diff] [blame] | 44 | MODULE_DEVICE_TABLE (usb, wdm_ids); |
| 45 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 46 | #define WDM_MINOR_BASE 176 |
| 47 | |
| 48 | |
| 49 | #define WDM_IN_USE 1 |
| 50 | #define WDM_DISCONNECTING 2 |
| 51 | #define WDM_RESULT 3 |
| 52 | #define WDM_READ 4 |
| 53 | #define WDM_INT_STALL 5 |
| 54 | #define WDM_POLL_RUNNING 6 |
| 55 | |
| 56 | |
| 57 | #define WDM_MAX 16 |
| 58 | |
| 59 | |
| 60 | static DEFINE_MUTEX(wdm_mutex); |
| 61 | |
| 62 | /* --- method tables --- */ |
| 63 | |
| 64 | struct wdm_device { |
| 65 | u8 *inbuf; /* buffer for response */ |
| 66 | u8 *outbuf; /* buffer for command */ |
| 67 | u8 *sbuf; /* buffer for status */ |
| 68 | u8 *ubuf; /* buffer for copy to user space */ |
| 69 | |
| 70 | struct urb *command; |
| 71 | struct urb *response; |
| 72 | struct urb *validity; |
| 73 | struct usb_interface *intf; |
| 74 | struct usb_ctrlrequest *orq; |
| 75 | struct usb_ctrlrequest *irq; |
| 76 | spinlock_t iuspin; |
| 77 | |
| 78 | unsigned long flags; |
| 79 | u16 bufsize; |
| 80 | u16 wMaxCommand; |
| 81 | u16 wMaxPacketSize; |
| 82 | u16 bMaxPacketSize0; |
| 83 | __le16 inum; |
| 84 | int reslength; |
| 85 | int length; |
| 86 | int read; |
| 87 | int count; |
| 88 | dma_addr_t shandle; |
| 89 | dma_addr_t ihandle; |
| 90 | struct mutex wlock; |
| 91 | struct mutex rlock; |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 92 | struct mutex plock; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 93 | wait_queue_head_t wait; |
| 94 | struct work_struct rxwork; |
| 95 | int werr; |
| 96 | int rerr; |
| 97 | }; |
| 98 | |
| 99 | static struct usb_driver wdm_driver; |
| 100 | |
| 101 | /* --- callbacks --- */ |
| 102 | static void wdm_out_callback(struct urb *urb) |
| 103 | { |
| 104 | struct wdm_device *desc; |
| 105 | desc = urb->context; |
| 106 | spin_lock(&desc->iuspin); |
| 107 | desc->werr = urb->status; |
| 108 | spin_unlock(&desc->iuspin); |
| 109 | clear_bit(WDM_IN_USE, &desc->flags); |
| 110 | kfree(desc->outbuf); |
| 111 | wake_up(&desc->wait); |
| 112 | } |
| 113 | |
| 114 | static void wdm_in_callback(struct urb *urb) |
| 115 | { |
| 116 | struct wdm_device *desc = urb->context; |
| 117 | int status = urb->status; |
| 118 | |
| 119 | spin_lock(&desc->iuspin); |
| 120 | |
| 121 | if (status) { |
| 122 | switch (status) { |
| 123 | case -ENOENT: |
| 124 | dev_dbg(&desc->intf->dev, |
| 125 | "nonzero urb status received: -ENOENT"); |
| 126 | break; |
| 127 | case -ECONNRESET: |
| 128 | dev_dbg(&desc->intf->dev, |
| 129 | "nonzero urb status received: -ECONNRESET"); |
| 130 | break; |
| 131 | case -ESHUTDOWN: |
| 132 | dev_dbg(&desc->intf->dev, |
| 133 | "nonzero urb status received: -ESHUTDOWN"); |
| 134 | break; |
| 135 | case -EPIPE: |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 136 | dev_err(&desc->intf->dev, |
| 137 | "nonzero urb status received: -EPIPE\n"); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 138 | break; |
| 139 | default: |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 140 | dev_err(&desc->intf->dev, |
| 141 | "Unexpected error %d\n", status); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | desc->rerr = status; |
| 147 | desc->reslength = urb->actual_length; |
| 148 | memmove(desc->ubuf + desc->length, desc->inbuf, desc->reslength); |
| 149 | desc->length += desc->reslength; |
| 150 | wake_up(&desc->wait); |
| 151 | |
| 152 | set_bit(WDM_READ, &desc->flags); |
| 153 | spin_unlock(&desc->iuspin); |
| 154 | } |
| 155 | |
| 156 | static void wdm_int_callback(struct urb *urb) |
| 157 | { |
| 158 | int rv = 0; |
| 159 | int status = urb->status; |
| 160 | struct wdm_device *desc; |
| 161 | struct usb_ctrlrequest *req; |
| 162 | struct usb_cdc_notification *dr; |
| 163 | |
| 164 | desc = urb->context; |
| 165 | req = desc->irq; |
| 166 | dr = (struct usb_cdc_notification *)desc->sbuf; |
| 167 | |
| 168 | if (status) { |
| 169 | switch (status) { |
| 170 | case -ESHUTDOWN: |
| 171 | case -ENOENT: |
| 172 | case -ECONNRESET: |
| 173 | return; /* unplug */ |
| 174 | case -EPIPE: |
| 175 | set_bit(WDM_INT_STALL, &desc->flags); |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 176 | dev_err(&desc->intf->dev, "Stall on int endpoint\n"); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 177 | goto sw; /* halt is cleared in work */ |
| 178 | default: |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 179 | dev_err(&desc->intf->dev, |
| 180 | "nonzero urb status received: %d\n", status); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 181 | break; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | if (urb->actual_length < sizeof(struct usb_cdc_notification)) { |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 186 | dev_err(&desc->intf->dev, "wdm_int_callback - %d bytes\n", |
| 187 | urb->actual_length); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 188 | goto exit; |
| 189 | } |
| 190 | |
| 191 | switch (dr->bNotificationType) { |
| 192 | case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: |
| 193 | dev_dbg(&desc->intf->dev, |
| 194 | "NOTIFY_RESPONSE_AVAILABLE received: index %d len %d", |
| 195 | dr->wIndex, dr->wLength); |
| 196 | break; |
| 197 | |
| 198 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: |
| 199 | |
| 200 | dev_dbg(&desc->intf->dev, |
| 201 | "NOTIFY_NETWORK_CONNECTION %s network", |
| 202 | dr->wValue ? "connected to" : "disconnected from"); |
| 203 | goto exit; |
| 204 | default: |
| 205 | clear_bit(WDM_POLL_RUNNING, &desc->flags); |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 206 | dev_err(&desc->intf->dev, |
| 207 | "unknown notification %d received: index %d len %d\n", |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 208 | dr->bNotificationType, dr->wIndex, dr->wLength); |
| 209 | goto exit; |
| 210 | } |
| 211 | |
| 212 | req->bRequestType = (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE); |
| 213 | req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE; |
| 214 | req->wValue = 0; |
| 215 | req->wIndex = desc->inum; |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 216 | req->wLength = cpu_to_le16(desc->wMaxCommand); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 217 | |
| 218 | usb_fill_control_urb( |
| 219 | desc->response, |
| 220 | interface_to_usbdev(desc->intf), |
| 221 | /* using common endpoint 0 */ |
| 222 | usb_rcvctrlpipe(interface_to_usbdev(desc->intf), 0), |
| 223 | (unsigned char *)req, |
| 224 | desc->inbuf, |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 225 | desc->wMaxCommand, |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 226 | wdm_in_callback, |
| 227 | desc |
| 228 | ); |
| 229 | desc->response->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 230 | spin_lock(&desc->iuspin); |
| 231 | clear_bit(WDM_READ, &desc->flags); |
| 232 | if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 233 | rv = usb_submit_urb(desc->response, GFP_ATOMIC); |
| 234 | dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", |
| 235 | __func__, rv); |
| 236 | } |
| 237 | spin_unlock(&desc->iuspin); |
| 238 | if (rv < 0) { |
| 239 | if (rv == -EPERM) |
| 240 | return; |
| 241 | if (rv == -ENOMEM) { |
| 242 | sw: |
| 243 | rv = schedule_work(&desc->rxwork); |
| 244 | if (rv) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 245 | dev_err(&desc->intf->dev, |
| 246 | "Cannot schedule work\n"); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | exit: |
| 250 | rv = usb_submit_urb(urb, GFP_ATOMIC); |
| 251 | if (rv) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 252 | dev_err(&desc->intf->dev, |
| 253 | "%s - usb_submit_urb failed with result %d\n", |
| 254 | __func__, rv); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 255 | |
| 256 | } |
| 257 | |
| 258 | static void kill_urbs(struct wdm_device *desc) |
| 259 | { |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 260 | /* the order here is essential */ |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 261 | usb_kill_urb(desc->command); |
| 262 | usb_kill_urb(desc->validity); |
| 263 | usb_kill_urb(desc->response); |
| 264 | } |
| 265 | |
| 266 | static void free_urbs(struct wdm_device *desc) |
| 267 | { |
| 268 | usb_free_urb(desc->validity); |
| 269 | usb_free_urb(desc->response); |
| 270 | usb_free_urb(desc->command); |
| 271 | } |
| 272 | |
| 273 | static void cleanup(struct wdm_device *desc) |
| 274 | { |
| 275 | usb_buffer_free(interface_to_usbdev(desc->intf), |
| 276 | desc->wMaxPacketSize, |
| 277 | desc->sbuf, |
| 278 | desc->validity->transfer_dma); |
| 279 | usb_buffer_free(interface_to_usbdev(desc->intf), |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 280 | desc->wMaxCommand, |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 281 | desc->inbuf, |
| 282 | desc->response->transfer_dma); |
| 283 | kfree(desc->orq); |
| 284 | kfree(desc->irq); |
| 285 | kfree(desc->ubuf); |
| 286 | free_urbs(desc); |
| 287 | kfree(desc); |
| 288 | } |
| 289 | |
| 290 | static ssize_t wdm_write |
| 291 | (struct file *file, const char __user *buffer, size_t count, loff_t *ppos) |
| 292 | { |
| 293 | u8 *buf; |
| 294 | int rv = -EMSGSIZE, r, we; |
| 295 | struct wdm_device *desc = file->private_data; |
| 296 | struct usb_ctrlrequest *req; |
| 297 | |
| 298 | if (count > desc->wMaxCommand) |
| 299 | count = desc->wMaxCommand; |
| 300 | |
| 301 | spin_lock_irq(&desc->iuspin); |
| 302 | we = desc->werr; |
| 303 | desc->werr = 0; |
| 304 | spin_unlock_irq(&desc->iuspin); |
| 305 | if (we < 0) |
| 306 | return -EIO; |
| 307 | |
| 308 | r = mutex_lock_interruptible(&desc->wlock); /* concurrent writes */ |
| 309 | rv = -ERESTARTSYS; |
| 310 | if (r) |
| 311 | goto outnl; |
| 312 | |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 313 | r = usb_autopm_get_interface(desc->intf); |
| 314 | if (r < 0) |
| 315 | goto outnp; |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 316 | |
| 317 | if (!file->f_flags && O_NONBLOCK) |
| 318 | r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, |
| 319 | &desc->flags)); |
| 320 | else |
| 321 | if (test_bit(WDM_IN_USE, &desc->flags)) |
| 322 | r = -EAGAIN; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 323 | if (r < 0) |
| 324 | goto out; |
| 325 | |
| 326 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 327 | rv = -ENODEV; |
| 328 | goto out; |
| 329 | } |
| 330 | |
| 331 | desc->outbuf = buf = kmalloc(count, GFP_KERNEL); |
| 332 | if (!buf) { |
| 333 | rv = -ENOMEM; |
| 334 | goto out; |
| 335 | } |
| 336 | |
| 337 | r = copy_from_user(buf, buffer, count); |
| 338 | if (r > 0) { |
| 339 | kfree(buf); |
| 340 | rv = -EFAULT; |
| 341 | goto out; |
| 342 | } |
| 343 | |
| 344 | req = desc->orq; |
| 345 | usb_fill_control_urb( |
| 346 | desc->command, |
| 347 | interface_to_usbdev(desc->intf), |
| 348 | /* using common endpoint 0 */ |
| 349 | usb_sndctrlpipe(interface_to_usbdev(desc->intf), 0), |
| 350 | (unsigned char *)req, |
| 351 | buf, |
| 352 | count, |
| 353 | wdm_out_callback, |
| 354 | desc |
| 355 | ); |
| 356 | |
| 357 | req->bRequestType = (USB_DIR_OUT | USB_TYPE_CLASS | |
| 358 | USB_RECIP_INTERFACE); |
| 359 | req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND; |
| 360 | req->wValue = 0; |
| 361 | req->wIndex = desc->inum; |
| 362 | req->wLength = cpu_to_le16(count); |
| 363 | set_bit(WDM_IN_USE, &desc->flags); |
| 364 | |
| 365 | rv = usb_submit_urb(desc->command, GFP_KERNEL); |
| 366 | if (rv < 0) { |
| 367 | kfree(buf); |
| 368 | clear_bit(WDM_IN_USE, &desc->flags); |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 369 | dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 370 | } else { |
| 371 | dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d", |
| 372 | req->wIndex); |
| 373 | } |
| 374 | out: |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 375 | usb_autopm_put_interface(desc->intf); |
| 376 | outnp: |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 377 | mutex_unlock(&desc->wlock); |
| 378 | outnl: |
| 379 | return rv < 0 ? rv : count; |
| 380 | } |
| 381 | |
| 382 | static ssize_t wdm_read |
| 383 | (struct file *file, char __user *buffer, size_t count, loff_t *ppos) |
| 384 | { |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 385 | int rv, cntr = 0; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 386 | int i = 0; |
| 387 | struct wdm_device *desc = file->private_data; |
| 388 | |
| 389 | |
| 390 | rv = mutex_lock_interruptible(&desc->rlock); /*concurrent reads */ |
| 391 | if (rv < 0) |
| 392 | return -ERESTARTSYS; |
| 393 | |
| 394 | if (desc->length == 0) { |
| 395 | desc->read = 0; |
| 396 | retry: |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 397 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 398 | rv = -ENODEV; |
| 399 | goto err; |
| 400 | } |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 401 | i++; |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 402 | if (file->f_flags & O_NONBLOCK) { |
| 403 | if (!test_bit(WDM_READ, &desc->flags)) { |
| 404 | rv = cntr ? cntr : -EAGAIN; |
| 405 | goto err; |
| 406 | } |
| 407 | rv = 0; |
| 408 | } else { |
| 409 | rv = wait_event_interruptible(desc->wait, |
| 410 | test_bit(WDM_READ, &desc->flags)); |
| 411 | } |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 412 | |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 413 | /* may have happened while we slept */ |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 414 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 415 | rv = -ENODEV; |
| 416 | goto err; |
| 417 | } |
| 418 | usb_mark_last_busy(interface_to_usbdev(desc->intf)); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 419 | if (rv < 0) { |
| 420 | rv = -ERESTARTSYS; |
| 421 | goto err; |
| 422 | } |
| 423 | |
| 424 | spin_lock_irq(&desc->iuspin); |
| 425 | |
| 426 | if (desc->rerr) { /* read completed, error happened */ |
| 427 | int t = desc->rerr; |
| 428 | desc->rerr = 0; |
| 429 | spin_unlock_irq(&desc->iuspin); |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 430 | dev_err(&desc->intf->dev, |
| 431 | "reading had resulted in %d\n", t); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 432 | rv = -EIO; |
| 433 | goto err; |
| 434 | } |
| 435 | /* |
| 436 | * recheck whether we've lost the race |
| 437 | * against the completion handler |
| 438 | */ |
| 439 | if (!test_bit(WDM_READ, &desc->flags)) { /* lost race */ |
| 440 | spin_unlock_irq(&desc->iuspin); |
| 441 | goto retry; |
| 442 | } |
| 443 | if (!desc->reslength) { /* zero length read */ |
| 444 | spin_unlock_irq(&desc->iuspin); |
| 445 | goto retry; |
| 446 | } |
| 447 | clear_bit(WDM_READ, &desc->flags); |
| 448 | spin_unlock_irq(&desc->iuspin); |
| 449 | } |
| 450 | |
| 451 | cntr = count > desc->length ? desc->length : count; |
| 452 | rv = copy_to_user(buffer, desc->ubuf, cntr); |
| 453 | if (rv > 0) { |
| 454 | rv = -EFAULT; |
| 455 | goto err; |
| 456 | } |
| 457 | |
| 458 | for (i = 0; i < desc->length - cntr; i++) |
| 459 | desc->ubuf[i] = desc->ubuf[i + cntr]; |
| 460 | |
| 461 | desc->length -= cntr; |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 462 | /* in case we had outstanding data */ |
| 463 | if (!desc->length) |
| 464 | clear_bit(WDM_READ, &desc->flags); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 465 | rv = cntr; |
| 466 | |
| 467 | err: |
| 468 | mutex_unlock(&desc->rlock); |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 469 | if (rv < 0 && rv != -EAGAIN) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 470 | dev_err(&desc->intf->dev, "wdm_read: exit error\n"); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 471 | return rv; |
| 472 | } |
| 473 | |
| 474 | static int wdm_flush(struct file *file, fl_owner_t id) |
| 475 | { |
| 476 | struct wdm_device *desc = file->private_data; |
| 477 | |
| 478 | wait_event(desc->wait, !test_bit(WDM_IN_USE, &desc->flags)); |
| 479 | if (desc->werr < 0) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 480 | dev_err(&desc->intf->dev, "Error in flush path: %d\n", |
| 481 | desc->werr); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 482 | |
| 483 | return desc->werr; |
| 484 | } |
| 485 | |
| 486 | static unsigned int wdm_poll(struct file *file, struct poll_table_struct *wait) |
| 487 | { |
| 488 | struct wdm_device *desc = file->private_data; |
| 489 | unsigned long flags; |
| 490 | unsigned int mask = 0; |
| 491 | |
| 492 | spin_lock_irqsave(&desc->iuspin, flags); |
| 493 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 494 | mask = POLLERR; |
| 495 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 496 | goto desc_out; |
| 497 | } |
| 498 | if (test_bit(WDM_READ, &desc->flags)) |
| 499 | mask = POLLIN | POLLRDNORM; |
| 500 | if (desc->rerr || desc->werr) |
| 501 | mask |= POLLERR; |
| 502 | if (!test_bit(WDM_IN_USE, &desc->flags)) |
| 503 | mask |= POLLOUT | POLLWRNORM; |
| 504 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 505 | |
| 506 | poll_wait(file, &desc->wait, wait); |
| 507 | |
| 508 | desc_out: |
| 509 | return mask; |
| 510 | } |
| 511 | |
| 512 | static int wdm_open(struct inode *inode, struct file *file) |
| 513 | { |
| 514 | int minor = iminor(inode); |
| 515 | int rv = -ENODEV; |
| 516 | struct usb_interface *intf; |
| 517 | struct wdm_device *desc; |
| 518 | |
| 519 | mutex_lock(&wdm_mutex); |
| 520 | intf = usb_find_interface(&wdm_driver, minor); |
| 521 | if (!intf) |
| 522 | goto out; |
| 523 | |
| 524 | desc = usb_get_intfdata(intf); |
| 525 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) |
| 526 | goto out; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 527 | file->private_data = desc; |
| 528 | |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 529 | rv = usb_autopm_get_interface(desc->intf); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 530 | if (rv < 0) { |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 531 | dev_err(&desc->intf->dev, "Error autopm - %d\n", rv); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 532 | goto out; |
| 533 | } |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 534 | intf->needs_remote_wakeup = 1; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 535 | |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 536 | mutex_lock(&desc->plock); |
| 537 | if (!desc->count++) { |
| 538 | rv = usb_submit_urb(desc->validity, GFP_KERNEL); |
| 539 | if (rv < 0) { |
| 540 | desc->count--; |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 541 | dev_err(&desc->intf->dev, |
| 542 | "Error submitting int urb - %d\n", rv); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 543 | } |
| 544 | } else { |
| 545 | rv = 0; |
| 546 | } |
| 547 | mutex_unlock(&desc->plock); |
| 548 | usb_autopm_put_interface(desc->intf); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 549 | out: |
| 550 | mutex_unlock(&wdm_mutex); |
| 551 | return rv; |
| 552 | } |
| 553 | |
| 554 | static int wdm_release(struct inode *inode, struct file *file) |
| 555 | { |
| 556 | struct wdm_device *desc = file->private_data; |
| 557 | |
| 558 | mutex_lock(&wdm_mutex); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 559 | mutex_lock(&desc->plock); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 560 | desc->count--; |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 561 | mutex_unlock(&desc->plock); |
| 562 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 563 | if (!desc->count) { |
| 564 | dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); |
| 565 | kill_urbs(desc); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 566 | if (!test_bit(WDM_DISCONNECTING, &desc->flags)) |
| 567 | desc->intf->needs_remote_wakeup = 0; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 568 | } |
| 569 | mutex_unlock(&wdm_mutex); |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | static const struct file_operations wdm_fops = { |
| 574 | .owner = THIS_MODULE, |
| 575 | .read = wdm_read, |
| 576 | .write = wdm_write, |
| 577 | .open = wdm_open, |
| 578 | .flush = wdm_flush, |
| 579 | .release = wdm_release, |
| 580 | .poll = wdm_poll |
| 581 | }; |
| 582 | |
| 583 | static struct usb_class_driver wdm_class = { |
| 584 | .name = "cdc-wdm%d", |
| 585 | .fops = &wdm_fops, |
| 586 | .minor_base = WDM_MINOR_BASE, |
| 587 | }; |
| 588 | |
| 589 | /* --- error handling --- */ |
| 590 | static void wdm_rxwork(struct work_struct *work) |
| 591 | { |
| 592 | struct wdm_device *desc = container_of(work, struct wdm_device, rxwork); |
| 593 | unsigned long flags; |
| 594 | int rv; |
| 595 | |
| 596 | spin_lock_irqsave(&desc->iuspin, flags); |
| 597 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 598 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 599 | } else { |
| 600 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 601 | rv = usb_submit_urb(desc->response, GFP_KERNEL); |
| 602 | if (rv < 0 && rv != -EPERM) { |
| 603 | spin_lock_irqsave(&desc->iuspin, flags); |
| 604 | if (!test_bit(WDM_DISCONNECTING, &desc->flags)) |
| 605 | schedule_work(&desc->rxwork); |
| 606 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | /* --- hotplug --- */ |
| 612 | |
| 613 | static int wdm_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 614 | { |
| 615 | int rv = -EINVAL; |
| 616 | struct usb_device *udev = interface_to_usbdev(intf); |
| 617 | struct wdm_device *desc; |
| 618 | struct usb_host_interface *iface; |
| 619 | struct usb_endpoint_descriptor *ep; |
| 620 | struct usb_cdc_dmm_desc *dmhd; |
| 621 | u8 *buffer = intf->altsetting->extra; |
| 622 | int buflen = intf->altsetting->extralen; |
| 623 | u16 maxcom = 0; |
| 624 | |
| 625 | if (!buffer) |
| 626 | goto out; |
| 627 | |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 628 | while (buflen > 2) { |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 629 | if (buffer [1] != USB_DT_CS_INTERFACE) { |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 630 | dev_err(&intf->dev, "skipping garbage\n"); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 631 | goto next_desc; |
| 632 | } |
| 633 | |
| 634 | switch (buffer [2]) { |
| 635 | case USB_CDC_HEADER_TYPE: |
| 636 | break; |
| 637 | case USB_CDC_DMM_TYPE: |
| 638 | dmhd = (struct usb_cdc_dmm_desc *)buffer; |
| 639 | maxcom = le16_to_cpu(dmhd->wMaxCommand); |
| 640 | dev_dbg(&intf->dev, |
| 641 | "Finding maximum buffer length: %d", maxcom); |
| 642 | break; |
| 643 | default: |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 644 | dev_err(&intf->dev, |
| 645 | "Ignoring extra header, type %d, length %d\n", |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 646 | buffer[2], buffer[0]); |
| 647 | break; |
| 648 | } |
| 649 | next_desc: |
| 650 | buflen -= buffer[0]; |
| 651 | buffer += buffer[0]; |
| 652 | } |
| 653 | |
| 654 | rv = -ENOMEM; |
| 655 | desc = kzalloc(sizeof(struct wdm_device), GFP_KERNEL); |
| 656 | if (!desc) |
| 657 | goto out; |
| 658 | mutex_init(&desc->wlock); |
| 659 | mutex_init(&desc->rlock); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 660 | mutex_init(&desc->plock); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 661 | spin_lock_init(&desc->iuspin); |
| 662 | init_waitqueue_head(&desc->wait); |
| 663 | desc->wMaxCommand = maxcom; |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 664 | /* this will be expanded and needed in hardware endianness */ |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 665 | desc->inum = cpu_to_le16((u16)intf->cur_altsetting->desc.bInterfaceNumber); |
| 666 | desc->intf = intf; |
| 667 | INIT_WORK(&desc->rxwork, wdm_rxwork); |
| 668 | |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 669 | rv = -EINVAL; |
| 670 | iface = intf->cur_altsetting; |
| 671 | if (iface->desc.bNumEndpoints != 1) |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 672 | goto err; |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 673 | ep = &iface->endpoint[0].desc; |
| 674 | if (!ep || !usb_endpoint_is_int_in(ep)) |
| 675 | goto err; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 676 | |
Al Viro | fa4144b | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 677 | desc->wMaxPacketSize = le16_to_cpu(ep->wMaxPacketSize); |
| 678 | desc->bMaxPacketSize0 = udev->descriptor.bMaxPacketSize0; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 679 | |
| 680 | desc->orq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); |
| 681 | if (!desc->orq) |
| 682 | goto err; |
| 683 | desc->irq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); |
| 684 | if (!desc->irq) |
| 685 | goto err; |
| 686 | |
| 687 | desc->validity = usb_alloc_urb(0, GFP_KERNEL); |
| 688 | if (!desc->validity) |
| 689 | goto err; |
| 690 | |
| 691 | desc->response = usb_alloc_urb(0, GFP_KERNEL); |
| 692 | if (!desc->response) |
| 693 | goto err; |
| 694 | |
| 695 | desc->command = usb_alloc_urb(0, GFP_KERNEL); |
| 696 | if (!desc->command) |
| 697 | goto err; |
| 698 | |
| 699 | desc->ubuf = kmalloc(desc->wMaxCommand, GFP_KERNEL); |
| 700 | if (!desc->ubuf) |
| 701 | goto err; |
| 702 | |
| 703 | desc->sbuf = usb_buffer_alloc(interface_to_usbdev(intf), |
| 704 | desc->wMaxPacketSize, |
| 705 | GFP_KERNEL, |
| 706 | &desc->validity->transfer_dma); |
| 707 | if (!desc->sbuf) |
| 708 | goto err; |
| 709 | |
| 710 | desc->inbuf = usb_buffer_alloc(interface_to_usbdev(intf), |
| 711 | desc->bMaxPacketSize0, |
| 712 | GFP_KERNEL, |
| 713 | &desc->response->transfer_dma); |
| 714 | if (!desc->inbuf) |
| 715 | goto err2; |
| 716 | |
| 717 | usb_fill_int_urb( |
| 718 | desc->validity, |
| 719 | interface_to_usbdev(intf), |
| 720 | usb_rcvintpipe(interface_to_usbdev(intf), ep->bEndpointAddress), |
| 721 | desc->sbuf, |
| 722 | desc->wMaxPacketSize, |
| 723 | wdm_int_callback, |
| 724 | desc, |
| 725 | ep->bInterval |
| 726 | ); |
| 727 | desc->validity->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 728 | |
| 729 | usb_set_intfdata(intf, desc); |
| 730 | rv = usb_register_dev(intf, &wdm_class); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 731 | if (rv < 0) |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 732 | goto err3; |
| 733 | else |
| 734 | dev_info(&intf->dev, "cdc-wdm%d: USB WDM device\n", |
| 735 | intf->minor - WDM_MINOR_BASE); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 736 | out: |
| 737 | return rv; |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 738 | err3: |
| 739 | usb_set_intfdata(intf, NULL); |
| 740 | usb_buffer_free(interface_to_usbdev(desc->intf), |
| 741 | desc->bMaxPacketSize0, |
| 742 | desc->inbuf, |
| 743 | desc->response->transfer_dma); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 744 | err2: |
| 745 | usb_buffer_free(interface_to_usbdev(desc->intf), |
| 746 | desc->wMaxPacketSize, |
| 747 | desc->sbuf, |
| 748 | desc->validity->transfer_dma); |
| 749 | err: |
| 750 | free_urbs(desc); |
| 751 | kfree(desc->ubuf); |
| 752 | kfree(desc->orq); |
| 753 | kfree(desc->irq); |
| 754 | kfree(desc); |
| 755 | return rv; |
| 756 | } |
| 757 | |
| 758 | static void wdm_disconnect(struct usb_interface *intf) |
| 759 | { |
| 760 | struct wdm_device *desc; |
| 761 | unsigned long flags; |
| 762 | |
| 763 | usb_deregister_dev(intf, &wdm_class); |
| 764 | mutex_lock(&wdm_mutex); |
| 765 | desc = usb_get_intfdata(intf); |
| 766 | |
| 767 | /* the spinlock makes sure no new urbs are generated in the callbacks */ |
| 768 | spin_lock_irqsave(&desc->iuspin, flags); |
| 769 | set_bit(WDM_DISCONNECTING, &desc->flags); |
| 770 | set_bit(WDM_READ, &desc->flags); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 771 | /* to terminate pending flushes */ |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 772 | clear_bit(WDM_IN_USE, &desc->flags); |
| 773 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 774 | cancel_work_sync(&desc->rxwork); |
| 775 | kill_urbs(desc); |
| 776 | wake_up_all(&desc->wait); |
| 777 | if (!desc->count) |
| 778 | cleanup(desc); |
| 779 | mutex_unlock(&wdm_mutex); |
| 780 | } |
| 781 | |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 782 | static int wdm_suspend(struct usb_interface *intf, pm_message_t message) |
| 783 | { |
| 784 | struct wdm_device *desc = usb_get_intfdata(intf); |
| 785 | int rv = 0; |
| 786 | |
| 787 | dev_dbg(&desc->intf->dev, "wdm%d_suspend\n", intf->minor); |
| 788 | |
| 789 | mutex_lock(&desc->plock); |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 790 | #ifdef CONFIG_PM |
Alan Stern | 65bfd29 | 2008-11-25 16:39:18 -0500 | [diff] [blame] | 791 | if ((message.event & PM_EVENT_AUTO) && |
| 792 | test_bit(WDM_IN_USE, &desc->flags)) { |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 793 | rv = -EBUSY; |
| 794 | } else { |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 795 | #endif |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 796 | cancel_work_sync(&desc->rxwork); |
| 797 | kill_urbs(desc); |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 798 | #ifdef CONFIG_PM |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 799 | } |
Oliver Neukum | 3575858 | 2008-07-01 19:10:08 +0200 | [diff] [blame] | 800 | #endif |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 801 | mutex_unlock(&desc->plock); |
| 802 | |
| 803 | return rv; |
| 804 | } |
| 805 | |
| 806 | static int recover_from_urb_loss(struct wdm_device *desc) |
| 807 | { |
| 808 | int rv = 0; |
| 809 | |
| 810 | if (desc->count) { |
| 811 | rv = usb_submit_urb(desc->validity, GFP_NOIO); |
| 812 | if (rv < 0) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 813 | dev_err(&desc->intf->dev, |
| 814 | "Error resume submitting int urb - %d\n", rv); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 815 | } |
| 816 | return rv; |
| 817 | } |
| 818 | static int wdm_resume(struct usb_interface *intf) |
| 819 | { |
| 820 | struct wdm_device *desc = usb_get_intfdata(intf); |
| 821 | int rv; |
| 822 | |
| 823 | dev_dbg(&desc->intf->dev, "wdm%d_resume\n", intf->minor); |
| 824 | mutex_lock(&desc->plock); |
| 825 | rv = recover_from_urb_loss(desc); |
| 826 | mutex_unlock(&desc->plock); |
| 827 | return rv; |
| 828 | } |
| 829 | |
| 830 | static int wdm_pre_reset(struct usb_interface *intf) |
| 831 | { |
| 832 | struct wdm_device *desc = usb_get_intfdata(intf); |
| 833 | |
| 834 | mutex_lock(&desc->plock); |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | static int wdm_post_reset(struct usb_interface *intf) |
| 839 | { |
| 840 | struct wdm_device *desc = usb_get_intfdata(intf); |
| 841 | int rv; |
| 842 | |
| 843 | rv = recover_from_urb_loss(desc); |
| 844 | mutex_unlock(&desc->plock); |
| 845 | return 0; |
| 846 | } |
| 847 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 848 | static struct usb_driver wdm_driver = { |
| 849 | .name = "cdc_wdm", |
| 850 | .probe = wdm_probe, |
| 851 | .disconnect = wdm_disconnect, |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 852 | .suspend = wdm_suspend, |
| 853 | .resume = wdm_resume, |
| 854 | .reset_resume = wdm_resume, |
| 855 | .pre_reset = wdm_pre_reset, |
| 856 | .post_reset = wdm_post_reset, |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 857 | .id_table = wdm_ids, |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 858 | .supports_autosuspend = 1, |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 859 | }; |
| 860 | |
| 861 | /* --- low level module stuff --- */ |
| 862 | |
| 863 | static int __init wdm_init(void) |
| 864 | { |
| 865 | int rv; |
| 866 | |
| 867 | rv = usb_register(&wdm_driver); |
| 868 | |
| 869 | return rv; |
| 870 | } |
| 871 | |
| 872 | static void __exit wdm_exit(void) |
| 873 | { |
| 874 | usb_deregister(&wdm_driver); |
| 875 | } |
| 876 | |
| 877 | module_init(wdm_init); |
| 878 | module_exit(wdm_exit); |
| 879 | |
| 880 | MODULE_AUTHOR(DRIVER_AUTHOR); |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 881 | MODULE_DESCRIPTION(DRIVER_DESC); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 882 | MODULE_LICENSE("GPL"); |