wacom.c 28 KB

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