wacom.c 28 KB

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