wacom.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /*
  2. * USB Wacom Graphire and Wacom Intuos tablet support
  3. *
  4. * Copyright (c) 2000-2004 Vojtech Pavlik <vojtech@ucw.cz>
  5. * Copyright (c) 2000 Andreas Bach Aaen <abach@stofanet.dk>
  6. * Copyright (c) 2000 Clifford Wolf <clifford@clifford.at>
  7. * Copyright (c) 2000 Sam Mosel <sam.mosel@computer.org>
  8. * Copyright (c) 2000 James E. Blair <corvus@gnu.org>
  9. * Copyright (c) 2000 Daniel Egger <egger@suse.de>
  10. * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com>
  11. * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be>
  12. * Copyright (c) 2002-2006 Ping Cheng <pingc@wacom.com>
  13. *
  14. * ChangeLog:
  15. * v0.1 (vp) - Initial release
  16. * v0.2 (aba) - Support for all buttons / combinations
  17. * v0.3 (vp) - Support for Intuos added
  18. * v0.4 (sm) - Support for more Intuos models, menustrip
  19. * relative mode, proximity.
  20. * v0.5 (vp) - Big cleanup, nifty features removed,
  21. * they belong in userspace
  22. * v1.8 (vp) - Submit URB only when operating, moved to CVS,
  23. * use input_report_key instead of report_btn and
  24. * other cleanups
  25. * v1.11 (vp) - Add URB ->dev setting for new kernels
  26. * v1.11 (jb) - Add support for the 4D Mouse & Lens
  27. * v1.12 (de) - Add support for two more inking pen IDs
  28. * v1.14 (vp) - Use new USB device id probing scheme.
  29. * Fix Wacom Graphire mouse wheel
  30. * v1.18 (vp) - Fix mouse wheel direction
  31. * Make mouse relative
  32. * v1.20 (fl) - Report tool id for Intuos devices
  33. * - Multi tools support
  34. * - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...)
  35. * - Add PL models support
  36. * - Fix Wacom Graphire mouse wheel again
  37. * v1.21 (vp) - Removed protocol descriptions
  38. * - Added MISC_SERIAL for tool serial numbers
  39. * (gb) - Identify version on module load.
  40. * v1.21.1 (fl) - added Graphire2 support
  41. * v1.21.2 (fl) - added Intuos2 support
  42. * - added all the PL ids
  43. * v1.21.3 (fl) - added another eraser id from Neil Okamoto
  44. * - added smooth filter for Graphire from Peri Hankey
  45. * - added PenPartner support from Olaf van Es
  46. * - new tool ids from Ole Martin Bjoerndalen
  47. * v1.29 (pc) - Add support for more tablets
  48. * - Fix pressure reporting
  49. * v1.30 (vp) - Merge 2.4 and 2.5 drivers
  50. * - Since 2.5 now has input_sync(), remove MSC_SERIAL abuse
  51. * - Cleanups here and there
  52. * v1.30.1 (pi) - Added Graphire3 support
  53. * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ...
  54. * v1.43 (pc) - Added support for Cintiq 21UX
  55. * - Fixed a Graphire bug
  56. * - Merged wacom_intuos3_irq into wacom_intuos_irq
  57. * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc.
  58. * - Report Device IDs
  59. * v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19
  60. * - Minor data report fix
  61. */
  62. /*
  63. * This program is free software; you can redistribute it and/or modify
  64. * it under the terms of the GNU General Public License as published by
  65. * the Free Software Foundation; either version 2 of the License, or
  66. * (at your option) any later version.
  67. */
  68. #include <linux/kernel.h>
  69. #include <linux/slab.h>
  70. #include <linux/module.h>
  71. #include <linux/init.h>
  72. #include <linux/usb/input.h>
  73. #include <asm/unaligned.h>
  74. /*
  75. * Version Information
  76. */
  77. #define DRIVER_VERSION "v1.45"
  78. #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
  79. #define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
  80. #define DRIVER_LICENSE "GPL"
  81. MODULE_AUTHOR(DRIVER_AUTHOR);
  82. MODULE_DESCRIPTION(DRIVER_DESC);
  83. MODULE_LICENSE(DRIVER_LICENSE);
  84. #define USB_VENDOR_ID_WACOM 0x056a
  85. #define STYLUS_DEVICE_ID 0x02
  86. #define CURSOR_DEVICE_ID 0x06
  87. #define ERASER_DEVICE_ID 0x0A
  88. enum {
  89. PENPARTNER = 0,
  90. GRAPHIRE,
  91. WACOM_G4,
  92. PL,
  93. INTUOS,
  94. INTUOS3,
  95. INTUOS312,
  96. INTUOS319,
  97. CINTIQ,
  98. MAX_TYPE
  99. };
  100. struct wacom_features {
  101. char *name;
  102. int pktlen;
  103. int x_max;
  104. int y_max;
  105. int pressure_max;
  106. int distance_max;
  107. int type;
  108. usb_complete_t irq;
  109. };
  110. struct wacom {
  111. signed char *data;
  112. dma_addr_t data_dma;
  113. struct input_dev *dev;
  114. struct usb_device *usbdev;
  115. struct urb *irq;
  116. struct wacom_features *features;
  117. int tool[2];
  118. int id[2];
  119. __u32 serial[2];
  120. char phys[32];
  121. };
  122. #define USB_REQ_GET_REPORT 0x01
  123. #define USB_REQ_SET_REPORT 0x09
  124. static int usb_get_report(struct usb_interface *intf, unsigned char type,
  125. unsigned char id, void *buf, int size)
  126. {
  127. return usb_control_msg(interface_to_usbdev(intf),
  128. usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
  129. USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  130. (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
  131. buf, size, 100);
  132. }
  133. static int usb_set_report(struct usb_interface *intf, unsigned char type,
  134. unsigned char id, void *buf, int size)
  135. {
  136. return usb_control_msg(interface_to_usbdev(intf),
  137. usb_sndctrlpipe(interface_to_usbdev(intf), 0),
  138. USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  139. (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
  140. buf, size, 1000);
  141. }
  142. static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
  143. {
  144. struct wacom *wacom = urb->context;
  145. unsigned char *data = wacom->data;
  146. struct input_dev *dev = wacom->dev;
  147. int prox, pressure, id;
  148. int retval;
  149. switch (urb->status) {
  150. case 0:
  151. /* success */
  152. break;
  153. case -ECONNRESET:
  154. case -ENOENT:
  155. case -ESHUTDOWN:
  156. /* this urb is terminated, clean up */
  157. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  158. return;
  159. default:
  160. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  161. goto exit;
  162. }
  163. if (data[0] != 2) {
  164. dbg("wacom_pl_irq: received unknown report #%d", data[0]);
  165. goto exit;
  166. }
  167. prox = data[1] & 0x40;
  168. input_regs(dev, regs);
  169. id = ERASER_DEVICE_ID;
  170. if (prox) {
  171. pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
  172. if (wacom->features->pressure_max > 255)
  173. pressure = (pressure << 1) | ((data[4] >> 6) & 1);
  174. pressure += (wacom->features->pressure_max + 1) / 2;
  175. /*
  176. * if going from out of proximity into proximity select between the eraser
  177. * and the pen based on the state of the stylus2 button, choose eraser if
  178. * pressed else choose pen. if not a proximity change from out to in, send
  179. * an out of proximity for previous tool then a in for new tool.
  180. */
  181. if (!wacom->tool[0]) {
  182. /* Eraser bit set for DTF */
  183. if (data[1] & 0x10)
  184. wacom->tool[1] = BTN_TOOL_RUBBER;
  185. else
  186. /* Going into proximity select tool */
  187. wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
  188. } else {
  189. /* was entered with stylus2 pressed */
  190. if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
  191. /* report out proximity for previous tool */
  192. input_report_key(dev, wacom->tool[1], 0);
  193. input_sync(dev);
  194. wacom->tool[1] = BTN_TOOL_PEN;
  195. goto exit;
  196. }
  197. }
  198. if (wacom->tool[1] != BTN_TOOL_RUBBER) {
  199. /* Unknown tool selected default to pen tool */
  200. wacom->tool[1] = BTN_TOOL_PEN;
  201. id = STYLUS_DEVICE_ID;
  202. }
  203. input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */
  204. input_report_abs(dev, ABS_MISC, id); /* report tool id */
  205. input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
  206. input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
  207. input_report_abs(dev, ABS_PRESSURE, pressure);
  208. input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
  209. input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
  210. /* Only allow the stylus2 button to be reported for the pen tool. */
  211. input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
  212. } else {
  213. /* report proximity-out of a (valid) tool */
  214. if (wacom->tool[1] != BTN_TOOL_RUBBER) {
  215. /* Unknown tool selected default to pen tool */
  216. wacom->tool[1] = BTN_TOOL_PEN;
  217. }
  218. input_report_key(dev, wacom->tool[1], prox);
  219. }
  220. wacom->tool[0] = prox; /* Save proximity state */
  221. input_sync(dev);
  222. exit:
  223. retval = usb_submit_urb (urb, GFP_ATOMIC);
  224. if (retval)
  225. err ("%s - usb_submit_urb failed with result %d",
  226. __FUNCTION__, retval);
  227. }
  228. static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
  229. {
  230. struct wacom *wacom = urb->context;
  231. unsigned char *data = wacom->data;
  232. struct input_dev *dev = wacom->dev;
  233. int retval, id;
  234. switch (urb->status) {
  235. case 0:
  236. /* success */
  237. break;
  238. case -ECONNRESET:
  239. case -ENOENT:
  240. case -ESHUTDOWN:
  241. /* this urb is terminated, clean up */
  242. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  243. return;
  244. default:
  245. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  246. goto exit;
  247. }
  248. if (data[0] != 2) {
  249. printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
  250. goto exit;
  251. }
  252. input_regs(dev, regs);
  253. if (data[1] & 0x04) {
  254. input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20);
  255. input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
  256. id = ERASER_DEVICE_ID;
  257. } else {
  258. input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20);
  259. input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
  260. id = STYLUS_DEVICE_ID;
  261. }
  262. input_report_abs(dev, ABS_MISC, id); /* report tool id */
  263. input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[2]));
  264. input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[4]));
  265. input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
  266. input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
  267. input_report_key(dev, BTN_STYLUS2, data[1] & 0x10);
  268. input_sync(dev);
  269. exit:
  270. retval = usb_submit_urb (urb, GFP_ATOMIC);
  271. if (retval)
  272. err ("%s - usb_submit_urb failed with result %d",
  273. __FUNCTION__, retval);
  274. }
  275. static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
  276. {
  277. struct wacom *wacom = urb->context;
  278. unsigned char *data = wacom->data;
  279. struct input_dev *dev = wacom->dev;
  280. int retval;
  281. switch (urb->status) {
  282. case 0:
  283. /* success */
  284. break;
  285. case -ECONNRESET:
  286. case -ENOENT:
  287. case -ESHUTDOWN:
  288. /* this urb is terminated, clean up */
  289. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  290. return;
  291. default:
  292. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  293. goto exit;
  294. }
  295. if (data[0] != 2) {
  296. printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
  297. goto exit;
  298. }
  299. input_regs(dev, regs);
  300. input_report_key(dev, BTN_TOOL_PEN, 1);
  301. input_report_abs(dev, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
  302. input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[1]));
  303. input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[3]));
  304. input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127);
  305. input_report_key(dev, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
  306. input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
  307. input_sync(dev);
  308. exit:
  309. retval = usb_submit_urb (urb, GFP_ATOMIC);
  310. if (retval)
  311. err ("%s - usb_submit_urb failed with result %d",
  312. __FUNCTION__, retval);
  313. }
  314. static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
  315. {
  316. struct wacom *wacom = urb->context;
  317. unsigned char *data = wacom->data;
  318. struct input_dev *dev = wacom->dev;
  319. int x, y, id, rw;
  320. int retval;
  321. switch (urb->status) {
  322. case 0:
  323. /* success */
  324. break;
  325. case -ECONNRESET:
  326. case -ENOENT:
  327. case -ESHUTDOWN:
  328. /* this urb is terminated, clean up */
  329. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  330. return;
  331. default:
  332. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  333. goto exit;
  334. }
  335. if (data[0] == 99) return; /* for Volito tablets */
  336. if (data[0] != 2) {
  337. dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
  338. goto exit;
  339. }
  340. input_regs(dev, regs);
  341. id = STYLUS_DEVICE_ID;
  342. if (data[1] & 0x10) { /* in prox */
  343. switch ((data[1] >> 5) & 3) {
  344. case 0: /* Pen */
  345. wacom->tool[0] = BTN_TOOL_PEN;
  346. break;
  347. case 1: /* Rubber */
  348. wacom->tool[0] = BTN_TOOL_RUBBER;
  349. id = ERASER_DEVICE_ID;
  350. break;
  351. case 2: /* Mouse with wheel */
  352. input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
  353. if (wacom->features->type == WACOM_G4) {
  354. rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
  355. input_report_rel(dev, REL_WHEEL, -rw);
  356. } else
  357. input_report_rel(dev, REL_WHEEL, -(signed char) data[6]);
  358. /* fall through */
  359. case 3: /* Mouse without wheel */
  360. wacom->tool[0] = BTN_TOOL_MOUSE;
  361. id = CURSOR_DEVICE_ID;
  362. input_report_key(dev, BTN_LEFT, data[1] & 0x01);
  363. input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
  364. if (wacom->features->type == WACOM_G4)
  365. input_report_abs(dev, ABS_DISTANCE, data[6]);
  366. else
  367. input_report_abs(dev, ABS_DISTANCE, data[7]);
  368. break;
  369. }
  370. }
  371. if (data[1] & 0x90) {
  372. x = le16_to_cpu(*(__le16 *) &data[2]);
  373. y = le16_to_cpu(*(__le16 *) &data[4]);
  374. input_report_abs(dev, ABS_X, x);
  375. input_report_abs(dev, ABS_Y, y);
  376. if (wacom->tool[0] != BTN_TOOL_MOUSE) {
  377. input_report_abs(dev, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8));
  378. input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
  379. input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
  380. input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
  381. }
  382. }
  383. if (data[1] & 0x10)
  384. input_report_abs(dev, ABS_MISC, id); /* report tool id */
  385. else
  386. input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
  387. input_report_key(dev, wacom->tool[0], data[1] & 0x10);
  388. input_sync(dev);
  389. /* send pad data */
  390. if (wacom->features->type == WACOM_G4) {
  391. if ((wacom->serial[1] & 0xc0) != (data[7] & 0xf8)) {
  392. wacom->id[1] = 1;
  393. wacom->serial[1] = (data[7] & 0xf8);
  394. input_report_key(dev, BTN_0, (data[7] & 0x40));
  395. input_report_key(dev, BTN_4, (data[7] & 0x80));
  396. rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
  397. input_report_rel(dev, REL_WHEEL, rw);
  398. input_report_key(dev, BTN_TOOL_FINGER, 0xf0);
  399. input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
  400. } else if (wacom->id[1]) {
  401. wacom->id[1] = 0;
  402. input_report_key(dev, BTN_TOOL_FINGER, 0);
  403. input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
  404. }
  405. input_sync(dev);
  406. }
  407. exit:
  408. retval = usb_submit_urb (urb, GFP_ATOMIC);
  409. if (retval)
  410. err ("%s - usb_submit_urb failed with result %d",
  411. __FUNCTION__, retval);
  412. }
  413. static int wacom_intuos_inout(struct urb *urb)
  414. {
  415. struct wacom *wacom = urb->context;
  416. unsigned char *data = wacom->data;
  417. struct input_dev *dev = wacom->dev;
  418. int idx;
  419. /* tool number */
  420. idx = data[1] & 0x01;
  421. /* Enter report */
  422. if ((data[1] & 0xfc) == 0xc0) {
  423. /* serial number of the tool */
  424. wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
  425. (data[4] << 20) + (data[5] << 12) +
  426. (data[6] << 4) + (data[7] >> 4);
  427. wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
  428. switch (wacom->id[idx]) {
  429. case 0x812: /* Inking pen */
  430. case 0x801: /* Intuos3 Inking pen */
  431. case 0x012:
  432. wacom->tool[idx] = BTN_TOOL_PENCIL;
  433. break;
  434. case 0x822: /* Pen */
  435. case 0x842:
  436. case 0x852:
  437. case 0x823: /* Intuos3 Grip Pen */
  438. case 0x813: /* Intuos3 Classic Pen */
  439. case 0x885: /* Intuos3 Marker Pen */
  440. case 0x022:
  441. wacom->tool[idx] = BTN_TOOL_PEN;
  442. break;
  443. case 0x832: /* Stroke pen */
  444. case 0x032:
  445. wacom->tool[idx] = BTN_TOOL_BRUSH;
  446. break;
  447. case 0x007: /* Mouse 4D and 2D */
  448. case 0x09c:
  449. case 0x094:
  450. case 0x017: /* Intuos3 2D Mouse */
  451. wacom->tool[idx] = BTN_TOOL_MOUSE;
  452. break;
  453. case 0x096: /* Lens cursor */
  454. case 0x097: /* Intuos3 Lens cursor */
  455. wacom->tool[idx] = BTN_TOOL_LENS;
  456. break;
  457. case 0x82a: /* Eraser */
  458. case 0x85a:
  459. case 0x91a:
  460. case 0xd1a:
  461. case 0x0fa:
  462. case 0x82b: /* Intuos3 Grip Pen Eraser */
  463. case 0x81b: /* Intuos3 Classic Pen Eraser */
  464. case 0x91b: /* Intuos3 Airbrush Eraser */
  465. wacom->tool[idx] = BTN_TOOL_RUBBER;
  466. break;
  467. case 0xd12:
  468. case 0x912:
  469. case 0x112:
  470. case 0x913: /* Intuos3 Airbrush */
  471. wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
  472. break;
  473. default: /* Unknown tool */
  474. wacom->tool[idx] = BTN_TOOL_PEN;
  475. }
  476. if(!((wacom->tool[idx] == BTN_TOOL_LENS) &&
  477. ((wacom->features->type == INTUOS312)
  478. || (wacom->features->type == INTUOS319)))) {
  479. input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
  480. input_report_key(dev, wacom->tool[idx], 1);
  481. input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  482. input_sync(dev);
  483. }
  484. return 1;
  485. }
  486. /* Exit report */
  487. if ((data[1] & 0xfe) == 0x80) {
  488. input_report_key(dev, wacom->tool[idx], 0);
  489. input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
  490. input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  491. input_sync(dev);
  492. return 1;
  493. }
  494. if((wacom->tool[idx] == BTN_TOOL_LENS) && ((wacom->features->type == INTUOS312)
  495. || (wacom->features->type == INTUOS319)))
  496. return 1;
  497. else
  498. return 0;
  499. }
  500. static void wacom_intuos_general(struct urb *urb)
  501. {
  502. struct wacom *wacom = urb->context;
  503. unsigned char *data = wacom->data;
  504. struct input_dev *dev = wacom->dev;
  505. unsigned int t;
  506. /* general pen packet */
  507. if ((data[1] & 0xb8) == 0xa0) {
  508. t = (data[6] << 2) | ((data[7] >> 6) & 3);
  509. input_report_abs(dev, ABS_PRESSURE, t);
  510. input_report_abs(dev, ABS_TILT_X,
  511. ((data[7] << 1) & 0x7e) | (data[8] >> 7));
  512. input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
  513. input_report_key(dev, BTN_STYLUS, data[1] & 2);
  514. input_report_key(dev, BTN_STYLUS2, data[1] & 4);
  515. input_report_key(dev, BTN_TOUCH, t > 10);
  516. }
  517. /* airbrush second packet */
  518. if ((data[1] & 0xbc) == 0xb4) {
  519. input_report_abs(dev, ABS_WHEEL,
  520. (data[6] << 2) | ((data[7] >> 6) & 3));
  521. input_report_abs(dev, ABS_TILT_X,
  522. ((data[7] << 1) & 0x7e) | (data[8] >> 7));
  523. input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
  524. }
  525. return;
  526. }
  527. static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
  528. {
  529. struct wacom *wacom = urb->context;
  530. unsigned char *data = wacom->data;
  531. struct input_dev *dev = wacom->dev;
  532. unsigned int t;
  533. int idx;
  534. int retval;
  535. switch (urb->status) {
  536. case 0:
  537. /* success */
  538. break;
  539. case -ECONNRESET:
  540. case -ENOENT:
  541. case -ESHUTDOWN:
  542. /* this urb is terminated, clean up */
  543. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  544. return;
  545. default:
  546. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  547. goto exit;
  548. }
  549. if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
  550. dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
  551. goto exit;
  552. }
  553. input_regs(dev, regs);
  554. /* tool number */
  555. idx = data[1] & 0x01;
  556. /* pad packets. Works as a second tool and is always in prox */
  557. if (data[0] == 12) {
  558. /* initiate the pad as a device */
  559. if (wacom->tool[1] != BTN_TOOL_FINGER)
  560. wacom->tool[1] = BTN_TOOL_FINGER;
  561. input_report_key(dev, BTN_0, (data[5] & 0x01));
  562. input_report_key(dev, BTN_1, (data[5] & 0x02));
  563. input_report_key(dev, BTN_2, (data[5] & 0x04));
  564. input_report_key(dev, BTN_3, (data[5] & 0x08));
  565. input_report_key(dev, BTN_4, (data[6] & 0x01));
  566. input_report_key(dev, BTN_5, (data[6] & 0x02));
  567. input_report_key(dev, BTN_6, (data[6] & 0x04));
  568. input_report_key(dev, BTN_7, (data[6] & 0x08));
  569. input_report_abs(dev, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
  570. input_report_abs(dev, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
  571. if((data[5] & 0x0f) | (data[6] & 0x0f) | (data[1] & 0x1f) | data[2])
  572. input_report_key(dev, wacom->tool[1], 1);
  573. else
  574. input_report_key(dev, wacom->tool[1], 0);
  575. input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff);
  576. input_sync(dev);
  577. goto exit;
  578. }
  579. /* process in/out prox events */
  580. if (wacom_intuos_inout(urb))
  581. goto exit;
  582. /* Cintiq doesn't send data when RDY bit isn't set */
  583. if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
  584. goto exit;
  585. if (wacom->features->type >= INTUOS3) {
  586. input_report_abs(dev, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
  587. input_report_abs(dev, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
  588. input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
  589. } else {
  590. input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
  591. input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
  592. input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
  593. }
  594. /* process general packets */
  595. wacom_intuos_general(urb);
  596. /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
  597. if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
  598. if (data[1] & 0x02) {
  599. /* Rotation packet */
  600. if (wacom->features->type >= INTUOS3) {
  601. /* I3 marker pen rotation reported as wheel
  602. * due to valuator limitation
  603. */
  604. t = (data[6] << 3) | ((data[7] >> 5) & 7);
  605. t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
  606. ((t-1) / 2 + 450)) : (450 - t / 2) ;
  607. input_report_abs(dev, ABS_WHEEL, t);
  608. } else {
  609. /* 4D mouse rotation packet */
  610. t = (data[6] << 3) | ((data[7] >> 5) & 7);
  611. input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ?
  612. ((t - 1) / 2) : -t / 2);
  613. }
  614. } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3) {
  615. /* 4D mouse packet */
  616. input_report_key(dev, BTN_LEFT, data[8] & 0x01);
  617. input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
  618. input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
  619. input_report_key(dev, BTN_SIDE, data[8] & 0x20);
  620. input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
  621. t = (data[6] << 2) | ((data[7] >> 6) & 3);
  622. input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
  623. } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
  624. /* 2D mouse packet */
  625. input_report_key(dev, BTN_LEFT, data[8] & 0x04);
  626. input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
  627. input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
  628. input_report_rel(dev, REL_WHEEL, (data[8] & 0x01)
  629. - ((data[8] & 0x02) >> 1));
  630. /* I3 2D mouse side buttons */
  631. if (wacom->features->type == INTUOS3) {
  632. input_report_key(dev, BTN_SIDE, data[8] & 0x40);
  633. input_report_key(dev, BTN_EXTRA, data[8] & 0x20);
  634. }
  635. } else if (wacom->features->type < INTUOS3) {
  636. /* Lens cursor packets */
  637. input_report_key(dev, BTN_LEFT, data[8] & 0x01);
  638. input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
  639. input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
  640. input_report_key(dev, BTN_SIDE, data[8] & 0x10);
  641. input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
  642. }
  643. }
  644. input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
  645. input_report_key(dev, wacom->tool[idx], 1);
  646. input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
  647. input_sync(dev);
  648. exit:
  649. retval = usb_submit_urb (urb, GFP_ATOMIC);
  650. if (retval)
  651. err ("%s - usb_submit_urb failed with result %d",
  652. __FUNCTION__, retval);
  653. }
  654. static struct wacom_features wacom_features[] = {
  655. { "Wacom Penpartner", 7, 5040, 3780, 255, 32, PENPARTNER, wacom_penpartner_irq },
  656. { "Wacom Graphire", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
  657. { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
  658. { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq },
  659. { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq },
  660. { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq },
  661. { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 32, WACOM_G4, wacom_graphire_irq },
  662. { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 32, WACOM_G4, wacom_graphire_irq },
  663. { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
  664. { "Wacom PenStation2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
  665. { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
  666. { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 32, GRAPHIRE, wacom_graphire_irq },
  667. { "Wacom PenPartner2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
  668. { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
  669. { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
  670. { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
  671. { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
  672. { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
  673. { "Wacom PL400", 8, 5408, 4056, 255, 32, PL, wacom_pl_irq },
  674. { "Wacom PL500", 8, 6144, 4608, 255, 32, PL, wacom_pl_irq },
  675. { "Wacom PL600", 8, 6126, 4604, 255, 32, PL, wacom_pl_irq },
  676. { "Wacom PL600SX", 8, 6260, 5016, 255, 32, PL, wacom_pl_irq },
  677. { "Wacom PL550", 8, 6144, 4608, 511, 32, PL, wacom_pl_irq },
  678. { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq },
  679. { "Wacom PL700", 8, 6758, 5406, 511, 32, PL, wacom_pl_irq },
  680. { "Wacom PL510", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
  681. { "Wacom DTU710", 8, 34080, 27660, 511, 32, PL, wacom_pl_irq },
  682. { "Wacom DTF521", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
  683. { "Wacom DTF720", 8, 6858, 5506, 511, 32, PL, wacom_pl_irq },
  684. { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq },
  685. { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
  686. { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
  687. { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
  688. { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
  689. { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
  690. { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq },
  691. { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq },
  692. { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq },
  693. { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 15, INTUOS312, wacom_intuos_irq },
  694. { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 15, INTUOS319, wacom_intuos_irq },
  695. { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 15, INTUOS3, wacom_intuos_irq },
  696. { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq },
  697. { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
  698. { }
  699. };
  700. static struct usb_device_id wacom_ids[] = {
  701. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
  702. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
  703. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
  704. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
  705. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
  706. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
  707. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
  708. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
  709. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
  710. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
  711. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
  712. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
  713. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
  714. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
  715. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
  716. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
  717. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
  718. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
  719. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
  720. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
  721. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
  722. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
  723. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
  724. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
  725. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
  726. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
  727. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
  728. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
  729. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC3) },
  730. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
  731. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
  732. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
  733. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
  734. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
  735. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
  736. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
  737. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
  738. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
  739. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
  740. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
  741. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
  742. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
  743. { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
  744. { }
  745. };
  746. MODULE_DEVICE_TABLE(usb, wacom_ids);
  747. static int wacom_open(struct input_dev *dev)
  748. {
  749. struct wacom *wacom = dev->private;
  750. wacom->irq->dev = wacom->usbdev;
  751. if (usb_submit_urb(wacom->irq, GFP_KERNEL))
  752. return -EIO;
  753. return 0;
  754. }
  755. static void wacom_close(struct input_dev *dev)
  756. {
  757. struct wacom *wacom = dev->private;
  758. usb_kill_urb(wacom->irq);
  759. }
  760. static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
  761. {
  762. struct usb_device *dev = interface_to_usbdev(intf);
  763. struct usb_endpoint_descriptor *endpoint;
  764. struct wacom *wacom;
  765. struct input_dev *input_dev;
  766. char rep_data[2], limit = 0;
  767. wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
  768. input_dev = input_allocate_device();
  769. if (!wacom || !input_dev)
  770. goto fail1;
  771. wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
  772. if (!wacom->data)
  773. goto fail1;
  774. wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
  775. if (!wacom->irq)
  776. goto fail2;
  777. wacom->usbdev = dev;
  778. wacom->dev = input_dev;
  779. usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
  780. strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
  781. wacom->features = wacom_features + (id - wacom_ids);
  782. if (wacom->features->pktlen > 10)
  783. BUG();
  784. input_dev->name = wacom->features->name;
  785. usb_to_input_id(dev, &input_dev->id);
  786. input_dev->cdev.dev = &intf->dev;
  787. input_dev->private = wacom;
  788. input_dev->open = wacom_open;
  789. input_dev->close = wacom_close;
  790. input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
  791. input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
  792. input_set_abs_params(input_dev, ABS_X, 0, wacom->features->x_max, 4, 0);
  793. input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0);
  794. input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0);
  795. input_dev->absbit[LONG(ABS_MISC)] |= BIT(ABS_MISC);
  796. switch (wacom->features->type) {
  797. case WACOM_G4:
  798. input_dev->evbit[0] |= BIT(EV_MSC);
  799. input_dev->mscbit[0] |= BIT(MSC_SERIAL);
  800. input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
  801. input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
  802. /* fall through */
  803. case GRAPHIRE:
  804. input_dev->evbit[0] |= BIT(EV_REL);
  805. input_dev->relbit[0] |= BIT(REL_WHEEL);
  806. input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
  807. input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
  808. input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
  809. break;
  810. case INTUOS3:
  811. case INTUOS312:
  812. case INTUOS319:
  813. case CINTIQ:
  814. input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
  815. input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
  816. input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0);
  817. input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0);
  818. /* fall through */
  819. case INTUOS:
  820. input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
  821. input_dev->mscbit[0] |= BIT(MSC_SERIAL);
  822. input_dev->relbit[0] |= BIT(REL_WHEEL);
  823. input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
  824. input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
  825. | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
  826. input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
  827. input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
  828. input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
  829. input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
  830. input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
  831. input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
  832. break;
  833. case PL:
  834. input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
  835. break;
  836. }
  837. endpoint = &intf->cur_altsetting->endpoint[0].desc;
  838. if (wacom->features->pktlen > 10)
  839. BUG();
  840. usb_fill_int_urb(wacom->irq, dev,
  841. usb_rcvintpipe(dev, endpoint->bEndpointAddress),
  842. wacom->data, wacom->features->pktlen,
  843. wacom->features->irq, wacom, endpoint->bInterval);
  844. wacom->irq->transfer_dma = wacom->data_dma;
  845. wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  846. input_register_device(wacom->dev);
  847. /* Ask the tablet to report tablet data. Repeat until it succeeds */
  848. do {
  849. rep_data[0] = 2;
  850. rep_data[1] = 2;
  851. usb_set_report(intf, 3, 2, rep_data, 2);
  852. usb_get_report(intf, 3, 2, rep_data, 2);
  853. } while (rep_data[1] != 2 && limit++ < 5);
  854. usb_set_intfdata(intf, wacom);
  855. return 0;
  856. fail2: usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
  857. fail1: input_free_device(input_dev);
  858. kfree(wacom);
  859. return -ENOMEM;
  860. }
  861. static void wacom_disconnect(struct usb_interface *intf)
  862. {
  863. struct wacom *wacom = usb_get_intfdata (intf);
  864. usb_set_intfdata(intf, NULL);
  865. if (wacom) {
  866. usb_kill_urb(wacom->irq);
  867. input_unregister_device(wacom->dev);
  868. usb_free_urb(wacom->irq);
  869. usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma);
  870. kfree(wacom);
  871. }
  872. }
  873. static struct usb_driver wacom_driver = {
  874. .name = "wacom",
  875. .probe = wacom_probe,
  876. .disconnect = wacom_disconnect,
  877. .id_table = wacom_ids,
  878. };
  879. static int __init wacom_init(void)
  880. {
  881. int result = usb_register(&wacom_driver);
  882. if (result == 0)
  883. info(DRIVER_VERSION ":" DRIVER_DESC);
  884. return result;
  885. }
  886. static void __exit wacom_exit(void)
  887. {
  888. usb_deregister(&wacom_driver);
  889. }
  890. module_init(wacom_init);
  891. module_exit(wacom_exit);