hid-core.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  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-2008 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 + hid->report_enum[type].numbered;
  545. if (*max < size)
  546. *max = size;
  547. }
  548. }
  549. static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
  550. {
  551. struct usbhid_device *usbhid = hid->driver_data;
  552. if (!(usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->inbuf_dma)))
  553. return -1;
  554. if (!(usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->outbuf_dma)))
  555. return -1;
  556. if (!(usbhid->cr = usb_buffer_alloc(dev, sizeof(*(usbhid->cr)), GFP_ATOMIC, &usbhid->cr_dma)))
  557. return -1;
  558. if (!(usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->ctrlbuf_dma)))
  559. return -1;
  560. return 0;
  561. }
  562. static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count)
  563. {
  564. struct usbhid_device *usbhid = hid->driver_data;
  565. struct usb_device *dev = hid_to_usb_dev(hid);
  566. struct usb_interface *intf = usbhid->intf;
  567. struct usb_host_interface *interface = intf->cur_altsetting;
  568. int ret;
  569. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  570. HID_REQ_SET_REPORT,
  571. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  572. ((HID_OUTPUT_REPORT + 1) << 8) | *buf,
  573. interface->desc.bInterfaceNumber, buf + 1, count - 1,
  574. USB_CTRL_SET_TIMEOUT);
  575. /* count also the report id */
  576. if (ret > 0)
  577. ret++;
  578. return ret;
  579. }
  580. static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
  581. {
  582. struct usbhid_device *usbhid = hid->driver_data;
  583. usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma);
  584. usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma);
  585. usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma);
  586. usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
  587. }
  588. static int usbhid_parse(struct hid_device *hid)
  589. {
  590. struct usb_interface *intf = to_usb_interface(hid->dev.parent);
  591. struct usb_host_interface *interface = intf->cur_altsetting;
  592. struct usb_device *dev = interface_to_usbdev (intf);
  593. struct hid_descriptor *hdesc;
  594. u32 quirks = 0;
  595. unsigned int rsize = 0;
  596. char *rdesc;
  597. int ret, n;
  598. quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),
  599. le16_to_cpu(dev->descriptor.idProduct));
  600. /* Many keyboards and mice don't like to be polled for reports,
  601. * so we will always set the HID_QUIRK_NOGET flag for them. */
  602. if (interface->desc.bInterfaceSubClass == USB_INTERFACE_SUBCLASS_BOOT) {
  603. if (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_KEYBOARD ||
  604. interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
  605. quirks |= HID_QUIRK_NOGET;
  606. }
  607. if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&
  608. (!interface->desc.bNumEndpoints ||
  609. usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {
  610. dbg_hid("class descriptor not present\n");
  611. return -ENODEV;
  612. }
  613. hid->version = le16_to_cpu(hdesc->bcdHID);
  614. hid->country = hdesc->bCountryCode;
  615. for (n = 0; n < hdesc->bNumDescriptors; n++)
  616. if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)
  617. rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
  618. if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
  619. dbg_hid("weird size of report descriptor (%u)\n", rsize);
  620. return -EINVAL;
  621. }
  622. if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) {
  623. dbg_hid("couldn't allocate rdesc memory\n");
  624. return -ENOMEM;
  625. }
  626. hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
  627. ret = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber,
  628. HID_DT_REPORT, rdesc, rsize);
  629. if (ret < 0) {
  630. dbg_hid("reading report descriptor failed\n");
  631. kfree(rdesc);
  632. goto err;
  633. }
  634. dbg_hid("report descriptor (size %u, read %d) = ", rsize, n);
  635. for (n = 0; n < rsize; n++)
  636. dbg_hid_line(" %02x", (unsigned char) rdesc[n]);
  637. dbg_hid_line("\n");
  638. ret = hid_parse_report(hid, rdesc, rsize);
  639. kfree(rdesc);
  640. if (ret) {
  641. dbg_hid("parsing report descriptor failed\n");
  642. goto err;
  643. }
  644. hid->quirks = quirks;
  645. return 0;
  646. err:
  647. return ret;
  648. }
  649. static int usbhid_start(struct hid_device *hid)
  650. {
  651. struct usb_interface *intf = to_usb_interface(hid->dev.parent);
  652. struct usb_host_interface *interface = intf->cur_altsetting;
  653. struct usb_device *dev = interface_to_usbdev(intf);
  654. struct usbhid_device *usbhid = hid->driver_data;
  655. unsigned int n, insize = 0;
  656. int ret;
  657. clear_bit(HID_DISCONNECTED, &usbhid->iofl);
  658. usbhid->bufsize = HID_MIN_BUFFER_SIZE;
  659. hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize);
  660. hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize);
  661. hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize);
  662. if (usbhid->bufsize > HID_MAX_BUFFER_SIZE)
  663. usbhid->bufsize = HID_MAX_BUFFER_SIZE;
  664. hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
  665. if (insize > HID_MAX_BUFFER_SIZE)
  666. insize = HID_MAX_BUFFER_SIZE;
  667. if (hid_alloc_buffers(dev, hid)) {
  668. ret = -ENOMEM;
  669. goto fail;
  670. }
  671. for (n = 0; n < interface->desc.bNumEndpoints; n++) {
  672. struct usb_endpoint_descriptor *endpoint;
  673. int pipe;
  674. int interval;
  675. endpoint = &interface->endpoint[n].desc;
  676. if ((endpoint->bmAttributes & 3) != 3) /* Not an interrupt endpoint */
  677. continue;
  678. interval = endpoint->bInterval;
  679. /* Some vendors give fullspeed interval on highspeed devides */
  680. if (hid->quirks & HID_QUIRK_FULLSPEED_INTERVAL &&
  681. dev->speed == USB_SPEED_HIGH) {
  682. interval = fls(endpoint->bInterval*8);
  683. printk(KERN_INFO "%s: Fixing fullspeed to highspeed interval: %d -> %d\n",
  684. hid->name, endpoint->bInterval, interval);
  685. }
  686. /* Change the polling interval of mice. */
  687. if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
  688. interval = hid_mousepoll_interval;
  689. ret = -ENOMEM;
  690. if (usb_endpoint_dir_in(endpoint)) {
  691. if (usbhid->urbin)
  692. continue;
  693. if (!(usbhid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
  694. goto fail;
  695. pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
  696. usb_fill_int_urb(usbhid->urbin, dev, pipe, usbhid->inbuf, insize,
  697. hid_irq_in, hid, interval);
  698. usbhid->urbin->transfer_dma = usbhid->inbuf_dma;
  699. usbhid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  700. } else {
  701. if (usbhid->urbout)
  702. continue;
  703. if (!(usbhid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
  704. goto fail;
  705. pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress);
  706. usb_fill_int_urb(usbhid->urbout, dev, pipe, usbhid->outbuf, 0,
  707. hid_irq_out, hid, interval);
  708. usbhid->urbout->transfer_dma = usbhid->outbuf_dma;
  709. usbhid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  710. }
  711. }
  712. init_waitqueue_head(&usbhid->wait);
  713. INIT_WORK(&usbhid->reset_work, hid_reset);
  714. setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
  715. spin_lock_init(&usbhid->inlock);
  716. spin_lock_init(&usbhid->outlock);
  717. spin_lock_init(&usbhid->ctrllock);
  718. usbhid->intf = intf;
  719. usbhid->ifnum = interface->desc.bInterfaceNumber;
  720. usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
  721. if (!usbhid->urbctrl) {
  722. ret = -ENOMEM;
  723. goto fail;
  724. }
  725. usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr,
  726. usbhid->ctrlbuf, 1, hid_ctrl, hid);
  727. usbhid->urbctrl->setup_dma = usbhid->cr_dma;
  728. usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma;
  729. usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
  730. usbhid_init_reports(hid);
  731. hid_dump_device(hid);
  732. set_bit(HID_STARTED, &usbhid->iofl);
  733. return 0;
  734. fail:
  735. usb_free_urb(usbhid->urbin);
  736. usb_free_urb(usbhid->urbout);
  737. usb_free_urb(usbhid->urbctrl);
  738. usbhid->urbin = NULL;
  739. usbhid->urbout = NULL;
  740. usbhid->urbctrl = NULL;
  741. hid_free_buffers(dev, hid);
  742. return ret;
  743. }
  744. static void usbhid_stop(struct hid_device *hid)
  745. {
  746. struct usbhid_device *usbhid = hid->driver_data;
  747. if (WARN_ON(!usbhid))
  748. return;
  749. clear_bit(HID_STARTED, &usbhid->iofl);
  750. spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
  751. set_bit(HID_DISCONNECTED, &usbhid->iofl);
  752. spin_unlock_irq(&usbhid->inlock);
  753. usb_kill_urb(usbhid->urbin);
  754. usb_kill_urb(usbhid->urbout);
  755. usb_kill_urb(usbhid->urbctrl);
  756. del_timer_sync(&usbhid->io_retry);
  757. cancel_work_sync(&usbhid->reset_work);
  758. if (hid->claimed & HID_CLAIMED_INPUT)
  759. hidinput_disconnect(hid);
  760. if (hid->claimed & HID_CLAIMED_HIDDEV)
  761. hiddev_disconnect(hid);
  762. if (hid->claimed & HID_CLAIMED_HIDRAW)
  763. hidraw_disconnect(hid);
  764. hid->claimed = 0;
  765. usb_free_urb(usbhid->urbin);
  766. usb_free_urb(usbhid->urbctrl);
  767. usb_free_urb(usbhid->urbout);
  768. usbhid->urbin = NULL; /* don't mess up next start */
  769. usbhid->urbctrl = NULL;
  770. usbhid->urbout = NULL;
  771. hid_free_buffers(hid_to_usb_dev(hid), hid);
  772. }
  773. static struct hid_ll_driver usb_hid_driver = {
  774. .parse = usbhid_parse,
  775. .start = usbhid_start,
  776. .stop = usbhid_stop,
  777. .open = usbhid_open,
  778. .close = usbhid_close,
  779. .hidinput_input_event = usb_hidinput_input_event,
  780. };
  781. static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
  782. {
  783. struct usb_host_interface *interface = intf->cur_altsetting;
  784. struct usb_device *dev = interface_to_usbdev(intf);
  785. struct usbhid_device *usbhid;
  786. struct hid_device *hid;
  787. unsigned int n, has_in = 0;
  788. size_t len;
  789. int ret;
  790. dbg_hid("HID probe called for ifnum %d\n",
  791. intf->altsetting->desc.bInterfaceNumber);
  792. for (n = 0; n < interface->desc.bNumEndpoints; n++)
  793. if (usb_endpoint_is_int_in(&interface->endpoint[n].desc))
  794. has_in++;
  795. if (!has_in) {
  796. dev_err(&intf->dev, "couldn't find an input interrupt "
  797. "endpoint\n");
  798. return -ENODEV;
  799. }
  800. hid = hid_allocate_device();
  801. if (IS_ERR(hid))
  802. return PTR_ERR(hid);
  803. usb_set_intfdata(intf, hid);
  804. hid->ll_driver = &usb_hid_driver;
  805. hid->hid_output_raw_report = usbhid_output_raw_report;
  806. hid->ff_init = hid_pidff_init;
  807. #ifdef CONFIG_USB_HIDDEV
  808. hid->hiddev_connect = hiddev_connect;
  809. hid->hiddev_hid_event = hiddev_hid_event;
  810. hid->hiddev_report_event = hiddev_report_event;
  811. #endif
  812. hid->dev.parent = &intf->dev;
  813. hid->bus = BUS_USB;
  814. hid->vendor = le16_to_cpu(dev->descriptor.idVendor);
  815. hid->product = le16_to_cpu(dev->descriptor.idProduct);
  816. hid->name[0] = 0;
  817. if (intf->cur_altsetting->desc.bInterfaceProtocol ==
  818. USB_INTERFACE_PROTOCOL_MOUSE)
  819. hid->type = HID_TYPE_USBMOUSE;
  820. if (dev->manufacturer)
  821. strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
  822. if (dev->product) {
  823. if (dev->manufacturer)
  824. strlcat(hid->name, " ", sizeof(hid->name));
  825. strlcat(hid->name, dev->product, sizeof(hid->name));
  826. }
  827. if (!strlen(hid->name))
  828. snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
  829. le16_to_cpu(dev->descriptor.idVendor),
  830. le16_to_cpu(dev->descriptor.idProduct));
  831. usb_make_path(dev, hid->phys, sizeof(hid->phys));
  832. strlcat(hid->phys, "/input", sizeof(hid->phys));
  833. len = strlen(hid->phys);
  834. if (len < sizeof(hid->phys) - 1)
  835. snprintf(hid->phys + len, sizeof(hid->phys) - len,
  836. "%d", intf->altsetting[0].desc.bInterfaceNumber);
  837. if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
  838. hid->uniq[0] = 0;
  839. usbhid = kzalloc(sizeof(*usbhid), GFP_KERNEL);
  840. if (usbhid == NULL) {
  841. ret = -ENOMEM;
  842. goto err;
  843. }
  844. hid->driver_data = usbhid;
  845. usbhid->hid = hid;
  846. ret = hid_add_device(hid);
  847. if (ret) {
  848. if (ret != -ENODEV)
  849. dev_err(&intf->dev, "can't add hid device: %d\n", ret);
  850. goto err_free;
  851. }
  852. return 0;
  853. err_free:
  854. kfree(usbhid);
  855. err:
  856. hid_destroy_device(hid);
  857. return ret;
  858. }
  859. static void hid_disconnect(struct usb_interface *intf)
  860. {
  861. struct hid_device *hid = usb_get_intfdata(intf);
  862. struct usbhid_device *usbhid;
  863. if (WARN_ON(!hid))
  864. return;
  865. usbhid = hid->driver_data;
  866. hid_destroy_device(hid);
  867. kfree(usbhid);
  868. }
  869. static int hid_suspend(struct usb_interface *intf, pm_message_t message)
  870. {
  871. struct hid_device *hid = usb_get_intfdata (intf);
  872. struct usbhid_device *usbhid = hid->driver_data;
  873. if (!test_bit(HID_STARTED, &usbhid->iofl))
  874. return 0;
  875. spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
  876. set_bit(HID_SUSPENDED, &usbhid->iofl);
  877. spin_unlock_irq(&usbhid->inlock);
  878. del_timer_sync(&usbhid->io_retry);
  879. usb_kill_urb(usbhid->urbin);
  880. dev_dbg(&intf->dev, "suspend\n");
  881. return 0;
  882. }
  883. static int hid_resume(struct usb_interface *intf)
  884. {
  885. struct hid_device *hid = usb_get_intfdata (intf);
  886. struct usbhid_device *usbhid = hid->driver_data;
  887. int status;
  888. if (!test_bit(HID_STARTED, &usbhid->iofl))
  889. return 0;
  890. clear_bit(HID_SUSPENDED, &usbhid->iofl);
  891. usbhid->retry_delay = 0;
  892. status = hid_start_in(hid);
  893. dev_dbg(&intf->dev, "resume status %d\n", status);
  894. return status;
  895. }
  896. /* Treat USB reset pretty much the same as suspend/resume */
  897. static int hid_pre_reset(struct usb_interface *intf)
  898. {
  899. /* FIXME: What if the interface is already suspended? */
  900. hid_suspend(intf, PMSG_ON);
  901. return 0;
  902. }
  903. /* Same routine used for post_reset and reset_resume */
  904. static int hid_post_reset(struct usb_interface *intf)
  905. {
  906. struct usb_device *dev = interface_to_usbdev (intf);
  907. hid_set_idle(dev, intf->cur_altsetting->desc.bInterfaceNumber, 0, 0);
  908. /* FIXME: Any more reinitialization needed? */
  909. return hid_resume(intf);
  910. }
  911. static struct usb_device_id hid_usb_ids [] = {
  912. { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
  913. .bInterfaceClass = USB_INTERFACE_CLASS_HID },
  914. { } /* Terminating entry */
  915. };
  916. MODULE_DEVICE_TABLE (usb, hid_usb_ids);
  917. static struct usb_driver hid_driver = {
  918. .name = "usbhid",
  919. .probe = hid_probe,
  920. .disconnect = hid_disconnect,
  921. .suspend = hid_suspend,
  922. .resume = hid_resume,
  923. .reset_resume = hid_post_reset,
  924. .pre_reset = hid_pre_reset,
  925. .post_reset = hid_post_reset,
  926. .id_table = hid_usb_ids,
  927. .supports_autosuspend = 1,
  928. };
  929. static const struct hid_device_id hid_usb_table[] = {
  930. { HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) },
  931. { }
  932. };
  933. static struct hid_driver hid_usb_driver = {
  934. .name = "generic-usb",
  935. .id_table = hid_usb_table,
  936. };
  937. static int __init hid_init(void)
  938. {
  939. int retval;
  940. retval = hid_register_driver(&hid_usb_driver);
  941. if (retval)
  942. goto hid_register_fail;
  943. retval = usbhid_quirks_init(quirks_param);
  944. if (retval)
  945. goto usbhid_quirks_init_fail;
  946. retval = hiddev_init();
  947. if (retval)
  948. goto hiddev_init_fail;
  949. retval = usb_register(&hid_driver);
  950. if (retval)
  951. goto usb_register_fail;
  952. printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
  953. DRIVER_DESC "\n");
  954. return 0;
  955. usb_register_fail:
  956. hiddev_exit();
  957. hiddev_init_fail:
  958. usbhid_quirks_exit();
  959. usbhid_quirks_init_fail:
  960. hid_unregister_driver(&hid_usb_driver);
  961. hid_register_fail:
  962. return retval;
  963. }
  964. static void __exit hid_exit(void)
  965. {
  966. usb_deregister(&hid_driver);
  967. hiddev_exit();
  968. usbhid_quirks_exit();
  969. hid_unregister_driver(&hid_usb_driver);
  970. }
  971. module_init(hid_init);
  972. module_exit(hid_exit);
  973. MODULE_AUTHOR(DRIVER_AUTHOR);
  974. MODULE_DESCRIPTION(DRIVER_DESC);
  975. MODULE_LICENSE(DRIVER_LICENSE);