wacom.c 32 KB

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