2 * $Id: wacom.c,v 1.23 2001/05/29 12:57:18 vojtech Exp $
4 * Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@suse.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>
12 * USB Wacom Graphire and Wacom Intuos tablet support
17 * v0.1 (vp) - Initial release
18 * v0.2 (aba) - Support for all buttons / combinations
19 * v0.3 (vp) - Support for Intuos added
20 * v0.4 (sm) - Support for more Intuos models, menustrip
21 * relative mode, proximity.
22 * v0.5 (vp) - Big cleanup, nifty features removed,
23 * they belong in userspace
24 * v1.8 (vp) - Submit URB only when operating, moved to CVS,
25 * use input_report_key instead of report_btn and
27 * v1.11 (vp) - Add URB ->dev setting for new kernels
28 * v1.11 (jb) - Add support for the 4D Mouse & Lens
29 * v1.12 (de) - Add support for two more inking pen IDs
30 * v1.14 (vp) - Use new USB device id probing scheme.
31 * Fix Wacom Graphire mouse wheel
32 * v1.18 (vp) - Fix mouse wheel direction
34 * v1.20 (fl) - Report tool id for Intuos devices
35 * - Multi tools support
36 * - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...)
37 * - Add PL models support
38 * - Fix Wacom Graphire mouse wheel again
39 * v1.21 (vp) - Removed protocol descriptions
40 * - Added MISC_SERIAL for tool serial numbers
41 * (gb) - Identify version on module load.
42 * v1.21.1 (fl) - added Graphire2 support
43 * v1.21.2 (fl) - added Intuos2 support
44 * - added all the PL ids
45 * v1.21.3 (fl) - added another eraser id from Neil Okamoto
46 * - added smooth filter for Graphire from Peri Hankey
47 * - added PenPartner support from Olaf van Es
48 * - new tool ids from Ole Martin Bjoerndalen
52 * This program is free software; you can redistribute it and/or modify
53 * it under the terms of the GNU General Public License as published by
54 * the Free Software Foundation; either version 2 of the License, or
55 * (at your option) any later version.
57 * This program is distributed in the hope that it will be useful,
58 * but WITHOUT ANY WARRANTY; without even the implied warranty of
59 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60 * GNU General Public License for more details.
62 * You should have received a copy of the GNU General Public License
63 * along with this program; if not, write to the Free Software
64 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
66 * Should you need to contact me, the author, you can do so either by
67 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
68 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
71 #include <linux/kernel.h>
72 #include <linux/slab.h>
73 #include <linux/input.h>
74 #include <linux/module.h>
75 #include <linux/init.h>
76 #include <linux/usb.h>
81 #define DRIVER_VERSION "v1.21.3"
82 #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@suse.cz>"
83 #define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
85 MODULE_AUTHOR( DRIVER_AUTHOR );
86 MODULE_DESCRIPTION( DRIVER_DESC );
87 MODULE_LICENSE("GPL");
89 #define USB_VENDOR_ID_WACOM 0x056a
91 struct wacom_features {
98 void (*irq)(struct urb *urb);
100 unsigned long absbit;
101 unsigned long relbit;
102 unsigned long btnbit;
103 unsigned long digibit;
107 signed char data[10];
108 struct input_dev dev;
109 struct usb_device *usbdev;
111 struct wacom_features *features;
117 static void wacom_pl_irq(struct urb *urb)
119 struct wacom *wacom = urb->context;
120 unsigned char *data = wacom->data;
121 struct input_dev *dev = &wacom->dev;
124 if (urb->status) return;
127 printk(KERN_ERR "wacom_pl_irq: received unknown report #%d\n", data[0]);
131 prox = data[1] & 0x20;
133 input_report_key(dev, BTN_TOOL_PEN, prox);
136 int pressure = (data[4] & 0x04) >> 2 | ((__u32)(data[7] & 0x7f) << 1);
138 input_report_abs(dev, ABS_X, data[3] | ((__u32)data[2] << 8) | ((__u32)(data[1] & 0x03) << 16));
139 input_report_abs(dev, ABS_Y, data[6] | ((__u32)data[5] << 8) | ((__u32)(data[4] & 0x03) << 8));
140 input_report_abs(dev, ABS_PRESSURE, (data[7] & 0x80) ? (255 - pressure) : (pressure + 255));
141 input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
142 input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
143 input_report_key(dev, BTN_STYLUS2, data[4] & 0x20);
146 input_event(dev, EV_MSC, MSC_SERIAL, 0);
149 static void wacom_penpartner_irq(struct urb *urb)
151 struct wacom *wacom = urb->context;
152 unsigned char *data = wacom->data;
153 struct input_dev *dev = &wacom->dev;
158 if (urb->status) return;
160 x = data[2] << 8 | data[1];
161 y = data[4] << 8 | data[3];
163 leftmb = ((pressure > -80) && !(data[5] &20));
165 input_report_key(dev, BTN_TOOL_PEN, 1);
167 input_report_abs(dev, ABS_X, x);
168 input_report_abs(dev, ABS_Y, y);
169 input_report_abs(dev, ABS_PRESSURE, pressure+127);
170 input_report_key(dev, BTN_LEFT, leftmb);
171 input_report_key(dev, BTN_RIGHT, (data[5] & 0x40));
173 input_event(dev, EV_MSC, MSC_SERIAL, leftmb);
176 static void wacom_graphire_irq(struct urb *urb)
178 struct wacom *wacom = urb->context;
179 unsigned char *data = wacom->data;
180 struct input_dev *dev = &wacom->dev;
183 if (urb->status) return;
186 printk(KERN_ERR "wacom_graphire_irq: received unknown report #%d\n", data[0]);
190 x = data[2] | ((__u32)data[3] << 8);
191 y = data[4] | ((__u32)data[5] << 8);
193 switch ((data[1] >> 5) & 3) {
196 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x80);
200 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x80);
204 input_report_key(dev, BTN_TOOL_MOUSE, data[7] > 24);
205 input_report_key(dev, BTN_LEFT, data[1] & 0x01);
206 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
207 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
208 input_report_abs(dev, ABS_DISTANCE, data[7]);
209 input_report_rel(dev, REL_WHEEL, (signed char) data[6]);
211 input_report_abs(dev, ABS_X, x);
212 input_report_abs(dev, ABS_Y, y);
214 input_event(dev, EV_MSC, MSC_SERIAL, data[1] & 0x01);
218 if (data[1] & 0x80) {
219 input_report_abs(dev, ABS_X, x);
220 input_report_abs(dev, ABS_Y, y);
223 input_report_abs(dev, ABS_PRESSURE, data[6] | ((__u32)data[7] << 8));
224 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
225 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
226 input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
228 input_event(dev, EV_MSC, MSC_SERIAL, data[1] & 0x01);
231 static void wacom_intuos_irq(struct urb *urb)
233 struct wacom *wacom = urb->context;
234 unsigned char *data = wacom->data;
235 struct input_dev *dev = &wacom->dev;
239 if (urb->status) return;
242 printk(KERN_ERR "wacom_intuos_irq: received unknown report #%d\n", data[0]);
247 idx = data[1] & 0x01;
249 if ((data[1] & 0xfc) == 0xc0) { /* Enter report */
251 wacom->serial[idx] = ((__u32)(data[3] & 0x0f) << 4) + /* serial number of the tool */
252 ((__u32)data[4] << 16) + ((__u32)data[5] << 12) +
253 ((__u32)data[6] << 4) + (data[7] >> 4);
255 switch (((__u32)data[2] << 4) | (data[3] >> 4)) {
257 case 0x012: wacom->tool[idx] = BTN_TOOL_PENCIL; break; /* Inking pen */
260 case 0x022: wacom->tool[idx] = BTN_TOOL_PEN; break; /* Pen */
262 case 0x032: wacom->tool[idx] = BTN_TOOL_BRUSH; break; /* Stroke pen */
265 case 0x094: wacom->tool[idx] = BTN_TOOL_MOUSE; break; /* Mouse 4D */
266 case 0x096: wacom->tool[idx] = BTN_TOOL_LENS; break; /* Lens cursor */
270 case 0x0fa: wacom->tool[idx] = BTN_TOOL_RUBBER; break; /* Eraser */
271 case 0x112: wacom->tool[idx] = BTN_TOOL_AIRBRUSH; break; /* Airbrush */
272 default: wacom->tool[idx] = BTN_TOOL_PEN; break; /* Unknown tool */
275 input_report_key(dev, wacom->tool[idx], 1);
276 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
280 if ((data[1] & 0xfe) == 0x80) { /* Exit report */
281 input_report_key(dev, wacom->tool[idx], 0);
282 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
286 input_report_abs(dev, ABS_X, ((__u32)data[2] << 8) | data[3]);
287 input_report_abs(dev, ABS_Y, ((__u32)data[4] << 8) | data[5]);
288 input_report_abs(dev, ABS_DISTANCE, data[9] >> 4);
290 if ((data[1] & 0xb8) == 0xa0) { /* general pen packet */
291 input_report_abs(dev, ABS_PRESSURE, t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3));
292 input_report_abs(dev, ABS_TILT_X, ((data[7] << 1) & 0x7e) | (data[8] >> 7));
293 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
294 input_report_key(dev, BTN_STYLUS, data[1] & 2);
295 input_report_key(dev, BTN_STYLUS2, data[1] & 4);
296 input_report_key(dev, BTN_TOUCH, t > 10);
299 if ((data[1] & 0xbc) == 0xb4) { /* airbrush second packet */
300 input_report_abs(dev, ABS_WHEEL, ((__u32)data[6] << 2) | ((data[7] >> 6) & 3));
301 input_report_abs(dev, ABS_TILT_X, ((data[7] << 1) & 0x7e) | (data[8] >> 7));
302 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
305 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) { /* 4D mouse or Lens cursor packets */
307 if (data[1] & 0x02) { /* Rotation packet */
309 input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ?
310 ((__u32)data[6] << 2) | ((data[7] >> 6) & 3):
311 (-(((__u32)data[6] << 2) | ((data[7] >> 6) & 3))) - 1);
315 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
316 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
317 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
319 if ((data[1] & 0x10) == 0) { /* 4D mouse packets */
321 input_report_key(dev, BTN_SIDE, data[8] & 0x20);
322 input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
323 input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ?
324 ((__u32)data[6] << 2) | ((data[7] >> 6) & 3) :
325 -((__u32)data[6] << 2) | ((data[7] >> 6) & 3));
327 } else { /* Lens cursor packets */
329 input_report_key(dev, BTN_SIDE, data[8] & 0x10);
330 input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
335 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
338 #define WACOM_INTUOS_TOOLS (BIT(BTN_TOOL_BRUSH) | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS))
339 #define WACOM_INTUOS_BUTTONS (BIT(BTN_SIDE) | BIT(BTN_EXTRA))
340 #define WACOM_INTUOS_ABS (BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE))
342 struct wacom_features wacom_features[] = {
343 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, wacom_penpartner_irq,
345 { "Wacom Graphire", 8, 10206, 7422, 511, 32, wacom_graphire_irq,
346 BIT(EV_REL), 0, BIT(REL_WHEEL), 0 },
347 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, wacom_graphire_irq,
348 BIT(EV_REL), 0, BIT(REL_WHEEL), 0 },
349 { "Wacom Graphire2 5x7", 8, 10206, 7422, 511, 32, wacom_graphire_irq,
350 BIT(EV_REL), 0, BIT(REL_WHEEL), 0 },
351 { "Wacom Intuos 4x5", 10, 12700, 10360, 1023, 15, wacom_intuos_irq,
352 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
353 { "Wacom Intuos 6x8", 10, 20320, 15040, 1023, 15, wacom_intuos_irq,
354 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
355 { "Wacom Intuos 9x12", 10, 30480, 23060, 1023, 15, wacom_intuos_irq,
356 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
357 { "Wacom Intuos 12x12", 10, 30480, 30480, 1023, 15, wacom_intuos_irq,
358 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
359 { "Wacom Intuos 12x18", 10, 47720, 30480, 1023, 15, wacom_intuos_irq,
360 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
361 { "Wacom PL400", 8, 12328, 9256, 511, 32, wacom_pl_irq,
363 { "Wacom PL500", 8, 12328, 9256, 511, 32, wacom_pl_irq,
365 { "Wacom PL600", 8, 12328, 9256, 511, 32, wacom_pl_irq,
367 { "Wacom PL600SX", 8, 12328, 9256, 511, 32, wacom_pl_irq,
369 { "Wacom PL550", 8, 12328, 9256, 511, 32, wacom_pl_irq,
371 { "Wacom PL800", 8, 12328, 9256, 511, 32, wacom_pl_irq,
373 { "Wacom Intuos2 4x5", 10, 12700, 10360, 1023, 15, wacom_intuos_irq,
374 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
375 { "Wacom Intuos2 6x8", 10, 20320, 15040, 1023, 15, wacom_intuos_irq,
376 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
377 { "Wacom Intuos2 9x12", 10, 30480, 23060, 1023, 15, wacom_intuos_irq,
378 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
379 { "Wacom Intuos2 12x12", 10, 30480, 30480, 1023, 15, wacom_intuos_irq,
380 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
381 { "Wacom Intuos2 12x18", 10, 47720, 30480, 1023, 15, wacom_intuos_irq,
382 0, WACOM_INTUOS_ABS, 0, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
386 struct usb_device_id wacom_ids[] = {
387 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00), driver_info: 0 },
388 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10), driver_info: 1 },
389 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11), driver_info: 2 },
390 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12), driver_info: 3 },
391 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20), driver_info: 4 },
392 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21), driver_info: 5 },
393 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22), driver_info: 6 },
394 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23), driver_info: 7 },
395 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24), driver_info: 8 },
396 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30), driver_info: 9 },
397 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31), driver_info: 10 },
398 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32), driver_info: 11 },
399 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33), driver_info: 12 },
400 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34), driver_info: 13 },
401 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35), driver_info: 14 },
402 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41), driver_info: 15 },
403 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42), driver_info: 16 },
404 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43), driver_info: 17 },
405 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44), driver_info: 18 },
406 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45), driver_info: 19 },
410 MODULE_DEVICE_TABLE(usb, wacom_ids);
412 static int wacom_open(struct input_dev *dev)
414 struct wacom *wacom = dev->private;
419 wacom->irq.dev = wacom->usbdev;
420 if (usb_submit_urb(&wacom->irq))
426 static void wacom_close(struct input_dev *dev)
428 struct wacom *wacom = dev->private;
431 usb_unlink_urb(&wacom->irq);
434 static void *wacom_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id)
436 struct usb_endpoint_descriptor *endpoint;
438 char rep_data[2] = {0x02, 0x02};
440 if (!(wacom = kmalloc(sizeof(struct wacom), GFP_KERNEL))) return NULL;
441 memset(wacom, 0, sizeof(struct wacom));
443 wacom->features = wacom_features + id->driver_info;
445 wacom->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC) | wacom->features->evbit;
446 wacom->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE) | BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) | wacom->features->absbit;
447 wacom->dev.relbit[0] |= wacom->features->relbit;
448 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | wacom->features->btnbit;
449 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) |
450 BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2) | wacom->features->digibit;
451 wacom->dev.mscbit[0] |= BIT(MSC_SERIAL);
453 wacom->dev.absmax[ABS_X] = wacom->features->x_max;
454 wacom->dev.absmax[ABS_Y] = wacom->features->y_max;
455 wacom->dev.absmax[ABS_PRESSURE] = wacom->features->pressure_max;
456 wacom->dev.absmax[ABS_DISTANCE] = wacom->features->distance_max;
457 wacom->dev.absmax[ABS_TILT_X] = 127;
458 wacom->dev.absmax[ABS_TILT_Y] = 127;
459 wacom->dev.absmax[ABS_WHEEL] = 1023;
461 wacom->dev.absmin[ABS_RZ] = -900;
462 wacom->dev.absmax[ABS_RZ] = 899;
463 wacom->dev.absmin[ABS_THROTTLE] = -1023;
464 wacom->dev.absmax[ABS_THROTTLE] = 1023;
466 wacom->dev.absfuzz[ABS_X] = 4;
467 wacom->dev.absfuzz[ABS_Y] = 4;
469 wacom->dev.private = wacom;
470 wacom->dev.open = wacom_open;
471 wacom->dev.close = wacom_close;
473 wacom->dev.name = wacom->features->name;
474 wacom->dev.idbus = BUS_USB;
475 wacom->dev.idvendor = dev->descriptor.idVendor;
476 wacom->dev.idproduct = dev->descriptor.idProduct;
477 wacom->dev.idversion = dev->descriptor.bcdDevice;
480 endpoint = dev->config[0].interface[ifnum].altsetting[0].endpoint + 0;
482 usb_set_idle(dev, dev->config[0].interface[ifnum].altsetting[0].bInterfaceNumber, 0, 0);
484 FILL_INT_URB(&wacom->irq, dev, usb_rcvintpipe(dev, endpoint->bEndpointAddress),
485 wacom->data, wacom->features->pktlen, wacom->features->irq, wacom, endpoint->bInterval);
487 input_register_device(&wacom->dev);
489 /* ask the tablet to report tablet data */
490 usb_set_report(dev, ifnum, 3, 2, rep_data, 2);
491 usb_set_report(dev, ifnum, 3, 5, rep_data, 0);
492 usb_set_report(dev, ifnum, 3, 6, rep_data, 0);
494 printk(KERN_INFO "input%d: %s on usb%d:%d.%d\n",
495 wacom->dev.number, wacom->features->name, dev->bus->busnum, dev->devnum, ifnum);
500 static void wacom_disconnect(struct usb_device *dev, void *ptr)
502 struct wacom *wacom = ptr;
503 usb_unlink_urb(&wacom->irq);
504 input_unregister_device(&wacom->dev);
508 static struct usb_driver wacom_driver = {
511 disconnect: wacom_disconnect,
515 static int __init wacom_init(void)
517 usb_register(&wacom_driver);
518 info(DRIVER_VERSION " " DRIVER_AUTHOR);
523 static void __exit wacom_exit(void)
525 usb_deregister(&wacom_driver);
528 module_init(wacom_init);
529 module_exit(wacom_exit);