wacom_sys.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  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 || WACOM_24HDT)
  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 if (features->type == WACOM_24HDT) {
  348. features->x_max =
  349. get_unaligned_le16(&report[i + 3]);
  350. features->x_phy =
  351. get_unaligned_le16(&report[i + 8]);
  352. features->unit = report[i - 1];
  353. features->unitExpo = report[i - 3];
  354. i += 12;
  355. } else {
  356. features->x_max =
  357. get_unaligned_le16(&report[i + 3]);
  358. features->x_phy =
  359. get_unaligned_le16(&report[i + 6]);
  360. features->unit = report[i + 9];
  361. features->unitExpo = report[i + 11];
  362. i += 12;
  363. }
  364. } else if (pen) {
  365. /* penabled only accepts exact bytes of data */
  366. if (features->type == TABLETPC2FG)
  367. features->pktlen = WACOM_PKGLEN_GRAPHIRE;
  368. features->device_type = BTN_TOOL_PEN;
  369. features->x_max =
  370. get_unaligned_le16(&report[i + 3]);
  371. i += 4;
  372. }
  373. }
  374. break;
  375. case HID_USAGE_Y:
  376. if (usage == WCM_DESKTOP) {
  377. if (finger) {
  378. int type = features->type;
  379. if (type == TABLETPC2FG || type == MTSCREEN) {
  380. features->y_max =
  381. get_unaligned_le16(&report[i + 3]);
  382. features->y_phy =
  383. get_unaligned_le16(&report[i + 6]);
  384. i += 7;
  385. } else if (type == WACOM_24HDT) {
  386. features->y_max =
  387. get_unaligned_le16(&report[i + 3]);
  388. features->y_phy =
  389. get_unaligned_le16(&report[i - 2]);
  390. i += 7;
  391. } else if (type == BAMBOO_PT) {
  392. features->y_phy =
  393. get_unaligned_le16(&report[i + 3]);
  394. features->y_max =
  395. get_unaligned_le16(&report[i + 6]);
  396. i += 12;
  397. } else {
  398. features->y_max =
  399. features->x_max;
  400. features->y_phy =
  401. get_unaligned_le16(&report[i + 3]);
  402. i += 4;
  403. }
  404. } else if (pen) {
  405. features->y_max =
  406. get_unaligned_le16(&report[i + 3]);
  407. i += 4;
  408. }
  409. }
  410. break;
  411. case HID_USAGE_FINGER:
  412. finger = 1;
  413. i++;
  414. break;
  415. /*
  416. * Requiring Stylus Usage will ignore boot mouse
  417. * X/Y values and some cases of invalid Digitizer X/Y
  418. * values commonly reported.
  419. */
  420. case HID_USAGE_STYLUS:
  421. pen = 1;
  422. i++;
  423. break;
  424. case HID_USAGE_CONTACTMAX:
  425. /* leave touch_max as is if predefined */
  426. if (!features->touch_max)
  427. wacom_retrieve_report_data(intf, features);
  428. i++;
  429. break;
  430. }
  431. break;
  432. case HID_COLLECTION_END:
  433. /* reset UsagePage and Finger */
  434. finger = usage = 0;
  435. break;
  436. case HID_COLLECTION:
  437. i++;
  438. switch (report[i]) {
  439. case HID_COLLECTION_LOGICAL:
  440. i += wacom_parse_logical_collection(&report[i],
  441. features);
  442. break;
  443. }
  444. break;
  445. }
  446. }
  447. out:
  448. result = 0;
  449. kfree(report);
  450. return result;
  451. }
  452. static int wacom_set_device_mode(struct usb_interface *intf, int report_id, int length, int mode)
  453. {
  454. unsigned char *rep_data;
  455. int error = -ENOMEM, limit = 0;
  456. rep_data = kzalloc(length, GFP_KERNEL);
  457. if (!rep_data)
  458. return error;
  459. rep_data[0] = report_id;
  460. rep_data[1] = mode;
  461. do {
  462. error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
  463. report_id, rep_data, length, 1);
  464. if (error >= 0)
  465. error = wacom_get_report(intf, WAC_HID_FEATURE_REPORT,
  466. report_id, rep_data, length, 1);
  467. } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES);
  468. kfree(rep_data);
  469. return error < 0 ? error : 0;
  470. }
  471. /*
  472. * Switch the tablet into its most-capable mode. Wacom tablets are
  473. * typically configured to power-up in a mode which sends mouse-like
  474. * reports to the OS. To get absolute position, pressure data, etc.
  475. * from the tablet, it is necessary to switch the tablet out of this
  476. * mode and into one which sends the full range of tablet data.
  477. */
  478. static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
  479. {
  480. if (features->device_type == BTN_TOOL_FINGER) {
  481. if (features->type > TABLETPC) {
  482. /* MT Tablet PC touch */
  483. return wacom_set_device_mode(intf, 3, 4, 4);
  484. }
  485. else if (features->type == WACOM_24HDT) {
  486. return wacom_set_device_mode(intf, 18, 3, 2);
  487. }
  488. } else if (features->device_type == BTN_TOOL_PEN) {
  489. if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
  490. return wacom_set_device_mode(intf, 2, 2, 2);
  491. }
  492. }
  493. return 0;
  494. }
  495. static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
  496. struct wacom_features *features)
  497. {
  498. int error = 0;
  499. struct usb_host_interface *interface = intf->cur_altsetting;
  500. struct hid_descriptor *hid_desc;
  501. /* default features */
  502. features->device_type = BTN_TOOL_PEN;
  503. features->x_fuzz = 4;
  504. features->y_fuzz = 4;
  505. features->pressure_fuzz = 0;
  506. features->distance_fuzz = 0;
  507. /*
  508. * The wireless device HID is basic and layout conflicts with
  509. * other tablets (monitor and touch interface can look like pen).
  510. * Skip the query for this type and modify defaults based on
  511. * interface number.
  512. */
  513. if (features->type == WIRELESS) {
  514. if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
  515. features->device_type = 0;
  516. } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
  517. features->device_type = BTN_TOOL_FINGER;
  518. features->pktlen = WACOM_PKGLEN_BBTOUCH3;
  519. }
  520. }
  521. /* only devices that support touch need to retrieve the info */
  522. if (features->type < BAMBOO_PT) {
  523. goto out;
  524. }
  525. error = usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc);
  526. if (error) {
  527. error = usb_get_extra_descriptor(&interface->endpoint[0],
  528. HID_DEVICET_REPORT, &hid_desc);
  529. if (error) {
  530. dev_err(&intf->dev,
  531. "can not retrieve extra class descriptor\n");
  532. goto out;
  533. }
  534. }
  535. error = wacom_parse_hid(intf, hid_desc, features);
  536. if (error)
  537. goto out;
  538. wacom_fix_phy_from_hid(features);
  539. out:
  540. return error;
  541. }
  542. struct wacom_usbdev_data {
  543. struct list_head list;
  544. struct kref kref;
  545. struct usb_device *dev;
  546. struct wacom_shared shared;
  547. };
  548. static LIST_HEAD(wacom_udev_list);
  549. static DEFINE_MUTEX(wacom_udev_list_lock);
  550. static struct usb_device *wacom_get_sibling(struct usb_device *dev, int vendor, int product)
  551. {
  552. int port1;
  553. struct usb_device *sibling;
  554. if (vendor == 0 && product == 0)
  555. return dev;
  556. if (dev->parent == NULL)
  557. return NULL;
  558. usb_hub_for_each_child(dev->parent, port1, sibling) {
  559. struct usb_device_descriptor *d;
  560. if (sibling == NULL)
  561. continue;
  562. d = &sibling->descriptor;
  563. if (d->idVendor == vendor && d->idProduct == product)
  564. return sibling;
  565. }
  566. return NULL;
  567. }
  568. static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev)
  569. {
  570. struct wacom_usbdev_data *data;
  571. list_for_each_entry(data, &wacom_udev_list, list) {
  572. if (data->dev == dev) {
  573. kref_get(&data->kref);
  574. return data;
  575. }
  576. }
  577. return NULL;
  578. }
  579. static int wacom_add_shared_data(struct wacom_wac *wacom,
  580. struct usb_device *dev)
  581. {
  582. struct wacom_usbdev_data *data;
  583. int retval = 0;
  584. mutex_lock(&wacom_udev_list_lock);
  585. data = wacom_get_usbdev_data(dev);
  586. if (!data) {
  587. data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL);
  588. if (!data) {
  589. retval = -ENOMEM;
  590. goto out;
  591. }
  592. kref_init(&data->kref);
  593. data->dev = dev;
  594. list_add_tail(&data->list, &wacom_udev_list);
  595. }
  596. wacom->shared = &data->shared;
  597. out:
  598. mutex_unlock(&wacom_udev_list_lock);
  599. return retval;
  600. }
  601. static void wacom_release_shared_data(struct kref *kref)
  602. {
  603. struct wacom_usbdev_data *data =
  604. container_of(kref, struct wacom_usbdev_data, kref);
  605. mutex_lock(&wacom_udev_list_lock);
  606. list_del(&data->list);
  607. mutex_unlock(&wacom_udev_list_lock);
  608. kfree(data);
  609. }
  610. static void wacom_remove_shared_data(struct wacom_wac *wacom)
  611. {
  612. struct wacom_usbdev_data *data;
  613. if (wacom->shared) {
  614. data = container_of(wacom->shared, struct wacom_usbdev_data, shared);
  615. kref_put(&data->kref, wacom_release_shared_data);
  616. wacom->shared = NULL;
  617. }
  618. }
  619. static int wacom_led_control(struct wacom *wacom)
  620. {
  621. unsigned char *buf;
  622. int retval;
  623. buf = kzalloc(9, GFP_KERNEL);
  624. if (!buf)
  625. return -ENOMEM;
  626. if (wacom->wacom_wac.features.type >= INTUOS5S &&
  627. wacom->wacom_wac.features.type <= INTUOS5L) {
  628. /*
  629. * Touch Ring and crop mark LED luminance may take on
  630. * one of four values:
  631. * 0 = Low; 1 = Medium; 2 = High; 3 = Off
  632. */
  633. int ring_led = wacom->led.select[0] & 0x03;
  634. int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
  635. int crop_lum = 0;
  636. buf[0] = WAC_CMD_LED_CONTROL;
  637. buf[1] = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
  638. }
  639. else {
  640. int led = wacom->led.select[0] | 0x4;
  641. if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
  642. wacom->wacom_wac.features.type == WACOM_24HD)
  643. led |= (wacom->led.select[1] << 4) | 0x40;
  644. buf[0] = WAC_CMD_LED_CONTROL;
  645. buf[1] = led;
  646. buf[2] = wacom->led.llv;
  647. buf[3] = wacom->led.hlv;
  648. buf[4] = wacom->led.img_lum;
  649. }
  650. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL,
  651. buf, 9, WAC_CMD_RETRIES);
  652. kfree(buf);
  653. return retval;
  654. }
  655. static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
  656. {
  657. unsigned char *buf;
  658. int i, retval;
  659. buf = kzalloc(259, GFP_KERNEL);
  660. if (!buf)
  661. return -ENOMEM;
  662. /* Send 'start' command */
  663. buf[0] = WAC_CMD_ICON_START;
  664. buf[1] = 1;
  665. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
  666. buf, 2, WAC_CMD_RETRIES);
  667. if (retval < 0)
  668. goto out;
  669. buf[0] = WAC_CMD_ICON_XFER;
  670. buf[1] = button_id & 0x07;
  671. for (i = 0; i < 4; i++) {
  672. buf[2] = i;
  673. memcpy(buf + 3, img + i * 256, 256);
  674. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER,
  675. buf, 259, WAC_CMD_RETRIES);
  676. if (retval < 0)
  677. break;
  678. }
  679. /* Send 'stop' */
  680. buf[0] = WAC_CMD_ICON_START;
  681. buf[1] = 0;
  682. wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
  683. buf, 2, WAC_CMD_RETRIES);
  684. out:
  685. kfree(buf);
  686. return retval;
  687. }
  688. static ssize_t wacom_led_select_store(struct device *dev, int set_id,
  689. const char *buf, size_t count)
  690. {
  691. struct wacom *wacom = dev_get_drvdata(dev);
  692. unsigned int id;
  693. int err;
  694. err = kstrtouint(buf, 10, &id);
  695. if (err)
  696. return err;
  697. mutex_lock(&wacom->lock);
  698. wacom->led.select[set_id] = id & 0x3;
  699. err = wacom_led_control(wacom);
  700. mutex_unlock(&wacom->lock);
  701. return err < 0 ? err : count;
  702. }
  703. #define DEVICE_LED_SELECT_ATTR(SET_ID) \
  704. static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
  705. struct device_attribute *attr, const char *buf, size_t count) \
  706. { \
  707. return wacom_led_select_store(dev, SET_ID, buf, count); \
  708. } \
  709. static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
  710. struct device_attribute *attr, char *buf) \
  711. { \
  712. struct wacom *wacom = dev_get_drvdata(dev); \
  713. return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
  714. } \
  715. static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
  716. wacom_led##SET_ID##_select_show, \
  717. wacom_led##SET_ID##_select_store)
  718. DEVICE_LED_SELECT_ATTR(0);
  719. DEVICE_LED_SELECT_ATTR(1);
  720. static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
  721. const char *buf, size_t count)
  722. {
  723. unsigned int value;
  724. int err;
  725. err = kstrtouint(buf, 10, &value);
  726. if (err)
  727. return err;
  728. mutex_lock(&wacom->lock);
  729. *dest = value & 0x7f;
  730. err = wacom_led_control(wacom);
  731. mutex_unlock(&wacom->lock);
  732. return err < 0 ? err : count;
  733. }
  734. #define DEVICE_LUMINANCE_ATTR(name, field) \
  735. static ssize_t wacom_##name##_luminance_store(struct device *dev, \
  736. struct device_attribute *attr, const char *buf, size_t count) \
  737. { \
  738. struct wacom *wacom = dev_get_drvdata(dev); \
  739. \
  740. return wacom_luminance_store(wacom, &wacom->led.field, \
  741. buf, count); \
  742. } \
  743. static DEVICE_ATTR(name##_luminance, S_IWUSR, \
  744. NULL, wacom_##name##_luminance_store)
  745. DEVICE_LUMINANCE_ATTR(status0, llv);
  746. DEVICE_LUMINANCE_ATTR(status1, hlv);
  747. DEVICE_LUMINANCE_ATTR(buttons, img_lum);
  748. static ssize_t wacom_button_image_store(struct device *dev, int button_id,
  749. const char *buf, size_t count)
  750. {
  751. struct wacom *wacom = dev_get_drvdata(dev);
  752. int err;
  753. if (count != 1024)
  754. return -EINVAL;
  755. mutex_lock(&wacom->lock);
  756. err = wacom_led_putimage(wacom, button_id, buf);
  757. mutex_unlock(&wacom->lock);
  758. return err < 0 ? err : count;
  759. }
  760. #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
  761. static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
  762. struct device_attribute *attr, const char *buf, size_t count) \
  763. { \
  764. return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
  765. } \
  766. static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
  767. NULL, wacom_btnimg##BUTTON_ID##_store)
  768. DEVICE_BTNIMG_ATTR(0);
  769. DEVICE_BTNIMG_ATTR(1);
  770. DEVICE_BTNIMG_ATTR(2);
  771. DEVICE_BTNIMG_ATTR(3);
  772. DEVICE_BTNIMG_ATTR(4);
  773. DEVICE_BTNIMG_ATTR(5);
  774. DEVICE_BTNIMG_ATTR(6);
  775. DEVICE_BTNIMG_ATTR(7);
  776. static struct attribute *cintiq_led_attrs[] = {
  777. &dev_attr_status_led0_select.attr,
  778. &dev_attr_status_led1_select.attr,
  779. NULL
  780. };
  781. static struct attribute_group cintiq_led_attr_group = {
  782. .name = "wacom_led",
  783. .attrs = cintiq_led_attrs,
  784. };
  785. static struct attribute *intuos4_led_attrs[] = {
  786. &dev_attr_status0_luminance.attr,
  787. &dev_attr_status1_luminance.attr,
  788. &dev_attr_status_led0_select.attr,
  789. &dev_attr_buttons_luminance.attr,
  790. &dev_attr_button0_rawimg.attr,
  791. &dev_attr_button1_rawimg.attr,
  792. &dev_attr_button2_rawimg.attr,
  793. &dev_attr_button3_rawimg.attr,
  794. &dev_attr_button4_rawimg.attr,
  795. &dev_attr_button5_rawimg.attr,
  796. &dev_attr_button6_rawimg.attr,
  797. &dev_attr_button7_rawimg.attr,
  798. NULL
  799. };
  800. static struct attribute_group intuos4_led_attr_group = {
  801. .name = "wacom_led",
  802. .attrs = intuos4_led_attrs,
  803. };
  804. static struct attribute *intuos5_led_attrs[] = {
  805. &dev_attr_status0_luminance.attr,
  806. &dev_attr_status_led0_select.attr,
  807. NULL
  808. };
  809. static struct attribute_group intuos5_led_attr_group = {
  810. .name = "wacom_led",
  811. .attrs = intuos5_led_attrs,
  812. };
  813. static int wacom_initialize_leds(struct wacom *wacom)
  814. {
  815. int error;
  816. /* Initialize default values */
  817. switch (wacom->wacom_wac.features.type) {
  818. case INTUOS4S:
  819. case INTUOS4:
  820. case INTUOS4L:
  821. wacom->led.select[0] = 0;
  822. wacom->led.select[1] = 0;
  823. wacom->led.llv = 10;
  824. wacom->led.hlv = 20;
  825. wacom->led.img_lum = 10;
  826. error = sysfs_create_group(&wacom->intf->dev.kobj,
  827. &intuos4_led_attr_group);
  828. break;
  829. case WACOM_24HD:
  830. case WACOM_21UX2:
  831. wacom->led.select[0] = 0;
  832. wacom->led.select[1] = 0;
  833. wacom->led.llv = 0;
  834. wacom->led.hlv = 0;
  835. wacom->led.img_lum = 0;
  836. error = sysfs_create_group(&wacom->intf->dev.kobj,
  837. &cintiq_led_attr_group);
  838. break;
  839. case INTUOS5S:
  840. case INTUOS5:
  841. case INTUOS5L:
  842. wacom->led.select[0] = 0;
  843. wacom->led.select[1] = 0;
  844. wacom->led.llv = 32;
  845. wacom->led.hlv = 0;
  846. wacom->led.img_lum = 0;
  847. error = sysfs_create_group(&wacom->intf->dev.kobj,
  848. &intuos5_led_attr_group);
  849. break;
  850. default:
  851. return 0;
  852. }
  853. if (error) {
  854. dev_err(&wacom->intf->dev,
  855. "cannot create sysfs group err: %d\n", error);
  856. return error;
  857. }
  858. wacom_led_control(wacom);
  859. return 0;
  860. }
  861. static void wacom_destroy_leds(struct wacom *wacom)
  862. {
  863. switch (wacom->wacom_wac.features.type) {
  864. case INTUOS4S:
  865. case INTUOS4:
  866. case INTUOS4L:
  867. sysfs_remove_group(&wacom->intf->dev.kobj,
  868. &intuos4_led_attr_group);
  869. break;
  870. case WACOM_24HD:
  871. case WACOM_21UX2:
  872. sysfs_remove_group(&wacom->intf->dev.kobj,
  873. &cintiq_led_attr_group);
  874. break;
  875. case INTUOS5S:
  876. case INTUOS5:
  877. case INTUOS5L:
  878. sysfs_remove_group(&wacom->intf->dev.kobj,
  879. &intuos5_led_attr_group);
  880. break;
  881. }
  882. }
  883. static enum power_supply_property wacom_battery_props[] = {
  884. POWER_SUPPLY_PROP_CAPACITY
  885. };
  886. static int wacom_battery_get_property(struct power_supply *psy,
  887. enum power_supply_property psp,
  888. union power_supply_propval *val)
  889. {
  890. struct wacom *wacom = container_of(psy, struct wacom, battery);
  891. int ret = 0;
  892. switch (psp) {
  893. case POWER_SUPPLY_PROP_CAPACITY:
  894. val->intval =
  895. wacom->wacom_wac.battery_capacity * 100 / 31;
  896. break;
  897. default:
  898. ret = -EINVAL;
  899. break;
  900. }
  901. return ret;
  902. }
  903. static int wacom_initialize_battery(struct wacom *wacom)
  904. {
  905. int error = 0;
  906. if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) {
  907. wacom->battery.properties = wacom_battery_props;
  908. wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
  909. wacom->battery.get_property = wacom_battery_get_property;
  910. wacom->battery.name = "wacom_battery";
  911. wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
  912. wacom->battery.use_for_apm = 0;
  913. error = power_supply_register(&wacom->usbdev->dev,
  914. &wacom->battery);
  915. if (!error)
  916. power_supply_powers(&wacom->battery,
  917. &wacom->usbdev->dev);
  918. }
  919. return error;
  920. }
  921. static void wacom_destroy_battery(struct wacom *wacom)
  922. {
  923. if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR &&
  924. wacom->battery.dev) {
  925. power_supply_unregister(&wacom->battery);
  926. wacom->battery.dev = NULL;
  927. }
  928. }
  929. static int wacom_register_input(struct wacom *wacom)
  930. {
  931. struct input_dev *input_dev;
  932. struct usb_interface *intf = wacom->intf;
  933. struct usb_device *dev = interface_to_usbdev(intf);
  934. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  935. int error;
  936. input_dev = input_allocate_device();
  937. if (!input_dev) {
  938. error = -ENOMEM;
  939. goto fail1;
  940. }
  941. input_dev->name = wacom_wac->name;
  942. input_dev->dev.parent = &intf->dev;
  943. input_dev->open = wacom_open;
  944. input_dev->close = wacom_close;
  945. usb_to_input_id(dev, &input_dev->id);
  946. input_set_drvdata(input_dev, wacom);
  947. wacom_wac->input = input_dev;
  948. error = wacom_setup_input_capabilities(input_dev, wacom_wac);
  949. if (error)
  950. goto fail1;
  951. error = input_register_device(input_dev);
  952. if (error)
  953. goto fail2;
  954. return 0;
  955. fail2:
  956. input_free_device(input_dev);
  957. wacom_wac->input = NULL;
  958. fail1:
  959. return error;
  960. }
  961. static void wacom_wireless_work(struct work_struct *work)
  962. {
  963. struct wacom *wacom = container_of(work, struct wacom, work);
  964. struct usb_device *usbdev = wacom->usbdev;
  965. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  966. struct wacom *wacom1, *wacom2;
  967. struct wacom_wac *wacom_wac1, *wacom_wac2;
  968. int error;
  969. /*
  970. * Regardless if this is a disconnect or a new tablet,
  971. * remove any existing input and battery devices.
  972. */
  973. wacom_destroy_battery(wacom);
  974. /* Stylus interface */
  975. wacom1 = usb_get_intfdata(usbdev->config->interface[1]);
  976. wacom_wac1 = &(wacom1->wacom_wac);
  977. if (wacom_wac1->input)
  978. input_unregister_device(wacom_wac1->input);
  979. wacom_wac1->input = NULL;
  980. /* Touch interface */
  981. wacom2 = usb_get_intfdata(usbdev->config->interface[2]);
  982. wacom_wac2 = &(wacom2->wacom_wac);
  983. if (wacom_wac2->input)
  984. input_unregister_device(wacom_wac2->input);
  985. wacom_wac2->input = NULL;
  986. if (wacom_wac->pid == 0) {
  987. dev_info(&wacom->intf->dev, "wireless tablet disconnected\n");
  988. } else {
  989. const struct usb_device_id *id = wacom_ids;
  990. dev_info(&wacom->intf->dev,
  991. "wireless tablet connected with PID %x\n",
  992. wacom_wac->pid);
  993. while (id->match_flags) {
  994. if (id->idVendor == USB_VENDOR_ID_WACOM &&
  995. id->idProduct == wacom_wac->pid)
  996. break;
  997. id++;
  998. }
  999. if (!id->match_flags) {
  1000. dev_info(&wacom->intf->dev,
  1001. "ignoring unknown PID.\n");
  1002. return;
  1003. }
  1004. /* Stylus interface */
  1005. wacom_wac1->features =
  1006. *((struct wacom_features *)id->driver_info);
  1007. wacom_wac1->features.device_type = BTN_TOOL_PEN;
  1008. error = wacom_register_input(wacom1);
  1009. if (error)
  1010. goto fail1;
  1011. /* Touch interface */
  1012. wacom_wac2->features =
  1013. *((struct wacom_features *)id->driver_info);
  1014. wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
  1015. wacom_wac2->features.device_type = BTN_TOOL_FINGER;
  1016. wacom_set_phy_from_res(&wacom_wac2->features);
  1017. wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
  1018. error = wacom_register_input(wacom2);
  1019. if (error)
  1020. goto fail2;
  1021. error = wacom_initialize_battery(wacom);
  1022. if (error)
  1023. goto fail3;
  1024. }
  1025. return;
  1026. fail3:
  1027. input_unregister_device(wacom_wac2->input);
  1028. wacom_wac2->input = NULL;
  1029. fail2:
  1030. input_unregister_device(wacom_wac1->input);
  1031. wacom_wac1->input = NULL;
  1032. fail1:
  1033. return;
  1034. }
  1035. static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1036. {
  1037. struct usb_device *dev = interface_to_usbdev(intf);
  1038. struct usb_endpoint_descriptor *endpoint;
  1039. struct wacom *wacom;
  1040. struct wacom_wac *wacom_wac;
  1041. struct wacom_features *features;
  1042. int error;
  1043. if (!id->driver_info)
  1044. return -EINVAL;
  1045. wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
  1046. if (!wacom)
  1047. return -ENOMEM;
  1048. wacom_wac = &wacom->wacom_wac;
  1049. wacom_wac->features = *((struct wacom_features *)id->driver_info);
  1050. features = &wacom_wac->features;
  1051. if (features->pktlen > WACOM_PKGLEN_MAX) {
  1052. error = -EINVAL;
  1053. goto fail1;
  1054. }
  1055. wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX,
  1056. GFP_KERNEL, &wacom->data_dma);
  1057. if (!wacom_wac->data) {
  1058. error = -ENOMEM;
  1059. goto fail1;
  1060. }
  1061. wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
  1062. if (!wacom->irq) {
  1063. error = -ENOMEM;
  1064. goto fail2;
  1065. }
  1066. wacom->usbdev = dev;
  1067. wacom->intf = intf;
  1068. mutex_init(&wacom->lock);
  1069. INIT_WORK(&wacom->work, wacom_wireless_work);
  1070. usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
  1071. strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
  1072. endpoint = &intf->cur_altsetting->endpoint[0].desc;
  1073. /* Retrieve the physical and logical size for touch devices */
  1074. error = wacom_retrieve_hid_descriptor(intf, features);
  1075. if (error)
  1076. goto fail3;
  1077. /*
  1078. * Intuos5 has no useful data about its touch interface in its
  1079. * HID descriptor. If this is the touch interface (wMaxPacketSize
  1080. * of WACOM_PKGLEN_BBTOUCH3), override the table values.
  1081. */
  1082. if (features->type >= INTUOS5S && features->type <= INTUOS5L) {
  1083. if (endpoint->wMaxPacketSize == WACOM_PKGLEN_BBTOUCH3) {
  1084. features->device_type = BTN_TOOL_FINGER;
  1085. features->pktlen = WACOM_PKGLEN_BBTOUCH3;
  1086. wacom_set_phy_from_res(features);
  1087. features->x_max = 4096;
  1088. features->y_max = 4096;
  1089. } else {
  1090. features->device_type = BTN_TOOL_PEN;
  1091. }
  1092. }
  1093. wacom_setup_device_quirks(features);
  1094. strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
  1095. if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
  1096. struct usb_device *other_dev;
  1097. /* Append the device type to the name */
  1098. strlcat(wacom_wac->name,
  1099. features->device_type == BTN_TOOL_PEN ?
  1100. " Pen" : " Finger",
  1101. sizeof(wacom_wac->name));
  1102. other_dev = wacom_get_sibling(dev, features->oVid, features->oPid);
  1103. if (other_dev == NULL || wacom_get_usbdev_data(other_dev) == NULL)
  1104. other_dev = dev;
  1105. error = wacom_add_shared_data(wacom_wac, other_dev);
  1106. if (error)
  1107. goto fail3;
  1108. }
  1109. usb_fill_int_urb(wacom->irq, dev,
  1110. usb_rcvintpipe(dev, endpoint->bEndpointAddress),
  1111. wacom_wac->data, features->pktlen,
  1112. wacom_sys_irq, wacom, endpoint->bInterval);
  1113. wacom->irq->transfer_dma = wacom->data_dma;
  1114. wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1115. error = wacom_initialize_leds(wacom);
  1116. if (error)
  1117. goto fail4;
  1118. if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
  1119. error = wacom_register_input(wacom);
  1120. if (error)
  1121. goto fail5;
  1122. }
  1123. /* Note that if query fails it is not a hard failure */
  1124. wacom_query_tablet_data(intf, features);
  1125. usb_set_intfdata(intf, wacom);
  1126. if (features->quirks & WACOM_QUIRK_MONITOR) {
  1127. if (usb_submit_urb(wacom->irq, GFP_KERNEL))
  1128. goto fail5;
  1129. }
  1130. return 0;
  1131. fail5: wacom_destroy_leds(wacom);
  1132. fail4: wacom_remove_shared_data(wacom_wac);
  1133. fail3: usb_free_urb(wacom->irq);
  1134. fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
  1135. fail1: kfree(wacom);
  1136. return error;
  1137. }
  1138. static void wacom_disconnect(struct usb_interface *intf)
  1139. {
  1140. struct wacom *wacom = usb_get_intfdata(intf);
  1141. usb_set_intfdata(intf, NULL);
  1142. usb_kill_urb(wacom->irq);
  1143. cancel_work_sync(&wacom->work);
  1144. if (wacom->wacom_wac.input)
  1145. input_unregister_device(wacom->wacom_wac.input);
  1146. wacom_destroy_battery(wacom);
  1147. wacom_destroy_leds(wacom);
  1148. usb_free_urb(wacom->irq);
  1149. usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
  1150. wacom->wacom_wac.data, wacom->data_dma);
  1151. wacom_remove_shared_data(&wacom->wacom_wac);
  1152. kfree(wacom);
  1153. }
  1154. static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
  1155. {
  1156. struct wacom *wacom = usb_get_intfdata(intf);
  1157. mutex_lock(&wacom->lock);
  1158. usb_kill_urb(wacom->irq);
  1159. mutex_unlock(&wacom->lock);
  1160. return 0;
  1161. }
  1162. static int wacom_resume(struct usb_interface *intf)
  1163. {
  1164. struct wacom *wacom = usb_get_intfdata(intf);
  1165. struct wacom_features *features = &wacom->wacom_wac.features;
  1166. int rv = 0;
  1167. mutex_lock(&wacom->lock);
  1168. /* switch to wacom mode first */
  1169. wacom_query_tablet_data(intf, features);
  1170. wacom_led_control(wacom);
  1171. if ((wacom->open || features->quirks & WACOM_QUIRK_MONITOR)
  1172. && usb_submit_urb(wacom->irq, GFP_NOIO) < 0)
  1173. rv = -EIO;
  1174. mutex_unlock(&wacom->lock);
  1175. return rv;
  1176. }
  1177. static int wacom_reset_resume(struct usb_interface *intf)
  1178. {
  1179. return wacom_resume(intf);
  1180. }
  1181. static struct usb_driver wacom_driver = {
  1182. .name = "wacom",
  1183. .id_table = wacom_ids,
  1184. .probe = wacom_probe,
  1185. .disconnect = wacom_disconnect,
  1186. .suspend = wacom_suspend,
  1187. .resume = wacom_resume,
  1188. .reset_resume = wacom_reset_resume,
  1189. .supports_autosuspend = 1,
  1190. };
  1191. module_usb_driver(wacom_driver);