wacom_sys.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  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. static int wacom_parse_logical_collection(unsigned char *report,
  190. struct wacom_features *features)
  191. {
  192. int length = 0;
  193. if (features->type == BAMBOO_PT) {
  194. /* Logical collection is only used by 3rd gen Bamboo Touch */
  195. features->pktlen = WACOM_PKGLEN_BBTOUCH3;
  196. features->device_type = BTN_TOOL_FINGER;
  197. features->x_max = features->y_max =
  198. get_unaligned_le16(&report[10]);
  199. length = 11;
  200. }
  201. return length;
  202. }
  203. static void wacom_retrieve_report_data(struct usb_interface *intf,
  204. struct wacom_features *features)
  205. {
  206. int result = 0;
  207. unsigned char *rep_data;
  208. rep_data = kmalloc(2, GFP_KERNEL);
  209. if (rep_data) {
  210. rep_data[0] = 12;
  211. result = wacom_get_report(intf, WAC_HID_FEATURE_REPORT,
  212. rep_data[0], rep_data, 2,
  213. WAC_MSG_RETRIES);
  214. if (result >= 0 && rep_data[1] > 2)
  215. features->touch_max = rep_data[1];
  216. kfree(rep_data);
  217. }
  218. }
  219. /*
  220. * Interface Descriptor of wacom devices can be incomplete and
  221. * inconsistent so wacom_features table is used to store stylus
  222. * device's packet lengths, various maximum values, and tablet
  223. * resolution based on product ID's.
  224. *
  225. * For devices that contain 2 interfaces, wacom_features table is
  226. * inaccurate for the touch interface. Since the Interface Descriptor
  227. * for touch interfaces has pretty complete data, this function exists
  228. * to query tablet for this missing information instead of hard coding in
  229. * an additional table.
  230. *
  231. * A typical Interface Descriptor for a stylus will contain a
  232. * boot mouse application collection that is not of interest and this
  233. * function will ignore it.
  234. *
  235. * It also contains a digitizer application collection that also is not
  236. * of interest since any information it contains would be duplicate
  237. * of what is in wacom_features. Usually it defines a report of an array
  238. * of bytes that could be used as max length of the stylus packet returned.
  239. * If it happens to define a Digitizer-Stylus Physical Collection then
  240. * the X and Y logical values contain valid data but it is ignored.
  241. *
  242. * A typical Interface Descriptor for a touch interface will contain a
  243. * Digitizer-Finger Physical Collection which will define both logical
  244. * X/Y maximum as well as the physical size of tablet. Since touch
  245. * interfaces haven't supported pressure or distance, this is enough
  246. * information to override invalid values in the wacom_features table.
  247. *
  248. * 3rd gen Bamboo Touch no longer define a Digitizer-Finger Pysical
  249. * Collection. Instead they define a Logical Collection with a single
  250. * Logical Maximum for both X and Y.
  251. *
  252. * Intuos5 touch interface does not contain useful data. We deal with
  253. * this after returning from this function.
  254. */
  255. static int wacom_parse_hid(struct usb_interface *intf,
  256. struct hid_descriptor *hid_desc,
  257. struct wacom_features *features)
  258. {
  259. struct usb_device *dev = interface_to_usbdev(intf);
  260. char limit = 0;
  261. /* result has to be defined as int for some devices */
  262. int result = 0;
  263. int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
  264. unsigned char *report;
  265. report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
  266. if (!report)
  267. return -ENOMEM;
  268. /* retrive report descriptors */
  269. do {
  270. result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  271. USB_REQ_GET_DESCRIPTOR,
  272. USB_RECIP_INTERFACE | USB_DIR_IN,
  273. HID_DEVICET_REPORT << 8,
  274. intf->altsetting[0].desc.bInterfaceNumber, /* interface */
  275. report,
  276. hid_desc->wDescriptorLength,
  277. 5000); /* 5 secs */
  278. } while (result < 0 && limit++ < WAC_MSG_RETRIES);
  279. /* No need to parse the Descriptor. It isn't an error though */
  280. if (result < 0)
  281. goto out;
  282. for (i = 0; i < hid_desc->wDescriptorLength; i++) {
  283. switch (report[i]) {
  284. case HID_USAGE_PAGE:
  285. switch (report[i + 1]) {
  286. case HID_USAGE_PAGE_DIGITIZER:
  287. usage = WCM_DIGITIZER;
  288. i++;
  289. break;
  290. case HID_USAGE_PAGE_DESKTOP:
  291. usage = WCM_DESKTOP;
  292. i++;
  293. break;
  294. }
  295. break;
  296. case HID_USAGE:
  297. switch (report[i + 1]) {
  298. case HID_USAGE_X:
  299. if (usage == WCM_DESKTOP) {
  300. if (finger) {
  301. features->device_type = BTN_TOOL_FINGER;
  302. switch (features->type) {
  303. case TABLETPC2FG:
  304. features->pktlen = WACOM_PKGLEN_TPC2FG;
  305. break;
  306. case MTSCREEN:
  307. case WACOM_24HDT:
  308. features->pktlen = WACOM_PKGLEN_MTOUCH;
  309. break;
  310. case MTTPC:
  311. features->pktlen = WACOM_PKGLEN_MTTPC;
  312. break;
  313. case BAMBOO_PT:
  314. features->pktlen = WACOM_PKGLEN_BBTOUCH;
  315. break;
  316. default:
  317. features->pktlen = WACOM_PKGLEN_GRAPHIRE;
  318. break;
  319. }
  320. switch (features->type) {
  321. case BAMBOO_PT:
  322. features->x_phy =
  323. get_unaligned_le16(&report[i + 5]);
  324. features->x_max =
  325. get_unaligned_le16(&report[i + 8]);
  326. i += 15;
  327. break;
  328. case WACOM_24HDT:
  329. features->x_max =
  330. get_unaligned_le16(&report[i + 3]);
  331. features->x_phy =
  332. get_unaligned_le16(&report[i + 8]);
  333. features->unit = report[i - 1];
  334. features->unitExpo = report[i - 3];
  335. i += 12;
  336. break;
  337. default:
  338. features->x_max =
  339. get_unaligned_le16(&report[i + 3]);
  340. features->x_phy =
  341. get_unaligned_le16(&report[i + 6]);
  342. features->unit = report[i + 9];
  343. features->unitExpo = report[i + 11];
  344. i += 12;
  345. break;
  346. }
  347. } else if (pen) {
  348. /* penabled only accepts exact bytes of data */
  349. if (features->type >= TABLETPC)
  350. features->pktlen = WACOM_PKGLEN_GRAPHIRE;
  351. features->device_type = BTN_TOOL_PEN;
  352. features->x_max =
  353. get_unaligned_le16(&report[i + 3]);
  354. i += 4;
  355. }
  356. }
  357. break;
  358. case HID_USAGE_Y:
  359. if (usage == WCM_DESKTOP) {
  360. if (finger) {
  361. switch (features->type) {
  362. case TABLETPC2FG:
  363. case MTSCREEN:
  364. case MTTPC:
  365. features->y_max =
  366. get_unaligned_le16(&report[i + 3]);
  367. features->y_phy =
  368. get_unaligned_le16(&report[i + 6]);
  369. i += 7;
  370. break;
  371. case WACOM_24HDT:
  372. features->y_max =
  373. get_unaligned_le16(&report[i + 3]);
  374. features->y_phy =
  375. get_unaligned_le16(&report[i - 2]);
  376. i += 7;
  377. break;
  378. case BAMBOO_PT:
  379. features->y_phy =
  380. get_unaligned_le16(&report[i + 3]);
  381. features->y_max =
  382. get_unaligned_le16(&report[i + 6]);
  383. i += 12;
  384. break;
  385. default:
  386. features->y_max =
  387. features->x_max;
  388. features->y_phy =
  389. get_unaligned_le16(&report[i + 3]);
  390. i += 4;
  391. break;
  392. }
  393. } else if (pen) {
  394. features->y_max =
  395. get_unaligned_le16(&report[i + 3]);
  396. i += 4;
  397. }
  398. }
  399. break;
  400. case HID_USAGE_FINGER:
  401. finger = 1;
  402. i++;
  403. break;
  404. /*
  405. * Requiring Stylus Usage will ignore boot mouse
  406. * X/Y values and some cases of invalid Digitizer X/Y
  407. * values commonly reported.
  408. */
  409. case HID_USAGE_STYLUS:
  410. pen = 1;
  411. i++;
  412. break;
  413. case HID_USAGE_CONTACTMAX:
  414. /* leave touch_max as is if predefined */
  415. if (!features->touch_max)
  416. wacom_retrieve_report_data(intf, features);
  417. i++;
  418. break;
  419. }
  420. break;
  421. case HID_COLLECTION_END:
  422. /* reset UsagePage and Finger */
  423. finger = usage = 0;
  424. break;
  425. case HID_COLLECTION:
  426. i++;
  427. switch (report[i]) {
  428. case HID_COLLECTION_LOGICAL:
  429. i += wacom_parse_logical_collection(&report[i],
  430. features);
  431. break;
  432. }
  433. break;
  434. }
  435. }
  436. out:
  437. result = 0;
  438. kfree(report);
  439. return result;
  440. }
  441. static int wacom_set_device_mode(struct usb_interface *intf, int report_id, int length, int mode)
  442. {
  443. unsigned char *rep_data;
  444. int error = -ENOMEM, limit = 0;
  445. rep_data = kzalloc(length, GFP_KERNEL);
  446. if (!rep_data)
  447. return error;
  448. do {
  449. rep_data[0] = report_id;
  450. rep_data[1] = mode;
  451. error = wacom_set_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->type == WACOM_24HDT || features->type == CINTIQ_HYBRID) {
  472. return wacom_set_device_mode(intf, 18, 3, 2);
  473. }
  474. } else if (features->device_type == BTN_TOOL_PEN) {
  475. if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
  476. return wacom_set_device_mode(intf, 2, 2, 2);
  477. }
  478. }
  479. return 0;
  480. }
  481. static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
  482. struct wacom_features *features)
  483. {
  484. int error = 0;
  485. struct usb_host_interface *interface = intf->cur_altsetting;
  486. struct hid_descriptor *hid_desc;
  487. /* default features */
  488. features->device_type = BTN_TOOL_PEN;
  489. features->x_fuzz = 4;
  490. features->y_fuzz = 4;
  491. features->pressure_fuzz = 0;
  492. features->distance_fuzz = 0;
  493. /*
  494. * The wireless device HID is basic and layout conflicts with
  495. * other tablets (monitor and touch interface can look like pen).
  496. * Skip the query for this type and modify defaults based on
  497. * interface number.
  498. */
  499. if (features->type == WIRELESS) {
  500. if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
  501. features->device_type = 0;
  502. } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
  503. features->device_type = BTN_TOOL_FINGER;
  504. features->pktlen = WACOM_PKGLEN_BBTOUCH3;
  505. }
  506. }
  507. /* only devices that support touch need to retrieve the info */
  508. if (features->type < BAMBOO_PT) {
  509. goto out;
  510. }
  511. error = usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc);
  512. if (error) {
  513. error = usb_get_extra_descriptor(&interface->endpoint[0],
  514. HID_DEVICET_REPORT, &hid_desc);
  515. if (error) {
  516. dev_err(&intf->dev,
  517. "can not retrieve extra class descriptor\n");
  518. goto out;
  519. }
  520. }
  521. error = wacom_parse_hid(intf, hid_desc, 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 usb_device *wacom_get_sibling(struct usb_device *dev, int vendor, int product)
  534. {
  535. int port1;
  536. struct usb_device *sibling;
  537. if (vendor == 0 && product == 0)
  538. return dev;
  539. if (dev->parent == NULL)
  540. return NULL;
  541. usb_hub_for_each_child(dev->parent, port1, sibling) {
  542. struct usb_device_descriptor *d;
  543. if (sibling == NULL)
  544. continue;
  545. d = &sibling->descriptor;
  546. if (d->idVendor == vendor && d->idProduct == product)
  547. return sibling;
  548. }
  549. return NULL;
  550. }
  551. static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev)
  552. {
  553. struct wacom_usbdev_data *data;
  554. list_for_each_entry(data, &wacom_udev_list, list) {
  555. if (data->dev == dev) {
  556. kref_get(&data->kref);
  557. return data;
  558. }
  559. }
  560. return NULL;
  561. }
  562. static int wacom_add_shared_data(struct wacom_wac *wacom,
  563. struct usb_device *dev)
  564. {
  565. struct wacom_usbdev_data *data;
  566. int retval = 0;
  567. mutex_lock(&wacom_udev_list_lock);
  568. data = wacom_get_usbdev_data(dev);
  569. if (!data) {
  570. data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL);
  571. if (!data) {
  572. retval = -ENOMEM;
  573. goto out;
  574. }
  575. kref_init(&data->kref);
  576. data->dev = dev;
  577. list_add_tail(&data->list, &wacom_udev_list);
  578. }
  579. wacom->shared = &data->shared;
  580. out:
  581. mutex_unlock(&wacom_udev_list_lock);
  582. return retval;
  583. }
  584. static void wacom_release_shared_data(struct kref *kref)
  585. {
  586. struct wacom_usbdev_data *data =
  587. container_of(kref, struct wacom_usbdev_data, kref);
  588. mutex_lock(&wacom_udev_list_lock);
  589. list_del(&data->list);
  590. mutex_unlock(&wacom_udev_list_lock);
  591. kfree(data);
  592. }
  593. static void wacom_remove_shared_data(struct wacom_wac *wacom)
  594. {
  595. struct wacom_usbdev_data *data;
  596. if (wacom->shared) {
  597. data = container_of(wacom->shared, struct wacom_usbdev_data, shared);
  598. kref_put(&data->kref, wacom_release_shared_data);
  599. wacom->shared = NULL;
  600. }
  601. }
  602. static int wacom_led_control(struct wacom *wacom)
  603. {
  604. unsigned char *buf;
  605. int retval;
  606. buf = kzalloc(9, GFP_KERNEL);
  607. if (!buf)
  608. return -ENOMEM;
  609. if (wacom->wacom_wac.features.type >= INTUOS5S &&
  610. wacom->wacom_wac.features.type <= INTUOS5L) {
  611. /*
  612. * Touch Ring and crop mark LED luminance may take on
  613. * one of four values:
  614. * 0 = Low; 1 = Medium; 2 = High; 3 = Off
  615. */
  616. int ring_led = wacom->led.select[0] & 0x03;
  617. int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
  618. int crop_lum = 0;
  619. buf[0] = WAC_CMD_LED_CONTROL;
  620. buf[1] = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
  621. }
  622. else {
  623. int led = wacom->led.select[0] | 0x4;
  624. if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
  625. wacom->wacom_wac.features.type == WACOM_24HD)
  626. led |= (wacom->led.select[1] << 4) | 0x40;
  627. buf[0] = WAC_CMD_LED_CONTROL;
  628. buf[1] = led;
  629. buf[2] = wacom->led.llv;
  630. buf[3] = wacom->led.hlv;
  631. buf[4] = wacom->led.img_lum;
  632. }
  633. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_LED_CONTROL,
  634. buf, 9, WAC_CMD_RETRIES);
  635. kfree(buf);
  636. return retval;
  637. }
  638. static int wacom_led_putimage(struct wacom *wacom, int button_id, const void *img)
  639. {
  640. unsigned char *buf;
  641. int i, retval;
  642. buf = kzalloc(259, GFP_KERNEL);
  643. if (!buf)
  644. return -ENOMEM;
  645. /* Send 'start' command */
  646. buf[0] = WAC_CMD_ICON_START;
  647. buf[1] = 1;
  648. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
  649. buf, 2, WAC_CMD_RETRIES);
  650. if (retval < 0)
  651. goto out;
  652. buf[0] = WAC_CMD_ICON_XFER;
  653. buf[1] = button_id & 0x07;
  654. for (i = 0; i < 4; i++) {
  655. buf[2] = i;
  656. memcpy(buf + 3, img + i * 256, 256);
  657. retval = wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_XFER,
  658. buf, 259, WAC_CMD_RETRIES);
  659. if (retval < 0)
  660. break;
  661. }
  662. /* Send 'stop' */
  663. buf[0] = WAC_CMD_ICON_START;
  664. buf[1] = 0;
  665. wacom_set_report(wacom->intf, 0x03, WAC_CMD_ICON_START,
  666. buf, 2, WAC_CMD_RETRIES);
  667. out:
  668. kfree(buf);
  669. return retval;
  670. }
  671. static ssize_t wacom_led_select_store(struct device *dev, int set_id,
  672. const char *buf, size_t count)
  673. {
  674. struct wacom *wacom = dev_get_drvdata(dev);
  675. unsigned int id;
  676. int err;
  677. err = kstrtouint(buf, 10, &id);
  678. if (err)
  679. return err;
  680. mutex_lock(&wacom->lock);
  681. wacom->led.select[set_id] = id & 0x3;
  682. err = wacom_led_control(wacom);
  683. mutex_unlock(&wacom->lock);
  684. return err < 0 ? err : count;
  685. }
  686. #define DEVICE_LED_SELECT_ATTR(SET_ID) \
  687. static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
  688. struct device_attribute *attr, const char *buf, size_t count) \
  689. { \
  690. return wacom_led_select_store(dev, SET_ID, buf, count); \
  691. } \
  692. static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
  693. struct device_attribute *attr, char *buf) \
  694. { \
  695. struct wacom *wacom = dev_get_drvdata(dev); \
  696. return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
  697. } \
  698. static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
  699. wacom_led##SET_ID##_select_show, \
  700. wacom_led##SET_ID##_select_store)
  701. DEVICE_LED_SELECT_ATTR(0);
  702. DEVICE_LED_SELECT_ATTR(1);
  703. static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
  704. const char *buf, size_t count)
  705. {
  706. unsigned int value;
  707. int err;
  708. err = kstrtouint(buf, 10, &value);
  709. if (err)
  710. return err;
  711. mutex_lock(&wacom->lock);
  712. *dest = value & 0x7f;
  713. err = wacom_led_control(wacom);
  714. mutex_unlock(&wacom->lock);
  715. return err < 0 ? err : count;
  716. }
  717. #define DEVICE_LUMINANCE_ATTR(name, field) \
  718. static ssize_t wacom_##name##_luminance_store(struct device *dev, \
  719. struct device_attribute *attr, const char *buf, size_t count) \
  720. { \
  721. struct wacom *wacom = dev_get_drvdata(dev); \
  722. \
  723. return wacom_luminance_store(wacom, &wacom->led.field, \
  724. buf, count); \
  725. } \
  726. static DEVICE_ATTR(name##_luminance, S_IWUSR, \
  727. NULL, wacom_##name##_luminance_store)
  728. DEVICE_LUMINANCE_ATTR(status0, llv);
  729. DEVICE_LUMINANCE_ATTR(status1, hlv);
  730. DEVICE_LUMINANCE_ATTR(buttons, img_lum);
  731. static ssize_t wacom_button_image_store(struct device *dev, int button_id,
  732. const char *buf, size_t count)
  733. {
  734. struct wacom *wacom = dev_get_drvdata(dev);
  735. int err;
  736. if (count != 1024)
  737. return -EINVAL;
  738. mutex_lock(&wacom->lock);
  739. err = wacom_led_putimage(wacom, button_id, buf);
  740. mutex_unlock(&wacom->lock);
  741. return err < 0 ? err : count;
  742. }
  743. #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
  744. static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
  745. struct device_attribute *attr, const char *buf, size_t count) \
  746. { \
  747. return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
  748. } \
  749. static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
  750. NULL, wacom_btnimg##BUTTON_ID##_store)
  751. DEVICE_BTNIMG_ATTR(0);
  752. DEVICE_BTNIMG_ATTR(1);
  753. DEVICE_BTNIMG_ATTR(2);
  754. DEVICE_BTNIMG_ATTR(3);
  755. DEVICE_BTNIMG_ATTR(4);
  756. DEVICE_BTNIMG_ATTR(5);
  757. DEVICE_BTNIMG_ATTR(6);
  758. DEVICE_BTNIMG_ATTR(7);
  759. static struct attribute *cintiq_led_attrs[] = {
  760. &dev_attr_status_led0_select.attr,
  761. &dev_attr_status_led1_select.attr,
  762. NULL
  763. };
  764. static struct attribute_group cintiq_led_attr_group = {
  765. .name = "wacom_led",
  766. .attrs = cintiq_led_attrs,
  767. };
  768. static struct attribute *intuos4_led_attrs[] = {
  769. &dev_attr_status0_luminance.attr,
  770. &dev_attr_status1_luminance.attr,
  771. &dev_attr_status_led0_select.attr,
  772. &dev_attr_buttons_luminance.attr,
  773. &dev_attr_button0_rawimg.attr,
  774. &dev_attr_button1_rawimg.attr,
  775. &dev_attr_button2_rawimg.attr,
  776. &dev_attr_button3_rawimg.attr,
  777. &dev_attr_button4_rawimg.attr,
  778. &dev_attr_button5_rawimg.attr,
  779. &dev_attr_button6_rawimg.attr,
  780. &dev_attr_button7_rawimg.attr,
  781. NULL
  782. };
  783. static struct attribute_group intuos4_led_attr_group = {
  784. .name = "wacom_led",
  785. .attrs = intuos4_led_attrs,
  786. };
  787. static struct attribute *intuos5_led_attrs[] = {
  788. &dev_attr_status0_luminance.attr,
  789. &dev_attr_status_led0_select.attr,
  790. NULL
  791. };
  792. static struct attribute_group intuos5_led_attr_group = {
  793. .name = "wacom_led",
  794. .attrs = intuos5_led_attrs,
  795. };
  796. static int wacom_initialize_leds(struct wacom *wacom)
  797. {
  798. int error;
  799. /* Initialize default values */
  800. switch (wacom->wacom_wac.features.type) {
  801. case INTUOS4S:
  802. case INTUOS4:
  803. case INTUOS4L:
  804. wacom->led.select[0] = 0;
  805. wacom->led.select[1] = 0;
  806. wacom->led.llv = 10;
  807. wacom->led.hlv = 20;
  808. wacom->led.img_lum = 10;
  809. error = sysfs_create_group(&wacom->intf->dev.kobj,
  810. &intuos4_led_attr_group);
  811. break;
  812. case WACOM_24HD:
  813. case WACOM_21UX2:
  814. wacom->led.select[0] = 0;
  815. wacom->led.select[1] = 0;
  816. wacom->led.llv = 0;
  817. wacom->led.hlv = 0;
  818. wacom->led.img_lum = 0;
  819. error = sysfs_create_group(&wacom->intf->dev.kobj,
  820. &cintiq_led_attr_group);
  821. break;
  822. case INTUOS5S:
  823. case INTUOS5:
  824. case INTUOS5L:
  825. if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) {
  826. wacom->led.select[0] = 0;
  827. wacom->led.select[1] = 0;
  828. wacom->led.llv = 32;
  829. wacom->led.hlv = 0;
  830. wacom->led.img_lum = 0;
  831. error = sysfs_create_group(&wacom->intf->dev.kobj,
  832. &intuos5_led_attr_group);
  833. } else
  834. return 0;
  835. break;
  836. default:
  837. return 0;
  838. }
  839. if (error) {
  840. dev_err(&wacom->intf->dev,
  841. "cannot create sysfs group err: %d\n", error);
  842. return error;
  843. }
  844. wacom_led_control(wacom);
  845. return 0;
  846. }
  847. static void wacom_destroy_leds(struct wacom *wacom)
  848. {
  849. switch (wacom->wacom_wac.features.type) {
  850. case INTUOS4S:
  851. case INTUOS4:
  852. case INTUOS4L:
  853. sysfs_remove_group(&wacom->intf->dev.kobj,
  854. &intuos4_led_attr_group);
  855. break;
  856. case WACOM_24HD:
  857. case WACOM_21UX2:
  858. sysfs_remove_group(&wacom->intf->dev.kobj,
  859. &cintiq_led_attr_group);
  860. break;
  861. case INTUOS5S:
  862. case INTUOS5:
  863. case INTUOS5L:
  864. if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN)
  865. sysfs_remove_group(&wacom->intf->dev.kobj,
  866. &intuos5_led_attr_group);
  867. break;
  868. }
  869. }
  870. static enum power_supply_property wacom_battery_props[] = {
  871. POWER_SUPPLY_PROP_CAPACITY
  872. };
  873. static int wacom_battery_get_property(struct power_supply *psy,
  874. enum power_supply_property psp,
  875. union power_supply_propval *val)
  876. {
  877. struct wacom *wacom = container_of(psy, struct wacom, battery);
  878. int ret = 0;
  879. switch (psp) {
  880. case POWER_SUPPLY_PROP_CAPACITY:
  881. val->intval =
  882. wacom->wacom_wac.battery_capacity * 100 / 31;
  883. break;
  884. default:
  885. ret = -EINVAL;
  886. break;
  887. }
  888. return ret;
  889. }
  890. static int wacom_initialize_battery(struct wacom *wacom)
  891. {
  892. int error = 0;
  893. if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR) {
  894. wacom->battery.properties = wacom_battery_props;
  895. wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
  896. wacom->battery.get_property = wacom_battery_get_property;
  897. wacom->battery.name = "wacom_battery";
  898. wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
  899. wacom->battery.use_for_apm = 0;
  900. error = power_supply_register(&wacom->usbdev->dev,
  901. &wacom->battery);
  902. if (!error)
  903. power_supply_powers(&wacom->battery,
  904. &wacom->usbdev->dev);
  905. }
  906. return error;
  907. }
  908. static void wacom_destroy_battery(struct wacom *wacom)
  909. {
  910. if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_MONITOR &&
  911. wacom->battery.dev) {
  912. power_supply_unregister(&wacom->battery);
  913. wacom->battery.dev = NULL;
  914. }
  915. }
  916. static int wacom_register_input(struct wacom *wacom)
  917. {
  918. struct input_dev *input_dev;
  919. struct usb_interface *intf = wacom->intf;
  920. struct usb_device *dev = interface_to_usbdev(intf);
  921. struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
  922. int error;
  923. input_dev = input_allocate_device();
  924. if (!input_dev) {
  925. error = -ENOMEM;
  926. goto fail1;
  927. }
  928. input_dev->name = wacom_wac->name;
  929. input_dev->dev.parent = &intf->dev;
  930. input_dev->open = wacom_open;
  931. input_dev->close = wacom_close;
  932. usb_to_input_id(dev, &input_dev->id);
  933. input_set_drvdata(input_dev, wacom);
  934. wacom_wac->input = input_dev;
  935. error = wacom_setup_input_capabilities(input_dev, wacom_wac);
  936. if (error)
  937. goto fail1;
  938. error = input_register_device(input_dev);
  939. if (error)
  940. goto fail2;
  941. return 0;
  942. fail2:
  943. input_free_device(input_dev);
  944. wacom_wac->input = NULL;
  945. fail1:
  946. return error;
  947. }
  948. static void wacom_wireless_work(struct work_struct *work)
  949. {
  950. struct wacom *wacom = container_of(work, struct wacom, work);
  951. struct usb_device *usbdev = wacom->usbdev;
  952. struct wacom_wac *wacom_wac = &wacom->wacom_wac;
  953. struct wacom *wacom1, *wacom2;
  954. struct wacom_wac *wacom_wac1, *wacom_wac2;
  955. int error;
  956. /*
  957. * Regardless if this is a disconnect or a new tablet,
  958. * remove any existing input and battery devices.
  959. */
  960. wacom_destroy_battery(wacom);
  961. /* Stylus interface */
  962. wacom1 = usb_get_intfdata(usbdev->config->interface[1]);
  963. wacom_wac1 = &(wacom1->wacom_wac);
  964. if (wacom_wac1->input)
  965. input_unregister_device(wacom_wac1->input);
  966. wacom_wac1->input = NULL;
  967. /* Touch interface */
  968. wacom2 = usb_get_intfdata(usbdev->config->interface[2]);
  969. wacom_wac2 = &(wacom2->wacom_wac);
  970. if (wacom_wac2->input)
  971. input_unregister_device(wacom_wac2->input);
  972. wacom_wac2->input = NULL;
  973. if (wacom_wac->pid == 0) {
  974. dev_info(&wacom->intf->dev, "wireless tablet disconnected\n");
  975. } else {
  976. const struct usb_device_id *id = wacom_ids;
  977. dev_info(&wacom->intf->dev,
  978. "wireless tablet connected with PID %x\n",
  979. wacom_wac->pid);
  980. while (id->match_flags) {
  981. if (id->idVendor == USB_VENDOR_ID_WACOM &&
  982. id->idProduct == wacom_wac->pid)
  983. break;
  984. id++;
  985. }
  986. if (!id->match_flags) {
  987. dev_info(&wacom->intf->dev,
  988. "ignoring unknown PID.\n");
  989. return;
  990. }
  991. /* Stylus interface */
  992. wacom_wac1->features =
  993. *((struct wacom_features *)id->driver_info);
  994. wacom_wac1->features.device_type = BTN_TOOL_PEN;
  995. error = wacom_register_input(wacom1);
  996. if (error)
  997. goto fail1;
  998. /* Touch interface */
  999. wacom_wac2->features =
  1000. *((struct wacom_features *)id->driver_info);
  1001. wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
  1002. wacom_wac2->features.device_type = BTN_TOOL_FINGER;
  1003. wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
  1004. error = wacom_register_input(wacom2);
  1005. if (error)
  1006. goto fail2;
  1007. error = wacom_initialize_battery(wacom);
  1008. if (error)
  1009. goto fail3;
  1010. }
  1011. return;
  1012. fail3:
  1013. input_unregister_device(wacom_wac2->input);
  1014. wacom_wac2->input = NULL;
  1015. fail2:
  1016. input_unregister_device(wacom_wac1->input);
  1017. wacom_wac1->input = NULL;
  1018. fail1:
  1019. return;
  1020. }
  1021. /*
  1022. * Not all devices report physical dimensions from HID.
  1023. * Compute the default from hardcoded logical dimension
  1024. * and resolution before driver overwrites them.
  1025. */
  1026. static void wacom_set_default_phy(struct wacom_features *features)
  1027. {
  1028. if (features->x_resolution) {
  1029. features->x_phy = (features->x_max * 100) /
  1030. features->x_resolution;
  1031. features->y_phy = (features->y_max * 100) /
  1032. features->y_resolution;
  1033. }
  1034. }
  1035. static void wacom_calculate_res(struct wacom_features *features)
  1036. {
  1037. features->x_resolution = wacom_calc_hid_res(features->x_max,
  1038. features->x_phy,
  1039. features->unit,
  1040. features->unitExpo);
  1041. features->y_resolution = wacom_calc_hid_res(features->y_max,
  1042. features->y_phy,
  1043. features->unit,
  1044. features->unitExpo);
  1045. }
  1046. static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1047. {
  1048. struct usb_device *dev = interface_to_usbdev(intf);
  1049. struct usb_endpoint_descriptor *endpoint;
  1050. struct wacom *wacom;
  1051. struct wacom_wac *wacom_wac;
  1052. struct wacom_features *features;
  1053. int error;
  1054. if (!id->driver_info)
  1055. return -EINVAL;
  1056. wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
  1057. if (!wacom)
  1058. return -ENOMEM;
  1059. wacom_wac = &wacom->wacom_wac;
  1060. wacom_wac->features = *((struct wacom_features *)id->driver_info);
  1061. features = &wacom_wac->features;
  1062. if (features->pktlen > WACOM_PKGLEN_MAX) {
  1063. error = -EINVAL;
  1064. goto fail1;
  1065. }
  1066. wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX,
  1067. GFP_KERNEL, &wacom->data_dma);
  1068. if (!wacom_wac->data) {
  1069. error = -ENOMEM;
  1070. goto fail1;
  1071. }
  1072. wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
  1073. if (!wacom->irq) {
  1074. error = -ENOMEM;
  1075. goto fail2;
  1076. }
  1077. wacom->usbdev = dev;
  1078. wacom->intf = intf;
  1079. mutex_init(&wacom->lock);
  1080. INIT_WORK(&wacom->work, wacom_wireless_work);
  1081. usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
  1082. strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
  1083. endpoint = &intf->cur_altsetting->endpoint[0].desc;
  1084. /* set the default size in case we do not get them from hid */
  1085. wacom_set_default_phy(features);
  1086. /* Retrieve the physical and logical size for touch devices */
  1087. error = wacom_retrieve_hid_descriptor(intf, features);
  1088. if (error)
  1089. goto fail3;
  1090. /*
  1091. * Intuos5 has no useful data about its touch interface in its
  1092. * HID descriptor. If this is the touch interface (wMaxPacketSize
  1093. * of WACOM_PKGLEN_BBTOUCH3), override the table values.
  1094. */
  1095. if (features->type >= INTUOS5S && features->type <= INTUOS5L) {
  1096. if (endpoint->wMaxPacketSize == WACOM_PKGLEN_BBTOUCH3) {
  1097. features->device_type = BTN_TOOL_FINGER;
  1098. features->pktlen = WACOM_PKGLEN_BBTOUCH3;
  1099. features->x_max = 4096;
  1100. features->y_max = 4096;
  1101. } else {
  1102. features->device_type = BTN_TOOL_PEN;
  1103. }
  1104. }
  1105. wacom_setup_device_quirks(features);
  1106. /* set unit to "100th of a mm" for devices not reported by HID */
  1107. if (!features->unit) {
  1108. features->unit = 0x11;
  1109. features->unitExpo = 16 - 3;
  1110. }
  1111. wacom_calculate_res(features);
  1112. strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
  1113. if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
  1114. struct usb_device *other_dev;
  1115. /* Append the device type to the name */
  1116. strlcat(wacom_wac->name,
  1117. features->device_type == BTN_TOOL_PEN ?
  1118. " Pen" : " Finger",
  1119. sizeof(wacom_wac->name));
  1120. other_dev = wacom_get_sibling(dev, features->oVid, features->oPid);
  1121. if (other_dev == NULL || wacom_get_usbdev_data(other_dev) == NULL)
  1122. other_dev = dev;
  1123. error = wacom_add_shared_data(wacom_wac, other_dev);
  1124. if (error)
  1125. goto fail3;
  1126. }
  1127. usb_fill_int_urb(wacom->irq, dev,
  1128. usb_rcvintpipe(dev, endpoint->bEndpointAddress),
  1129. wacom_wac->data, features->pktlen,
  1130. wacom_sys_irq, wacom, endpoint->bInterval);
  1131. wacom->irq->transfer_dma = wacom->data_dma;
  1132. wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1133. error = wacom_initialize_leds(wacom);
  1134. if (error)
  1135. goto fail4;
  1136. if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
  1137. error = wacom_register_input(wacom);
  1138. if (error)
  1139. goto fail5;
  1140. }
  1141. /* Note that if query fails it is not a hard failure */
  1142. wacom_query_tablet_data(intf, features);
  1143. usb_set_intfdata(intf, wacom);
  1144. if (features->quirks & WACOM_QUIRK_MONITOR) {
  1145. if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
  1146. error = -EIO;
  1147. goto fail5;
  1148. }
  1149. }
  1150. return 0;
  1151. fail5: wacom_destroy_leds(wacom);
  1152. fail4: wacom_remove_shared_data(wacom_wac);
  1153. fail3: usb_free_urb(wacom->irq);
  1154. fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
  1155. fail1: kfree(wacom);
  1156. return error;
  1157. }
  1158. static void wacom_disconnect(struct usb_interface *intf)
  1159. {
  1160. struct wacom *wacom = usb_get_intfdata(intf);
  1161. usb_set_intfdata(intf, NULL);
  1162. usb_kill_urb(wacom->irq);
  1163. cancel_work_sync(&wacom->work);
  1164. if (wacom->wacom_wac.input)
  1165. input_unregister_device(wacom->wacom_wac.input);
  1166. wacom_destroy_battery(wacom);
  1167. wacom_destroy_leds(wacom);
  1168. usb_free_urb(wacom->irq);
  1169. usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
  1170. wacom->wacom_wac.data, wacom->data_dma);
  1171. wacom_remove_shared_data(&wacom->wacom_wac);
  1172. kfree(wacom);
  1173. }
  1174. static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
  1175. {
  1176. struct wacom *wacom = usb_get_intfdata(intf);
  1177. mutex_lock(&wacom->lock);
  1178. usb_kill_urb(wacom->irq);
  1179. mutex_unlock(&wacom->lock);
  1180. return 0;
  1181. }
  1182. static int wacom_resume(struct usb_interface *intf)
  1183. {
  1184. struct wacom *wacom = usb_get_intfdata(intf);
  1185. struct wacom_features *features = &wacom->wacom_wac.features;
  1186. int rv = 0;
  1187. mutex_lock(&wacom->lock);
  1188. /* switch to wacom mode first */
  1189. wacom_query_tablet_data(intf, features);
  1190. wacom_led_control(wacom);
  1191. if ((wacom->open || (features->quirks & WACOM_QUIRK_MONITOR)) &&
  1192. usb_submit_urb(wacom->irq, GFP_NOIO) < 0)
  1193. rv = -EIO;
  1194. mutex_unlock(&wacom->lock);
  1195. return rv;
  1196. }
  1197. static int wacom_reset_resume(struct usb_interface *intf)
  1198. {
  1199. return wacom_resume(intf);
  1200. }
  1201. static struct usb_driver wacom_driver = {
  1202. .name = "wacom",
  1203. .id_table = wacom_ids,
  1204. .probe = wacom_probe,
  1205. .disconnect = wacom_disconnect,
  1206. .suspend = wacom_suspend,
  1207. .resume = wacom_resume,
  1208. .reset_resume = wacom_reset_resume,
  1209. .supports_autosuspend = 1,
  1210. };
  1211. module_usb_driver(wacom_driver);