wacom.c 29 KB

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