wacom.c 28 KB

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