]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/hid/usbhid/hid-core.c
USB HID: provide hook for hidraw write()
[net-next-2.6.git] / drivers / hid / usbhid / hid-core.c
CommitLineData
1da177e4
LT
1/*
2 * USB HID support for Linux
3 *
4 * Copyright (c) 1999 Andreas Gal
bf0964dc
MH
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
b55fd23c 7 * Copyright (c) 2006-2007 Jiri Kosina
1da177e4
LT
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>
1da177e4
LT
21#include <linux/list.h>
22#include <linux/mm.h>
23#include <linux/smp_lock.h>
24#include <linux/spinlock.h>
25#include <asm/unaligned.h>
26#include <asm/byteorder.h>
27#include <linux/input.h>
28#include <linux/wait.h>
29
1da177e4
LT
30#include <linux/usb.h>
31
dde5845a 32#include <linux/hid.h>
1da177e4 33#include <linux/hiddev.h>
c080d89a 34#include <linux/hid-debug.h>
4916b3a5 35#include "usbhid.h"
1da177e4
LT
36
37/*
38 * Version Information
39 */
40
bf0964dc 41#define DRIVER_VERSION "v2.6"
f142b3a4 42#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik, Jiri Kosina"
1da177e4
LT
43#define DRIVER_DESC "USB HID core driver"
44#define DRIVER_LICENSE "GPL"
45
46static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick",
47 "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"};
48/*
49 * Module parameters.
50 */
51
52static unsigned int hid_mousepoll_interval;
53module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
54MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
55
876b9276
PW
56/* Quirks specified at module load time */
57static char *quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL };
58module_param_array_named(quirks, quirks_param, charp, NULL, 0444);
59MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying "
60 " quirks=vendorID:productID:quirks"
61 " where vendorID, productID, and quirks are all in"
62 " 0x-prefixed hex");
ea9a4a8b
JK
63static char *rdesc_quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL };
64module_param_array_named(rdesc_quirks, rdesc_quirks_param, charp, NULL, 0444);
65MODULE_PARM_DESC(rdesc_quirks, "Add/modify report descriptor quirks by specifying "
66 " rdesc_quirks=vendorID:productID:rdesc_quirks"
67 " where vendorID, productID, and rdesc_quirks are all in"
68 " 0x-prefixed hex");
1da177e4 69/*
48b4554a 70 * Input submission and I/O error handler.
1da177e4
LT
71 */
72
48b4554a
JK
73static void hid_io_error(struct hid_device *hid);
74
75/* Start up the input URB */
76static int hid_start_in(struct hid_device *hid)
1da177e4 77{
1da177e4 78 unsigned long flags;
48b4554a
JK
79 int rc = 0;
80 struct usbhid_device *usbhid = hid->driver_data;
1da177e4 81
48b4554a
JK
82 spin_lock_irqsave(&usbhid->inlock, flags);
83 if (hid->open > 0 && !test_bit(HID_SUSPENDED, &usbhid->iofl) &&
84 !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) {
85 rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC);
86 if (rc != 0)
87 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
1da177e4 88 }
48b4554a
JK
89 spin_unlock_irqrestore(&usbhid->inlock, flags);
90 return rc;
1da177e4
LT
91}
92
48b4554a
JK
93/* I/O retry timer routine */
94static void hid_retry_timeout(unsigned long _hid)
1da177e4 95{
48b4554a 96 struct hid_device *hid = (struct hid_device *) _hid;
4916b3a5 97 struct usbhid_device *usbhid = hid->driver_data;
1da177e4 98
48b4554a
JK
99 dev_dbg(&usbhid->intf->dev, "retrying intr urb\n");
100 if (hid_start_in(hid))
101 hid_io_error(hid);
1da177e4
LT
102}
103
48b4554a
JK
104/* Workqueue routine to reset the device or clear a halt */
105static void hid_reset(struct work_struct *work)
1da177e4 106{
48b4554a
JK
107 struct usbhid_device *usbhid =
108 container_of(work, struct usbhid_device, reset_work);
109 struct hid_device *hid = usbhid->hid;
110 int rc_lock, rc = 0;
1da177e4 111
48b4554a
JK
112 if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) {
113 dev_dbg(&usbhid->intf->dev, "clear halt\n");
114 rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe);
115 clear_bit(HID_CLEAR_HALT, &usbhid->iofl);
116 hid_start_in(hid);
117 }
1da177e4 118
48b4554a
JK
119 else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) {
120 dev_dbg(&usbhid->intf->dev, "resetting device\n");
121 rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf);
122 if (rc_lock >= 0) {
123 rc = usb_reset_composite_device(hid_to_usb_dev(hid), usbhid->intf);
124 if (rc_lock)
125 usb_unlock_device(hid_to_usb_dev(hid));
1da177e4 126 }
48b4554a 127 clear_bit(HID_RESET_PENDING, &usbhid->iofl);
1da177e4
LT
128 }
129
48b4554a
JK
130 switch (rc) {
131 case 0:
132 if (!test_bit(HID_IN_RUNNING, &usbhid->iofl))
133 hid_io_error(hid);
134 break;
135 default:
58037eb9 136 err_hid("can't reset device, %s-%s/input%d, status %d",
48b4554a
JK
137 hid_to_usb_dev(hid)->bus->bus_name,
138 hid_to_usb_dev(hid)->devpath,
139 usbhid->ifnum, rc);
140 /* FALLTHROUGH */
141 case -EHOSTUNREACH:
142 case -ENODEV:
143 case -EINTR:
144 break;
1da177e4 145 }
1da177e4
LT
146}
147
48b4554a
JK
148/* Main I/O error handler */
149static void hid_io_error(struct hid_device *hid)
dde5845a 150{
48b4554a
JK
151 unsigned long flags;
152 struct usbhid_device *usbhid = hid->driver_data;
dde5845a 153
48b4554a 154 spin_lock_irqsave(&usbhid->inlock, flags);
dde5845a 155
48b4554a
JK
156 /* Stop when disconnected */
157 if (usb_get_intfdata(usbhid->intf) == NULL)
158 goto done;
dde5845a 159
5e2a55f2
AS
160 /* If it has been a while since the last error, we'll assume
161 * this a brand new error and reset the retry timeout. */
162 if (time_after(jiffies, usbhid->stop_retry + HZ/2))
163 usbhid->retry_delay = 0;
164
48b4554a
JK
165 /* When an error occurs, retry at increasing intervals */
166 if (usbhid->retry_delay == 0) {
167 usbhid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */
168 usbhid->stop_retry = jiffies + msecs_to_jiffies(1000);
169 } else if (usbhid->retry_delay < 100)
170 usbhid->retry_delay *= 2;
dde5845a 171
48b4554a 172 if (time_after(jiffies, usbhid->stop_retry)) {
4916b3a5 173
48b4554a
JK
174 /* Retries failed, so do a port reset */
175 if (!test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) {
176 schedule_work(&usbhid->reset_work);
177 goto done;
178 }
1da177e4
LT
179 }
180
48b4554a
JK
181 mod_timer(&usbhid->io_retry,
182 jiffies + msecs_to_jiffies(usbhid->retry_delay));
183done:
184 spin_unlock_irqrestore(&usbhid->inlock, flags);
1da177e4
LT
185}
186
48b4554a
JK
187/*
188 * Input interrupt completion handler.
189 */
854561b0 190
48b4554a 191static void hid_irq_in(struct urb *urb)
1da177e4 192{
48b4554a
JK
193 struct hid_device *hid = urb->context;
194 struct usbhid_device *usbhid = hid->driver_data;
195 int status;
1da177e4 196
48b4554a
JK
197 switch (urb->status) {
198 case 0: /* success */
199 usbhid->retry_delay = 0;
200 hid_input_report(urb->context, HID_INPUT_REPORT,
201 urb->transfer_buffer,
202 urb->actual_length, 1);
203 break;
204 case -EPIPE: /* stall */
205 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
206 set_bit(HID_CLEAR_HALT, &usbhid->iofl);
207 schedule_work(&usbhid->reset_work);
208 return;
209 case -ECONNRESET: /* unlink */
210 case -ENOENT:
211 case -ESHUTDOWN: /* unplug */
212 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
213 return;
214 case -EILSEQ: /* protocol error or unplug */
215 case -EPROTO: /* protocol error or unplug */
216 case -ETIME: /* protocol error or unplug */
217 case -ETIMEDOUT: /* Should never happen, but... */
218 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
219 hid_io_error(hid);
220 return;
221 default: /* error */
222 warn("input irq status %d received", urb->status);
223 }
1da177e4 224
48b4554a
JK
225 status = usb_submit_urb(urb, GFP_ATOMIC);
226 if (status) {
227 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
228 if (status != -EPERM) {
58037eb9 229 err_hid("can't resubmit intr, %s-%s/input%d, status %d",
48b4554a
JK
230 hid_to_usb_dev(hid)->bus->bus_name,
231 hid_to_usb_dev(hid)->devpath,
232 usbhid->ifnum, status);
233 hid_io_error(hid);
234 }
235 }
1da177e4
LT
236}
237
48b4554a 238static int hid_submit_out(struct hid_device *hid)
1da177e4 239{
48b4554a 240 struct hid_report *report;
4916b3a5
JK
241 struct usbhid_device *usbhid = hid->driver_data;
242
48b4554a 243 report = usbhid->out[usbhid->outtail];
1da177e4 244
48b4554a
JK
245 hid_output_report(report, usbhid->outbuf);
246 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
247 usbhid->urbout->dev = hid_to_usb_dev(hid);
1d3e2023 248
58037eb9 249 dbg_hid("submitting out urb\n");
d57cdcff 250
48b4554a 251 if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) {
58037eb9 252 err_hid("usb_submit_urb(out) failed");
48b4554a
JK
253 return -1;
254 }
1da177e4 255
48b4554a
JK
256 return 0;
257}
258
259static int hid_submit_ctrl(struct hid_device *hid)
1da177e4
LT
260{
261 struct hid_report *report;
48b4554a
JK
262 unsigned char dir;
263 int len;
4916b3a5 264 struct usbhid_device *usbhid = hid->driver_data;
1da177e4 265
48b4554a
JK
266 report = usbhid->ctrl[usbhid->ctrltail].report;
267 dir = usbhid->ctrl[usbhid->ctrltail].dir;
1da177e4 268
48b4554a
JK
269 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
270 if (dir == USB_DIR_OUT) {
271 hid_output_report(report, usbhid->ctrlbuf);
272 usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0);
273 usbhid->urbctrl->transfer_buffer_length = len;
274 } else {
275 int maxpacket, padlen;
1da177e4 276
48b4554a
JK
277 usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0);
278 maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0);
279 if (maxpacket > 0) {
280 padlen = (len + maxpacket - 1) / maxpacket;
281 padlen *= maxpacket;
282 if (padlen > usbhid->bufsize)
283 padlen = usbhid->bufsize;
284 } else
285 padlen = 0;
286 usbhid->urbctrl->transfer_buffer_length = padlen;
1da177e4 287 }
48b4554a 288 usbhid->urbctrl->dev = hid_to_usb_dev(hid);
1da177e4 289
48b4554a
JK
290 usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
291 usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
292 usbhid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
293 usbhid->cr->wIndex = cpu_to_le16(usbhid->ifnum);
294 usbhid->cr->wLength = cpu_to_le16(len);
1da177e4 295
58037eb9 296 dbg_hid("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u\n",
48b4554a
JK
297 usbhid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report",
298 usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength);
1da177e4 299
48b4554a 300 if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) {
58037eb9 301 err_hid("usb_submit_urb(ctrl) failed");
48b4554a
JK
302 return -1;
303 }
1da177e4 304
48b4554a
JK
305 return 0;
306}
1da177e4 307
48b4554a
JK
308/*
309 * Output interrupt completion handler.
310 */
1da177e4 311
48b4554a
JK
312static void hid_irq_out(struct urb *urb)
313{
314 struct hid_device *hid = urb->context;
315 struct usbhid_device *usbhid = hid->driver_data;
316 unsigned long flags;
317 int unplug = 0;
1da177e4 318
48b4554a
JK
319 switch (urb->status) {
320 case 0: /* success */
321 break;
322 case -ESHUTDOWN: /* unplug */
323 unplug = 1;
324 case -EILSEQ: /* protocol error or unplug */
325 case -EPROTO: /* protocol error or unplug */
326 case -ECONNRESET: /* unlink */
327 case -ENOENT:
328 break;
329 default: /* error */
330 warn("output irq status %d received", urb->status);
331 }
1da177e4 332
48b4554a 333 spin_lock_irqsave(&usbhid->outlock, flags);
1da177e4 334
48b4554a
JK
335 if (unplug)
336 usbhid->outtail = usbhid->outhead;
337 else
338 usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1);
1da177e4 339
48b4554a
JK
340 if (usbhid->outhead != usbhid->outtail) {
341 if (hid_submit_out(hid)) {
342 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
343 wake_up(&hid->wait);
344 }
345 spin_unlock_irqrestore(&usbhid->outlock, flags);
346 return;
347 }
1da177e4 348
48b4554a
JK
349 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
350 spin_unlock_irqrestore(&usbhid->outlock, flags);
351 wake_up(&hid->wait);
352}
6345fdfd 353
48b4554a
JK
354/*
355 * Control pipe completion handler.
356 */
1da177e4 357
48b4554a
JK
358static void hid_ctrl(struct urb *urb)
359{
360 struct hid_device *hid = urb->context;
361 struct usbhid_device *usbhid = hid->driver_data;
362 unsigned long flags;
363 int unplug = 0;
1da177e4 364
48b4554a 365 spin_lock_irqsave(&usbhid->ctrllock, flags);
1da177e4 366
48b4554a
JK
367 switch (urb->status) {
368 case 0: /* success */
369 if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN)
370 hid_input_report(urb->context, usbhid->ctrl[usbhid->ctrltail].report->type,
371 urb->transfer_buffer, urb->actual_length, 0);
372 break;
373 case -ESHUTDOWN: /* unplug */
374 unplug = 1;
375 case -EILSEQ: /* protocol error or unplug */
376 case -EPROTO: /* protocol error or unplug */
377 case -ECONNRESET: /* unlink */
378 case -ENOENT:
379 case -EPIPE: /* report not available */
380 break;
381 default: /* error */
382 warn("ctrl urb status %d received", urb->status);
383 }
1da177e4 384
48b4554a
JK
385 if (unplug)
386 usbhid->ctrltail = usbhid->ctrlhead;
387 else
388 usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
1da177e4 389
48b4554a
JK
390 if (usbhid->ctrlhead != usbhid->ctrltail) {
391 if (hid_submit_ctrl(hid)) {
392 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
393 wake_up(&hid->wait);
394 }
395 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
396 return;
397 }
1da177e4 398
48b4554a
JK
399 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
400 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
401 wake_up(&hid->wait);
402}
1da177e4 403
48b4554a
JK
404void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir)
405{
406 int head;
407 unsigned long flags;
408 struct usbhid_device *usbhid = hid->driver_data;
1da177e4 409
48b4554a
JK
410 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
411 return;
b857c651 412
48b4554a 413 if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
1da177e4 414
48b4554a 415 spin_lock_irqsave(&usbhid->outlock, flags);
1da177e4 416
48b4554a
JK
417 if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) {
418 spin_unlock_irqrestore(&usbhid->outlock, flags);
419 warn("output queue full");
420 return;
421 }
1da177e4 422
48b4554a
JK
423 usbhid->out[usbhid->outhead] = report;
424 usbhid->outhead = head;
4871d3be 425
48b4554a
JK
426 if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl))
427 if (hid_submit_out(hid))
428 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
8fd6db47 429
48b4554a
JK
430 spin_unlock_irqrestore(&usbhid->outlock, flags);
431 return;
432 }
1da177e4 433
48b4554a 434 spin_lock_irqsave(&usbhid->ctrllock, flags);
940824b0 435
48b4554a
JK
436 if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) {
437 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
438 warn("control queue full");
439 return;
440 }
8fd80133 441
48b4554a
JK
442 usbhid->ctrl[usbhid->ctrlhead].report = report;
443 usbhid->ctrl[usbhid->ctrlhead].dir = dir;
444 usbhid->ctrlhead = head;
8fd80133 445
48b4554a
JK
446 if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl))
447 if (hid_submit_ctrl(hid))
448 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
931e24b9 449
48b4554a
JK
450 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
451}
23b0d968 452
48b4554a
JK
453static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
454{
e0712985 455 struct hid_device *hid = input_get_drvdata(dev);
48b4554a
JK
456 struct hid_field *field;
457 int offset;
41ad5fba 458
48b4554a
JK
459 if (type == EV_FF)
460 return input_ff_event(dev, type, code, value);
8d2bad87 461
48b4554a
JK
462 if (type != EV_LED)
463 return -1;
5556feae 464
48b4554a
JK
465 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
466 warn("event field not found");
467 return -1;
468 }
4a1a4d8b 469
48b4554a
JK
470 hid_set_field(field, offset, value);
471 usbhid_submit_report(hid, field->report, USB_DIR_OUT);
1da177e4 472
48b4554a
JK
473 return 0;
474}
1da177e4 475
48b4554a
JK
476int usbhid_wait_io(struct hid_device *hid)
477{
478 struct usbhid_device *usbhid = hid->driver_data;
25914662 479
48b4554a
JK
480 if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) &&
481 !test_bit(HID_OUT_RUNNING, &usbhid->iofl)),
482 10*HZ)) {
58037eb9 483 dbg_hid("timeout waiting for ctrl or out queue to clear\n");
48b4554a
JK
484 return -1;
485 }
1da177e4 486
48b4554a
JK
487 return 0;
488}
53880546 489
48b4554a
JK
490static int hid_set_idle(struct usb_device *dev, int ifnum, int report, int idle)
491{
492 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
493 HID_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, (idle << 8) | report,
494 ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT);
495}
1da177e4 496
48b4554a
JK
497static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
498 unsigned char type, void *buf, int size)
499{
500 int result, retries = 4;
1da177e4 501
48b4554a 502 memset(buf, 0, size);
1da177e4 503
48b4554a
JK
504 do {
505 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
506 USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN,
507 (type << 8), ifnum, buf, size, USB_CTRL_GET_TIMEOUT);
508 retries--;
509 } while (result < size && retries);
510 return result;
511}
940824b0 512
48b4554a
JK
513int usbhid_open(struct hid_device *hid)
514{
515 ++hid->open;
516 if (hid_start_in(hid))
517 hid_io_error(hid);
518 return 0;
519}
a417a21e 520
48b4554a
JK
521void usbhid_close(struct hid_device *hid)
522{
523 struct usbhid_device *usbhid = hid->driver_data;
eab9edd2 524
48b4554a
JK
525 if (!--hid->open)
526 usb_kill_urb(usbhid->urbin);
527}
1d3e2023 528
48b4554a
JK
529/*
530 * Initialize all reports
531 */
41ad5fba 532
48b4554a
JK
533void usbhid_init_reports(struct hid_device *hid)
534{
535 struct hid_report *report;
536 struct usbhid_device *usbhid = hid->driver_data;
537 int err, ret;
41ad5fba 538
48b4554a
JK
539 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
540 usbhid_submit_report(hid, report, USB_DIR_IN);
5556feae 541
48b4554a
JK
542 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
543 usbhid_submit_report(hid, report, USB_DIR_IN);
4a1a4d8b 544
48b4554a
JK
545 err = 0;
546 ret = usbhid_wait_io(hid);
547 while (ret) {
548 err |= ret;
549 if (test_bit(HID_CTRL_RUNNING, &usbhid->iofl))
550 usb_kill_urb(usbhid->urbctrl);
551 if (test_bit(HID_OUT_RUNNING, &usbhid->iofl))
552 usb_kill_urb(usbhid->urbout);
553 ret = usbhid_wait_io(hid);
554 }
3f9b4076 555
48b4554a
JK
556 if (err)
557 warn("timeout initializing reports");
558}
1da177e4 559
713c8aad
PZ
560/*
561 * Reset LEDs which BIOS might have left on. For now, just NumLock (0x01).
562 */
563static int hid_find_field_early(struct hid_device *hid, unsigned int page,
564 unsigned int hid_code, struct hid_field **pfield)
565{
566 struct hid_report *report;
567 struct hid_field *field;
568 struct hid_usage *usage;
569 int i, j;
570
571 list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) {
572 for (i = 0; i < report->maxfield; i++) {
573 field = report->field[i];
574 for (j = 0; j < field->maxusage; j++) {
575 usage = &field->usage[j];
576 if ((usage->hid & HID_USAGE_PAGE) == page &&
577 (usage->hid & 0xFFFF) == hid_code) {
578 *pfield = field;
579 return j;
580 }
581 }
582 }
583 }
584 return -1;
585}
586
587static void usbhid_set_leds(struct hid_device *hid)
588{
589 struct hid_field *field;
590 int offset;
591
592 if ((offset = hid_find_field_early(hid, HID_UP_LED, 0x01, &field)) != -1) {
593 hid_set_field(field, offset, 0);
594 usbhid_submit_report(hid, field->report, USB_DIR_OUT);
595 }
596}
597
bf0964dc
MH
598/*
599 * Traverse the supplied list of reports and find the longest
600 */
601static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max)
602{
603 struct hid_report *report;
604 int size;
605
606 list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
607 size = ((report->size - 1) >> 3) + 1;
608 if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered)
609 size++;
610 if (*max < size)
611 *max = size;
612 }
613}
614
1da177e4
LT
615static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
616{
4916b3a5
JK
617 struct usbhid_device *usbhid = hid->driver_data;
618
619 if (!(usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->inbuf_dma)))
1da177e4 620 return -1;
4916b3a5 621 if (!(usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->outbuf_dma)))
1da177e4 622 return -1;
4916b3a5 623 if (!(usbhid->cr = usb_buffer_alloc(dev, sizeof(*(usbhid->cr)), GFP_ATOMIC, &usbhid->cr_dma)))
1da177e4 624 return -1;
4916b3a5 625 if (!(usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->ctrlbuf_dma)))
1da177e4
LT
626 return -1;
627
628 return 0;
629}
630
efc493f9
JK
631static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count)
632{
633 struct usbhid_device *usbhid = hid->driver_data;
634 struct usb_device *dev = hid_to_usb_dev(hid);
635 struct usb_interface *intf = usbhid->intf;
636 struct usb_host_interface *interface = intf->cur_altsetting;
637 int ret;
638
639 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
640 HID_REQ_SET_REPORT,
641 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
642 cpu_to_le16(((HID_OUTPUT_REPORT + 1) << 8) | *buf),
643 interface->desc.bInterfaceNumber, buf + 1, count - 1,
644 USB_CTRL_SET_TIMEOUT);
645
646 /* count also the report id */
647 if (ret > 0)
648 ret++;
649
650 return ret;
651}
652
1da177e4
LT
653static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
654{
4916b3a5
JK
655 struct usbhid_device *usbhid = hid->driver_data;
656
6675c5bd
DT
657 usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma);
658 usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma);
659 usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma);
660 usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
1da177e4
LT
661}
662
4a1a4d8b
GL
663/*
664 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
665 * to "operational". Without this, the ps3 controller will not report any
666 * events.
667 */
668static void hid_fixup_sony_ps3_controller(struct usb_device *dev, int ifnum)
669{
670 int result;
671 char *buf = kmalloc(18, GFP_KERNEL);
672
673 if (!buf)
674 return;
675
676 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
677 HID_REQ_GET_REPORT,
678 USB_DIR_IN | USB_TYPE_CLASS |
679 USB_RECIP_INTERFACE,
680 (3 << 8) | 0xf2, ifnum, buf, 17,
681 USB_CTRL_GET_TIMEOUT);
682
683 if (result < 0)
58037eb9 684 err_hid("%s failed: %d\n", __func__, result);
4a1a4d8b
GL
685
686 kfree(buf);
687}
688
1da177e4
LT
689static struct hid_device *usb_hid_configure(struct usb_interface *intf)
690{
691 struct usb_host_interface *interface = intf->cur_altsetting;
692 struct usb_device *dev = interface_to_usbdev (intf);
693 struct hid_descriptor *hdesc;
694 struct hid_device *hid;
2eb5dc30 695 u32 quirks = 0;
4cbe7d28 696 unsigned rsize = 0;
c5b7c7c3
DT
697 char *rdesc;
698 int n, len, insize = 0;
4916b3a5 699 struct usbhid_device *usbhid;
1da177e4 700
2eb5dc30
PW
701 quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),
702 le16_to_cpu(dev->descriptor.idProduct));
1da177e4 703
0f28b55d
AS
704 /* Many keyboards and mice don't like to be polled for reports,
705 * so we will always set the HID_QUIRK_NOGET flag for them. */
706 if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
707 if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||
708 interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
709 quirks |= HID_QUIRK_NOGET;
710 }
711
1da177e4
LT
712 if (quirks & HID_QUIRK_IGNORE)
713 return NULL;
714
a417a21e
SS
715 if ((quirks & HID_QUIRK_IGNORE_MOUSE) &&
716 (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE))
717 return NULL;
718
719
c5b7c7c3
DT
720 if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&
721 (!interface->desc.bNumEndpoints ||
722 usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {
58037eb9 723 dbg_hid("class descriptor not present\n");
c5b7c7c3 724 return NULL;
1da177e4
LT
725 }
726
727 for (n = 0; n < hdesc->bNumDescriptors; n++)
728 if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)
729 rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
730
731 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
58037eb9 732 dbg_hid("weird size of report descriptor (%u)\n", rsize);
1da177e4
LT
733 return NULL;
734 }
735
736 if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) {
58037eb9 737 dbg_hid("couldn't allocate rdesc memory\n");
1da177e4
LT
738 return NULL;
739 }
740
854561b0
VP
741 hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
742
1da177e4 743 if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) {
58037eb9 744 dbg_hid("reading report descriptor failed\n");
1da177e4
LT
745 kfree(rdesc);
746 return NULL;
747 }
748
ea9a4a8b
JK
749 usbhid_fixup_report_descriptor(le16_to_cpu(dev->descriptor.idVendor),
750 le16_to_cpu(dev->descriptor.idProduct), rdesc,
751 rsize, rdesc_quirks_param);
66da8769 752
58037eb9 753 dbg_hid("report descriptor (size %u, read %d) = ", rsize, n);
1da177e4 754 for (n = 0; n < rsize; n++)
58037eb9
JK
755 dbg_hid_line(" %02x", (unsigned char) rdesc[n]);
756 dbg_hid_line("\n");
1da177e4
LT
757
758 if (!(hid = hid_parse_report(rdesc, n))) {
58037eb9 759 dbg_hid("parsing report descriptor failed\n");
1da177e4
LT
760 kfree(rdesc);
761 return NULL;
762 }
763
764 kfree(rdesc);
765 hid->quirks = quirks;
766
4916b3a5 767 if (!(usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL)))
de1a7b03 768 goto fail_no_usbhid;
4916b3a5
JK
769
770 hid->driver_data = usbhid;
771 usbhid->hid = hid;
772
773 usbhid->bufsize = HID_MIN_BUFFER_SIZE;
774 hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize);
775 hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize);
776 hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize);
bf0964dc 777
4916b3a5
JK
778 if (usbhid->bufsize > HID_MAX_BUFFER_SIZE)
779 usbhid->bufsize = HID_MAX_BUFFER_SIZE;
bf0964dc
MH
780
781 hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
782
783 if (insize > HID_MAX_BUFFER_SIZE)
784 insize = HID_MAX_BUFFER_SIZE;
785
1da177e4
LT
786 if (hid_alloc_buffers(dev, hid)) {
787 hid_free_buffers(dev, hid);
788 goto fail;
789 }
790
791 for (n = 0; n < interface->desc.bNumEndpoints; n++) {
792
793 struct usb_endpoint_descriptor *endpoint;
794 int pipe;
795 int interval;
796
797 endpoint = &interface->endpoint[n].desc;
798 if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */
799 continue;
800
1da177e4 801 interval = endpoint->bInterval;
1da177e4
LT
802
803 /* Change the polling interval of mice. */
804 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
805 interval = hid_mousepoll_interval;
05f091ab 806
0f12aa03 807 if (usb_endpoint_dir_in(endpoint)) {
4916b3a5 808 if (usbhid->urbin)
1da177e4 809 continue;
4916b3a5 810 if (!(usbhid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
1da177e4
LT
811 goto fail;
812 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
4916b3a5 813 usb_fill_int_urb(usbhid->urbin, dev, pipe, usbhid->inbuf, insize,
1da177e4 814 hid_irq_in, hid, interval);
4916b3a5
JK
815 usbhid->urbin->transfer_dma = usbhid->inbuf_dma;
816 usbhid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1da177e4 817 } else {
4916b3a5 818 if (usbhid->urbout)
1da177e4 819 continue;
4916b3a5 820 if (!(usbhid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
1da177e4
LT
821 goto fail;
822 pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress);
4916b3a5 823 usb_fill_int_urb(usbhid->urbout, dev, pipe, usbhid->outbuf, 0,
1da177e4 824 hid_irq_out, hid, interval);
4916b3a5
JK
825 usbhid->urbout->transfer_dma = usbhid->outbuf_dma;
826 usbhid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1da177e4
LT
827 }
828 }
829
4916b3a5 830 if (!usbhid->urbin) {
58037eb9 831 err_hid("couldn't find an input interrupt endpoint");
1da177e4
LT
832 goto fail;
833 }
834
835 init_waitqueue_head(&hid->wait);
836
4916b3a5
JK
837 INIT_WORK(&usbhid->reset_work, hid_reset);
838 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
aef4e266 839
4916b3a5
JK
840 spin_lock_init(&usbhid->inlock);
841 spin_lock_init(&usbhid->outlock);
842 spin_lock_init(&usbhid->ctrllock);
1da177e4
LT
843
844 hid->version = le16_to_cpu(hdesc->bcdHID);
845 hid->country = hdesc->bCountryCode;
be820975 846 hid->dev = &intf->dev;
4916b3a5
JK
847 usbhid->intf = intf;
848 usbhid->ifnum = interface->desc.bInterfaceNumber;
1da177e4
LT
849
850 hid->name[0] = 0;
851
c5b7c7c3
DT
852 if (dev->manufacturer)
853 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
854
855 if (dev->product) {
856 if (dev->manufacturer)
857 strlcat(hid->name, " ", sizeof(hid->name));
858 strlcat(hid->name, dev->product, sizeof(hid->name));
859 }
860
861 if (!strlen(hid->name))
862 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
863 le16_to_cpu(dev->descriptor.idVendor),
864 le16_to_cpu(dev->descriptor.idProduct));
1da177e4 865
229695e5 866 hid->bus = BUS_USB;
9fa2ad5f
JB
867 hid->vendor = le16_to_cpu(dev->descriptor.idVendor);
868 hid->product = le16_to_cpu(dev->descriptor.idProduct);
229695e5 869
c5b7c7c3
DT
870 usb_make_path(dev, hid->phys, sizeof(hid->phys));
871 strlcat(hid->phys, "/input", sizeof(hid->phys));
872 len = strlen(hid->phys);
873 if (len < sizeof(hid->phys) - 1)
874 snprintf(hid->phys + len, sizeof(hid->phys) - len,
875 "%d", intf->altsetting[0].desc.bInterfaceNumber);
1da177e4
LT
876
877 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
878 hid->uniq[0] = 0;
879
4916b3a5
JK
880 usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
881 if (!usbhid->urbctrl)
1da177e4 882 goto fail;
c5b7c7c3 883
4916b3a5
JK
884 usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr,
885 usbhid->ctrlbuf, 1, hid_ctrl, hid);
886 usbhid->urbctrl->setup_dma = usbhid->cr_dma;
887 usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma;
888 usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
229695e5 889 hid->hidinput_input_event = usb_hidinput_input_event;
7c379146
JK
890 hid->hid_open = usbhid_open;
891 hid->hid_close = usbhid_close;
aa938f79
JK
892#ifdef CONFIG_USB_HIDDEV
893 hid->hiddev_hid_event = hiddev_hid_event;
aa8de2f0 894 hid->hiddev_report_event = hiddev_report_event;
aa938f79 895#endif
efc493f9 896 hid->hid_output_raw_report = usbhid_output_raw_report;
1da177e4
LT
897 return hid;
898
899fail:
4916b3a5
JK
900 usb_free_urb(usbhid->urbin);
901 usb_free_urb(usbhid->urbout);
902 usb_free_urb(usbhid->urbctrl);
22f675f3 903 hid_free_buffers(dev, hid);
cda5ecf8 904 kfree(usbhid);
de1a7b03 905fail_no_usbhid:
1da177e4
LT
906 hid_free_device(hid);
907
908 return NULL;
909}
910
911static void hid_disconnect(struct usb_interface *intf)
912{
913 struct hid_device *hid = usb_get_intfdata (intf);
4916b3a5 914 struct usbhid_device *usbhid;
1da177e4
LT
915
916 if (!hid)
917 return;
918
4916b3a5
JK
919 usbhid = hid->driver_data;
920
921 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
1da177e4 922 usb_set_intfdata(intf, NULL);
4916b3a5
JK
923 spin_unlock_irq(&usbhid->inlock);
924 usb_kill_urb(usbhid->urbin);
925 usb_kill_urb(usbhid->urbout);
926 usb_kill_urb(usbhid->urbctrl);
1da177e4 927
4916b3a5 928 del_timer_sync(&usbhid->io_retry);
2fa45a4c 929 cancel_work_sync(&usbhid->reset_work);
aef4e266 930
1da177e4
LT
931 if (hid->claimed & HID_CLAIMED_INPUT)
932 hidinput_disconnect(hid);
933 if (hid->claimed & HID_CLAIMED_HIDDEV)
934 hiddev_disconnect(hid);
935
4916b3a5
JK
936 usb_free_urb(usbhid->urbin);
937 usb_free_urb(usbhid->urbctrl);
938 usb_free_urb(usbhid->urbout);
1da177e4 939
be820975 940 hid_free_buffers(hid_to_usb_dev(hid), hid);
22f675f3 941 kfree(usbhid);
1da177e4
LT
942 hid_free_device(hid);
943}
944
945static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
946{
947 struct hid_device *hid;
948 char path[64];
949 int i;
950 char *c;
951
58037eb9 952 dbg_hid("HID probe called for ifnum %d\n",
1da177e4
LT
953 intf->altsetting->desc.bInterfaceNumber);
954
955 if (!(hid = usb_hid_configure(intf)))
479f6ea8 956 return -ENODEV;
1da177e4 957
4916b3a5 958 usbhid_init_reports(hid);
1da177e4 959 hid_dump_device(hid);
713c8aad
PZ
960 if (hid->quirks & HID_QUIRK_RESET_LEDS)
961 usbhid_set_leds(hid);
1da177e4
LT
962
963 if (!hidinput_connect(hid))
964 hid->claimed |= HID_CLAIMED_INPUT;
965 if (!hiddev_connect(hid))
966 hid->claimed |= HID_CLAIMED_HIDDEV;
967
968 usb_set_intfdata(intf, hid);
969
970 if (!hid->claimed) {
971 printk ("HID device not claimed by input or hiddev\n");
972 hid_disconnect(intf);
479f6ea8 973 return -ENODEV;
1da177e4
LT
974 }
975
c4146067 976 if ((hid->claimed & HID_CLAIMED_INPUT))
4916b3a5
JK
977 hid_ff_init(hid);
978
4a1a4d8b
GL
979 if (hid->quirks & HID_QUIRK_SONY_PS3_CONTROLLER)
980 hid_fixup_sony_ps3_controller(interface_to_usbdev(intf),
981 intf->cur_altsetting->desc.bInterfaceNumber);
982
1da177e4
LT
983 printk(KERN_INFO);
984
985 if (hid->claimed & HID_CLAIMED_INPUT)
986 printk("input");
987 if (hid->claimed == (HID_CLAIMED_INPUT | HID_CLAIMED_HIDDEV))
988 printk(",");
989 if (hid->claimed & HID_CLAIMED_HIDDEV)
990 printk("hiddev%d", hid->minor);
991
992 c = "Device";
993 for (i = 0; i < hid->maxcollection; i++) {
994 if (hid->collection[i].type == HID_COLLECTION_APPLICATION &&
995 (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
996 (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) {
997 c = hid_types[hid->collection[i].usage & 0xffff];
998 break;
999 }
1000 }
1001
1002 usb_make_path(interface_to_usbdev(intf), path, 63);
1003
1004 printk(": USB HID v%x.%02x %s [%s] on %s\n",
1005 hid->version >> 8, hid->version & 0xff, c, hid->name, path);
1006
1007 return 0;
1008}
1009
27d72e85 1010static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1da177e4
LT
1011{
1012 struct hid_device *hid = usb_get_intfdata (intf);
4916b3a5 1013 struct usbhid_device *usbhid = hid->driver_data;
1da177e4 1014
4916b3a5
JK
1015 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
1016 set_bit(HID_SUSPENDED, &usbhid->iofl);
1017 spin_unlock_irq(&usbhid->inlock);
1018 del_timer(&usbhid->io_retry);
1019 usb_kill_urb(usbhid->urbin);
1da177e4
LT
1020 dev_dbg(&intf->dev, "suspend\n");
1021 return 0;
1022}
1023
1024static int hid_resume(struct usb_interface *intf)
1025{
1026 struct hid_device *hid = usb_get_intfdata (intf);
4916b3a5 1027 struct usbhid_device *usbhid = hid->driver_data;
1da177e4
LT
1028 int status;
1029
4916b3a5
JK
1030 clear_bit(HID_SUSPENDED, &usbhid->iofl);
1031 usbhid->retry_delay = 0;
aef4e266 1032 status = hid_start_in(hid);
1da177e4
LT
1033 dev_dbg(&intf->dev, "resume status %d\n", status);
1034 return status;
1035}
1036
df9a1f48 1037/* Treat USB reset pretty much the same as suspend/resume */
f07600cf 1038static int hid_pre_reset(struct usb_interface *intf)
df9a1f48
AS
1039{
1040 /* FIXME: What if the interface is already suspended? */
1041 hid_suspend(intf, PMSG_ON);
f07600cf 1042 return 0;
df9a1f48
AS
1043}
1044
f07600cf
AS
1045/* Same routine used for post_reset and reset_resume */
1046static int hid_post_reset(struct usb_interface *intf)
df9a1f48
AS
1047{
1048 struct usb_device *dev = interface_to_usbdev (intf);
1049
1050 hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0);
1051 /* FIXME: Any more reinitialization needed? */
1052
f07600cf 1053 return hid_resume(intf);
df9a1f48
AS
1054}
1055
1da177e4
LT
1056static struct usb_device_id hid_usb_ids [] = {
1057 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
1058 .bInterfaceClass = USB_INTERFACE_CLASS_HID },
1059 { } /* Terminating entry */
1060};
1061
1062MODULE_DEVICE_TABLE (usb, hid_usb_ids);
1063
1064static struct usb_driver hid_driver = {
1da177e4
LT
1065 .name = "usbhid",
1066 .probe = hid_probe,
1067 .disconnect = hid_disconnect,
1068 .suspend = hid_suspend,
1069 .resume = hid_resume,
f07600cf 1070 .reset_resume = hid_post_reset,
df9a1f48
AS
1071 .pre_reset = hid_pre_reset,
1072 .post_reset = hid_post_reset,
1da177e4
LT
1073 .id_table = hid_usb_ids,
1074};
1075
1076static int __init hid_init(void)
1077{
1078 int retval;
876b9276
PW
1079 retval = usbhid_quirks_init(quirks_param);
1080 if (retval)
1081 goto usbhid_quirks_init_fail;
1da177e4
LT
1082 retval = hiddev_init();
1083 if (retval)
1084 goto hiddev_init_fail;
1085 retval = usb_register(&hid_driver);
1086 if (retval)
1087 goto usb_register_fail;
1088 info(DRIVER_VERSION ":" DRIVER_DESC);
1089
1090 return 0;
1091usb_register_fail:
1092 hiddev_exit();
1093hiddev_init_fail:
876b9276
PW
1094 usbhid_quirks_exit();
1095usbhid_quirks_init_fail:
1da177e4
LT
1096 return retval;
1097}
1098
1099static void __exit hid_exit(void)
1100{
1101 usb_deregister(&hid_driver);
1102 hiddev_exit();
876b9276 1103 usbhid_quirks_exit();
1da177e4
LT
1104}
1105
1106module_init(hid_init);
1107module_exit(hid_exit);
1108
1109MODULE_AUTHOR(DRIVER_AUTHOR);
1110MODULE_DESCRIPTION(DRIVER_DESC);
1111MODULE_LICENSE(DRIVER_LICENSE);