[PATCH] Generic HID layer - code split
[linux-2.6] / drivers / usb / input / hid-core.c
1 /*
2  *  USB HID support for Linux
3  *
4  *  Copyright (c) 1999 Andreas Gal
5  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7  *  Copyright (c) 2006 Jiri Kosina
8  */
9
10 /*
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by the Free
13  * Software Foundation; either version 2 of the License, or (at your option)
14  * any later version.
15  */
16
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/list.h>
23 #include <linux/mm.h>
24 #include <linux/smp_lock.h>
25 #include <linux/spinlock.h>
26 #include <asm/unaligned.h>
27 #include <asm/byteorder.h>
28 #include <linux/input.h>
29 #include <linux/wait.h>
30
31 #undef DEBUG
32 #undef DEBUG_DATA
33
34 #include <linux/usb.h>
35
36 #include <linux/hid.h>
37 #include <linux/hiddev.h>
38
39 /*
40  * Version Information
41  */
42
43 #define DRIVER_VERSION "v2.6"
44 #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
45 #define DRIVER_DESC "USB HID core driver"
46 #define DRIVER_LICENSE "GPL"
47
48 static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick",
49                                 "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"};
50 /*
51  * Module parameters.
52  */
53
54 static unsigned int hid_mousepoll_interval;
55 module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
56 MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
57
58 /*
59  * Input submission and I/O error handler.
60  */
61
62 static void hid_io_error(struct hid_device *hid);
63
64 /* Start up the input URB */
65 static int hid_start_in(struct hid_device *hid)
66 {
67         unsigned long flags;
68         int rc = 0;
69
70         spin_lock_irqsave(&hid->inlock, flags);
71         if (hid->open > 0 && !test_bit(HID_SUSPENDED, &hid->iofl) &&
72                         !test_and_set_bit(HID_IN_RUNNING, &hid->iofl)) {
73                 rc = usb_submit_urb(hid->urbin, GFP_ATOMIC);
74                 if (rc != 0)
75                         clear_bit(HID_IN_RUNNING, &hid->iofl);
76         }
77         spin_unlock_irqrestore(&hid->inlock, flags);
78         return rc;
79 }
80
81 /* I/O retry timer routine */
82 static void hid_retry_timeout(unsigned long _hid)
83 {
84         struct hid_device *hid = (struct hid_device *) _hid;
85
86         dev_dbg(&hid->intf->dev, "retrying intr urb\n");
87         if (hid_start_in(hid))
88                 hid_io_error(hid);
89 }
90
91 /* Workqueue routine to reset the device or clear a halt */
92 static void hid_reset(struct work_struct *work)
93 {
94         struct hid_device *hid =
95                 container_of(work, struct hid_device, reset_work);
96         int rc_lock, rc = 0;
97
98         if (test_bit(HID_CLEAR_HALT, &hid->iofl)) {
99                 dev_dbg(&hid->intf->dev, "clear halt\n");
100                 rc = usb_clear_halt(hid->dev, hid->urbin->pipe);
101                 clear_bit(HID_CLEAR_HALT, &hid->iofl);
102                 hid_start_in(hid);
103         }
104
105         else if (test_bit(HID_RESET_PENDING, &hid->iofl)) {
106                 dev_dbg(&hid->intf->dev, "resetting device\n");
107                 rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf);
108                 if (rc_lock >= 0) {
109                         rc = usb_reset_composite_device(hid->dev, hid->intf);
110                         if (rc_lock)
111                                 usb_unlock_device(hid->dev);
112                 }
113                 clear_bit(HID_RESET_PENDING, &hid->iofl);
114         }
115
116         switch (rc) {
117         case 0:
118                 if (!test_bit(HID_IN_RUNNING, &hid->iofl))
119                         hid_io_error(hid);
120                 break;
121         default:
122                 err("can't reset device, %s-%s/input%d, status %d",
123                                 hid->dev->bus->bus_name,
124                                 hid->dev->devpath,
125                                 hid->ifnum, rc);
126                 /* FALLTHROUGH */
127         case -EHOSTUNREACH:
128         case -ENODEV:
129         case -EINTR:
130                 break;
131         }
132 }
133
134 /* Main I/O error handler */
135 static void hid_io_error(struct hid_device *hid)
136 {
137         unsigned long flags;
138
139         spin_lock_irqsave(&hid->inlock, flags);
140
141         /* Stop when disconnected */
142         if (usb_get_intfdata(hid->intf) == NULL)
143                 goto done;
144
145         /* When an error occurs, retry at increasing intervals */
146         if (hid->retry_delay == 0) {
147                 hid->retry_delay = 13;  /* Then 26, 52, 104, 104, ... */
148                 hid->stop_retry = jiffies + msecs_to_jiffies(1000);
149         } else if (hid->retry_delay < 100)
150                 hid->retry_delay *= 2;
151
152         if (time_after(jiffies, hid->stop_retry)) {
153
154                 /* Retries failed, so do a port reset */
155                 if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) {
156                         schedule_work(&hid->reset_work);
157                         goto done;
158                 }
159         }
160
161         mod_timer(&hid->io_retry,
162                         jiffies + msecs_to_jiffies(hid->retry_delay));
163 done:
164         spin_unlock_irqrestore(&hid->inlock, flags);
165 }
166
167
168 static int hid_input_report(int type, struct urb *urb, int interrupt)
169 {
170         struct hid_device *hid = urb->context;
171         struct hid_report_enum *report_enum = hid->report_enum + type;
172         u8 *data = urb->transfer_buffer;
173         int len = urb->actual_length;
174         struct hid_report *report;
175         int n, size;
176
177         if (!len) {
178                 dbg("empty report");
179                 return -1;
180         }
181
182 #ifdef DEBUG_DATA
183         printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", len, report_enum->numbered ? "" : "un");
184 #endif
185
186         n = 0;                          /* Normally report number is 0 */
187         if (report_enum->numbered) {    /* Device uses numbered reports, data[0] is report number */
188                 n = *data++;
189                 len--;
190         }
191
192 #ifdef DEBUG_DATA
193         {
194                 int i;
195                 printk(KERN_DEBUG __FILE__ ": report %d (size %u) = ", n, len);
196                 for (i = 0; i < len; i++)
197                         printk(" %02x", data[i]);
198                 printk("\n");
199         }
200 #endif
201
202         if (!(report = report_enum->report_id_hash[n])) {
203                 dbg("undefined report_id %d received", n);
204                 return -1;
205         }
206
207         size = ((report->size - 1) >> 3) + 1;
208
209         if (len < size) {
210                 dbg("report %d is too short, (%d < %d)", report->id, len, size);
211                 memset(data + len, 0, size - len);
212         }
213
214         if (hid->claimed & HID_CLAIMED_HIDDEV)
215                 hiddev_report_event(hid, report);
216
217         for (n = 0; n < report->maxfield; n++)
218                 hid_input_field(hid, report->field[n], data, interrupt);
219
220         if (hid->claimed & HID_CLAIMED_INPUT)
221                 hidinput_report_event(hid, report);
222
223         return 0;
224 }
225
226 /*
227  * Input interrupt completion handler.
228  */
229
230 static void hid_irq_in(struct urb *urb)
231 {
232         struct hid_device       *hid = urb->context;
233         int                     status;
234
235         switch (urb->status) {
236                 case 0:                 /* success */
237                         hid->retry_delay = 0;
238                         hid_input_report(HID_INPUT_REPORT, urb, 1);
239                         break;
240                 case -EPIPE:            /* stall */
241                         clear_bit(HID_IN_RUNNING, &hid->iofl);
242                         set_bit(HID_CLEAR_HALT, &hid->iofl);
243                         schedule_work(&hid->reset_work);
244                         return;
245                 case -ECONNRESET:       /* unlink */
246                 case -ENOENT:
247                 case -ESHUTDOWN:        /* unplug */
248                         clear_bit(HID_IN_RUNNING, &hid->iofl);
249                         return;
250                 case -EILSEQ:           /* protocol error or unplug */
251                 case -EPROTO:           /* protocol error or unplug */
252                 case -ETIME:            /* protocol error or unplug */
253                 case -ETIMEDOUT:        /* Should never happen, but... */
254                         clear_bit(HID_IN_RUNNING, &hid->iofl);
255                         hid_io_error(hid);
256                         return;
257                 default:                /* error */
258                         warn("input irq status %d received", urb->status);
259         }
260
261         status = usb_submit_urb(urb, GFP_ATOMIC);
262         if (status) {
263                 clear_bit(HID_IN_RUNNING, &hid->iofl);
264                 if (status != -EPERM) {
265                         err("can't resubmit intr, %s-%s/input%d, status %d",
266                                         hid->dev->bus->bus_name,
267                                         hid->dev->devpath,
268                                         hid->ifnum, status);
269                         hid_io_error(hid);
270                 }
271         }
272 }
273
274 /*
275  * Find a report field with a specified HID usage.
276  */
277 #if 0
278 struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_usage, int type)
279 {
280         struct hid_report *report;
281         int i;
282
283         list_for_each_entry(report, &hid->report_enum[type].report_list, list)
284                 for (i = 0; i < report->maxfield; i++)
285                         if (report->field[i]->logical == wanted_usage)
286                                 return report->field[i];
287         return NULL;
288 }
289 #endif  /*  0  */
290
291 static int hid_submit_out(struct hid_device *hid)
292 {
293         struct hid_report *report;
294
295         report = hid->out[hid->outtail];
296
297         hid_output_report(report, hid->outbuf);
298         hid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
299         hid->urbout->dev = hid->dev;
300
301         dbg("submitting out urb");
302
303         if (usb_submit_urb(hid->urbout, GFP_ATOMIC)) {
304                 err("usb_submit_urb(out) failed");
305                 return -1;
306         }
307
308         return 0;
309 }
310
311 static int hid_submit_ctrl(struct hid_device *hid)
312 {
313         struct hid_report *report;
314         unsigned char dir;
315         int len;
316
317         report = hid->ctrl[hid->ctrltail].report;
318         dir = hid->ctrl[hid->ctrltail].dir;
319
320         len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
321         if (dir == USB_DIR_OUT) {
322                 hid_output_report(report, hid->ctrlbuf);
323                 hid->urbctrl->pipe = usb_sndctrlpipe(hid->dev, 0);
324                 hid->urbctrl->transfer_buffer_length = len;
325         } else {
326                 int maxpacket, padlen;
327
328                 hid->urbctrl->pipe = usb_rcvctrlpipe(hid->dev, 0);
329                 maxpacket = usb_maxpacket(hid->dev, hid->urbctrl->pipe, 0);
330                 if (maxpacket > 0) {
331                         padlen = (len + maxpacket - 1) / maxpacket;
332                         padlen *= maxpacket;
333                         if (padlen > hid->bufsize)
334                                 padlen = hid->bufsize;
335                 } else
336                         padlen = 0;
337                 hid->urbctrl->transfer_buffer_length = padlen;
338         }
339         hid->urbctrl->dev = hid->dev;
340
341         hid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
342         hid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
343         hid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
344         hid->cr->wIndex = cpu_to_le16(hid->ifnum);
345         hid->cr->wLength = cpu_to_le16(len);
346
347         dbg("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u",
348                 hid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report",
349                 hid->cr->wValue, hid->cr->wIndex, hid->cr->wLength);
350
351         if (usb_submit_urb(hid->urbctrl, GFP_ATOMIC)) {
352                 err("usb_submit_urb(ctrl) failed");
353                 return -1;
354         }
355
356         return 0;
357 }
358
359 /*
360  * Output interrupt completion handler.
361  */
362
363 static void hid_irq_out(struct urb *urb)
364 {
365         struct hid_device *hid = urb->context;
366         unsigned long flags;
367         int unplug = 0;
368
369         switch (urb->status) {
370                 case 0:                 /* success */
371                         break;
372                 case -ESHUTDOWN:        /* unplug */
373                         unplug = 1;
374                 case -EILSEQ:           /* protocol error or unplug */
375                 case -EPROTO:           /* protocol error or unplug */
376                 case -ECONNRESET:       /* unlink */
377                 case -ENOENT:
378                         break;
379                 default:                /* error */
380                         warn("output irq status %d received", urb->status);
381         }
382
383         spin_lock_irqsave(&hid->outlock, flags);
384
385         if (unplug)
386                 hid->outtail = hid->outhead;
387         else
388                 hid->outtail = (hid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1);
389
390         if (hid->outhead != hid->outtail) {
391                 if (hid_submit_out(hid)) {
392                         clear_bit(HID_OUT_RUNNING, &hid->iofl);
393                         wake_up(&hid->wait);
394                 }
395                 spin_unlock_irqrestore(&hid->outlock, flags);
396                 return;
397         }
398
399         clear_bit(HID_OUT_RUNNING, &hid->iofl);
400         spin_unlock_irqrestore(&hid->outlock, flags);
401         wake_up(&hid->wait);
402 }
403
404 /*
405  * Control pipe completion handler.
406  */
407
408 static void hid_ctrl(struct urb *urb)
409 {
410         struct hid_device *hid = urb->context;
411         unsigned long flags;
412         int unplug = 0;
413
414         spin_lock_irqsave(&hid->ctrllock, flags);
415
416         switch (urb->status) {
417                 case 0:                 /* success */
418                         if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN)
419                                 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0);
420                         break;
421                 case -ESHUTDOWN:        /* unplug */
422                         unplug = 1;
423                 case -EILSEQ:           /* protocol error or unplug */
424                 case -EPROTO:           /* protocol error or unplug */
425                 case -ECONNRESET:       /* unlink */
426                 case -ENOENT:
427                 case -EPIPE:            /* report not available */
428                         break;
429                 default:                /* error */
430                         warn("ctrl urb status %d received", urb->status);
431         }
432
433         if (unplug)
434                 hid->ctrltail = hid->ctrlhead;
435         else
436                 hid->ctrltail = (hid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
437
438         if (hid->ctrlhead != hid->ctrltail) {
439                 if (hid_submit_ctrl(hid)) {
440                         clear_bit(HID_CTRL_RUNNING, &hid->iofl);
441                         wake_up(&hid->wait);
442                 }
443                 spin_unlock_irqrestore(&hid->ctrllock, flags);
444                 return;
445         }
446
447         clear_bit(HID_CTRL_RUNNING, &hid->iofl);
448         spin_unlock_irqrestore(&hid->ctrllock, flags);
449         wake_up(&hid->wait);
450 }
451
452 void hid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir)
453 {
454         int head;
455         unsigned long flags;
456
457         if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
458                 return;
459
460         if (hid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
461
462                 spin_lock_irqsave(&hid->outlock, flags);
463
464                 if ((head = (hid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == hid->outtail) {
465                         spin_unlock_irqrestore(&hid->outlock, flags);
466                         warn("output queue full");
467                         return;
468                 }
469
470                 hid->out[hid->outhead] = report;
471                 hid->outhead = head;
472
473                 if (!test_and_set_bit(HID_OUT_RUNNING, &hid->iofl))
474                         if (hid_submit_out(hid))
475                                 clear_bit(HID_OUT_RUNNING, &hid->iofl);
476
477                 spin_unlock_irqrestore(&hid->outlock, flags);
478                 return;
479         }
480
481         spin_lock_irqsave(&hid->ctrllock, flags);
482
483         if ((head = (hid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == hid->ctrltail) {
484                 spin_unlock_irqrestore(&hid->ctrllock, flags);
485                 warn("control queue full");
486                 return;
487         }
488
489         hid->ctrl[hid->ctrlhead].report = report;
490         hid->ctrl[hid->ctrlhead].dir = dir;
491         hid->ctrlhead = head;
492
493         if (!test_and_set_bit(HID_CTRL_RUNNING, &hid->iofl))
494                 if (hid_submit_ctrl(hid))
495                         clear_bit(HID_CTRL_RUNNING, &hid->iofl);
496
497         spin_unlock_irqrestore(&hid->ctrllock, flags);
498 }
499
500 static int hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
501 {
502         struct hid_device *hid = dev->private;
503         struct hid_field *field;
504         int offset;
505
506         if (type == EV_FF)
507                 return input_ff_event(dev, type, code, value);
508
509         if (type != EV_LED)
510                 return -1;
511
512         if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
513                 warn("event field not found");
514                 return -1;
515         }
516
517         hid_set_field(field, offset, value);
518         hid_submit_report(hid, field->report, USB_DIR_OUT);
519
520         return 0;
521 }
522
523 int hid_wait_io(struct hid_device *hid)
524 {
525         if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &hid->iofl) &&
526                                         !test_bit(HID_OUT_RUNNING, &hid->iofl)),
527                                         10*HZ)) {
528                 dbg("timeout waiting for ctrl or out queue to clear");
529                 return -1;
530         }
531
532         return 0;
533 }
534
535 static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle)
536 {
537         return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
538                 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report,
539                 ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
540 }
541
542 static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
543                 unsigned char type, void *buf, int size)
544 {
545         int result, retries = 4;
546
547         memset(buf,0,size);     // Make sure we parse really received data
548
549         do {
550                 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
551                                 USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN,
552                                 (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT);
553                 retries--;
554         } while (result < size && retries);
555         return result;
556 }
557
558 int hid_open(struct hid_device *hid)
559 {
560         ++hid->open;
561         if (hid_start_in(hid))
562                 hid_io_error(hid);
563         return 0;
564 }
565
566 void hid_close(struct hid_device *hid)
567 {
568         if (!--hid->open)
569                 usb_kill_urb(hid->urbin);
570 }
571
572 static int hidinput_open(struct input_dev *dev)
573 {
574         struct hid_device *hid = dev->private;
575         return hid_open(hid);
576 }
577
578 static void hidinput_close(struct input_dev *dev)
579 {
580         struct hid_device *hid = dev->private;
581         hid_close(hid);
582 }
583
584 #define USB_VENDOR_ID_PANJIT            0x134c
585
586 #define USB_VENDOR_ID_TURBOX            0x062a
587 #define USB_DEVICE_ID_TURBOX_KEYBOARD   0x0201
588
589 /*
590  * Initialize all reports
591  */
592
593 void hid_init_reports(struct hid_device *hid)
594 {
595         struct hid_report *report;
596         int err, ret;
597
598         list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
599                 hid_submit_report(hid, report, USB_DIR_IN);
600
601         list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
602                 hid_submit_report(hid, report, USB_DIR_IN);
603
604         err = 0;
605         ret = hid_wait_io(hid);
606         while (ret) {
607                 err |= ret;
608                 if (test_bit(HID_CTRL_RUNNING, &hid->iofl))
609                         usb_kill_urb(hid->urbctrl);
610                 if (test_bit(HID_OUT_RUNNING, &hid->iofl))
611                         usb_kill_urb(hid->urbout);
612                 ret = hid_wait_io(hid);
613         }
614
615         if (err)
616                 warn("timeout initializing reports");
617 }
618
619 #define USB_VENDOR_ID_GTCO              0x078c
620 #define USB_DEVICE_ID_GTCO_90           0x0090
621 #define USB_DEVICE_ID_GTCO_100          0x0100
622 #define USB_DEVICE_ID_GTCO_101          0x0101
623 #define USB_DEVICE_ID_GTCO_103          0x0103
624 #define USB_DEVICE_ID_GTCO_104          0x0104
625 #define USB_DEVICE_ID_GTCO_105          0x0105
626 #define USB_DEVICE_ID_GTCO_106          0x0106
627 #define USB_DEVICE_ID_GTCO_107          0x0107
628 #define USB_DEVICE_ID_GTCO_108          0x0108
629 #define USB_DEVICE_ID_GTCO_200          0x0200
630 #define USB_DEVICE_ID_GTCO_201          0x0201
631 #define USB_DEVICE_ID_GTCO_202          0x0202
632 #define USB_DEVICE_ID_GTCO_203          0x0203
633 #define USB_DEVICE_ID_GTCO_204          0x0204
634 #define USB_DEVICE_ID_GTCO_205          0x0205
635 #define USB_DEVICE_ID_GTCO_206          0x0206
636 #define USB_DEVICE_ID_GTCO_207          0x0207
637 #define USB_DEVICE_ID_GTCO_300          0x0300
638 #define USB_DEVICE_ID_GTCO_301          0x0301
639 #define USB_DEVICE_ID_GTCO_302          0x0302
640 #define USB_DEVICE_ID_GTCO_303          0x0303
641 #define USB_DEVICE_ID_GTCO_304          0x0304
642 #define USB_DEVICE_ID_GTCO_305          0x0305
643 #define USB_DEVICE_ID_GTCO_306          0x0306
644 #define USB_DEVICE_ID_GTCO_307          0x0307
645 #define USB_DEVICE_ID_GTCO_308          0x0308
646 #define USB_DEVICE_ID_GTCO_309          0x0309
647 #define USB_DEVICE_ID_GTCO_400          0x0400
648 #define USB_DEVICE_ID_GTCO_401          0x0401
649 #define USB_DEVICE_ID_GTCO_402          0x0402
650 #define USB_DEVICE_ID_GTCO_403          0x0403
651 #define USB_DEVICE_ID_GTCO_404          0x0404
652 #define USB_DEVICE_ID_GTCO_405          0x0405
653 #define USB_DEVICE_ID_GTCO_500          0x0500
654 #define USB_DEVICE_ID_GTCO_501          0x0501
655 #define USB_DEVICE_ID_GTCO_502          0x0502
656 #define USB_DEVICE_ID_GTCO_503          0x0503
657 #define USB_DEVICE_ID_GTCO_504          0x0504
658 #define USB_DEVICE_ID_GTCO_1000         0x1000
659 #define USB_DEVICE_ID_GTCO_1001         0x1001
660 #define USB_DEVICE_ID_GTCO_1002         0x1002
661 #define USB_DEVICE_ID_GTCO_1003         0x1003
662 #define USB_DEVICE_ID_GTCO_1004         0x1004
663 #define USB_DEVICE_ID_GTCO_1005         0x1005
664 #define USB_DEVICE_ID_GTCO_1006         0x1006
665
666 #define USB_VENDOR_ID_WACOM             0x056a
667
668 #define USB_VENDOR_ID_ACECAD            0x0460
669 #define USB_DEVICE_ID_ACECAD_FLAIR      0x0004
670 #define USB_DEVICE_ID_ACECAD_302        0x0008
671
672 #define USB_VENDOR_ID_KBGEAR            0x084e
673 #define USB_DEVICE_ID_KBGEAR_JAMSTUDIO  0x1001
674
675 #define USB_VENDOR_ID_AIPTEK            0x08ca
676 #define USB_DEVICE_ID_AIPTEK_01         0x0001
677 #define USB_DEVICE_ID_AIPTEK_10         0x0010
678 #define USB_DEVICE_ID_AIPTEK_20         0x0020
679 #define USB_DEVICE_ID_AIPTEK_21         0x0021
680 #define USB_DEVICE_ID_AIPTEK_22         0x0022
681 #define USB_DEVICE_ID_AIPTEK_23         0x0023
682 #define USB_DEVICE_ID_AIPTEK_24         0x0024
683
684 #define USB_VENDOR_ID_GRIFFIN           0x077d
685 #define USB_DEVICE_ID_POWERMATE         0x0410
686 #define USB_DEVICE_ID_SOUNDKNOB         0x04AA
687
688 #define USB_VENDOR_ID_ATEN              0x0557
689 #define USB_DEVICE_ID_ATEN_UC100KM      0x2004
690 #define USB_DEVICE_ID_ATEN_CS124U       0x2202
691 #define USB_DEVICE_ID_ATEN_2PORTKVM     0x2204
692 #define USB_DEVICE_ID_ATEN_4PORTKVM     0x2205
693 #define USB_DEVICE_ID_ATEN_4PORTKVMC    0x2208
694
695 #define USB_VENDOR_ID_TOPMAX            0x0663
696 #define USB_DEVICE_ID_TOPMAX_COBRAPAD   0x0103
697
698 #define USB_VENDOR_ID_HAPP              0x078b
699 #define USB_DEVICE_ID_UGCI_DRIVING      0x0010
700 #define USB_DEVICE_ID_UGCI_FLYING       0x0020
701 #define USB_DEVICE_ID_UGCI_FIGHTING     0x0030
702
703 #define USB_VENDOR_ID_MGE               0x0463
704 #define USB_DEVICE_ID_MGE_UPS           0xffff
705 #define USB_DEVICE_ID_MGE_UPS1          0x0001
706
707 #define USB_VENDOR_ID_ONTRAK            0x0a07
708 #define USB_DEVICE_ID_ONTRAK_ADU100     0x0064
709
710 #define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f
711 #define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100
712
713 #define USB_VENDOR_ID_A4TECH            0x09da
714 #define USB_DEVICE_ID_A4TECH_WCP32PU    0x0006
715
716 #define USB_VENDOR_ID_AASHIMA           0x06d6
717 #define USB_DEVICE_ID_AASHIMA_GAMEPAD   0x0025
718 #define USB_DEVICE_ID_AASHIMA_PREDATOR  0x0026
719
720 #define USB_VENDOR_ID_CYPRESS           0x04b4
721 #define USB_DEVICE_ID_CYPRESS_MOUSE     0x0001
722 #define USB_DEVICE_ID_CYPRESS_HIDCOM    0x5500
723 #define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE        0x7417
724
725 #define USB_VENDOR_ID_BERKSHIRE         0x0c98
726 #define USB_DEVICE_ID_BERKSHIRE_PCWD    0x1140
727
728 #define USB_VENDOR_ID_ALPS              0x0433
729 #define USB_DEVICE_ID_IBM_GAMEPAD       0x1101
730
731 #define USB_VENDOR_ID_SAITEK            0x06a3
732 #define USB_DEVICE_ID_SAITEK_RUMBLEPAD  0xff17
733
734 #define USB_VENDOR_ID_NEC               0x073e
735 #define USB_DEVICE_ID_NEC_USB_GAME_PAD  0x0301
736
737 #define USB_VENDOR_ID_CHIC              0x05fe
738 #define USB_DEVICE_ID_CHIC_GAMEPAD      0x0014
739
740 #define USB_VENDOR_ID_GLAB              0x06c2
741 #define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
742 #define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039
743 #define USB_DEVICE_ID_0_0_4_IF_KIT      0x0040
744 #define USB_DEVICE_ID_0_16_16_IF_KIT    0x0044
745 #define USB_DEVICE_ID_8_8_8_IF_KIT      0x0045
746 #define USB_DEVICE_ID_0_8_7_IF_KIT      0x0051
747 #define USB_DEVICE_ID_0_8_8_IF_KIT      0x0053
748 #define USB_DEVICE_ID_PHIDGET_MOTORCONTROL      0x0058
749
750 #define USB_VENDOR_ID_WISEGROUP         0x0925
751 #define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101
752 #define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104
753 #define USB_DEVICE_ID_8_8_4_IF_KIT      0x8201
754 #define USB_DEVICE_ID_DUAL_USB_JOYPAD   0x8866
755
756 #define USB_VENDOR_ID_WISEGROUP_LTD     0x6677
757 #define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802
758
759 #define USB_VENDOR_ID_CODEMERCS         0x07c0
760 #define USB_DEVICE_ID_CODEMERCS_IOW40   0x1500
761 #define USB_DEVICE_ID_CODEMERCS_IOW24   0x1501
762 #define USB_DEVICE_ID_CODEMERCS_IOW48   0x1502
763 #define USB_DEVICE_ID_CODEMERCS_IOW28   0x1503
764
765 #define USB_VENDOR_ID_DELORME           0x1163
766 #define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100
767 #define USB_DEVICE_ID_DELORME_EM_LT20   0x0200
768
769 #define USB_VENDOR_ID_MCC               0x09db
770 #define USB_DEVICE_ID_MCC_PMD1024LS     0x0076
771 #define USB_DEVICE_ID_MCC_PMD1208LS     0x007a
772
773 #define USB_VENDOR_ID_VERNIER           0x08f7
774 #define USB_DEVICE_ID_VERNIER_LABPRO    0x0001
775 #define USB_DEVICE_ID_VERNIER_GOTEMP    0x0002
776 #define USB_DEVICE_ID_VERNIER_SKIP      0x0003
777 #define USB_DEVICE_ID_VERNIER_CYCLOPS   0x0004
778
779 #define USB_VENDOR_ID_LD                0x0f11
780 #define USB_DEVICE_ID_LD_CASSY          0x1000
781 #define USB_DEVICE_ID_LD_POCKETCASSY    0x1010
782 #define USB_DEVICE_ID_LD_MOBILECASSY    0x1020
783 #define USB_DEVICE_ID_LD_JWM            0x1080
784 #define USB_DEVICE_ID_LD_DMMP           0x1081
785 #define USB_DEVICE_ID_LD_UMIP           0x1090
786 #define USB_DEVICE_ID_LD_XRAY1          0x1100
787 #define USB_DEVICE_ID_LD_XRAY2          0x1101
788 #define USB_DEVICE_ID_LD_VIDEOCOM       0x1200
789 #define USB_DEVICE_ID_LD_COM3LAB        0x2000
790 #define USB_DEVICE_ID_LD_TELEPORT       0x2010
791 #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020
792 #define USB_DEVICE_ID_LD_POWERCONTROL   0x2030
793 #define USB_DEVICE_ID_LD_MACHINETEST    0x2040
794
795 #define USB_VENDOR_ID_APPLE             0x05ac
796 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
797 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI       0x020e
798 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO        0x020f
799 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
800 #define USB_DEVICE_ID_APPLE_GEYSER_ISO  0x0215
801 #define USB_DEVICE_ID_APPLE_GEYSER_JIS  0x0216
802 #define USB_DEVICE_ID_APPLE_GEYSER3_ANSI        0x0217
803 #define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218
804 #define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219
805 #define USB_DEVICE_ID_APPLE_GEYSER4_ANSI        0x021a
806 #define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b
807 #define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c
808 #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY    0x030a
809 #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY     0x030b
810
811 #define USB_VENDOR_ID_CHERRY            0x046a
812 #define USB_DEVICE_ID_CHERRY_CYMOTION   0x0023
813
814 #define USB_VENDOR_ID_YEALINK           0x6993
815 #define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K       0xb001
816
817 #define USB_VENDOR_ID_ALCOR             0x058f
818 #define USB_DEVICE_ID_ALCOR_USBRS232    0x9720
819
820 #define USB_VENDOR_ID_SUN               0x0430
821 #define USB_DEVICE_ID_RARITAN_KVM_DONGLE        0xcdab
822
823 #define USB_VENDOR_ID_AIRCABLE          0x16CA
824 #define USB_DEVICE_ID_AIRCABLE1         0x1502
825
826 #define USB_VENDOR_ID_LOGITECH          0x046d
827 #define USB_DEVICE_ID_LOGITECH_USB_RECEIVER     0xc101
828
829 /*
830  * Alphabetically sorted blacklist by quirk type.
831  */
832
833 static const struct hid_blacklist {
834         __u16 idVendor;
835         __u16 idProduct;
836         unsigned quirks;
837 } hid_blacklist[] = {
838
839         { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE },
840         { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE },
841         { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE },
842         { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21, HID_QUIRK_IGNORE },
843         { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE },
844         { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE },
845         { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE },
846         { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE },
847         { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE },
848         { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE },
849         { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE },
850         { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24, HID_QUIRK_IGNORE },
851         { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE },
852         { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE },
853         { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE },
854         { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE },
855         { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE },
856         { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE },
857         { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE },
858         { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
859         { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
860         { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE },
861         { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT, HID_QUIRK_IGNORE },
862         { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE },
863         { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT, HID_QUIRK_IGNORE },
864         { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE },
865         { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL, HID_QUIRK_IGNORE },
866         { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE },
867         { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE },
868         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE },
869         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100, HID_QUIRK_IGNORE },
870         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101, HID_QUIRK_IGNORE },
871         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103, HID_QUIRK_IGNORE },
872         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104, HID_QUIRK_IGNORE },
873         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105, HID_QUIRK_IGNORE },
874         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106, HID_QUIRK_IGNORE },
875         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107, HID_QUIRK_IGNORE },
876         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108, HID_QUIRK_IGNORE },
877         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200, HID_QUIRK_IGNORE },
878         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201, HID_QUIRK_IGNORE },
879         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202, HID_QUIRK_IGNORE },
880         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203, HID_QUIRK_IGNORE },
881         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204, HID_QUIRK_IGNORE },
882         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205, HID_QUIRK_IGNORE },
883         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206, HID_QUIRK_IGNORE },
884         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207, HID_QUIRK_IGNORE },
885         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300, HID_QUIRK_IGNORE },
886         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301, HID_QUIRK_IGNORE },
887         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302, HID_QUIRK_IGNORE },
888         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303, HID_QUIRK_IGNORE },
889         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304, HID_QUIRK_IGNORE },
890         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305, HID_QUIRK_IGNORE },
891         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306, HID_QUIRK_IGNORE },
892         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307, HID_QUIRK_IGNORE },
893         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308, HID_QUIRK_IGNORE },
894         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309, HID_QUIRK_IGNORE },
895         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400, HID_QUIRK_IGNORE },
896         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401, HID_QUIRK_IGNORE },
897         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402, HID_QUIRK_IGNORE },
898         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403, HID_QUIRK_IGNORE },
899         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404, HID_QUIRK_IGNORE },
900         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405, HID_QUIRK_IGNORE },
901         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500, HID_QUIRK_IGNORE },
902         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501, HID_QUIRK_IGNORE },
903         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE },
904         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE },
905         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE },
906         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE },
907         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE },
908         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE },
909         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003, HID_QUIRK_IGNORE },
910         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
911         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
912         { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
913         { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
914         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
915         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE },
916         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY, HID_QUIRK_IGNORE },
917         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM, HID_QUIRK_IGNORE },
918         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP, HID_QUIRK_IGNORE },
919         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP, HID_QUIRK_IGNORE },
920         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1, HID_QUIRK_IGNORE },
921         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2, HID_QUIRK_IGNORE },
922         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM, HID_QUIRK_IGNORE },
923         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB, HID_QUIRK_IGNORE },
924         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT, HID_QUIRK_IGNORE },
925         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER, HID_QUIRK_IGNORE },
926         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL, HID_QUIRK_IGNORE },
927         { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST, HID_QUIRK_IGNORE },
928         { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE },
929         { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE },
930         { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE },
931         { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE },
932         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE },
933         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20, HID_QUIRK_IGNORE },
934         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30, HID_QUIRK_IGNORE },
935         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE },
936         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108, HID_QUIRK_IGNORE },
937         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118, HID_QUIRK_IGNORE },
938         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE },
939         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE },
940         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE },
941         { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE },
942         { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO, HID_QUIRK_IGNORE },
943         { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE },
944         { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE },
945         { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE },
946         { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
947         { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
948         { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT, HID_QUIRK_IGNORE },
949         { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE },
950
951         { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE },
952         { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE },
953
954         { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET },
955         { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET },
956         { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
957         { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
958         { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
959         { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
960         { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
961         { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
962
963         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL },
964         { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
965         { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 },
966
967         { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD },
968         { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD },
969         { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD },
970         { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
971         { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
972         { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
973         { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
974         { USB_VENDOR_ID_NEC, USB_DEVICE_ID_NEC_USB_GAME_PAD, HID_QUIRK_BADPAD },
975         { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
976         { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
977
978         { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION },
979
980         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
981         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO, HID_QUIRK_POWERBOOK_HAS_FN },
982         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
983         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
984         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
985         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
986         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
987         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
988         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
989         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN },
990         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
991         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
992         { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
993
994         { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE },
995         { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE },
996         { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE },
997         { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE },
998
999         { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
1000
1001         { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_USB_RECEIVER, HID_QUIRK_BAD_RELATIVE_KEYS },
1002
1003         { 0, 0 }
1004 };
1005
1006 /*
1007  * Traverse the supplied list of reports and find the longest
1008  */
1009 static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max)
1010 {
1011         struct hid_report *report;
1012         int size;
1013
1014         list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
1015                 size = ((report->size - 1) >> 3) + 1;
1016                 if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered)
1017                         size++;
1018                 if (*max < size)
1019                         *max = size;
1020         }
1021 }
1022
1023 static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
1024 {
1025         if (!(hid->inbuf = usb_buffer_alloc(dev, hid->bufsize, GFP_ATOMIC, &hid->inbuf_dma)))
1026                 return -1;
1027         if (!(hid->outbuf = usb_buffer_alloc(dev, hid->bufsize, GFP_ATOMIC, &hid->outbuf_dma)))
1028                 return -1;
1029         if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), GFP_ATOMIC, &hid->cr_dma)))
1030                 return -1;
1031         if (!(hid->ctrlbuf = usb_buffer_alloc(dev, hid->bufsize, GFP_ATOMIC, &hid->ctrlbuf_dma)))
1032                 return -1;
1033
1034         return 0;
1035 }
1036
1037 static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
1038 {
1039         if (hid->inbuf)
1040                 usb_buffer_free(dev, hid->bufsize, hid->inbuf, hid->inbuf_dma);
1041         if (hid->outbuf)
1042                 usb_buffer_free(dev, hid->bufsize, hid->outbuf, hid->outbuf_dma);
1043         if (hid->cr)
1044                 usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma);
1045         if (hid->ctrlbuf)
1046                 usb_buffer_free(dev, hid->bufsize, hid->ctrlbuf, hid->ctrlbuf_dma);
1047 }
1048
1049 /*
1050  * Cherry Cymotion keyboard have an invalid HID report descriptor,
1051  * that needs fixing before we can parse it.
1052  */
1053
1054 static void hid_fixup_cymotion_descriptor(char *rdesc, int rsize)
1055 {
1056         if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
1057                 info("Fixing up Cherry Cymotion report descriptor");
1058                 rdesc[11] = rdesc[16] = 0xff;
1059                 rdesc[12] = rdesc[17] = 0x03;
1060         }
1061 }
1062
1063 static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1064 {
1065         struct usb_host_interface *interface = intf->cur_altsetting;
1066         struct usb_device *dev = interface_to_usbdev (intf);
1067         struct hid_descriptor *hdesc;
1068         struct hid_device *hid;
1069         unsigned quirks = 0, rsize = 0;
1070         char *rdesc;
1071         int n, len, insize = 0;
1072
1073         /* Ignore all Wacom devices */
1074         if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM)
1075                 return NULL;
1076
1077         for (n = 0; hid_blacklist[n].idVendor; n++)
1078                 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) &&
1079                         (hid_blacklist[n].idProduct == le16_to_cpu(dev->descriptor.idProduct)))
1080                                 quirks = hid_blacklist[n].quirks;
1081
1082         /* Many keyboards and mice don't like to be polled for reports,
1083          * so we will always set the HID_QUIRK_NOGET flag for them. */
1084         if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
1085                 if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||
1086                         interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
1087                                 quirks |= HID_QUIRK_NOGET;
1088         }
1089
1090         if (quirks & HID_QUIRK_IGNORE)
1091                 return NULL;
1092
1093         if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&
1094             (!interface->desc.bNumEndpoints ||
1095              usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {
1096                 dbg("class descriptor not present\n");
1097                 return NULL;
1098         }
1099
1100         for (n = 0; n < hdesc->bNumDescriptors; n++)
1101                 if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)
1102                         rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
1103
1104         if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
1105                 dbg("weird size of report descriptor (%u)", rsize);
1106                 return NULL;
1107         }
1108
1109         if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) {
1110                 dbg("couldn't allocate rdesc memory");
1111                 return NULL;
1112         }
1113
1114         hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
1115
1116         if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) {
1117                 dbg("reading report descriptor failed");
1118                 kfree(rdesc);
1119                 return NULL;
1120         }
1121
1122         if ((quirks & HID_QUIRK_CYMOTION))
1123                 hid_fixup_cymotion_descriptor(rdesc, rsize);
1124
1125 #ifdef DEBUG_DATA
1126         printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n);
1127         for (n = 0; n < rsize; n++)
1128                 printk(" %02x", (unsigned char) rdesc[n]);
1129         printk("\n");
1130 #endif
1131
1132         if (!(hid = hid_parse_report(rdesc, n))) {
1133                 dbg("parsing report descriptor failed");
1134                 kfree(rdesc);
1135                 return NULL;
1136         }
1137
1138         kfree(rdesc);
1139         hid->quirks = quirks;
1140
1141         hid->bufsize = HID_MIN_BUFFER_SIZE;
1142         hid_find_max_report(hid, HID_INPUT_REPORT, &hid->bufsize);
1143         hid_find_max_report(hid, HID_OUTPUT_REPORT, &hid->bufsize);
1144         hid_find_max_report(hid, HID_FEATURE_REPORT, &hid->bufsize);
1145
1146         if (hid->bufsize > HID_MAX_BUFFER_SIZE)
1147                 hid->bufsize = HID_MAX_BUFFER_SIZE;
1148
1149         hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
1150
1151         if (insize > HID_MAX_BUFFER_SIZE)
1152                 insize = HID_MAX_BUFFER_SIZE;
1153
1154         if (hid_alloc_buffers(dev, hid)) {
1155                 hid_free_buffers(dev, hid);
1156                 goto fail;
1157         }
1158
1159         for (n = 0; n < interface->desc.bNumEndpoints; n++) {
1160
1161                 struct usb_endpoint_descriptor *endpoint;
1162                 int pipe;
1163                 int interval;
1164
1165                 endpoint = &interface->endpoint[n].desc;
1166                 if ((endpoint->bmAttributes & 3) != 3)          /* Not an interrupt endpoint */
1167                         continue;
1168
1169                 interval = endpoint->bInterval;
1170
1171                 /* Change the polling interval of mice. */
1172                 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
1173                         interval = hid_mousepoll_interval;
1174
1175                 if (usb_endpoint_dir_in(endpoint)) {
1176                         if (hid->urbin)
1177                                 continue;
1178                         if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
1179                                 goto fail;
1180                         pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
1181                         usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, insize,
1182                                          hid_irq_in, hid, interval);
1183                         hid->urbin->transfer_dma = hid->inbuf_dma;
1184                         hid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1185                 } else {
1186                         if (hid->urbout)
1187                                 continue;
1188                         if (!(hid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
1189                                 goto fail;
1190                         pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress);
1191                         usb_fill_int_urb(hid->urbout, dev, pipe, hid->outbuf, 0,
1192                                          hid_irq_out, hid, interval);
1193                         hid->urbout->transfer_dma = hid->outbuf_dma;
1194                         hid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1195                 }
1196         }
1197
1198         if (!hid->urbin) {
1199                 err("couldn't find an input interrupt endpoint");
1200                 goto fail;
1201         }
1202
1203         init_waitqueue_head(&hid->wait);
1204
1205         INIT_WORK(&hid->reset_work, hid_reset);
1206         setup_timer(&hid->io_retry, hid_retry_timeout, (unsigned long) hid);
1207
1208         spin_lock_init(&hid->inlock);
1209         spin_lock_init(&hid->outlock);
1210         spin_lock_init(&hid->ctrllock);
1211
1212         hid->version = le16_to_cpu(hdesc->bcdHID);
1213         hid->country = hdesc->bCountryCode;
1214         hid->dev = dev;
1215         hid->intf = intf;
1216         hid->ifnum = interface->desc.bInterfaceNumber;
1217
1218         hid->name[0] = 0;
1219
1220         if (dev->manufacturer)
1221                 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
1222
1223         if (dev->product) {
1224                 if (dev->manufacturer)
1225                         strlcat(hid->name, " ", sizeof(hid->name));
1226                 strlcat(hid->name, dev->product, sizeof(hid->name));
1227         }
1228
1229         if (!strlen(hid->name))
1230                 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
1231                          le16_to_cpu(dev->descriptor.idVendor),
1232                          le16_to_cpu(dev->descriptor.idProduct));
1233
1234         usb_make_path(dev, hid->phys, sizeof(hid->phys));
1235         strlcat(hid->phys, "/input", sizeof(hid->phys));
1236         len = strlen(hid->phys);
1237         if (len < sizeof(hid->phys) - 1)
1238                 snprintf(hid->phys + len, sizeof(hid->phys) - len,
1239                          "%d", intf->altsetting[0].desc.bInterfaceNumber);
1240
1241         if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
1242                 hid->uniq[0] = 0;
1243
1244         hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
1245         if (!hid->urbctrl)
1246                 goto fail;
1247
1248         usb_fill_control_urb(hid->urbctrl, dev, 0, (void *) hid->cr,
1249                              hid->ctrlbuf, 1, hid_ctrl, hid);
1250         hid->urbctrl->setup_dma = hid->cr_dma;
1251         hid->urbctrl->transfer_dma = hid->ctrlbuf_dma;
1252         hid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
1253
1254         return hid;
1255
1256 fail:
1257         usb_free_urb(hid->urbin);
1258         usb_free_urb(hid->urbout);
1259         usb_free_urb(hid->urbctrl);
1260         hid_free_buffers(dev, hid);
1261         hid_free_device(hid);
1262
1263         return NULL;
1264 }
1265
1266 static void hid_disconnect(struct usb_interface *intf)
1267 {
1268         struct hid_device *hid = usb_get_intfdata (intf);
1269
1270         if (!hid)
1271                 return;
1272
1273         spin_lock_irq(&hid->inlock);    /* Sync with error handler */
1274         usb_set_intfdata(intf, NULL);
1275         spin_unlock_irq(&hid->inlock);
1276         usb_kill_urb(hid->urbin);
1277         usb_kill_urb(hid->urbout);
1278         usb_kill_urb(hid->urbctrl);
1279
1280         del_timer_sync(&hid->io_retry);
1281         flush_scheduled_work();
1282
1283         if (hid->claimed & HID_CLAIMED_INPUT)
1284                 hidinput_disconnect(hid);
1285         if (hid->claimed & HID_CLAIMED_HIDDEV)
1286                 hiddev_disconnect(hid);
1287
1288         usb_free_urb(hid->urbin);
1289         usb_free_urb(hid->urbctrl);
1290         usb_free_urb(hid->urbout);
1291
1292         hid_free_buffers(hid->dev, hid);
1293         hid_free_device(hid);
1294 }
1295
1296 static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
1297 {
1298         struct hid_device *hid;
1299         char path[64];
1300         int i;
1301         char *c;
1302
1303         dbg("HID probe called for ifnum %d",
1304                         intf->altsetting->desc.bInterfaceNumber);
1305
1306         if (!(hid = usb_hid_configure(intf)))
1307                 return -ENODEV;
1308
1309         hid_init_reports(hid);
1310         hid_dump_device(hid);
1311
1312         if (!hidinput_connect(hid))
1313                 hid->claimed |= HID_CLAIMED_INPUT;
1314         if (!hiddev_connect(hid))
1315                 hid->claimed |= HID_CLAIMED_HIDDEV;
1316
1317         usb_set_intfdata(intf, hid);
1318
1319         if (!hid->claimed) {
1320                 printk ("HID device not claimed by input or hiddev\n");
1321                 hid_disconnect(intf);
1322                 return -ENODEV;
1323         }
1324
1325         printk(KERN_INFO);
1326
1327         if (hid->claimed & HID_CLAIMED_INPUT)
1328                 printk("input");
1329         if (hid->claimed == (HID_CLAIMED_INPUT | HID_CLAIMED_HIDDEV))
1330                 printk(",");
1331         if (hid->claimed & HID_CLAIMED_HIDDEV)
1332                 printk("hiddev%d", hid->minor);
1333
1334         c = "Device";
1335         for (i = 0; i < hid->maxcollection; i++) {
1336                 if (hid->collection[i].type == HID_COLLECTION_APPLICATION &&
1337                     (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1338                     (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) {
1339                         c = hid_types[hid->collection[i].usage & 0xffff];
1340                         break;
1341                 }
1342         }
1343
1344         usb_make_path(interface_to_usbdev(intf), path, 63);
1345
1346         printk(": USB HID v%x.%02x %s [%s] on %s\n",
1347                 hid->version >> 8, hid->version & 0xff, c, hid->name, path);
1348
1349         return 0;
1350 }
1351
1352 static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1353 {
1354         struct hid_device *hid = usb_get_intfdata (intf);
1355
1356         spin_lock_irq(&hid->inlock);    /* Sync with error handler */
1357         set_bit(HID_SUSPENDED, &hid->iofl);
1358         spin_unlock_irq(&hid->inlock);
1359         del_timer(&hid->io_retry);
1360         usb_kill_urb(hid->urbin);
1361         dev_dbg(&intf->dev, "suspend\n");
1362         return 0;
1363 }
1364
1365 static int hid_resume(struct usb_interface *intf)
1366 {
1367         struct hid_device *hid = usb_get_intfdata (intf);
1368         int status;
1369
1370         clear_bit(HID_SUSPENDED, &hid->iofl);
1371         hid->retry_delay = 0;
1372         status = hid_start_in(hid);
1373         dev_dbg(&intf->dev, "resume status %d\n", status);
1374         return status;
1375 }
1376
1377 /* Treat USB reset pretty much the same as suspend/resume */
1378 static void hid_pre_reset(struct usb_interface *intf)
1379 {
1380         /* FIXME: What if the interface is already suspended? */
1381         hid_suspend(intf, PMSG_ON);
1382 }
1383
1384 static void hid_post_reset(struct usb_interface *intf)
1385 {
1386         struct usb_device *dev = interface_to_usbdev (intf);
1387
1388         hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0);
1389         /* FIXME: Any more reinitialization needed? */
1390
1391         hid_resume(intf);
1392 }
1393
1394 static struct usb_device_id hid_usb_ids [] = {
1395         { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
1396                 .bInterfaceClass = USB_INTERFACE_CLASS_HID },
1397         { }                                             /* Terminating entry */
1398 };
1399
1400 MODULE_DEVICE_TABLE (usb, hid_usb_ids);
1401
1402 static struct usb_driver hid_driver = {
1403         .name =         "usbhid",
1404         .probe =        hid_probe,
1405         .disconnect =   hid_disconnect,
1406         .suspend =      hid_suspend,
1407         .resume =       hid_resume,
1408         .pre_reset =    hid_pre_reset,
1409         .post_reset =   hid_post_reset,
1410         .id_table =     hid_usb_ids,
1411 };
1412
1413 static int __init hid_init(void)
1414 {
1415         int retval;
1416         retval = hiddev_init();
1417         if (retval)
1418                 goto hiddev_init_fail;
1419         retval = usb_register(&hid_driver);
1420         if (retval)
1421                 goto usb_register_fail;
1422         info(DRIVER_VERSION ":" DRIVER_DESC);
1423
1424         return 0;
1425 usb_register_fail:
1426         hiddev_exit();
1427 hiddev_init_fail:
1428         return retval;
1429 }
1430
1431 static void __exit hid_exit(void)
1432 {
1433         usb_deregister(&hid_driver);
1434         hiddev_exit();
1435 }
1436
1437 module_init(hid_init);
1438 module_exit(hid_exit);
1439
1440 MODULE_AUTHOR(DRIVER_AUTHOR);
1441 MODULE_DESCRIPTION(DRIVER_DESC);
1442 MODULE_LICENSE(DRIVER_LICENSE);