blob: 8de11deb5d1429dffb16febcd1d834623b59d0c5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -03002 * USB Skeleton driver - 2.2
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -030010 * This driver is based on the 2.6.3 version of drivers/usb/usb-skeleton.c
Alan Stern121e2872006-07-01 22:06:36 -040011 * but has been rewritten to be easier to read and use.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
13 */
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/init.h>
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <linux/kref.h>
21#include <asm/uaccess.h>
22#include <linux/usb.h>
Alan Stern121e2872006-07-01 22:06:36 -040023#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25
26/* Define these values to match your devices */
27#define USB_SKEL_VENDOR_ID 0xfff0
28#define USB_SKEL_PRODUCT_ID 0xfff0
29
30/* table of devices that work with this driver */
31static struct usb_device_id skel_table [] = {
32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
33 { } /* Terminating entry */
34};
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -030035MODULE_DEVICE_TABLE(usb, skel_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37
38/* Get a minor range for your devices from the usb maintainer */
39#define USB_SKEL_MINOR_BASE 192
40
Oliver Neukumff906512005-12-21 19:27:29 +010041/* our private defines. if this grows any larger, use your own .h file */
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -030042#define MAX_TRANSFER (PAGE_SIZE - 512)
Oliver Neukumba35e022007-03-01 14:31:02 +010043/* MAX_TRANSFER is chosen so that the VM is not stressed by
44 allocations > PAGE_SIZE and the number of packets in a page
45 is an integer 512 is the largest possible packet on EHCI */
Oliver Neukumff906512005-12-21 19:27:29 +010046#define WRITES_IN_FLIGHT 8
Oliver Neukumba35e022007-03-01 14:31:02 +010047/* arbitrarily chosen */
Oliver Neukumff906512005-12-21 19:27:29 +010048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/* Structure to hold all of our device specific stuff */
50struct usb_skel {
Oliver Neukumba35e022007-03-01 14:31:02 +010051 struct usb_device *udev; /* the usb device for this device */
52 struct usb_interface *interface; /* the interface for this device */
Oliver Neukumff906512005-12-21 19:27:29 +010053 struct semaphore limit_sem; /* limiting the number of writes in progress */
Oliver Neukum403dfb52007-05-25 13:42:56 +020054 struct usb_anchor submitted; /* in case we need to retract our submissions */
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -030055 unsigned char *bulk_in_buffer; /* the buffer to receive data */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 size_t bulk_in_size; /* the size of the receive buffer */
57 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
58 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
Oliver Neukum403dfb52007-05-25 13:42:56 +020059 int errors; /* the last request tanked */
Oliver Neukum758f7e162007-06-11 14:55:08 +020060 int open_count; /* count the number of openers */
Oliver Neukum403dfb52007-05-25 13:42:56 +020061 spinlock_t err_lock; /* lock for errors */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 struct kref kref;
Alan Stern121e2872006-07-01 22:06:36 -040063 struct mutex io_mutex; /* synchronize I/O with disconnect */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65#define to_skel_dev(d) container_of(d, struct usb_skel, kref)
66
67static struct usb_driver skel_driver;
Oliver Neukum403dfb52007-05-25 13:42:56 +020068static void skel_draw_down(struct usb_skel *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70static void skel_delete(struct kref *kref)
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -030071{
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 struct usb_skel *dev = to_skel_dev(kref);
73
74 usb_put_dev(dev->udev);
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -030075 kfree(dev->bulk_in_buffer);
76 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
79static int skel_open(struct inode *inode, struct file *file)
80{
81 struct usb_skel *dev;
82 struct usb_interface *interface;
83 int subminor;
84 int retval = 0;
85
86 subminor = iminor(inode);
87
88 interface = usb_find_interface(&skel_driver, subminor);
89 if (!interface) {
90 err ("%s - error, can't find device for minor %d",
91 __FUNCTION__, subminor);
92 retval = -ENODEV;
93 goto exit;
94 }
95
96 dev = usb_get_intfdata(interface);
97 if (!dev) {
98 retval = -ENODEV;
99 goto exit;
100 }
101
102 /* increment our usage count for the device */
103 kref_get(&dev->kref);
104
Oliver Neukum758f7e162007-06-11 14:55:08 +0200105 /* lock the device to allow correctly handling errors
106 * in resumption */
107 mutex_lock(&dev->io_mutex);
108
109 if (!dev->open_count++) {
110 retval = usb_autopm_get_interface(interface);
111 if (retval) {
112 dev->open_count--;
113 mutex_unlock(&dev->io_mutex);
114 kref_put(&dev->kref, skel_delete);
115 goto exit;
116 }
117 } /* else { //uncomment this block if you want exclusive open
118 retval = -EBUSY;
119 dev->open_count--;
120 mutex_unlock(&dev->io_mutex);
Oliver Neukum5b064702007-02-08 15:42:53 +0100121 kref_put(&dev->kref, skel_delete);
122 goto exit;
Oliver Neukum758f7e162007-06-11 14:55:08 +0200123 } */
124 /* prevent the device from being autosuspended */
Oliver Neukum5b064702007-02-08 15:42:53 +0100125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 /* save our object in the file's private structure */
127 file->private_data = dev;
128
129exit:
130 return retval;
131}
132
133static int skel_release(struct inode *inode, struct file *file)
134{
135 struct usb_skel *dev;
136
137 dev = (struct usb_skel *)file->private_data;
138 if (dev == NULL)
139 return -ENODEV;
140
Alan Stern01d883d2006-08-30 15:47:18 -0400141 /* allow the device to be autosuspended */
142 mutex_lock(&dev->io_mutex);
Oliver Neukum758f7e162007-06-11 14:55:08 +0200143 if (!--dev->open_count && dev->interface)
Alan Stern01d883d2006-08-30 15:47:18 -0400144 usb_autopm_put_interface(dev->interface);
145 mutex_unlock(&dev->io_mutex);
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 /* decrement the count on our device */
148 kref_put(&dev->kref, skel_delete);
149 return 0;
150}
151
Oliver Neukum403dfb52007-05-25 13:42:56 +0200152static int skel_flush(struct file *file, fl_owner_t id)
153{
154 struct usb_skel *dev;
155 int res;
156
157 dev = (struct usb_skel *)file->private_data;
158 if (dev == NULL)
159 return -ENODEV;
160
161 /* wait for io to stop */
162 mutex_lock(&dev->io_mutex);
163 skel_draw_down(dev);
164
165 /* read out errors, leave subsequent opens a clean slate */
166 spin_lock_irq(&dev->err_lock);
167 res = dev->errors ? (dev->errors == -EPIPE ? -EPIPE : -EIO) : 0;
168 dev->errors = 0;
169 spin_unlock_irq(&dev->err_lock);
170
171 mutex_unlock(&dev->io_mutex);
172
173 return res;
174}
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
177{
178 struct usb_skel *dev;
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -0300179 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 int bytes_read;
181
182 dev = (struct usb_skel *)file->private_data;
Alan Stern121e2872006-07-01 22:06:36 -0400183
184 mutex_lock(&dev->io_mutex);
185 if (!dev->interface) { /* disconnect() was called */
186 retval = -ENODEV;
187 goto exit;
188 }
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 /* do a blocking bulk read to get data from the device */
191 retval = usb_bulk_msg(dev->udev,
192 usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
193 dev->bulk_in_buffer,
194 min(dev->bulk_in_size, count),
195 &bytes_read, 10000);
196
197 /* if the read was successful, copy the data to userspace */
198 if (!retval) {
199 if (copy_to_user(buffer, dev->bulk_in_buffer, bytes_read))
200 retval = -EFAULT;
201 else
202 retval = bytes_read;
203 }
204
Alan Stern121e2872006-07-01 22:06:36 -0400205exit:
206 mutex_unlock(&dev->io_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return retval;
208}
209
David Howells7d12e782006-10-05 14:55:46 +0100210static void skel_write_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 struct usb_skel *dev;
213
214 dev = (struct usb_skel *)urb->context;
215
216 /* sync/async unlink faults aren't errors */
Oliver Neukum403dfb52007-05-25 13:42:56 +0200217 if (urb->status) {
218 if(!(urb->status == -ENOENT ||
219 urb->status == -ECONNRESET ||
220 urb->status == -ESHUTDOWN))
221 err("%s - nonzero write bulk status received: %d",
222 __FUNCTION__, urb->status);
223
224 spin_lock(&dev->err_lock);
225 dev->errors = urb->status;
226 spin_unlock(&dev->err_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228
229 /* free up our allocated buffer */
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -0300230 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 urb->transfer_buffer, urb->transfer_dma);
Oliver Neukumff906512005-12-21 19:27:29 +0100232 up(&dev->limit_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235static ssize_t skel_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos)
236{
237 struct usb_skel *dev;
238 int retval = 0;
239 struct urb *urb = NULL;
240 char *buf = NULL;
Sam Bishopc8dd7702005-12-22 17:11:02 -0700241 size_t writesize = min(count, (size_t)MAX_TRANSFER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 dev = (struct usb_skel *)file->private_data;
244
245 /* verify that we actually have some data to write */
246 if (count == 0)
247 goto exit;
248
Oliver Neukumff906512005-12-21 19:27:29 +0100249 /* limit the number of URBs in flight to stop a user from using up all RAM */
Sam Bishopc8dd7702005-12-22 17:11:02 -0700250 if (down_interruptible(&dev->limit_sem)) {
251 retval = -ERESTARTSYS;
252 goto exit;
253 }
Oliver Neukumff906512005-12-21 19:27:29 +0100254
Oliver Neukum403dfb52007-05-25 13:42:56 +0200255 spin_lock_irq(&dev->err_lock);
256 if ((retval = dev->errors) < 0) {
257 /* any error is reported once */
258 dev->errors = 0;
259 /* to preserve notifications about reset */
260 retval = (retval == -EPIPE) ? retval : -EIO;
261 }
262 spin_unlock_irq(&dev->err_lock);
263 if (retval < 0)
264 goto error;
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 /* create a urb, and a buffer for it, and copy the data to the urb */
267 urb = usb_alloc_urb(0, GFP_KERNEL);
268 if (!urb) {
269 retval = -ENOMEM;
270 goto error;
271 }
272
Oliver Neukumff906512005-12-21 19:27:29 +0100273 buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, &urb->transfer_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (!buf) {
275 retval = -ENOMEM;
276 goto error;
277 }
278
Oliver Neukumff906512005-12-21 19:27:29 +0100279 if (copy_from_user(buf, user_buffer, writesize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 retval = -EFAULT;
281 goto error;
282 }
283
Oliver Neukumba35e022007-03-01 14:31:02 +0100284 /* this lock makes sure we don't submit URBs to gone devices */
285 mutex_lock(&dev->io_mutex);
286 if (!dev->interface) { /* disconnect() was called */
287 mutex_unlock(&dev->io_mutex);
288 retval = -ENODEV;
289 goto error;
290 }
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 /* initialize the urb properly */
293 usb_fill_bulk_urb(urb, dev->udev,
294 usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
Oliver Neukumff906512005-12-21 19:27:29 +0100295 buf, writesize, skel_write_bulk_callback, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
Oliver Neukum403dfb52007-05-25 13:42:56 +0200297 usb_anchor_urb(urb, &dev->submitted);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 /* send the data out the bulk port */
300 retval = usb_submit_urb(urb, GFP_KERNEL);
Oliver Neukumba35e022007-03-01 14:31:02 +0100301 mutex_unlock(&dev->io_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 if (retval) {
303 err("%s - failed submitting write urb, error %d", __FUNCTION__, retval);
Oliver Neukum403dfb52007-05-25 13:42:56 +0200304 goto error_unanchor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306
307 /* release our reference to this urb, the USB core will eventually free it entirely */
308 usb_free_urb(urb);
309
Oliver Neukumba35e022007-03-01 14:31:02 +0100310
Oliver Neukumff906512005-12-21 19:27:29 +0100311 return writesize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Oliver Neukum403dfb52007-05-25 13:42:56 +0200313error_unanchor:
314 usb_unanchor_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315error:
Alan Stern121e2872006-07-01 22:06:36 -0400316 if (urb) {
317 usb_buffer_free(dev->udev, writesize, buf, urb->transfer_dma);
318 usb_free_urb(urb);
319 }
Oliver Neukumff906512005-12-21 19:27:29 +0100320 up(&dev->limit_sem);
Alan Stern121e2872006-07-01 22:06:36 -0400321
322exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 return retval;
324}
325
Luiz Fernando N. Capitulino066202d2006-08-05 20:37:11 -0300326static const struct file_operations skel_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 .owner = THIS_MODULE,
328 .read = skel_read,
329 .write = skel_write,
330 .open = skel_open,
331 .release = skel_release,
Oliver Neukum403dfb52007-05-25 13:42:56 +0200332 .flush = skel_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333};
334
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -0300335/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 * usb class driver info in order to get a minor number from the usb core,
Greg Kroah-Hartman595b14c2006-01-18 17:36:58 -0500337 * and to have the device registered with the driver core
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 */
339static struct usb_class_driver skel_class = {
Greg Kroah-Hartmand6e5bcf2005-06-20 21:15:16 -0700340 .name = "skel%d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 .fops = &skel_fops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 .minor_base = USB_SKEL_MINOR_BASE,
343};
344
345static int skel_probe(struct usb_interface *interface, const struct usb_device_id *id)
346{
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -0300347 struct usb_skel *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 struct usb_host_interface *iface_desc;
349 struct usb_endpoint_descriptor *endpoint;
350 size_t buffer_size;
351 int i;
352 int retval = -ENOMEM;
353
354 /* allocate memory for our device state and initialize it */
Oliver Neukumff906512005-12-21 19:27:29 +0100355 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -0300356 if (!dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 err("Out of memory");
358 goto error;
359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 kref_init(&dev->kref);
Oliver Neukumff906512005-12-21 19:27:29 +0100361 sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
Alan Stern121e2872006-07-01 22:06:36 -0400362 mutex_init(&dev->io_mutex);
Oliver Neukum403dfb52007-05-25 13:42:56 +0200363 spin_lock_init(&dev->err_lock);
364 init_usb_anchor(&dev->submitted);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 dev->udev = usb_get_dev(interface_to_usbdev(interface));
367 dev->interface = interface;
368
369 /* set up the endpoint information */
370 /* use only the first bulk-in and bulk-out endpoints */
371 iface_desc = interface->cur_altsetting;
372 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
373 endpoint = &iface_desc->endpoint[i].desc;
374
375 if (!dev->bulk_in_endpointAddr &&
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -0300376 usb_endpoint_is_bulk_in(endpoint)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 /* we found a bulk in endpoint */
378 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
379 dev->bulk_in_size = buffer_size;
380 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
381 dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
382 if (!dev->bulk_in_buffer) {
383 err("Could not allocate bulk_in_buffer");
384 goto error;
385 }
386 }
387
388 if (!dev->bulk_out_endpointAddr &&
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -0300389 usb_endpoint_is_bulk_out(endpoint)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 /* we found a bulk out endpoint */
391 dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
392 }
393 }
394 if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
395 err("Could not find both bulk-in and bulk-out endpoints");
396 goto error;
397 }
398
399 /* save our data pointer in this interface device */
400 usb_set_intfdata(interface, dev);
401
402 /* we can register the device now, as it is ready */
403 retval = usb_register_dev(interface, &skel_class);
404 if (retval) {
405 /* something prevented us from registering this driver */
406 err("Not able to get a minor for this device.");
407 usb_set_intfdata(interface, NULL);
408 goto error;
409 }
410
411 /* let the user know what node this device is now attached to */
412 info("USB Skeleton device now attached to USBSkel-%d", interface->minor);
413 return 0;
414
415error:
416 if (dev)
Oliver Neukumba35e022007-03-01 14:31:02 +0100417 /* this frees allocated memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 kref_put(&dev->kref, skel_delete);
419 return retval;
420}
421
422static void skel_disconnect(struct usb_interface *interface)
423{
424 struct usb_skel *dev;
425 int minor = interface->minor;
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 dev = usb_get_intfdata(interface);
428 usb_set_intfdata(interface, NULL);
429
430 /* give back our minor */
431 usb_deregister_dev(interface, &skel_class);
432
Alan Stern121e2872006-07-01 22:06:36 -0400433 /* prevent more I/O from starting */
434 mutex_lock(&dev->io_mutex);
435 dev->interface = NULL;
436 mutex_unlock(&dev->io_mutex);
437
Oliver Neukume73c7242007-06-11 14:54:02 +0200438 usb_kill_anchored_urbs(&dev->submitted);
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 /* decrement our usage count */
441 kref_put(&dev->kref, skel_delete);
442
443 info("USB Skeleton #%d now disconnected", minor);
444}
445
Oliver Neukum403dfb52007-05-25 13:42:56 +0200446static void skel_draw_down(struct usb_skel *dev)
447{
448 int time;
449
450 time = usb_wait_anchor_empty_timeout(&dev->submitted, 1000);
451 if (!time)
452 usb_kill_anchored_urbs(&dev->submitted);
453}
454
Oliver Neukum758f7e162007-06-11 14:55:08 +0200455static int skel_suspend(struct usb_interface *intf, pm_message_t message)
456{
457 struct usb_skel *dev = usb_get_intfdata(intf);
458
459 if (!dev)
460 return 0;
461 skel_draw_down(dev);
462 return 0;
463}
464
465static int skel_resume (struct usb_interface *intf)
466{
467 return 0;
468}
469
Oliver Neukum87d093e2007-06-11 14:55:51 +0200470static int skel_pre_reset(struct usb_interface *intf)
471{
472 struct usb_skel *dev = usb_get_intfdata(intf);
473
474 mutex_lock(&dev->io_mutex);
475 skel_draw_down(dev);
476
477 return 0;
478}
479
480static int skel_post_reset(struct usb_interface *intf)
481{
482 struct usb_skel *dev = usb_get_intfdata(intf);
483
484 /* we are sure no URBs are active - no locking needed */
485 dev->errors = -EPIPE;
486 mutex_unlock(&dev->io_mutex);
487
488 return 0;
489}
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491static struct usb_driver skel_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 .name = "skeleton",
493 .probe = skel_probe,
494 .disconnect = skel_disconnect,
Oliver Neukum758f7e162007-06-11 14:55:08 +0200495 .suspend = skel_suspend,
496 .resume = skel_resume,
Oliver Neukum87d093e2007-06-11 14:55:51 +0200497 .pre_reset = skel_pre_reset,
498 .post_reset = skel_post_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 .id_table = skel_table,
Oliver Neukumba35e022007-03-01 14:31:02 +0100500 .supports_autosuspend = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501};
502
503static int __init usb_skel_init(void)
504{
505 int result;
506
507 /* register this driver with the USB subsystem */
508 result = usb_register(&skel_driver);
509 if (result)
510 err("usb_register failed. Error number %d", result);
511
512 return result;
513}
514
515static void __exit usb_skel_exit(void)
516{
517 /* deregister this driver with the USB subsystem */
518 usb_deregister(&skel_driver);
519}
520
Luiz Fernando N. Capitulinoc0704542006-08-14 22:44:29 -0300521module_init(usb_skel_init);
522module_exit(usb_skel_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524MODULE_LICENSE("GPL");