wacom_sys.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * drivers/input/tablet/wacom_sys.c
  3. *
  4. * USB Wacom Graphire and Wacom Intuos tablet support - system specific code
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include "wacom.h"
  13. #include "wacom_wac.h"
  14. /* defines to get HID report descriptor */
  15. #define HID_DEVICET_HID (USB_TYPE_CLASS | 0x01)
  16. #define HID_DEVICET_REPORT (USB_TYPE_CLASS | 0x02)
  17. #define HID_USAGE_UNDEFINED 0x00
  18. #define HID_USAGE_PAGE 0x05
  19. #define HID_USAGE_PAGE_DIGITIZER 0x0d
  20. #define HID_USAGE_PAGE_DESKTOP 0x01
  21. #define HID_USAGE 0x09
  22. #define HID_USAGE_X 0x30
  23. #define HID_USAGE_Y 0x31
  24. #define HID_USAGE_X_TILT 0x3d
  25. #define HID_USAGE_Y_TILT 0x3e
  26. #define HID_USAGE_FINGER 0x22
  27. #define HID_USAGE_STYLUS 0x20
  28. #define HID_COLLECTION 0xc0
  29. enum {
  30. WCM_UNDEFINED = 0,
  31. WCM_DESKTOP,
  32. WCM_DIGITIZER,
  33. };
  34. struct hid_descriptor {
  35. struct usb_descriptor_header header;
  36. __le16 bcdHID;
  37. u8 bCountryCode;
  38. u8 bNumDescriptors;
  39. u8 bDescriptorType;
  40. __le16 wDescriptorLength;
  41. } __attribute__ ((packed));
  42. /* defines to get/set USB message */
  43. #define USB_REQ_GET_REPORT 0x01
  44. #define USB_REQ_SET_REPORT 0x09
  45. #define WAC_HID_FEATURE_REPORT 0x03
  46. static int usb_get_report(struct usb_interface *intf, unsigned char type,
  47. unsigned char id, void *buf, int size)
  48. {
  49. return usb_control_msg(interface_to_usbdev(intf),
  50. usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
  51. USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  52. (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
  53. buf, size, 100);
  54. }
  55. static int usb_set_report(struct usb_interface *intf, unsigned char type,
  56. unsigned char id, void *buf, int size)
  57. {
  58. return usb_control_msg(interface_to_usbdev(intf),
  59. usb_sndctrlpipe(interface_to_usbdev(intf), 0),
  60. USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  61. (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
  62. buf, size, 1000);
  63. }
  64. static struct input_dev * get_input_dev(struct wacom_combo *wcombo)
  65. {
  66. return wcombo->wacom->dev;
  67. }
  68. static void wacom_sys_irq(struct urb *urb)
  69. {
  70. struct wacom *wacom = urb->context;
  71. struct wacom_combo wcombo;
  72. int retval;
  73. switch (urb->status) {
  74. case 0:
  75. /* success */
  76. break;
  77. case -ECONNRESET:
  78. case -ENOENT:
  79. case -ESHUTDOWN:
  80. /* this urb is terminated, clean up */
  81. dbg("%s - urb shutting down with status: %d", __func__, urb->status);
  82. return;
  83. default:
  84. dbg("%s - nonzero urb status received: %d", __func__, urb->status);
  85. goto exit;
  86. }
  87. wcombo.wacom = wacom;
  88. wcombo.urb = urb;
  89. if (wacom_wac_irq(wacom->wacom_wac, (void *)&wcombo))
  90. input_sync(get_input_dev(&wcombo));
  91. exit:
  92. usb_mark_last_busy(wacom->usbdev);
  93. retval = usb_submit_urb (urb, GFP_ATOMIC);
  94. if (retval)
  95. err ("%s - usb_submit_urb failed with result %d",
  96. __func__, retval);
  97. }
  98. void wacom_report_key(void *wcombo, unsigned int key_type, int key_data)
  99. {
  100. input_report_key(get_input_dev((struct wacom_combo *)wcombo), key_type, key_data);
  101. }
  102. void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data)
  103. {
  104. input_report_abs(get_input_dev((struct wacom_combo *)wcombo), abs_type, abs_data);
  105. }
  106. void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data)
  107. {
  108. input_report_rel(get_input_dev((struct wacom_combo *)wcombo), rel_type, rel_data);
  109. }
  110. void wacom_input_event(void *wcombo, unsigned int type, unsigned int code, int value)
  111. {
  112. input_event(get_input_dev((struct wacom_combo *)wcombo), type, code, value);
  113. }
  114. __u16 wacom_be16_to_cpu(unsigned char *data)
  115. {
  116. __u16 value;
  117. value = be16_to_cpu(*(__be16 *) data);
  118. return value;
  119. }
  120. __u16 wacom_le16_to_cpu(unsigned char *data)
  121. {
  122. __u16 value;
  123. value = le16_to_cpu(*(__le16 *) data);
  124. return value;
  125. }
  126. void wacom_input_sync(void *wcombo)
  127. {
  128. input_sync(get_input_dev((struct wacom_combo *)wcombo));
  129. }
  130. static int wacom_open(struct input_dev *dev)
  131. {
  132. struct wacom *wacom = input_get_drvdata(dev);
  133. mutex_lock(&wacom->lock);
  134. wacom->irq->dev = wacom->usbdev;
  135. if (usb_autopm_get_interface(wacom->intf) < 0) {
  136. mutex_unlock(&wacom->lock);
  137. return -EIO;
  138. }
  139. if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
  140. usb_autopm_put_interface(wacom->intf);
  141. mutex_unlock(&wacom->lock);
  142. return -EIO;
  143. }
  144. wacom->open = 1;
  145. wacom->intf->needs_remote_wakeup = 1;
  146. mutex_unlock(&wacom->lock);
  147. return 0;
  148. }
  149. static void wacom_close(struct input_dev *dev)
  150. {
  151. struct wacom *wacom = input_get_drvdata(dev);
  152. mutex_lock(&wacom->lock);
  153. usb_kill_urb(wacom->irq);
  154. wacom->open = 0;
  155. wacom->intf->needs_remote_wakeup = 0;
  156. mutex_unlock(&wacom->lock);
  157. }
  158. void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  159. {
  160. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_1) |
  161. BIT_MASK(BTN_5);
  162. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  163. }
  164. void input_dev_g4(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  165. {
  166. input_dev->evbit[0] |= BIT_MASK(EV_MSC);
  167. input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
  168. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER);
  169. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) |
  170. BIT_MASK(BTN_4);
  171. }
  172. void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  173. {
  174. input_dev->evbit[0] |= BIT_MASK(EV_REL);
  175. input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);
  176. input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) |
  177. BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
  178. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
  179. BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_STYLUS2);
  180. input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
  181. }
  182. void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  183. {
  184. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER);
  185. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) |
  186. BIT_MASK(BTN_1) | BIT_MASK(BTN_2) | BIT_MASK(BTN_3);
  187. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  188. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  189. }
  190. void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  191. {
  192. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_4) |
  193. BIT_MASK(BTN_5) | BIT_MASK(BTN_6) | BIT_MASK(BTN_7);
  194. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  195. }
  196. void input_dev_i4s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  197. {
  198. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER);
  199. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) | BIT_MASK(BTN_1) | BIT_MASK(BTN_2) | BIT_MASK(BTN_3);
  200. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_4) | BIT_MASK(BTN_5) | BIT_MASK(BTN_6);
  201. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  202. }
  203. void input_dev_i4(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  204. {
  205. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_7) | BIT_MASK(BTN_8);
  206. }
  207. void input_dev_bee(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  208. {
  209. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_8) | BIT_MASK(BTN_9);
  210. }
  211. void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  212. {
  213. input_dev->evbit[0] |= BIT_MASK(EV_MSC) | BIT_MASK(EV_REL);
  214. input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
  215. input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);
  216. input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) |
  217. BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE) |
  218. BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
  219. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
  220. BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_TOOL_BRUSH) |
  221. BIT_MASK(BTN_TOOL_PENCIL) | BIT_MASK(BTN_TOOL_AIRBRUSH) |
  222. BIT_MASK(BTN_TOOL_LENS) | BIT_MASK(BTN_STYLUS2);
  223. input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
  224. input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
  225. input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
  226. input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
  227. input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
  228. input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
  229. }
  230. void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  231. {
  232. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_STYLUS2);
  233. }
  234. void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  235. {
  236. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER);
  237. }
  238. static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc,
  239. struct wacom_wac *wacom_wac)
  240. {
  241. struct usb_device *dev = interface_to_usbdev(intf);
  242. struct wacom_features *features = wacom_wac->features;
  243. char limit = 0, result = 0;
  244. int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
  245. unsigned char *report;
  246. report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
  247. if (!report)
  248. return -ENOMEM;
  249. /* retrive report descriptors */
  250. do {
  251. result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  252. USB_REQ_GET_DESCRIPTOR,
  253. USB_RECIP_INTERFACE | USB_DIR_IN,
  254. HID_DEVICET_REPORT << 8,
  255. intf->altsetting[0].desc.bInterfaceNumber, /* interface */
  256. report,
  257. hid_desc->wDescriptorLength,
  258. 5000); /* 5 secs */
  259. } while (result < 0 && limit++ < 5);
  260. /* No need to parse the Descriptor. It isn't an error though */
  261. if (result < 0)
  262. goto out;
  263. for (i = 0; i < hid_desc->wDescriptorLength; i++) {
  264. switch (report[i]) {
  265. case HID_USAGE_PAGE:
  266. switch (report[i + 1]) {
  267. case HID_USAGE_PAGE_DIGITIZER:
  268. usage = WCM_DIGITIZER;
  269. i++;
  270. break;
  271. case HID_USAGE_PAGE_DESKTOP:
  272. usage = WCM_DESKTOP;
  273. i++;
  274. break;
  275. }
  276. break;
  277. case HID_USAGE:
  278. switch (report[i + 1]) {
  279. case HID_USAGE_X:
  280. if (usage == WCM_DESKTOP) {
  281. if (finger) {
  282. features->touch_x_max =
  283. features->touch_y_max =
  284. wacom_le16_to_cpu(&report[i + 3]);
  285. features->x_max =
  286. wacom_le16_to_cpu(&report[i + 6]);
  287. i += 7;
  288. } else if (pen) {
  289. features->x_max =
  290. wacom_le16_to_cpu(&report[i + 3]);
  291. i += 4;
  292. }
  293. } else if (usage == WCM_DIGITIZER) {
  294. /* max pressure isn't reported
  295. features->pressure_max = (unsigned short)
  296. (report[i+4] << 8 | report[i + 3]);
  297. */
  298. features->pressure_max = 255;
  299. i += 4;
  300. }
  301. break;
  302. case HID_USAGE_Y:
  303. if (usage == WCM_DESKTOP)
  304. features->y_max =
  305. wacom_le16_to_cpu(&report[i + 3]);
  306. i += 4;
  307. break;
  308. case HID_USAGE_FINGER:
  309. finger = 1;
  310. i++;
  311. break;
  312. case HID_USAGE_STYLUS:
  313. pen = 1;
  314. i++;
  315. break;
  316. case HID_USAGE_UNDEFINED:
  317. if (usage == WCM_DESKTOP && finger) /* capacity */
  318. features->pressure_max =
  319. wacom_le16_to_cpu(&report[i + 3]);
  320. i += 4;
  321. break;
  322. }
  323. break;
  324. case HID_COLLECTION:
  325. /* reset UsagePage ans Finger */
  326. finger = usage = 0;
  327. break;
  328. }
  329. }
  330. out:
  331. result = 0;
  332. kfree(report);
  333. return result;
  334. }
  335. static int wacom_query_tablet_data(struct usb_interface *intf)
  336. {
  337. unsigned char *rep_data;
  338. int limit = 0;
  339. int error;
  340. rep_data = kmalloc(2, GFP_KERNEL);
  341. if (!rep_data)
  342. return -ENOMEM;
  343. do {
  344. rep_data[0] = 2;
  345. rep_data[1] = 2;
  346. error = usb_set_report(intf, WAC_HID_FEATURE_REPORT,
  347. 2, rep_data, 2);
  348. if (error >= 0)
  349. error = usb_get_report(intf,
  350. WAC_HID_FEATURE_REPORT, 2,
  351. rep_data, 2);
  352. } while ((error < 0 || rep_data[1] != 2) && limit++ < 5);
  353. kfree(rep_data);
  354. return error < 0 ? error : 0;
  355. }
  356. static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
  357. {
  358. struct usb_device *dev = interface_to_usbdev(intf);
  359. struct usb_host_interface *interface = intf->cur_altsetting;
  360. struct usb_endpoint_descriptor *endpoint;
  361. struct wacom *wacom;
  362. struct wacom_wac *wacom_wac;
  363. struct wacom_features *features;
  364. struct input_dev *input_dev;
  365. int error = -ENOMEM;
  366. struct hid_descriptor *hid_desc;
  367. wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
  368. wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL);
  369. input_dev = input_allocate_device();
  370. if (!wacom || !input_dev || !wacom_wac)
  371. goto fail1;
  372. wacom_wac->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
  373. if (!wacom_wac->data)
  374. goto fail1;
  375. wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
  376. if (!wacom->irq)
  377. goto fail2;
  378. wacom->usbdev = dev;
  379. wacom->dev = input_dev;
  380. wacom->intf = intf;
  381. mutex_init(&wacom->lock);
  382. usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
  383. strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
  384. wacom_wac->features = features = get_wacom_feature(id);
  385. BUG_ON(features->pktlen > 10);
  386. input_dev->name = wacom_wac->features->name;
  387. wacom->wacom_wac = wacom_wac;
  388. usb_to_input_id(dev, &input_dev->id);
  389. input_dev->dev.parent = &intf->dev;
  390. input_set_drvdata(input_dev, wacom);
  391. input_dev->open = wacom_open;
  392. input_dev->close = wacom_close;
  393. endpoint = &intf->cur_altsetting->endpoint[0].desc;
  394. /* Initialize touch_x_max and touch_y_max in case it is not defined */
  395. if (wacom_wac->features->type == TABLETPC) {
  396. features->touch_x_max = 1023;
  397. features->touch_y_max = 1023;
  398. } else {
  399. features->touch_x_max = 0;
  400. features->touch_y_max = 0;
  401. }
  402. /* TabletPC need to retrieve the physical and logical maximum from report descriptor */
  403. if (wacom_wac->features->type == TABLETPC) {
  404. if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) {
  405. if (usb_get_extra_descriptor(&interface->endpoint[0],
  406. HID_DEVICET_REPORT, &hid_desc)) {
  407. printk("wacom: can not retrive extra class descriptor\n");
  408. goto fail2;
  409. }
  410. }
  411. error = wacom_parse_hid(intf, hid_desc, wacom_wac);
  412. if (error)
  413. goto fail2;
  414. }
  415. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  416. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) |
  417. BIT_MASK(BTN_TOUCH) | BIT_MASK(BTN_STYLUS);
  418. input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0);
  419. input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0);
  420. input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0);
  421. if (features->type == TABLETPC) {
  422. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_DOUBLETAP);
  423. input_set_abs_params(input_dev, ABS_RX, 0, features->touch_x_max, 4, 0);
  424. input_set_abs_params(input_dev, ABS_RY, 0, features->touch_y_max, 4, 0);
  425. }
  426. input_dev->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
  427. wacom_init_input_dev(input_dev, wacom_wac);
  428. usb_fill_int_urb(wacom->irq, dev,
  429. usb_rcvintpipe(dev, endpoint->bEndpointAddress),
  430. wacom_wac->data, wacom_wac->features->pktlen,
  431. wacom_sys_irq, wacom, endpoint->bInterval);
  432. wacom->irq->transfer_dma = wacom->data_dma;
  433. wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  434. error = input_register_device(wacom->dev);
  435. if (error)
  436. goto fail3;
  437. /*
  438. * Ask the tablet to report tablet data if it is not a Tablet PC.
  439. * Note that if query fails it is not a hard failure.
  440. */
  441. if (wacom_wac->features->type != TABLETPC)
  442. wacom_query_tablet_data(intf);
  443. usb_set_intfdata(intf, wacom);
  444. return 0;
  445. fail3: usb_free_urb(wacom->irq);
  446. fail2: usb_buffer_free(dev, 10, wacom_wac->data, wacom->data_dma);
  447. fail1: input_free_device(input_dev);
  448. kfree(wacom);
  449. kfree(wacom_wac);
  450. return error;
  451. }
  452. static void wacom_disconnect(struct usb_interface *intf)
  453. {
  454. struct wacom *wacom = usb_get_intfdata(intf);
  455. usb_set_intfdata(intf, NULL);
  456. usb_kill_urb(wacom->irq);
  457. input_unregister_device(wacom->dev);
  458. usb_free_urb(wacom->irq);
  459. usb_buffer_free(interface_to_usbdev(intf), 10,
  460. wacom->wacom_wac->data, wacom->data_dma);
  461. kfree(wacom->wacom_wac);
  462. kfree(wacom);
  463. }
  464. static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
  465. {
  466. struct wacom *wacom = usb_get_intfdata(intf);
  467. mutex_lock(&wacom->lock);
  468. usb_kill_urb(wacom->irq);
  469. mutex_unlock(&wacom->lock);
  470. return 0;
  471. }
  472. static int wacom_resume(struct usb_interface *intf)
  473. {
  474. struct wacom *wacom = usb_get_intfdata(intf);
  475. int rv;
  476. mutex_lock(&wacom->lock);
  477. if (wacom->open)
  478. rv = usb_submit_urb(wacom->irq, GFP_NOIO);
  479. else
  480. rv = 0;
  481. mutex_unlock(&wacom->lock);
  482. return rv;
  483. }
  484. static int wacom_reset_resume(struct usb_interface *intf)
  485. {
  486. return wacom_resume(intf);
  487. }
  488. static struct usb_driver wacom_driver = {
  489. .name = "wacom",
  490. .probe = wacom_probe,
  491. .disconnect = wacom_disconnect,
  492. .suspend = wacom_suspend,
  493. .resume = wacom_resume,
  494. .reset_resume = wacom_reset_resume,
  495. .supports_autosuspend = 1,
  496. };
  497. static int __init wacom_init(void)
  498. {
  499. int result;
  500. wacom_driver.id_table = get_device_table();
  501. result = usb_register(&wacom_driver);
  502. if (result == 0)
  503. printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
  504. DRIVER_DESC "\n");
  505. return result;
  506. }
  507. static void __exit wacom_exit(void)
  508. {
  509. usb_deregister(&wacom_driver);
  510. }
  511. module_init(wacom_init);
  512. module_exit(wacom_exit);