wacom_sys.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. /*
  2. * drivers/input/tablet/wacom_sys.c
  3. *
  4. * USB Wacom 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_wac.h"
  13. #include "wacom.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_USAGE_CONTACTMAX 0x55
  29. #define HID_COLLECTION 0xa1
  30. #define HID_COLLECTION_LOGICAL 0x02
  31. #define HID_COLLECTION_END 0xc0
  32. enum {
  33. WCM_UNDEFINED = 0,
  34. WCM_DESKTOP,
  35. WCM_DIGITIZER,
  36. };
  37. struct hid_descriptor {
  38. struct usb_descriptor_header header;
  39. __le16 bcdHID;
  40. u8 bCountryCode;
  41. u8 bNumDescriptors;
  42. u8 bDescriptorType;
  43. __le16 wDescriptorLength;
  44. } __attribute__ ((packed));
  45. /* defines to get/set USB message */
  46. #define USB_REQ_GET_REPORT 0x01
  47. #define USB_REQ_SET_REPORT 0x09
  48. #define WAC_HID_FEATURE_REPORT 0x03
  49. #define WAC_MSG_RETRIES 5
  50. #define WAC_CMD_LED_CONTROL 0x20
  51. #define WAC_CMD_ICON_START 0x21
  52. #define WAC_CMD_ICON_XFER 0x23
  53. #define WAC_CMD_RETRIES 10
  54. static int wacom_get_report(struct usb_interface *intf, u8 type, u8 id,
  55. void *buf, size_t size, unsigned int retries)
  56. {
  57. struct usb_device *dev = interface_to_usbdev(intf);
  58. int retval;
  59. do {
  60. retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  61. USB_REQ_GET_REPORT,
  62. USB_DIR_IN | USB_TYPE_CLASS |
  63. USB_RECIP_INTERFACE,
  64. (type << 8) + id,
  65. intf->altsetting[0].desc.bInterfaceNumber,
  66. buf, size, 100);
  67. } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
  68. return retval;
  69. }
  70. static int wacom_set_report(struct usb_interface *intf, u8 type, u8 id,
  71. void *buf, size_t size, unsigned int retries)
  72. {
  73. struct usb_device *dev = interface_to_usbdev(intf);
  74. int retval;
  75. do {
  76. retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  77. USB_REQ_SET_REPORT,
  78. USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  79. (type << 8) + id,
  80. intf->altsetting[0].desc.bInterfaceNumber,
  81. buf, size, 1000);
  82. } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
  83. return retval;
  84. }
  85. static void wacom_sys_irq(struct urb *urb)
  86. {
  87. struct wacom *wacom = urb->context;
  88. struct device *dev = &wacom->intf->dev;
  89. int retval;
  90. switch (urb->status) {
  91. case 0:
  92. /* success */
  93. break;
  94. case -ECONNRESET:
  95. case -ENOENT:
  96. case -ESHUTDOWN:
  97. /* this urb is terminated, clean up */
  98. dev_dbg(dev, "%s - urb shutting down with status: %d\n",
  99. __func__, urb->status);
  100. return;
  101. default:
  102. dev_dbg(dev, "%s - nonzero urb status received: %d\n",
  103. __func__, urb->status);
  104. goto exit;
  105. }
  106. wacom_wac_irq(&wacom->wacom_wac, urb->actual_length);
  107. exit:
  108. usb_mark_last_busy(wacom->usbdev);
  109. retval = usb_submit_urb(urb, GFP_ATOMIC);
  110. if (retval)
  111. dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
  112. __func__, retval);
  113. }
  114. static int wacom_open(struct input_dev *dev)
  115. {
  116. struct wacom *wacom = input_get_drvdata(dev);
  117. int retval = 0;
  118. if (usb_autopm_get_interface(wacom->intf) < 0)
  119. return -EIO;
  120. mutex_lock(&wacom->lock);
  121. if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
  122. retval = -EIO;
  123. goto out;
  124. }
  125. wacom->open = true;
  126. wacom->intf->needs_remote_wakeup = 1;
  127. out:
  128. mutex_unlock(&wacom->lock);
  129. usb_autopm_put_interface(wacom->intf);
  130. return retval;
  131. }
  132. static void wacom_close(struct input_dev *dev)
  133. {
  134. struct wacom *wacom = input_get_drvdata(dev);
  135. int autopm_error;
  136. autopm_error = usb_autopm_get_interface(wacom->intf);
  137. mutex_lock(&wacom->lock);
  138. usb_kill_urb(wacom->irq);
  139. wacom->open = false;
  140. wacom->intf->needs_remote_wakeup = 0;
  141. mutex_unlock(&wacom->lock);
  142. if (!autopm_error)
  143. usb_autopm_put_interface(wacom->intf);
  144. }
  145. /*
  146. * Calculate the resolution of the X or Y axis, given appropriate HID data.
  147. * This function is little more than hidinput_calc_abs_res stripped down.
  148. */
  149. static int wacom_calc_hid_res(int logical_extents, int physical_extents,
  150. unsigned char unit, unsigned char exponent)
  151. {
  152. int prev, unit_exponent;
  153. /* Check if the extents are sane */
  154. if (logical_extents <= 0 || physical_extents <= 0)
  155. return 0;
  156. /* Get signed value of nybble-sized twos-compliment exponent */
  157. unit_exponent = exponent;
  158. if (unit_exponent > 7)
  159. unit_exponent -= 16;
  160. /* Convert physical_extents to millimeters */
  161. if (unit == 0x11) { /* If centimeters */
  162. unit_exponent += 1;
  163. } else if (unit == 0x13) { /* If inches */
  164. prev = physical_extents;
  165. physical_extents *= 254;
  166. if (physical_extents < prev)
  167. return 0;
  168. unit_exponent -= 1;
  169. } else {
  170. return 0;
  171. }
  172. /* Apply negative unit exponent */
  173. for (; unit_exponent < 0; unit_exponent++) {
  174. prev = logical_extents;
  175. logical_extents *= 10;
  176. if (logical_extents < prev)
  177. return 0;
  178. }
  179. /* Apply positive unit exponent */
  180. for (; unit_exponent > 0; unit_exponent--) {
  181. prev = physical_extents;
  182. physical_extents *= 10;
  183. if (physical_extents < prev)
  184. return 0;
  185. }
  186. /* Calculate resolution */
  187. return logical_extents / physical_extents;
  188. }
  189. /*
  190. * The physical dimension specified by the HID descriptor is likely not in
  191. * the "100th of a mm" units expected by wacom_calculate_touch_res. This
  192. * function adjusts the value of [xy]_phy based on the unit and exponent
  193. * provided by the HID descriptor. If an error occurs durring conversion
  194. * (e.g. from the unit being left unspecified) [xy]_phy is not modified.
  195. */
  196. static void wacom_fix_phy_from_hid(struct wacom_features *features)
  197. {
  198. int xres = wacom_calc_hid_res(features->x_max, features->x_phy,
  199. features->unit, features->unitExpo);
  200. int yres = wacom_calc_hid_res(features->y_max, features->y_phy,
  201. features->unit, features->unitExpo);
  202. if (xres > 0 && yres > 0) {
  203. features->x_phy = (100 * features->x_max) / xres;
  204. features->y_phy = (100 * features->y_max) / yres;
  205. }
  206. }
  207. /*
  208. * Static values for max X/Y and resolution of Pen interface is stored in
  209. * features. This mean physical size of active area can be computed.
  210. * This is useful to do when Pen and Touch have same active area of tablet.
  211. * This means for Touch device, we only need to find max X/Y value and we
  212. * have enough information to compute resolution of touch.
  213. */
  214. static void wacom_set_phy_from_res(struct wacom_features *features)
  215. {
  216. features->x_phy = (features->x_max * 100) / features->x_resolution;
  217. features->y_phy = (features->y_max * 100) / features->y_resolution;
  218. }
  219. static int wacom_parse_logical_collection(unsigned char *report,
  220. struct wacom_features *features)
  221. {
  222. int length = 0;
  223. if (features->type == BAMBOO_PT) {
  224. /* Logical collection is only used by 3rd gen Bamboo Touch */
  225. features->pktlen = WACOM_PKGLEN_BBTOUCH3;
  226. features->device_type = BTN_TOOL_FINGER;
  227. wacom_set_phy_from_res(features);
  228. features->x_max = features->y_max =
  229. get_unaligned_le16(&report[10]);
  230. length = 11;
  231. }
  232. return length;
  233. }
  234. static void wacom_retrieve_report_data(struct usb_interface *intf,
  235. struct wacom_features *features)
  236. {
  237. int result = 0;
  238. unsigned char *rep_data;
  239. rep_data = kmalloc(2, GFP_KERNEL);
  240. if (rep_data) {
  241. rep_data[0] = 12;
  242. result = wacom_get_report(intf, WAC_HID_FEATURE_REPORT,
  243. rep_data[0], rep_data, 2,
  244. WAC_MSG_RETRIES);
  245. if (result >= 0 && rep_data[1] > 2)
  246. features->touch_max = rep_data[1];
  247. kfree(rep_data);
  248. }
  249. }
  250. /*
  251. * Interface Descriptor of wacom devices can be incomplete and
  252. * inconsistent so wacom_features table is used to store stylus
  253. * device's packet lengths, various maximum values, and tablet
  254. * resolution based on product ID's.
  255. *
  256. * For devices that contain 2 interfaces, wacom_features table is
  257. * inaccurate for the touch interface. Since the Interface Descriptor
  258. * for touch interfaces has pretty complete data, this function exists
  259. * to query tablet for this missing information instead of hard coding in
  260. * an additional table.
  261. *
  262. * A typical Interface Descriptor for a stylus will contain a
  263. * boot mouse application collection that is not of interest and this
  264. * function will ignore it.
  265. *
  266. * It also contains a digitizer application collection that also is not
  267. * of interest since any information it contains would be duplicate
  268. * of what is in wacom_features. Usually it defines a report of an array
  269. * of bytes that could be used as max length of the stylus packet returned.
  270. * If it happens to define a Digitizer-Stylus Physical Collection then
  271. * the X and Y logical values contain valid data but it is ignored.
  272. *
  273. * A typical Interface Descriptor for a touch interface will contain a
  274. * Digitizer-Finger Physical Collection which will define both logical
  275. * X/Y maximum as well as the physical size of tablet. Since touch
  276. * interfaces haven't supported pressure or distance, this is enough
  277. * information to override invalid values in the wacom_features table.
  278. *
  279. * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical
  280. * Collection. Instead they define a Logical Collection with a single
  281. * Logical Maximum for both X and Y.
  282. *
  283. * Intuos5 touch interface does not contain useful data. We deal with
  284. * this after returning from this function.
  285. */
  286. static int wacom_parse_hid(struct usb_interface *intf,
  287. struct hid_descriptor *hid_desc,
  288. struct wacom_features *features)
  289. {
  290. struct usb_device *dev = interface_to_usbdev(intf);
  291. char limit = 0;
  292. /* result has to be defined as int for some devices */
  293. int result = 0;
  294. int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
  295. unsigned char *report;
  296. report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
  297. if (!report)
  298. return -ENOMEM;
  299. /* retrive report descriptors */
  300. do {
  301. result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  302. USB_REQ_GET_DESCRIPTOR,
  303. USB_RECIP_INTERFACE | USB_DIR_IN,
  304. HID_DEVICET_REPORT << 8,
  305. intf->altsetting[0].desc.bInterfaceNumber, /* interface */
  306. report,
  307. hid_desc->wDescriptorLength,
  308. 5000); /* 5 secs */
  309. } while (result < 0 && limit++ < WAC_MSG_RETRIES);
  310. /* No need to parse the Descriptor. It isn't an error though */
  311. if (result < 0)
  312. goto out;
  313. for (i = 0; i < hid_desc->wDescriptorLength; i++) {
  314. switch (report[i]) {
  315. case HID_USAGE_PAGE:
  316. switch (report[i + 1]) {
  317. case HID_USAGE_PAGE_DIGITIZER:
  318. usage = WCM_DIGITIZER;
  319. i++;
  320. break;
  321. case HID_USAGE_PAGE_DESKTOP:
  322. usage = WCM_DESKTOP;
  323. i++;
  324. break;
  325. }
  326. break;
  327. case HID_USAGE:
  328. switch (report[i + 1]) {
  329. case HID_USAGE_X:
  330. if (usage == WCM_DESKTOP) {
  331. if (finger) {
  332. features->device_type = BTN_TOOL_FINGER;
  333. if (features->type == TABLETPC2FG) {
  334. /* need to reset back */
  335. features->pktlen = WACOM_PKGLEN_TPC2FG;
  336. }
  337. if (features->type == MTSCREEN)
  338. features->pktlen = WACOM_PKGLEN_MTOUCH;
  339. if (features->type == BAMBOO_PT) {
  340. /* need to reset back */
  341. features->pktlen = WACOM_PKGLEN_BBTOUCH;
  342. features->x_phy =
  343. get_unaligned_le16(&report[i + 5]);
  344. features->x_max =
  345. get_unaligned_le16(&report[i + 8]);
  346. i += 15;
  347. } else {
  348. features->x_max =
  349. get_unaligned_le16(&report[i + 3]);
  350. features->x_phy =
  351. get_unaligned_le16(&report[i + 6]);
  352. features->unit = report[i + 9];
  353. features->unitExpo = report[i + 11];
  354. i += 12;
  355. }
  356. } else if (pen) {
  357. /* penabled only accepts exact bytes of data */
  358. if (features->type == TABLETPC2FG)
  359. features->pktlen = WACOM_PKGLEN_GRAPHIRE;
  360. features->device_type = BTN_TOOL_PEN;
  361. features->x_max =
  362. get_unaligned_le16(&report[i + 3]);
  363. i += 4;
  364. }
  365. }
  366. break;
  367. case HID_USAGE_Y:
  368. if (usage == WCM_DESKTOP) {
  369. if (finger) {
  370. int type = features->type;
  371. if (type == TABLETPC2FG || type == MTSCREEN) {
  372. features->y_max =
  373. get_unaligned_le16(&report[i + 3]);
  374. features->y_phy =
  375. get_unaligned_le16(&report[i + 6]);
  376. i += 7;
  377. } else if (type == BAMBOO_PT) {
  378. features->y_phy =
  379. get_unaligned_le16(&report[i + 3]);
  380. features->y_max =
  381. get_unaligned_le16(&report[i + 6]);
  382. i += 12;
  383. } else {
  384. features->y_max =
  385. features->x_max;
  386. features->y_phy =
  387. get_unaligned_le16(&report[i + 3]);
  388. i += 4;
  389. }
  390. } else if (pen) {
  391. features->y_max =
  392. get_unaligned_le16(&report[i + 3]);
  393. i += 4;
  394. }
  395. }
  396. break;
  397. case HID_USAGE_FINGER:
  398. finger = 1;
  399. i++;
  400. break;
  401. /*
  402. * Requiring Stylus Usage will ignore boot mouse
  403. * X/Y values and some cases of invalid Digitizer X/Y
  404. * values commonly reported.
  405. */
  406. case HID_USAGE_STYLUS:
  407. pen = 1;
  408. i++;
  409. break;
  410. case HID_USAGE_CONTACTMAX:
  411. /* leave touch_max as is if predefined */
  412. if (!features->touch_max)
  413. wacom_retrieve_report_data(intf, features);
  414. i++;
  415. break;
  416. }
  417. break;
  418. case HID_COLLECTION_END:
  419. /* reset UsagePage and Finger */
  420. finger = usage = 0;
  421. break;
  422. case HID_COLLECTION:
  423. i++;
  424. switch (report[i]) {
  425. case HID_COLLECTION_LOGICAL:
  426. i += wacom_parse_logical_collection(&report[i],
  427. features);
  428. break;
  429. }
  430. break;
  431. }
  432. }
  433. out:
  434. result = 0;
  435. kfree(report);
  436. return result;
  437. }
  438. static int wacom_set_device_mode(struct usb_interface *intf, int report_id, int length, int mode)
  439. {
  440. unsigned char *rep_data;
  441. int error = -ENOMEM, limit = 0;
  442. rep_data = kzalloc(length, GFP_KERNEL);
  443. if (!rep_data)
  444. return error;
  445. rep_data[0] = report_id;
  446. rep_data[1] = mode;
  447. do {
  448. error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
  449. report_id, rep_data, length, 1);
  450. if (error >= 0)
  451. error = wacom_get_report(intf, WAC_HID_FEATURE_REPORT,
  452. report_id, rep_data, length, 1);
  453. } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES);
  454. kfree(rep_data);
  455. return error < 0 ? error : 0;
  456. }
  457. /*
  458. * Switch the tablet into its most-capable mode. Wacom tablets are
  459. * typically configured to power-up in a mode which sends mouse-like
  460. * reports to the OS. To get absolute position, pressure data, etc.
  461. * from the tablet, it is necessary to switch the tablet out of this
  462. * mode and into one which sends the full range of tablet data.
  463. */
  464. static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
  465. {
  466. if (features->device_type == BTN_TOOL_FINGER) {
  467. if (features->type > TABLETPC) {
  468. /* MT Tablet PC touch */
  469. return wacom_set_device_mode(intf, 3, 4, 4);
  470. }
  471. } else if (features->device_type == BTN_TOOL_PEN) {
  472. if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
  473. return wacom_set_device_mode(intf, 2, 2, 2);
  474. }
  475. }
  476. return 0;
  477. }
  478. static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
  479. struct wacom_features *features)
  480. {
  481. int error = 0;
  482. struct usb_host_interface *interface = intf->cur_altsetting;
  483. struct hid_descriptor *hid_desc;
  484. /* default features */
  485. features->device_type = BTN_TOOL_PEN;
  486. features->x_fuzz = 4;
  487. features->y_fuzz = 4;
  488. features->pressure_fuzz = 0;
  489. features->distance_fuzz = 0;
  490. /*
  491. * The wireless device HID is basic and layout conflicts with
  492. * other tablets (monitor and touch interface can look like pen).
  493. * Skip the query for this type and modify defaults based on
  494. * interface number.
  495. */
  496. if (features->type == WIRELESS) {
  497. if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
  498. features->device_type = 0;
  499. } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
  500. features->device_type = BTN_TOOL_FINGER;
  501. features->pktlen = WACOM_PKGLEN_BBTOUCH3;
  502. }
  503. }
  504. /* only devices that support touch need to retrieve the info */
  505. if (features->type < BAMBOO_PT) {
  506. goto out;
  507. }
  508. error = usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc);
  509. if (error) {
  510. error = usb_get_extra_descriptor(&interface->endpoint[0],
  511. HID_DEVICET_REPORT, &hid_desc);
  512. if (error) {
  513. dev_err(&intf->dev,
  514. "can not retrieve extra class descriptor\n");
  515. goto out;
  516. }
  517. }
  518. error = wacom_parse_hid(intf, hid_desc, features);
  519. if (error)
  520. goto out;
  521. wacom_fix_phy_from_hid(features);
  522. out:
  523. return error;
  524. }
  525. struct wacom_usbdev_data {
  526. struct list_head list;
  527. struct kref kref;
  528. struct usb_device *dev;
  529. struct wacom_shared shared;
  530. };
  531. static LIST_HEAD(wacom_udev_list);
  532. static DEFINE_MUTEX(wacom_udev_list_lock);
  533. static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev)
  534. {
  535. struct wacom_usbdev_data *data;
  536. list_for_each_entry(data, &wacom_udev_list, list) {
  537. if (data->dev == dev) {
  538. kref_get(&data->kref);
  539. return data;
  540. }
  541. }
  542. return NULL;
  543. }
  544. static int wacom_add_shared_data(struct wacom_wac *wacom,
  545. struct usb_device *dev)
  546. {
  547. struct wacom_usbdev_data *data;
  548. int retval = 0;
  549. mutex_lock(&wacom_udev_list_lock);
  550. data = wacom_get_usbdev_data(dev);
  551. if (!data) {
  552. data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL);
  553. if (!data) {
  554. retval = -ENOMEM;
  555. goto out;
  556. }
  557. kref_init(&data->kref);
  558. data->dev = dev;
  559. list_add_tail(&data->list, &wacom_udev_list);
  560. }
  561. wacom->shared = &data->shared;
  562. out:
  563. mutex_unlock(&wacom_udev_list_lock);
  564. return retval;
  565. }
  566. static void wacom_release_shared_data(struct kref *kref)
  567. {
  568. struct wacom_usbdev_data *data =
  569. container_of(kref, struct wacom_usbdev_data, kref);
  570. mutex_lock(&wacom_udev_list_lock);
  571. list_del(&data->list);
  572. mutex_unlock(&wacom_udev_list_lock);
  573. kfree(data);
  574. }
  575. static void wacom_remove_shared_data(struct wacom_wac *wacom)
  576. {
  577. struct wacom_usbdev_data *data;
  578. if (wacom->shared) {
  579. data = container_of(wacom->shared, struct wacom_usbdev_data, shared);
  580. kref_put(&data->kref, wacom_release_shared_data);
  581. wacom->shared = NULL;
  582. }
  583. }
  584. static int wacom_led_control(struct wacom *wacom)
  585. {
  586. unsigned char *buf;
  587. int retval;
  588. buf = kzalloc(9, GFP_KERNEL);
  589. if (!buf)
  590. return -ENOMEM;
  591. if (wacom->wacom_wac.features.type >= INTUOS5S &&
  592. wacom->wacom_wac.features.type <= INTUOS5L) {
  593. /*
  594. * Touch Ring and crop mark LED luminance may take on
  595. * one of four values:
  596. * 0 = Low; 1 = Medium; 2 = High; 3 = Off
  597. */
  598. int ring_led = wacom->led.select[0] & 0x03;
  599. int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
  600. int crop_lum = 0;
  601. buf[0] = WAC_CMD_LED_CONTROL;
  602. buf[1] = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
  603. }
  604. else {
  605. int led = wacom->led.select[0] | 0x4;
  606. if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
  607. wacom->wacom_wac.features.type == WACOM_24HD)
  608. led |= (wacom->led.select[1] << 4) | 0x40;
  609. buf[0] = WAC_CMD_LED_CONTROL;
  610. buf[1] = led;
  611. buf[2] = wacom->led.llv;
  612. buf[3] = wacom->led.hlv;
  613. buf[4] = wacom->led.img_lum;
  614. }
  615. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL,
  616. buf, 9, WAC_CMD_RETRIES);
  617. kfree(buf);
  618. return retval;
  619. }
  620. static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
  621. {
  622. unsigned char *buf;
  623. int i, retval;
  624. buf = kzalloc(259, GFP_KERNEL);
  625. if (!buf)
  626. return -ENOMEM;
  627. /* Send 'start' command */
  628. buf[0] = WAC_CMD_ICON_START;
  629. buf[1] = 1;
  630. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
  631. buf, 2, WAC_CMD_RETRIES);
  632. if (retval < 0)
  633. goto out;
  634. buf[0] = WAC_CMD_ICON_XFER;
  635. buf[1] = button_id & 0x07;
  636. for (i = 0; i < 4; i++) {
  637. buf[2] = i;
  638. memcpy(buf + 3, img + i * 256, 256);
  639. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER,
  640. buf, 259, WAC_CMD_RETRIES);
  641. if (retval < 0)
  642. break;
  643. }
  644. /* Send 'stop' */
  645. buf[0] = WAC_CMD_ICON_START;
  646. buf[1] = 0;
  647. wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
  648. buf, 2, WAC_CMD_RETRIES);
  649. out:
  650. kfree(buf);
  651. return retval;
  652. }
  653. static ssize_t wacom_led_select_store(struct device *dev, int set_id,
  654. const char *buf, size_t count)
  655. {
  656. struct wacom *wacom = dev_get_drvdata(dev);
  657. unsigned int id;
  658. int err;
  659. err = kstrtouint(buf, 10, &id);
  660. if (err)
  661. return err;
  662. mutex_lock(&wacom->lock);
  663. wacom->led.select[set_id] = id & 0x3;
  664. err = wacom_led_control(wacom);
  665. mutex_unlock(&wacom->lock);
  666. return err < 0 ? err : count;
  667. }
  668. #define DEVICE_LED_SELECT_ATTR(SET_ID) \
  669. static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
  670. struct device_attribute *attr, const char *buf, size_t count) \
  671. { \
  672. return wacom_led_select_store(dev, SET_ID, buf, count); \
  673. } \
  674. static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
  675. struct device_attribute *attr, char *buf) \
  676. { \
  677. struct wacom *wacom = dev_get_drvdata(dev); \
  678. return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
  679. } \
  680. static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
  681. wacom_led##SET_ID##_select_show, \
  682. wacom_led##SET_ID##_select_store)
  683. DEVICE_LED_SELECT_ATTR(0);
  684. DEVICE_LED_SELECT_ATTR(1);
  685. static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
  686. const char *buf, size_t count)
  687. {
  688. unsigned int value;
  689. int err;
  690. err = kstrtouint(buf, 10, &value);
  691. if (err)
  692. return err;
  693. mutex_lock(&wacom->lock);
  694. *dest = value & 0x7f;
  695. err = wacom_led_control(wacom);
  696. mutex_unlock(&wacom->lock);
  697. return err < 0 ? err : count;
  698. }
  699. #define DEVICE_LUMINANCE_ATTR(name, field) \
  700. static ssize_t wacom_##name##_luminance_store(struct device *dev, \
  701. struct device_attribute *attr, const char *buf, size_t count) \
  702. { \
  703. struct wacom *wacom = dev_get_drvdata(dev); \
  704. \
  705. return wacom_luminance_store(wacom, &wacom->led.field, \
  706. buf, count); \
  707. } \
  708. static DEVICE_ATTR(name##_luminance, S_IWUSR, \
  709. NULL, wacom_##name##_luminance_store)
  710. DEVICE_LUMINANCE_ATTR(status0, llv);
  711. DEVICE_LUMINANCE_ATTR(status1, hlv);
  712. DEVICE_LUMINANCE_ATTR(buttons, img_lum);
  713. static ssize_t wacom_button_image_store(struct device *dev, int button_id,
  714. const char *buf, size_t count)
  715. {
  716. struct wacom *wacom = dev_get_drvdata(dev);
  717. int err;
  718. if (count != 1024)
  719. return -EINVAL;
  720. mutex_lock(&wacom->lock);
  721. err = wacom_led_putimage(wacom, button_id, buf);
  722. mutex_unlock(&wacom->lock);
  723. return err < 0 ? err : count;
  724. }
  725. #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
  726. static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
  727. struct device_attribute *attr, const char *buf, size_t count) \
  728. { \
  729. return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
  730. } \
  731. static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
  732. NULL, wacom_btnimg##BUTTON_ID##_store)
  733. DEVICE_BTNIMG_ATTR(0);
  734. DEVICE_BTNIMG_ATTR(1);
  735. DEVICE_BTNIMG_ATTR(2);
  736. DEVICE_BTNIMG_ATTR(3);
  737. DEVICE_BTNIMG_ATTR(4);
  738. DEVICE_BTNIMG_ATTR(5);
  739. DEVICE_BTNIMG_ATTR(6);
  740. DEVICE_BTNIMG_ATTR(7);
  741. static struct attribute *cintiq_led_attrs[] = {
  742. &dev_attr_status_led0_select.attr,
  743. &dev_attr_status_led1_select.attr,
  744. NULL
  745. };
  746. static struct attribute_group cintiq_led_attr_group = {
  747. .name = "wacom_led",
  748. .attrs = cintiq_led_attrs,
  749. };
  750. static struct attribute *intuos4_led_attrs[] = {
  751. &dev_attr_status0_luminance.attr,
  752. &dev_attr_status1_luminance.attr,
  753. &dev_attr_status_led0_select.attr,
  754. &dev_attr_buttons_luminance.attr,
  755. &dev_attr_button0_rawimg.attr,
  756. &dev_attr_button1_rawimg.attr,
  757. &dev_attr_button2_rawimg.attr,
  758. &dev_attr_button3_rawimg.attr,
  759. &dev_attr_button4_rawimg.attr,
  760. &dev_attr_button5_rawimg.attr,
  761. &dev_attr_button6_rawimg.attr,
  762. &dev_attr_button7_rawimg.attr,
  763. NULL
  764. };
  765. static struct attribute_group intuos4_led_attr_group = {
  766. .name = "wacom_led",
  767. .attrs = intuos4_led_attrs,
  768. };
  769. static struct attribute *intuos5_led_attrs[] = {
  770. &dev_attr_status0_luminance.attr,
  771. &dev_attr_status_led0_select.attr,
  772. NULL
  773. };
  774. static struct attribute_group intuos5_led_attr_group = {
  775. .name = "wacom_led",
  776. .attrs = intuos5_led_attrs,
  777. };
  778. static int wacom_initialize_leds(struct wacom *wacom)
  779. {
  780. int error;
  781. /* Initialize default values */
  782. switch (wacom->wacom_wac.features.type) {
  783. case INTUOS4S:
  784. case INTUOS4:
  785. case INTUOS4L:
  786. wacom->led.select[0] = 0;
  787. wacom->led.select[1] = 0;
  788. wacom->led.llv = 10;
  789. wacom->led.hlv = 20;
  790. wacom->led.img_lum = 10;
  791. error = sysfs_create_group(&wacom->intf->dev.kobj,
  792. &intuos4_led_attr_group);
  793. break;
  794. case WACOM_24HD:
  795. case WACOM_21UX2:
  796. wacom->led.select[0] = 0;
  797. wacom->led.select[1] = 0;
  798. wacom->led.llv = 0;
  799. wacom->led.hlv = 0;
  800. wacom->led.img_lum = 0;
  801. error = sysfs_create_group(&wacom->intf->dev.kobj,
  802. &cintiq_led_attr_group);
  803. break;
  804. case INTUOS5S:
  805. case INTUOS5:
  806. case INTUOS5L:
  807. wacom->led.select[0] = 0;
  808. wacom->led.select[1] = 0;
  809. wacom->led.llv = 32;
  810. wacom->led.hlv = 0;
  811. wacom->led.img_lum = 0;
  812. error = sysfs_create_group(&wacom->intf->dev.kobj,
  813. &intuos5_led_attr_group);
  814. break;
  815. default:
  816. return 0;
  817. }
  818. if (error) {
  819. dev_err(&wacom->intf->dev,
  820. "cannot create sysfs group err: %d\n", error);
  821. return error;
  822. }
  823. wacom_led_control(wacom);
  824. return 0;
  825. }
  826. static void wacom_destroy_leds(struct wacom *wacom)
  827. {
  828. switch (wacom->wacom_wac.features.type) {
  829. case INTUOS4S:
  830. case INTUOS4:
  831. case INTUOS4L:
  832. sysfs_remove_group(&wacom->intf->dev.kobj,
  833. &intuos4_led_attr_group);
  834. break;
  835. case WACOM_24HD:
  836. case WACOM_21UX2:
  837. sysfs_remove_group(&wacom->intf->dev.kobj,
  838. &cintiq_led_attr_group);
  839. break;
  840. case INTUOS5S:
  841. case INTUOS5:
  842. case INTUOS5L:
  843. sysfs_remove_group(&wacom->intf->dev.kobj,
  844. &intuos5_led_attr_group);
  845. break;
  846. }
  847. }
  848. static enum power_supply_property wacom_battery_props[] = {
  849. POWER_SUPPLY_PROP_CAPACITY
  850. };
  851. static int wacom_battery_get_property(struct power_supply *psy,
  852. enum power_supply_property psp,
  853. union power_supply_propval *val)
  854. {
  855. struct wacom *wacom = container_of(psy, struct wacom, battery);
  856. int ret = 0;
  857. switch (psp) {
  858. case POWER_SUPPLY_PROP_CAPACITY:
  859. val->intval =
  860. wacom->wacom_wac.battery_capacity * 100 / 31;
  861. break;
  862. default:
  863. ret = -EINVAL;
  864. break;
  865. }
  866. return ret;
  867. }
  868. static int wacom_initialize_battery(struct wacom *wacom)
  869. {
  870. int error = 0;
  871. if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) {
  872. wacom->battery.properties = wacom_battery_props;
  873. wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
  874. wacom->battery.get_property = wacom_battery_get_property;
  875. wacom->battery.name = "wacom_battery";
  876. wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
  877. wacom->battery.use_for_apm = 0;
  878. error = power_supply_register(&wacom->usbdev->dev,
  879. &wacom->battery);
  880. if (!error)
  881. power_supply_powers(&wacom->battery,
  882. &wacom->usbdev->dev);
  883. }
  884. return error;
  885. }
  886. static void wacom_destroy_battery(struct wacom *wacom)
  887. {
  888. if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR &&
  889. wacom->battery.dev) {
  890. power_supply_unregister(&wacom->battery);
  891. wacom->battery.dev = NULL;
  892. }
  893. }
  894. static int wacom_register_input(struct wacom *wacom)
  895. {
  896. struct input_dev *input_dev;
  897. struct usb_interface *intf = wacom->intf;
  898. struct usb_device *dev = interface_to_usbdev(intf);
  899. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  900. int error;
  901. input_dev = input_allocate_device();
  902. if (!input_dev) {
  903. error = -ENOMEM;
  904. goto fail1;
  905. }
  906. input_dev->name = wacom_wac->name;
  907. input_dev->dev.parent = &intf->dev;
  908. input_dev->open = wacom_open;
  909. input_dev->close = wacom_close;
  910. usb_to_input_id(dev, &input_dev->id);
  911. input_set_drvdata(input_dev, wacom);
  912. wacom_wac->input = input_dev;
  913. error = wacom_setup_input_capabilities(input_dev, wacom_wac);
  914. if (error)
  915. goto fail1;
  916. error = input_register_device(input_dev);
  917. if (error)
  918. goto fail2;
  919. return 0;
  920. fail2:
  921. input_free_device(input_dev);
  922. wacom_wac->input = NULL;
  923. fail1:
  924. return error;
  925. }
  926. static void wacom_wireless_work(struct work_struct *work)
  927. {
  928. struct wacom *wacom = container_of(work, struct wacom, work);
  929. struct usb_device *usbdev = wacom->usbdev;
  930. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  931. struct wacom *wacom1, *wacom2;
  932. struct wacom_wac *wacom_wac1, *wacom_wac2;
  933. int error;
  934. /*
  935. * Regardless if this is a disconnect or a new tablet,
  936. * remove any existing input and battery devices.
  937. */
  938. wacom_destroy_battery(wacom);
  939. /* Stylus interface */
  940. wacom1 = usb_get_intfdata(usbdev->config->interface[1]);
  941. wacom_wac1 = &(wacom1->wacom_wac);
  942. if (wacom_wac1->input)
  943. input_unregister_device(wacom_wac1->input);
  944. wacom_wac1->input = NULL;
  945. /* Touch interface */
  946. wacom2 = usb_get_intfdata(usbdev->config->interface[2]);
  947. wacom_wac2 = &(wacom2->wacom_wac);
  948. if (wacom_wac2->input)
  949. input_unregister_device(wacom_wac2->input);
  950. wacom_wac2->input = NULL;
  951. if (wacom_wac->pid == 0) {
  952. dev_info(&wacom->intf->dev, "wireless tablet disconnected\n");
  953. } else {
  954. const struct usb_device_id *id = wacom_ids;
  955. dev_info(&wacom->intf->dev,
  956. "wireless tablet connected with PID %x\n",
  957. wacom_wac->pid);
  958. while (id->match_flags) {
  959. if (id->idVendor == USB_VENDOR_ID_WACOM &&
  960. id->idProduct == wacom_wac->pid)
  961. break;
  962. id++;
  963. }
  964. if (!id->match_flags) {
  965. dev_info(&wacom->intf->dev,
  966. "ignoring unknown PID.\n");
  967. return;
  968. }
  969. /* Stylus interface */
  970. wacom_wac1->features =
  971. *((struct wacom_features *)id->driver_info);
  972. wacom_wac1->features.device_type = BTN_TOOL_PEN;
  973. error = wacom_register_input(wacom1);
  974. if (error)
  975. goto fail1;
  976. /* Touch interface */
  977. wacom_wac2->features =
  978. *((struct wacom_features *)id->driver_info);
  979. wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
  980. wacom_wac2->features.device_type = BTN_TOOL_FINGER;
  981. wacom_set_phy_from_res(&wacom_wac2->features);
  982. wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
  983. error = wacom_register_input(wacom2);
  984. if (error)
  985. goto fail2;
  986. error = wacom_initialize_battery(wacom);
  987. if (error)
  988. goto fail3;
  989. }
  990. return;
  991. fail3:
  992. input_unregister_device(wacom_wac2->input);
  993. wacom_wac2->input = NULL;
  994. fail2:
  995. input_unregister_device(wacom_wac1->input);
  996. wacom_wac1->input = NULL;
  997. fail1:
  998. return;
  999. }
  1000. static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1001. {
  1002. struct usb_device *dev = interface_to_usbdev(intf);
  1003. struct usb_endpoint_descriptor *endpoint;
  1004. struct wacom *wacom;
  1005. struct wacom_wac *wacom_wac;
  1006. struct wacom_features *features;
  1007. int error;
  1008. if (!id->driver_info)
  1009. return -EINVAL;
  1010. wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
  1011. if (!wacom)
  1012. return -ENOMEM;
  1013. wacom_wac = &wacom->wacom_wac;
  1014. wacom_wac->features = *((struct wacom_features *)id->driver_info);
  1015. features = &wacom_wac->features;
  1016. if (features->pktlen > WACOM_PKGLEN_MAX) {
  1017. error = -EINVAL;
  1018. goto fail1;
  1019. }
  1020. wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX,
  1021. GFP_KERNEL, &wacom->data_dma);
  1022. if (!wacom_wac->data) {
  1023. error = -ENOMEM;
  1024. goto fail1;
  1025. }
  1026. wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
  1027. if (!wacom->irq) {
  1028. error = -ENOMEM;
  1029. goto fail2;
  1030. }
  1031. wacom->usbdev = dev;
  1032. wacom->intf = intf;
  1033. mutex_init(&wacom->lock);
  1034. INIT_WORK(&wacom->work, wacom_wireless_work);
  1035. usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
  1036. strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
  1037. endpoint = &intf->cur_altsetting->endpoint[0].desc;
  1038. /* Retrieve the physical and logical size for touch devices */
  1039. error = wacom_retrieve_hid_descriptor(intf, features);
  1040. if (error)
  1041. goto fail3;
  1042. /*
  1043. * Intuos5 has no useful data about its touch interface in its
  1044. * HID descriptor. If this is the touch interface (wMaxPacketSize
  1045. * of WACOM_PKGLEN_BBTOUCH3), override the table values.
  1046. */
  1047. if (features->type >= INTUOS5S && features->type <= INTUOS5L) {
  1048. if (endpoint->wMaxPacketSize == WACOM_PKGLEN_BBTOUCH3) {
  1049. features->device_type = BTN_TOOL_FINGER;
  1050. features->pktlen = WACOM_PKGLEN_BBTOUCH3;
  1051. wacom_set_phy_from_res(features);
  1052. features->x_max = 4096;
  1053. features->y_max = 4096;
  1054. } else {
  1055. features->device_type = BTN_TOOL_PEN;
  1056. }
  1057. }
  1058. wacom_setup_device_quirks(features);
  1059. strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
  1060. if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
  1061. /* Append the device type to the name */
  1062. strlcat(wacom_wac->name,
  1063. features->device_type == BTN_TOOL_PEN ?
  1064. " Pen" : " Finger",
  1065. sizeof(wacom_wac->name));
  1066. error = wacom_add_shared_data(wacom_wac, dev);
  1067. if (error)
  1068. goto fail3;
  1069. }
  1070. usb_fill_int_urb(wacom->irq, dev,
  1071. usb_rcvintpipe(dev, endpoint->bEndpointAddress),
  1072. wacom_wac->data, features->pktlen,
  1073. wacom_sys_irq, wacom, endpoint->bInterval);
  1074. wacom->irq->transfer_dma = wacom->data_dma;
  1075. wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1076. error = wacom_initialize_leds(wacom);
  1077. if (error)
  1078. goto fail4;
  1079. if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
  1080. error = wacom_register_input(wacom);
  1081. if (error)
  1082. goto fail5;
  1083. }
  1084. /* Note that if query fails it is not a hard failure */
  1085. wacom_query_tablet_data(intf, features);
  1086. usb_set_intfdata(intf, wacom);
  1087. if (features->quirks & WACOM_QUIRK_MONITOR) {
  1088. if (usb_submit_urb(wacom->irq, GFP_KERNEL))
  1089. goto fail5;
  1090. }
  1091. return 0;
  1092. fail5: wacom_destroy_leds(wacom);
  1093. fail4: wacom_remove_shared_data(wacom_wac);
  1094. fail3: usb_free_urb(wacom->irq);
  1095. fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
  1096. fail1: kfree(wacom);
  1097. return error;
  1098. }
  1099. static void wacom_disconnect(struct usb_interface *intf)
  1100. {
  1101. struct wacom *wacom = usb_get_intfdata(intf);
  1102. usb_set_intfdata(intf, NULL);
  1103. usb_kill_urb(wacom->irq);
  1104. cancel_work_sync(&wacom->work);
  1105. if (wacom->wacom_wac.input)
  1106. input_unregister_device(wacom->wacom_wac.input);
  1107. wacom_destroy_battery(wacom);
  1108. wacom_destroy_leds(wacom);
  1109. usb_free_urb(wacom->irq);
  1110. usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
  1111. wacom->wacom_wac.data, wacom->data_dma);
  1112. wacom_remove_shared_data(&wacom->wacom_wac);
  1113. kfree(wacom);
  1114. }
  1115. static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
  1116. {
  1117. struct wacom *wacom = usb_get_intfdata(intf);
  1118. mutex_lock(&wacom->lock);
  1119. usb_kill_urb(wacom->irq);
  1120. mutex_unlock(&wacom->lock);
  1121. return 0;
  1122. }
  1123. static int wacom_resume(struct usb_interface *intf)
  1124. {
  1125. struct wacom *wacom = usb_get_intfdata(intf);
  1126. struct wacom_features *features = &wacom->wacom_wac.features;
  1127. int rv = 0;
  1128. mutex_lock(&wacom->lock);
  1129. /* switch to wacom mode first */
  1130. wacom_query_tablet_data(intf, features);
  1131. wacom_led_control(wacom);
  1132. if ((wacom->open || features->quirks & WACOM_QUIRK_MONITOR)
  1133. && usb_submit_urb(wacom->irq, GFP_NOIO) < 0)
  1134. rv = -EIO;
  1135. mutex_unlock(&wacom->lock);
  1136. return rv;
  1137. }
  1138. static int wacom_reset_resume(struct usb_interface *intf)
  1139. {
  1140. return wacom_resume(intf);
  1141. }
  1142. static struct usb_driver wacom_driver = {
  1143. .name = "wacom",
  1144. .id_table = wacom_ids,
  1145. .probe = wacom_probe,
  1146. .disconnect = wacom_disconnect,
  1147. .suspend = wacom_suspend,
  1148. .resume = wacom_resume,
  1149. .reset_resume = wacom_reset_resume,
  1150. .supports_autosuspend = 1,
  1151. };
  1152. module_usb_driver(wacom_driver);