hid-core.c 31 KB

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