2 * USB HID support for Linux
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) 2007-2008 Oliver Neukum
8 * Copyright (c) 2006-2009 Jiri Kosina
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/list.h>
24 #include <linux/mutex.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 #include <linux/workqueue.h>
32 #include <linux/usb.h>
34 #include <linux/hid.h>
35 #include <linux/hiddev.h>
36 #include <linux/hid-debug.h>
37 #include <linux/hidraw.h>
44 #define DRIVER_VERSION "v2.6"
45 #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik, Jiri Kosina"
46 #define DRIVER_DESC "USB HID core driver"
47 #define DRIVER_LICENSE "GPL"
53 static unsigned int hid_mousepoll_interval
;
54 module_param_named(mousepoll
, hid_mousepoll_interval
, uint
, 0644);
55 MODULE_PARM_DESC(mousepoll
, "Polling interval of mice");
57 static unsigned int ignoreled
;
58 module_param_named(ignoreled
, ignoreled
, uint
, 0644);
59 MODULE_PARM_DESC(ignoreled
, "Autosuspend with active leds");
61 /* Quirks specified at module load time */
62 static char *quirks_param
[MAX_USBHID_BOOT_QUIRKS
] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS
- 1) ] = NULL
};
63 module_param_array_named(quirks
, quirks_param
, charp
, NULL
, 0444);
64 MODULE_PARM_DESC(quirks
, "Add/modify USB HID quirks by specifying "
65 " quirks=vendorID:productID:quirks"
66 " where vendorID, productID, and quirks are all in"
69 * Input submission and I/O error handler.
71 static DEFINE_MUTEX(hid_open_mut
);
72 static struct workqueue_struct
*resumption_waker
;
74 static void hid_io_error(struct hid_device
*hid
);
75 static int hid_submit_out(struct hid_device
*hid
);
76 static int hid_submit_ctrl(struct hid_device
*hid
);
77 static void hid_cancel_delayed_stuff(struct usbhid_device
*usbhid
);
79 /* Start up the input URB */
80 static int hid_start_in(struct hid_device
*hid
)
84 struct usbhid_device
*usbhid
= hid
->driver_data
;
86 spin_lock_irqsave(&usbhid
->lock
, flags
);
88 !test_bit(HID_DISCONNECTED
, &usbhid
->iofl
) &&
89 !test_bit(HID_REPORTED_IDLE
, &usbhid
->iofl
) &&
90 !test_and_set_bit(HID_IN_RUNNING
, &usbhid
->iofl
)) {
91 rc
= usb_submit_urb(usbhid
->urbin
, GFP_ATOMIC
);
93 clear_bit(HID_IN_RUNNING
, &usbhid
->iofl
);
95 spin_unlock_irqrestore(&usbhid
->lock
, flags
);
99 /* I/O retry timer routine */
100 static void hid_retry_timeout(unsigned long _hid
)
102 struct hid_device
*hid
= (struct hid_device
*) _hid
;
103 struct usbhid_device
*usbhid
= hid
->driver_data
;
105 dev_dbg(&usbhid
->intf
->dev
, "retrying intr urb\n");
106 if (hid_start_in(hid
))
110 /* Workqueue routine to reset the device or clear a halt */
111 static void hid_reset(struct work_struct
*work
)
113 struct usbhid_device
*usbhid
=
114 container_of(work
, struct usbhid_device
, reset_work
);
115 struct hid_device
*hid
= usbhid
->hid
;
118 if (test_bit(HID_CLEAR_HALT
, &usbhid
->iofl
)) {
119 dev_dbg(&usbhid
->intf
->dev
, "clear halt\n");
120 rc
= usb_clear_halt(hid_to_usb_dev(hid
), usbhid
->urbin
->pipe
);
121 clear_bit(HID_CLEAR_HALT
, &usbhid
->iofl
);
125 else if (test_bit(HID_RESET_PENDING
, &usbhid
->iofl
)) {
126 dev_dbg(&usbhid
->intf
->dev
, "resetting device\n");
127 rc
= usb_lock_device_for_reset(hid_to_usb_dev(hid
), usbhid
->intf
);
129 rc
= usb_reset_device(hid_to_usb_dev(hid
));
130 usb_unlock_device(hid_to_usb_dev(hid
));
132 clear_bit(HID_RESET_PENDING
, &usbhid
->iofl
);
137 if (!test_bit(HID_IN_RUNNING
, &usbhid
->iofl
))
141 err_hid("can't reset device, %s-%s/input%d, status %d",
142 hid_to_usb_dev(hid
)->bus
->bus_name
,
143 hid_to_usb_dev(hid
)->devpath
,
153 /* Main I/O error handler */
154 static void hid_io_error(struct hid_device
*hid
)
157 struct usbhid_device
*usbhid
= hid
->driver_data
;
159 spin_lock_irqsave(&usbhid
->lock
, flags
);
161 /* Stop when disconnected */
162 if (test_bit(HID_DISCONNECTED
, &usbhid
->iofl
))
165 /* If it has been a while since the last error, we'll assume
166 * this a brand new error and reset the retry timeout. */
167 if (time_after(jiffies
, usbhid
->stop_retry
+ HZ
/2))
168 usbhid
->retry_delay
= 0;
170 /* When an error occurs, retry at increasing intervals */
171 if (usbhid
->retry_delay
== 0) {
172 usbhid
->retry_delay
= 13; /* Then 26, 52, 104, 104, ... */
173 usbhid
->stop_retry
= jiffies
+ msecs_to_jiffies(1000);
174 } else if (usbhid
->retry_delay
< 100)
175 usbhid
->retry_delay
*= 2;
177 if (time_after(jiffies
, usbhid
->stop_retry
)) {
179 /* Retries failed, so do a port reset */
180 if (!test_and_set_bit(HID_RESET_PENDING
, &usbhid
->iofl
)) {
181 schedule_work(&usbhid
->reset_work
);
186 mod_timer(&usbhid
->io_retry
,
187 jiffies
+ msecs_to_jiffies(usbhid
->retry_delay
));
189 spin_unlock_irqrestore(&usbhid
->lock
, flags
);
192 static void usbhid_mark_busy(struct usbhid_device
*usbhid
)
194 struct usb_interface
*intf
= usbhid
->intf
;
196 usb_mark_last_busy(interface_to_usbdev(intf
));
199 static int usbhid_restart_out_queue(struct usbhid_device
*usbhid
)
201 struct hid_device
*hid
= usb_get_intfdata(usbhid
->intf
);
207 if ((kicked
= (usbhid
->outhead
!= usbhid
->outtail
))) {
208 dbg("Kicking head %d tail %d", usbhid
->outhead
, usbhid
->outtail
);
209 if (hid_submit_out(hid
)) {
210 clear_bit(HID_OUT_RUNNING
, &usbhid
->iofl
);
211 wake_up(&usbhid
->wait
);
217 static int usbhid_restart_ctrl_queue(struct usbhid_device
*usbhid
)
219 struct hid_device
*hid
= usb_get_intfdata(usbhid
->intf
);
222 WARN_ON(hid
== NULL
);
226 if ((kicked
= (usbhid
->ctrlhead
!= usbhid
->ctrltail
))) {
227 dbg("Kicking head %d tail %d", usbhid
->ctrlhead
, usbhid
->ctrltail
);
228 if (hid_submit_ctrl(hid
)) {
229 clear_bit(HID_CTRL_RUNNING
, &usbhid
->iofl
);
230 wake_up(&usbhid
->wait
);
237 * Input interrupt completion handler.
240 static void hid_irq_in(struct urb
*urb
)
242 struct hid_device
*hid
= urb
->context
;
243 struct usbhid_device
*usbhid
= hid
->driver_data
;
246 switch (urb
->status
) {
247 case 0: /* success */
248 usbhid_mark_busy(usbhid
);
249 usbhid
->retry_delay
= 0;
250 hid_input_report(urb
->context
, HID_INPUT_REPORT
,
251 urb
->transfer_buffer
,
252 urb
->actual_length
, 1);
254 * autosuspend refused while keys are pressed
255 * because most keyboards don't wake up when
258 if (hid_check_keys_pressed(hid
))
259 set_bit(HID_KEYS_PRESSED
, &usbhid
->iofl
);
261 clear_bit(HID_KEYS_PRESSED
, &usbhid
->iofl
);
263 case -EPIPE
: /* stall */
264 usbhid_mark_busy(usbhid
);
265 clear_bit(HID_IN_RUNNING
, &usbhid
->iofl
);
266 set_bit(HID_CLEAR_HALT
, &usbhid
->iofl
);
267 schedule_work(&usbhid
->reset_work
);
269 case -ECONNRESET
: /* unlink */
271 case -ESHUTDOWN
: /* unplug */
272 clear_bit(HID_IN_RUNNING
, &usbhid
->iofl
);
274 case -EILSEQ
: /* protocol error or unplug */
275 case -EPROTO
: /* protocol error or unplug */
276 case -ETIME
: /* protocol error or unplug */
277 case -ETIMEDOUT
: /* Should never happen, but... */
278 usbhid_mark_busy(usbhid
);
279 clear_bit(HID_IN_RUNNING
, &usbhid
->iofl
);
283 dev_warn(&urb
->dev
->dev
, "input irq status %d "
284 "received\n", urb
->status
);
287 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
289 clear_bit(HID_IN_RUNNING
, &usbhid
->iofl
);
290 if (status
!= -EPERM
) {
291 err_hid("can't resubmit intr, %s-%s/input%d, status %d",
292 hid_to_usb_dev(hid
)->bus
->bus_name
,
293 hid_to_usb_dev(hid
)->devpath
,
294 usbhid
->ifnum
, status
);
300 static int hid_submit_out(struct hid_device
*hid
)
302 struct hid_report
*report
;
304 struct usbhid_device
*usbhid
= hid
->driver_data
;
306 report
= usbhid
->out
[usbhid
->outtail
].report
;
307 raw_report
= usbhid
->out
[usbhid
->outtail
].raw_report
;
309 if (!test_bit(HID_REPORTED_IDLE
, &usbhid
->iofl
)) {
310 usbhid
->urbout
->transfer_buffer_length
= ((report
->size
- 1) >> 3) + 1 + (report
->id
> 0);
311 usbhid
->urbout
->dev
= hid_to_usb_dev(hid
);
312 memcpy(usbhid
->outbuf
, raw_report
, usbhid
->urbout
->transfer_buffer_length
);
315 dbg_hid("submitting out urb\n");
317 if (usb_submit_urb(usbhid
->urbout
, GFP_ATOMIC
)) {
318 err_hid("usb_submit_urb(out) failed");
321 usbhid
->last_out
= jiffies
;
324 * queue work to wake up the device.
325 * as the work queue is freezeable, this is safe
326 * with respect to STD and STR
328 queue_work(resumption_waker
, &usbhid
->restart_work
);
334 static int hid_submit_ctrl(struct hid_device
*hid
)
336 struct hid_report
*report
;
340 struct usbhid_device
*usbhid
= hid
->driver_data
;
342 report
= usbhid
->ctrl
[usbhid
->ctrltail
].report
;
343 raw_report
= usbhid
->ctrl
[usbhid
->ctrltail
].raw_report
;
344 dir
= usbhid
->ctrl
[usbhid
->ctrltail
].dir
;
346 if (!test_bit(HID_REPORTED_IDLE
, &usbhid
->iofl
)) {
347 len
= ((report
->size
- 1) >> 3) + 1 + (report
->id
> 0);
348 if (dir
== USB_DIR_OUT
) {
349 usbhid
->urbctrl
->pipe
= usb_sndctrlpipe(hid_to_usb_dev(hid
), 0);
350 usbhid
->urbctrl
->transfer_buffer_length
= len
;
351 memcpy(usbhid
->ctrlbuf
, raw_report
, len
);
354 int maxpacket
, padlen
;
356 usbhid
->urbctrl
->pipe
= usb_rcvctrlpipe(hid_to_usb_dev(hid
), 0);
357 maxpacket
= usb_maxpacket(hid_to_usb_dev(hid
), usbhid
->urbctrl
->pipe
, 0);
359 padlen
= DIV_ROUND_UP(len
, maxpacket
);
361 if (padlen
> usbhid
->bufsize
)
362 padlen
= usbhid
->bufsize
;
365 usbhid
->urbctrl
->transfer_buffer_length
= padlen
;
367 usbhid
->urbctrl
->dev
= hid_to_usb_dev(hid
);
369 usbhid
->cr
->bRequestType
= USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| dir
;
370 usbhid
->cr
->bRequest
= (dir
== USB_DIR_OUT
) ? HID_REQ_SET_REPORT
: HID_REQ_GET_REPORT
;
371 usbhid
->cr
->wValue
= cpu_to_le16(((report
->type
+ 1) << 8) | report
->id
);
372 usbhid
->cr
->wIndex
= cpu_to_le16(usbhid
->ifnum
);
373 usbhid
->cr
->wLength
= cpu_to_le16(len
);
375 dbg_hid("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u\n",
376 usbhid
->cr
->bRequest
== HID_REQ_SET_REPORT
? "Set_Report" : "Get_Report",
377 usbhid
->cr
->wValue
, usbhid
->cr
->wIndex
, usbhid
->cr
->wLength
);
379 if (usb_submit_urb(usbhid
->urbctrl
, GFP_ATOMIC
)) {
380 err_hid("usb_submit_urb(ctrl) failed");
383 usbhid
->last_ctrl
= jiffies
;
386 * queue work to wake up the device.
387 * as the work queue is freezeable, this is safe
388 * with respect to STD and STR
390 queue_work(resumption_waker
, &usbhid
->restart_work
);
397 * Output interrupt completion handler.
400 static void hid_irq_out(struct urb
*urb
)
402 struct hid_device
*hid
= urb
->context
;
403 struct usbhid_device
*usbhid
= hid
->driver_data
;
407 switch (urb
->status
) {
408 case 0: /* success */
410 case -ESHUTDOWN
: /* unplug */
412 case -EILSEQ
: /* protocol error or unplug */
413 case -EPROTO
: /* protocol error or unplug */
414 case -ECONNRESET
: /* unlink */
418 dev_warn(&urb
->dev
->dev
, "output irq status %d "
419 "received\n", urb
->status
);
422 spin_lock_irqsave(&usbhid
->lock
, flags
);
425 usbhid
->outtail
= usbhid
->outhead
;
427 usbhid
->outtail
= (usbhid
->outtail
+ 1) & (HID_OUTPUT_FIFO_SIZE
- 1);
429 if (usbhid
->outhead
!= usbhid
->outtail
) {
430 if (hid_submit_out(hid
)) {
431 clear_bit(HID_OUT_RUNNING
, &usbhid
->iofl
);
432 wake_up(&usbhid
->wait
);
434 spin_unlock_irqrestore(&usbhid
->lock
, flags
);
438 clear_bit(HID_OUT_RUNNING
, &usbhid
->iofl
);
439 spin_unlock_irqrestore(&usbhid
->lock
, flags
);
440 wake_up(&usbhid
->wait
);
444 * Control pipe completion handler.
447 static void hid_ctrl(struct urb
*urb
)
449 struct hid_device
*hid
= urb
->context
;
450 struct usbhid_device
*usbhid
= hid
->driver_data
;
451 int unplug
= 0, status
= urb
->status
;
453 spin_lock(&usbhid
->lock
);
456 case 0: /* success */
457 if (usbhid
->ctrl
[usbhid
->ctrltail
].dir
== USB_DIR_IN
)
458 hid_input_report(urb
->context
,
459 usbhid
->ctrl
[usbhid
->ctrltail
].report
->type
,
460 urb
->transfer_buffer
, urb
->actual_length
, 0);
462 case -ESHUTDOWN
: /* unplug */
464 case -EILSEQ
: /* protocol error or unplug */
465 case -EPROTO
: /* protocol error or unplug */
466 case -ECONNRESET
: /* unlink */
468 case -EPIPE
: /* report not available */
471 dev_warn(&urb
->dev
->dev
, "ctrl urb status %d "
472 "received\n", status
);
476 usbhid
->ctrltail
= usbhid
->ctrlhead
;
478 usbhid
->ctrltail
= (usbhid
->ctrltail
+ 1) & (HID_CONTROL_FIFO_SIZE
- 1);
480 if (usbhid
->ctrlhead
!= usbhid
->ctrltail
) {
481 if (hid_submit_ctrl(hid
)) {
482 clear_bit(HID_CTRL_RUNNING
, &usbhid
->iofl
);
483 wake_up(&usbhid
->wait
);
485 spin_unlock(&usbhid
->lock
);
489 clear_bit(HID_CTRL_RUNNING
, &usbhid
->iofl
);
490 spin_unlock(&usbhid
->lock
);
491 wake_up(&usbhid
->wait
);
494 static void __usbhid_submit_report(struct hid_device
*hid
, struct hid_report
*report
,
498 struct usbhid_device
*usbhid
= hid
->driver_data
;
499 int len
= ((report
->size
- 1) >> 3) + 1 + (report
->id
> 0);
501 if ((hid
->quirks
& HID_QUIRK_NOGET
) && dir
== USB_DIR_IN
)
504 if (usbhid
->urbout
&& dir
== USB_DIR_OUT
&& report
->type
== HID_OUTPUT_REPORT
) {
505 if ((head
= (usbhid
->outhead
+ 1) & (HID_OUTPUT_FIFO_SIZE
- 1)) == usbhid
->outtail
) {
506 dev_warn(&hid
->dev
, "output queue full\n");
510 usbhid
->out
[usbhid
->outhead
].raw_report
= kmalloc(len
, GFP_ATOMIC
);
511 if (!usbhid
->out
[usbhid
->outhead
].raw_report
) {
512 dev_warn(&hid
->dev
, "output queueing failed\n");
515 hid_output_report(report
, usbhid
->out
[usbhid
->outhead
].raw_report
);
516 usbhid
->out
[usbhid
->outhead
].report
= report
;
517 usbhid
->outhead
= head
;
519 if (!test_and_set_bit(HID_OUT_RUNNING
, &usbhid
->iofl
)) {
520 if (hid_submit_out(hid
))
521 clear_bit(HID_OUT_RUNNING
, &usbhid
->iofl
);
524 * the queue is known to run
525 * but an earlier request may be stuck
526 * we may need to time out
527 * no race because this is called under
530 if (time_after(jiffies
, usbhid
->last_out
+ HZ
* 5))
531 usb_unlink_urb(usbhid
->urbout
);
536 if ((head
= (usbhid
->ctrlhead
+ 1) & (HID_CONTROL_FIFO_SIZE
- 1)) == usbhid
->ctrltail
) {
537 dev_warn(&hid
->dev
, "control queue full\n");
541 if (dir
== USB_DIR_OUT
) {
542 usbhid
->ctrl
[usbhid
->ctrlhead
].raw_report
= kmalloc(len
, GFP_ATOMIC
);
543 if (!usbhid
->ctrl
[usbhid
->ctrlhead
].raw_report
) {
544 dev_warn(&hid
->dev
, "control queueing failed\n");
547 hid_output_report(report
, usbhid
->ctrl
[usbhid
->ctrlhead
].raw_report
);
549 usbhid
->ctrl
[usbhid
->ctrlhead
].report
= report
;
550 usbhid
->ctrl
[usbhid
->ctrlhead
].dir
= dir
;
551 usbhid
->ctrlhead
= head
;
553 if (!test_and_set_bit(HID_CTRL_RUNNING
, &usbhid
->iofl
)) {
554 if (hid_submit_ctrl(hid
))
555 clear_bit(HID_CTRL_RUNNING
, &usbhid
->iofl
);
558 * the queue is known to run
559 * but an earlier request may be stuck
560 * we may need to time out
561 * no race because this is called under
564 if (time_after(jiffies
, usbhid
->last_ctrl
+ HZ
* 5))
565 usb_unlink_urb(usbhid
->urbctrl
);
569 void usbhid_submit_report(struct hid_device
*hid
, struct hid_report
*report
, unsigned char dir
)
571 struct usbhid_device
*usbhid
= hid
->driver_data
;
574 spin_lock_irqsave(&usbhid
->lock
, flags
);
575 __usbhid_submit_report(hid
, report
, dir
);
576 spin_unlock_irqrestore(&usbhid
->lock
, flags
);
578 EXPORT_SYMBOL_GPL(usbhid_submit_report
);
580 static int usb_hidinput_input_event(struct input_dev
*dev
, unsigned int type
, unsigned int code
, int value
)
582 struct hid_device
*hid
= input_get_drvdata(dev
);
583 struct usbhid_device
*usbhid
= hid
->driver_data
;
584 struct hid_field
*field
;
589 return input_ff_event(dev
, type
, code
, value
);
594 if ((offset
= hidinput_find_field(hid
, type
, code
, &field
)) == -1) {
595 dev_warn(&dev
->dev
, "event field not found\n");
599 hid_set_field(field
, offset
, value
);
601 spin_lock_irqsave(&usbhid
->lock
, flags
);
603 spin_unlock_irqrestore(&usbhid
->lock
, flags
);
605 spin_lock_irqsave(&usbhid
->lock
, flags
);
607 spin_unlock_irqrestore(&usbhid
->lock
, flags
);
609 usbhid_submit_report(hid
, field
->report
, USB_DIR_OUT
);
614 int usbhid_wait_io(struct hid_device
*hid
)
616 struct usbhid_device
*usbhid
= hid
->driver_data
;
618 if (!wait_event_timeout(usbhid
->wait
,
619 (!test_bit(HID_CTRL_RUNNING
, &usbhid
->iofl
) &&
620 !test_bit(HID_OUT_RUNNING
, &usbhid
->iofl
)),
622 dbg_hid("timeout waiting for ctrl or out queue to clear\n");
629 static int hid_set_idle(struct usb_device
*dev
, int ifnum
, int report
, int idle
)
631 return usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
632 HID_REQ_SET_IDLE
, USB_TYPE_CLASS
| USB_RECIP_INTERFACE
, (idle
<< 8) | report
,
633 ifnum
, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
636 static int hid_get_class_descriptor(struct usb_device
*dev
, int ifnum
,
637 unsigned char type
, void *buf
, int size
)
639 int result
, retries
= 4;
641 memset(buf
, 0, size
);
644 result
= usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0),
645 USB_REQ_GET_DESCRIPTOR
, USB_RECIP_INTERFACE
| USB_DIR_IN
,
646 (type
<< 8), ifnum
, buf
, size
, USB_CTRL_GET_TIMEOUT
);
648 } while (result
< size
&& retries
);
652 int usbhid_open(struct hid_device
*hid
)
654 struct usbhid_device
*usbhid
= hid
->driver_data
;
657 mutex_lock(&hid_open_mut
);
659 res
= usb_autopm_get_interface(usbhid
->intf
);
660 /* the device must be awake to reliable request remote wakeup */
663 mutex_unlock(&hid_open_mut
);
666 usbhid
->intf
->needs_remote_wakeup
= 1;
667 if (hid_start_in(hid
))
670 usb_autopm_put_interface(usbhid
->intf
);
672 mutex_unlock(&hid_open_mut
);
676 void usbhid_close(struct hid_device
*hid
)
678 struct usbhid_device
*usbhid
= hid
->driver_data
;
680 mutex_lock(&hid_open_mut
);
682 /* protecting hid->open to make sure we don't restart
683 * data acquistion due to a resumption we no longer
686 spin_lock_irq(&usbhid
->lock
);
688 spin_unlock_irq(&usbhid
->lock
);
689 hid_cancel_delayed_stuff(usbhid
);
690 usb_kill_urb(usbhid
->urbin
);
691 usbhid
->intf
->needs_remote_wakeup
= 0;
693 spin_unlock_irq(&usbhid
->lock
);
695 mutex_unlock(&hid_open_mut
);
699 * Initialize all reports
702 void usbhid_init_reports(struct hid_device
*hid
)
704 struct hid_report
*report
;
705 struct usbhid_device
*usbhid
= hid
->driver_data
;
708 list_for_each_entry(report
, &hid
->report_enum
[HID_INPUT_REPORT
].report_list
, list
)
709 usbhid_submit_report(hid
, report
, USB_DIR_IN
);
711 list_for_each_entry(report
, &hid
->report_enum
[HID_FEATURE_REPORT
].report_list
, list
)
712 usbhid_submit_report(hid
, report
, USB_DIR_IN
);
715 ret
= usbhid_wait_io(hid
);
718 if (test_bit(HID_CTRL_RUNNING
, &usbhid
->iofl
))
719 usb_kill_urb(usbhid
->urbctrl
);
720 if (test_bit(HID_OUT_RUNNING
, &usbhid
->iofl
))
721 usb_kill_urb(usbhid
->urbout
);
722 ret
= usbhid_wait_io(hid
);
726 dev_warn(&hid
->dev
, "timeout initializing reports\n");
730 * Reset LEDs which BIOS might have left on. For now, just NumLock (0x01).
732 static int hid_find_field_early(struct hid_device
*hid
, unsigned int page
,
733 unsigned int hid_code
, struct hid_field
**pfield
)
735 struct hid_report
*report
;
736 struct hid_field
*field
;
737 struct hid_usage
*usage
;
740 list_for_each_entry(report
, &hid
->report_enum
[HID_OUTPUT_REPORT
].report_list
, list
) {
741 for (i
= 0; i
< report
->maxfield
; i
++) {
742 field
= report
->field
[i
];
743 for (j
= 0; j
< field
->maxusage
; j
++) {
744 usage
= &field
->usage
[j
];
745 if ((usage
->hid
& HID_USAGE_PAGE
) == page
&&
746 (usage
->hid
& 0xFFFF) == hid_code
) {
756 void usbhid_set_leds(struct hid_device
*hid
)
758 struct hid_field
*field
;
761 if ((offset
= hid_find_field_early(hid
, HID_UP_LED
, 0x01, &field
)) != -1) {
762 hid_set_field(field
, offset
, 0);
763 usbhid_submit_report(hid
, field
->report
, USB_DIR_OUT
);
766 EXPORT_SYMBOL_GPL(usbhid_set_leds
);
769 * Traverse the supplied list of reports and find the longest
771 static void hid_find_max_report(struct hid_device
*hid
, unsigned int type
,
774 struct hid_report
*report
;
777 list_for_each_entry(report
, &hid
->report_enum
[type
].report_list
, list
) {
778 size
= ((report
->size
- 1) >> 3) + 1 + hid
->report_enum
[type
].numbered
;
784 static int hid_alloc_buffers(struct usb_device
*dev
, struct hid_device
*hid
)
786 struct usbhid_device
*usbhid
= hid
->driver_data
;
788 usbhid
->inbuf
= usb_buffer_alloc(dev
, usbhid
->bufsize
, GFP_KERNEL
,
790 usbhid
->outbuf
= usb_buffer_alloc(dev
, usbhid
->bufsize
, GFP_KERNEL
,
791 &usbhid
->outbuf_dma
);
792 usbhid
->cr
= usb_buffer_alloc(dev
, sizeof(*usbhid
->cr
), GFP_KERNEL
,
794 usbhid
->ctrlbuf
= usb_buffer_alloc(dev
, usbhid
->bufsize
, GFP_KERNEL
,
795 &usbhid
->ctrlbuf_dma
);
796 if (!usbhid
->inbuf
|| !usbhid
->outbuf
|| !usbhid
->cr
||
803 static int usbhid_output_raw_report(struct hid_device
*hid
, __u8
*buf
, size_t count
)
805 struct usbhid_device
*usbhid
= hid
->driver_data
;
806 struct usb_device
*dev
= hid_to_usb_dev(hid
);
807 struct usb_interface
*intf
= usbhid
->intf
;
808 struct usb_host_interface
*interface
= intf
->cur_altsetting
;
811 ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
813 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
,
814 ((HID_OUTPUT_REPORT
+ 1) << 8) | *buf
,
815 interface
->desc
.bInterfaceNumber
, buf
+ 1, count
- 1,
816 USB_CTRL_SET_TIMEOUT
);
818 /* count also the report id */
825 static void usbhid_restart_queues(struct usbhid_device
*usbhid
)
828 usbhid_restart_out_queue(usbhid
);
829 usbhid_restart_ctrl_queue(usbhid
);
832 static void __usbhid_restart_queues(struct work_struct
*work
)
834 struct usbhid_device
*usbhid
=
835 container_of(work
, struct usbhid_device
, restart_work
);
838 r
= usb_autopm_get_interface(usbhid
->intf
);
841 usb_autopm_put_interface(usbhid
->intf
);
844 static void hid_free_buffers(struct usb_device
*dev
, struct hid_device
*hid
)
846 struct usbhid_device
*usbhid
= hid
->driver_data
;
848 usb_buffer_free(dev
, usbhid
->bufsize
, usbhid
->inbuf
, usbhid
->inbuf_dma
);
849 usb_buffer_free(dev
, usbhid
->bufsize
, usbhid
->outbuf
, usbhid
->outbuf_dma
);
850 usb_buffer_free(dev
, sizeof(*(usbhid
->cr
)), usbhid
->cr
, usbhid
->cr_dma
);
851 usb_buffer_free(dev
, usbhid
->bufsize
, usbhid
->ctrlbuf
, usbhid
->ctrlbuf_dma
);
854 static int usbhid_parse(struct hid_device
*hid
)
856 struct usb_interface
*intf
= to_usb_interface(hid
->dev
.parent
);
857 struct usb_host_interface
*interface
= intf
->cur_altsetting
;
858 struct usb_device
*dev
= interface_to_usbdev (intf
);
859 struct hid_descriptor
*hdesc
;
861 unsigned int rsize
= 0;
865 quirks
= usbhid_lookup_quirk(le16_to_cpu(dev
->descriptor
.idVendor
),
866 le16_to_cpu(dev
->descriptor
.idProduct
));
868 if (quirks
& HID_QUIRK_IGNORE
)
871 /* Many keyboards and mice don't like to be polled for reports,
872 * so we will always set the HID_QUIRK_NOGET flag for them. */
873 if (interface
->desc
.bInterfaceSubClass
== USB_INTERFACE_SUBCLASS_BOOT
) {
874 if (interface
->desc
.bInterfaceProtocol
== USB_INTERFACE_PROTOCOL_KEYBOARD
||
875 interface
->desc
.bInterfaceProtocol
== USB_INTERFACE_PROTOCOL_MOUSE
)
876 quirks
|= HID_QUIRK_NOGET
;
879 if (usb_get_extra_descriptor(interface
, HID_DT_HID
, &hdesc
) &&
880 (!interface
->desc
.bNumEndpoints
||
881 usb_get_extra_descriptor(&interface
->endpoint
[0], HID_DT_HID
, &hdesc
))) {
882 dbg_hid("class descriptor not present\n");
886 hid
->version
= le16_to_cpu(hdesc
->bcdHID
);
887 hid
->country
= hdesc
->bCountryCode
;
889 for (n
= 0; n
< hdesc
->bNumDescriptors
; n
++)
890 if (hdesc
->desc
[n
].bDescriptorType
== HID_DT_REPORT
)
891 rsize
= le16_to_cpu(hdesc
->desc
[n
].wDescriptorLength
);
893 if (!rsize
|| rsize
> HID_MAX_DESCRIPTOR_SIZE
) {
894 dbg_hid("weird size of report descriptor (%u)\n", rsize
);
898 if (!(rdesc
= kmalloc(rsize
, GFP_KERNEL
))) {
899 dbg_hid("couldn't allocate rdesc memory\n");
903 hid_set_idle(dev
, interface
->desc
.bInterfaceNumber
, 0, 0);
905 ret
= hid_get_class_descriptor(dev
, interface
->desc
.bInterfaceNumber
,
906 HID_DT_REPORT
, rdesc
, rsize
);
908 dbg_hid("reading report descriptor failed\n");
913 ret
= hid_parse_report(hid
, rdesc
, rsize
);
916 dbg_hid("parsing report descriptor failed\n");
920 hid
->quirks
|= quirks
;
927 static int usbhid_start(struct hid_device
*hid
)
929 struct usb_interface
*intf
= to_usb_interface(hid
->dev
.parent
);
930 struct usb_host_interface
*interface
= intf
->cur_altsetting
;
931 struct usb_device
*dev
= interface_to_usbdev(intf
);
932 struct usbhid_device
*usbhid
= hid
->driver_data
;
933 unsigned int n
, insize
= 0;
936 clear_bit(HID_DISCONNECTED
, &usbhid
->iofl
);
938 usbhid
->bufsize
= HID_MIN_BUFFER_SIZE
;
939 hid_find_max_report(hid
, HID_INPUT_REPORT
, &usbhid
->bufsize
);
940 hid_find_max_report(hid
, HID_OUTPUT_REPORT
, &usbhid
->bufsize
);
941 hid_find_max_report(hid
, HID_FEATURE_REPORT
, &usbhid
->bufsize
);
943 if (usbhid
->bufsize
> HID_MAX_BUFFER_SIZE
)
944 usbhid
->bufsize
= HID_MAX_BUFFER_SIZE
;
946 hid_find_max_report(hid
, HID_INPUT_REPORT
, &insize
);
948 if (insize
> HID_MAX_BUFFER_SIZE
)
949 insize
= HID_MAX_BUFFER_SIZE
;
951 if (hid_alloc_buffers(dev
, hid
)) {
956 for (n
= 0; n
< interface
->desc
.bNumEndpoints
; n
++) {
957 struct usb_endpoint_descriptor
*endpoint
;
961 endpoint
= &interface
->endpoint
[n
].desc
;
962 if (!usb_endpoint_xfer_int(endpoint
))
965 interval
= endpoint
->bInterval
;
967 /* Some vendors give fullspeed interval on highspeed devides */
968 if (hid
->quirks
& HID_QUIRK_FULLSPEED_INTERVAL
&&
969 dev
->speed
== USB_SPEED_HIGH
) {
970 interval
= fls(endpoint
->bInterval
*8);
971 printk(KERN_INFO
"%s: Fixing fullspeed to highspeed interval: %d -> %d\n",
972 hid
->name
, endpoint
->bInterval
, interval
);
975 /* Change the polling interval of mice. */
976 if (hid
->collection
->usage
== HID_GD_MOUSE
&& hid_mousepoll_interval
> 0)
977 interval
= hid_mousepoll_interval
;
980 if (usb_endpoint_dir_in(endpoint
)) {
983 if (!(usbhid
->urbin
= usb_alloc_urb(0, GFP_KERNEL
)))
985 pipe
= usb_rcvintpipe(dev
, endpoint
->bEndpointAddress
);
986 usb_fill_int_urb(usbhid
->urbin
, dev
, pipe
, usbhid
->inbuf
, insize
,
987 hid_irq_in
, hid
, interval
);
988 usbhid
->urbin
->transfer_dma
= usbhid
->inbuf_dma
;
989 usbhid
->urbin
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
993 if (!(usbhid
->urbout
= usb_alloc_urb(0, GFP_KERNEL
)))
995 pipe
= usb_sndintpipe(dev
, endpoint
->bEndpointAddress
);
996 usb_fill_int_urb(usbhid
->urbout
, dev
, pipe
, usbhid
->outbuf
, 0,
997 hid_irq_out
, hid
, interval
);
998 usbhid
->urbout
->transfer_dma
= usbhid
->outbuf_dma
;
999 usbhid
->urbout
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1003 usbhid
->urbctrl
= usb_alloc_urb(0, GFP_KERNEL
);
1004 if (!usbhid
->urbctrl
) {
1009 usb_fill_control_urb(usbhid
->urbctrl
, dev
, 0, (void *) usbhid
->cr
,
1010 usbhid
->ctrlbuf
, 1, hid_ctrl
, hid
);
1011 usbhid
->urbctrl
->setup_dma
= usbhid
->cr_dma
;
1012 usbhid
->urbctrl
->transfer_dma
= usbhid
->ctrlbuf_dma
;
1013 usbhid
->urbctrl
->transfer_flags
|= (URB_NO_TRANSFER_DMA_MAP
| URB_NO_SETUP_DMA_MAP
);
1015 if (!(hid
->quirks
& HID_QUIRK_NO_INIT_REPORTS
))
1016 usbhid_init_reports(hid
);
1018 set_bit(HID_STARTED
, &usbhid
->iofl
);
1020 /* Some keyboards don't work until their LEDs have been set.
1021 * Since BIOSes do set the LEDs, it must be safe for any device
1022 * that supports the keyboard boot protocol.
1024 if (interface
->desc
.bInterfaceSubClass
== USB_INTERFACE_SUBCLASS_BOOT
&&
1025 interface
->desc
.bInterfaceProtocol
==
1026 USB_INTERFACE_PROTOCOL_KEYBOARD
)
1027 usbhid_set_leds(hid
);
1032 usb_free_urb(usbhid
->urbin
);
1033 usb_free_urb(usbhid
->urbout
);
1034 usb_free_urb(usbhid
->urbctrl
);
1035 usbhid
->urbin
= NULL
;
1036 usbhid
->urbout
= NULL
;
1037 usbhid
->urbctrl
= NULL
;
1038 hid_free_buffers(dev
, hid
);
1042 static void usbhid_stop(struct hid_device
*hid
)
1044 struct usbhid_device
*usbhid
= hid
->driver_data
;
1046 if (WARN_ON(!usbhid
))
1049 clear_bit(HID_STARTED
, &usbhid
->iofl
);
1050 spin_lock_irq(&usbhid
->lock
); /* Sync with error handler */
1051 set_bit(HID_DISCONNECTED
, &usbhid
->iofl
);
1052 spin_unlock_irq(&usbhid
->lock
);
1053 usb_kill_urb(usbhid
->urbin
);
1054 usb_kill_urb(usbhid
->urbout
);
1055 usb_kill_urb(usbhid
->urbctrl
);
1057 hid_cancel_delayed_stuff(usbhid
);
1061 usb_free_urb(usbhid
->urbin
);
1062 usb_free_urb(usbhid
->urbctrl
);
1063 usb_free_urb(usbhid
->urbout
);
1064 usbhid
->urbin
= NULL
; /* don't mess up next start */
1065 usbhid
->urbctrl
= NULL
;
1066 usbhid
->urbout
= NULL
;
1068 hid_free_buffers(hid_to_usb_dev(hid
), hid
);
1071 static int usbhid_power(struct hid_device
*hid
, int lvl
)
1076 case PM_HINT_FULLON
:
1077 r
= usbhid_get_power(hid
);
1079 case PM_HINT_NORMAL
:
1080 usbhid_put_power(hid
);
1086 static struct hid_ll_driver usb_hid_driver
= {
1087 .parse
= usbhid_parse
,
1088 .start
= usbhid_start
,
1089 .stop
= usbhid_stop
,
1090 .open
= usbhid_open
,
1091 .close
= usbhid_close
,
1092 .power
= usbhid_power
,
1093 .hidinput_input_event
= usb_hidinput_input_event
,
1096 static int usbhid_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1098 struct usb_host_interface
*interface
= intf
->cur_altsetting
;
1099 struct usb_device
*dev
= interface_to_usbdev(intf
);
1100 struct usbhid_device
*usbhid
;
1101 struct hid_device
*hid
;
1102 unsigned int n
, has_in
= 0;
1106 dbg_hid("HID probe called for ifnum %d\n",
1107 intf
->altsetting
->desc
.bInterfaceNumber
);
1109 for (n
= 0; n
< interface
->desc
.bNumEndpoints
; n
++)
1110 if (usb_endpoint_is_int_in(&interface
->endpoint
[n
].desc
))
1113 dev_err(&intf
->dev
, "couldn't find an input interrupt "
1118 hid
= hid_allocate_device();
1120 return PTR_ERR(hid
);
1122 usb_set_intfdata(intf
, hid
);
1123 hid
->ll_driver
= &usb_hid_driver
;
1124 hid
->hid_output_raw_report
= usbhid_output_raw_report
;
1125 hid
->ff_init
= hid_pidff_init
;
1126 #ifdef CONFIG_USB_HIDDEV
1127 hid
->hiddev_connect
= hiddev_connect
;
1128 hid
->hiddev_disconnect
= hiddev_disconnect
;
1129 hid
->hiddev_hid_event
= hiddev_hid_event
;
1130 hid
->hiddev_report_event
= hiddev_report_event
;
1132 hid
->dev
.parent
= &intf
->dev
;
1134 hid
->vendor
= le16_to_cpu(dev
->descriptor
.idVendor
);
1135 hid
->product
= le16_to_cpu(dev
->descriptor
.idProduct
);
1137 if (intf
->cur_altsetting
->desc
.bInterfaceProtocol
==
1138 USB_INTERFACE_PROTOCOL_MOUSE
)
1139 hid
->type
= HID_TYPE_USBMOUSE
;
1141 if (dev
->manufacturer
)
1142 strlcpy(hid
->name
, dev
->manufacturer
, sizeof(hid
->name
));
1145 if (dev
->manufacturer
)
1146 strlcat(hid
->name
, " ", sizeof(hid
->name
));
1147 strlcat(hid
->name
, dev
->product
, sizeof(hid
->name
));
1150 if (!strlen(hid
->name
))
1151 snprintf(hid
->name
, sizeof(hid
->name
), "HID %04x:%04x",
1152 le16_to_cpu(dev
->descriptor
.idVendor
),
1153 le16_to_cpu(dev
->descriptor
.idProduct
));
1155 usb_make_path(dev
, hid
->phys
, sizeof(hid
->phys
));
1156 strlcat(hid
->phys
, "/input", sizeof(hid
->phys
));
1157 len
= strlen(hid
->phys
);
1158 if (len
< sizeof(hid
->phys
) - 1)
1159 snprintf(hid
->phys
+ len
, sizeof(hid
->phys
) - len
,
1160 "%d", intf
->altsetting
[0].desc
.bInterfaceNumber
);
1162 if (usb_string(dev
, dev
->descriptor
.iSerialNumber
, hid
->uniq
, 64) <= 0)
1165 usbhid
= kzalloc(sizeof(*usbhid
), GFP_KERNEL
);
1166 if (usbhid
== NULL
) {
1171 hid
->driver_data
= usbhid
;
1173 usbhid
->intf
= intf
;
1174 usbhid
->ifnum
= interface
->desc
.bInterfaceNumber
;
1176 init_waitqueue_head(&usbhid
->wait
);
1177 INIT_WORK(&usbhid
->reset_work
, hid_reset
);
1178 INIT_WORK(&usbhid
->restart_work
, __usbhid_restart_queues
);
1179 setup_timer(&usbhid
->io_retry
, hid_retry_timeout
, (unsigned long) hid
);
1180 spin_lock_init(&usbhid
->lock
);
1182 ret
= hid_add_device(hid
);
1185 dev_err(&intf
->dev
, "can't add hid device: %d\n", ret
);
1193 hid_destroy_device(hid
);
1197 static void usbhid_disconnect(struct usb_interface
*intf
)
1199 struct hid_device
*hid
= usb_get_intfdata(intf
);
1200 struct usbhid_device
*usbhid
;
1205 usbhid
= hid
->driver_data
;
1206 hid_destroy_device(hid
);
1210 static void hid_cancel_delayed_stuff(struct usbhid_device
*usbhid
)
1212 del_timer_sync(&usbhid
->io_retry
);
1213 cancel_work_sync(&usbhid
->restart_work
);
1214 cancel_work_sync(&usbhid
->reset_work
);
1217 static void hid_cease_io(struct usbhid_device
*usbhid
)
1219 del_timer(&usbhid
->io_retry
);
1220 usb_kill_urb(usbhid
->urbin
);
1221 usb_kill_urb(usbhid
->urbctrl
);
1222 usb_kill_urb(usbhid
->urbout
);
1225 /* Treat USB reset pretty much the same as suspend/resume */
1226 static int hid_pre_reset(struct usb_interface
*intf
)
1228 struct hid_device
*hid
= usb_get_intfdata(intf
);
1229 struct usbhid_device
*usbhid
= hid
->driver_data
;
1231 spin_lock_irq(&usbhid
->lock
);
1232 set_bit(HID_RESET_PENDING
, &usbhid
->iofl
);
1233 spin_unlock_irq(&usbhid
->lock
);
1234 cancel_work_sync(&usbhid
->restart_work
);
1235 hid_cease_io(usbhid
);
1240 /* Same routine used for post_reset and reset_resume */
1241 static int hid_post_reset(struct usb_interface
*intf
)
1243 struct usb_device
*dev
= interface_to_usbdev (intf
);
1244 struct hid_device
*hid
= usb_get_intfdata(intf
);
1245 struct usbhid_device
*usbhid
= hid
->driver_data
;
1248 spin_lock_irq(&usbhid
->lock
);
1249 clear_bit(HID_RESET_PENDING
, &usbhid
->iofl
);
1250 spin_unlock_irq(&usbhid
->lock
);
1251 hid_set_idle(dev
, intf
->cur_altsetting
->desc
.bInterfaceNumber
, 0, 0);
1252 status
= hid_start_in(hid
);
1255 usbhid_restart_queues(usbhid
);
1260 int usbhid_get_power(struct hid_device
*hid
)
1262 struct usbhid_device
*usbhid
= hid
->driver_data
;
1264 return usb_autopm_get_interface(usbhid
->intf
);
1267 void usbhid_put_power(struct hid_device
*hid
)
1269 struct usbhid_device
*usbhid
= hid
->driver_data
;
1271 usb_autopm_put_interface(usbhid
->intf
);
1276 static int hid_suspend(struct usb_interface
*intf
, pm_message_t message
)
1278 struct hid_device
*hid
= usb_get_intfdata(intf
);
1279 struct usbhid_device
*usbhid
= hid
->driver_data
;
1280 struct usb_device
*udev
= interface_to_usbdev(intf
);
1283 if (udev
->auto_pm
) {
1284 spin_lock_irq(&usbhid
->lock
); /* Sync with error handler */
1285 if (!test_bit(HID_RESET_PENDING
, &usbhid
->iofl
)
1286 && !test_bit(HID_CLEAR_HALT
, &usbhid
->iofl
)
1287 && !test_bit(HID_OUT_RUNNING
, &usbhid
->iofl
)
1288 && !test_bit(HID_CTRL_RUNNING
, &usbhid
->iofl
)
1289 && !test_bit(HID_KEYS_PRESSED
, &usbhid
->iofl
)
1290 && (!usbhid
->ledcount
|| ignoreled
))
1292 set_bit(HID_REPORTED_IDLE
, &usbhid
->iofl
);
1293 spin_unlock_irq(&usbhid
->lock
);
1295 usbhid_mark_busy(usbhid
);
1296 spin_unlock_irq(&usbhid
->lock
);
1301 spin_lock_irq(&usbhid
->lock
);
1302 set_bit(HID_REPORTED_IDLE
, &usbhid
->iofl
);
1303 spin_unlock_irq(&usbhid
->lock
);
1304 if (usbhid_wait_io(hid
) < 0)
1308 if (!ignoreled
&& udev
->auto_pm
) {
1309 spin_lock_irq(&usbhid
->lock
);
1310 if (test_bit(HID_LED_ON
, &usbhid
->iofl
)) {
1311 spin_unlock_irq(&usbhid
->lock
);
1312 usbhid_mark_busy(usbhid
);
1315 spin_unlock_irq(&usbhid
->lock
);
1318 hid_cancel_delayed_stuff(usbhid
);
1319 hid_cease_io(usbhid
);
1321 if (udev
->auto_pm
&& test_bit(HID_KEYS_PRESSED
, &usbhid
->iofl
)) {
1322 /* lost race against keypresses */
1323 status
= hid_start_in(hid
);
1326 usbhid_mark_busy(usbhid
);
1329 dev_dbg(&intf
->dev
, "suspend\n");
1333 static int hid_resume(struct usb_interface
*intf
)
1335 struct hid_device
*hid
= usb_get_intfdata (intf
);
1336 struct usbhid_device
*usbhid
= hid
->driver_data
;
1339 if (!test_bit(HID_STARTED
, &usbhid
->iofl
))
1342 clear_bit(HID_REPORTED_IDLE
, &usbhid
->iofl
);
1343 usbhid_mark_busy(usbhid
);
1345 if (test_bit(HID_CLEAR_HALT
, &usbhid
->iofl
) ||
1346 test_bit(HID_RESET_PENDING
, &usbhid
->iofl
))
1347 schedule_work(&usbhid
->reset_work
);
1348 usbhid
->retry_delay
= 0;
1349 status
= hid_start_in(hid
);
1352 usbhid_restart_queues(usbhid
);
1354 dev_dbg(&intf
->dev
, "resume status %d\n", status
);
1358 static int hid_reset_resume(struct usb_interface
*intf
)
1360 struct hid_device
*hid
= usb_get_intfdata(intf
);
1361 struct usbhid_device
*usbhid
= hid
->driver_data
;
1363 clear_bit(HID_REPORTED_IDLE
, &usbhid
->iofl
);
1364 return hid_post_reset(intf
);
1367 #endif /* CONFIG_PM */
1369 static struct usb_device_id hid_usb_ids
[] = {
1370 { .match_flags
= USB_DEVICE_ID_MATCH_INT_CLASS
,
1371 .bInterfaceClass
= USB_INTERFACE_CLASS_HID
},
1372 { } /* Terminating entry */
1375 MODULE_DEVICE_TABLE (usb
, hid_usb_ids
);
1377 static struct usb_driver hid_driver
= {
1379 .probe
= usbhid_probe
,
1380 .disconnect
= usbhid_disconnect
,
1382 .suspend
= hid_suspend
,
1383 .resume
= hid_resume
,
1384 .reset_resume
= hid_reset_resume
,
1386 .pre_reset
= hid_pre_reset
,
1387 .post_reset
= hid_post_reset
,
1388 .id_table
= hid_usb_ids
,
1389 .supports_autosuspend
= 1,
1392 static const struct hid_device_id hid_usb_table
[] = {
1393 { HID_USB_DEVICE(HID_ANY_ID
, HID_ANY_ID
) },
1397 static struct hid_driver hid_usb_driver
= {
1398 .name
= "generic-usb",
1399 .id_table
= hid_usb_table
,
1402 static int __init
hid_init(void)
1404 int retval
= -ENOMEM
;
1406 resumption_waker
= create_freezeable_workqueue("usbhid_resumer");
1407 if (!resumption_waker
)
1409 retval
= hid_register_driver(&hid_usb_driver
);
1411 goto hid_register_fail
;
1412 retval
= usbhid_quirks_init(quirks_param
);
1414 goto usbhid_quirks_init_fail
;
1415 retval
= hiddev_init();
1417 goto hiddev_init_fail
;
1418 retval
= usb_register(&hid_driver
);
1420 goto usb_register_fail
;
1421 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_VERSION
":"
1428 usbhid_quirks_exit();
1429 usbhid_quirks_init_fail
:
1430 hid_unregister_driver(&hid_usb_driver
);
1432 destroy_workqueue(resumption_waker
);
1437 static void __exit
hid_exit(void)
1439 usb_deregister(&hid_driver
);
1441 usbhid_quirks_exit();
1442 hid_unregister_driver(&hid_usb_driver
);
1443 destroy_workqueue(resumption_waker
);
1446 module_init(hid_init
);
1447 module_exit(hid_exit
);
1449 MODULE_AUTHOR(DRIVER_AUTHOR
);
1450 MODULE_DESCRIPTION(DRIVER_DESC
);
1451 MODULE_LICENSE(DRIVER_LICENSE
);