wacom.c 33 KB

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