hid-core.c 32 KB

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