blob: 48df4cfd5a42274b7a756f37ce6869c646a590e3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Ping Chengb2f86362005-06-06 02:25:50 -050012 * Copyright (c) 2002-2005 Ping Cheng <pingc@wacom.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
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,
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -050021 * they belong in userspace
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * 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, ...
Ping Chengb2f86362005-06-06 02:25:50 -050054 * v1.43 (pc) - Added support for Cintiq 21UX
Ping Chengebb6f372005-11-17 09:46:51 -080055 * - Fixed a Graphire bug
56 * - Merged wacom_intuos3_irq into wacom_intuos_irq
57 * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc.
58 * - Report Device IDs
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 */
60
61/*
62 * This program is free software; you can redistribute it and/or modify
63 * it under the terms of the GNU General Public License as published by
64 * the Free Software Foundation; either version 2 of the License, or
65 * (at your option) any later version.
66 */
67
68#include <linux/kernel.h>
69#include <linux/slab.h>
70#include <linux/input.h>
71#include <linux/module.h>
72#include <linux/init.h>
73#include <linux/usb.h>
Dmitry Torokhov16a334c2005-06-30 00:49:08 -050074#include <linux/usb_input.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#include <asm/unaligned.h>
76#include <asm/byteorder.h>
77
78/*
79 * Version Information
80 */
Ping Chengebb6f372005-11-17 09:46:51 -080081#define DRIVER_VERSION "v1.44"
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
83#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
84#define DRIVER_LICENSE "GPL"
85
86MODULE_AUTHOR(DRIVER_AUTHOR);
87MODULE_DESCRIPTION(DRIVER_DESC);
88MODULE_LICENSE(DRIVER_LICENSE);
89
90#define USB_VENDOR_ID_WACOM 0x056a
Ping Chengebb6f372005-11-17 09:46:51 -080091#define STYLUS_DEVICE_ID 0x02
92#define CURSOR_DEVICE_ID 0x06
93#define ERASER_DEVICE_ID 0x0A
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Ping Chengb2f86362005-06-06 02:25:50 -050095enum {
96 PENPARTNER = 0,
97 GRAPHIRE,
Ping Chengebb6f372005-11-17 09:46:51 -080098 G4,
Ping Chengb2f86362005-06-06 02:25:50 -050099 PL,
100 INTUOS,
101 INTUOS3,
102 CINTIQ,
103 MAX_TYPE
104};
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106struct wacom_features {
107 char *name;
108 int pktlen;
109 int x_max;
110 int y_max;
111 int pressure_max;
112 int distance_max;
113 int type;
114 usb_complete_t irq;
115};
116
117struct wacom {
118 signed char *data;
119 dma_addr_t data_dma;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500120 struct input_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 struct usb_device *usbdev;
122 struct urb *irq;
123 struct wacom_features *features;
124 int tool[2];
Ping Chengebb6f372005-11-17 09:46:51 -0800125 int id[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 __u32 serial[2];
127 char phys[32];
128};
129
130#define USB_REQ_SET_REPORT 0x09
131static int usb_set_report(struct usb_interface *intf, unsigned char type,
132 unsigned char id, void *buf, int size)
133{
134 return usb_control_msg(interface_to_usbdev(intf),
135 usb_sndctrlpipe(interface_to_usbdev(intf), 0),
136 USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
137 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
138 buf, size, 1000);
139}
140
141static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
142{
143 struct wacom *wacom = urb->context;
144 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500145 struct input_dev *dev = wacom->dev;
Ping Chengebb6f372005-11-17 09:46:51 -0800146 int prox, pressure, id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 int retval;
148
149 switch (urb->status) {
150 case 0:
151 /* success */
152 break;
153 case -ECONNRESET:
154 case -ENOENT:
155 case -ESHUTDOWN:
156 /* this urb is terminated, clean up */
157 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
158 return;
159 default:
160 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
161 goto exit;
162 }
163
164 if (data[0] != 2) {
165 dbg("wacom_pl_irq: received unknown report #%d", data[0]);
166 goto exit;
167 }
168
169 prox = data[1] & 0x40;
170
171 input_regs(dev, regs);
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500172
Ping Chengebb6f372005-11-17 09:46:51 -0800173 id = ERASER_DEVICE_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (prox) {
175
176 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
177 if (wacom->features->pressure_max > 255)
178 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
179 pressure += (wacom->features->pressure_max + 1) / 2;
180
181 /*
182 * if going from out of proximity into proximity select between the eraser
183 * and the pen based on the state of the stylus2 button, choose eraser if
184 * pressed else choose pen. if not a proximity change from out to in, send
185 * an out of proximity for previous tool then a in for new tool.
186 */
187 if (!wacom->tool[0]) {
Ping Chengebb6f372005-11-17 09:46:51 -0800188 /* Eraser bit set for DTF */
189 if (data[1] & 0x10)
190 wacom->tool[1] = BTN_TOOL_RUBBER;
191 else
192 /* Going into proximity select tool */
193 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
Dmitry Torokhove5119882005-06-06 02:28:29 -0500194 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 /* was entered with stylus2 pressed */
Ping Chengebb6f372005-11-17 09:46:51 -0800196 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /* report out proximity for previous tool */
198 input_report_key(dev, wacom->tool[1], 0);
199 input_sync(dev);
200 wacom->tool[1] = BTN_TOOL_PEN;
201 goto exit;
202 }
203 }
204 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
205 /* Unknown tool selected default to pen tool */
206 wacom->tool[1] = BTN_TOOL_PEN;
Ping Chengebb6f372005-11-17 09:46:51 -0800207 id = STYLUS_DEVICE_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 }
Ping Chengebb6f372005-11-17 09:46:51 -0800209 input_report_key(dev, wacom->tool[1], id); /* report in proximity for tool */
Ping Chengb2f86362005-06-06 02:25:50 -0500210 input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
211 input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 input_report_abs(dev, ABS_PRESSURE, pressure);
213
214 input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
215 input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
216 /* Only allow the stylus2 button to be reported for the pen tool. */
217 input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
Dmitry Torokhove5119882005-06-06 02:28:29 -0500218 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 /* report proximity-out of a (valid) tool */
220 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
221 /* Unknown tool selected default to pen tool */
222 wacom->tool[1] = BTN_TOOL_PEN;
223 }
224 input_report_key(dev, wacom->tool[1], prox);
225 }
226
227 wacom->tool[0] = prox; /* Save proximity state */
228 input_sync(dev);
229
Dmitry Torokhove5119882005-06-06 02:28:29 -0500230 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 retval = usb_submit_urb (urb, GFP_ATOMIC);
232 if (retval)
233 err ("%s - usb_submit_urb failed with result %d",
234 __FUNCTION__, retval);
235}
236
237static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
238{
239 struct wacom *wacom = urb->context;
240 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500241 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 int retval;
243
244 switch (urb->status) {
245 case 0:
246 /* success */
247 break;
248 case -ECONNRESET:
249 case -ENOENT:
250 case -ESHUTDOWN:
251 /* this urb is terminated, clean up */
252 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
253 return;
254 default:
255 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
256 goto exit;
257 }
258
Dmitry Torokhove5119882005-06-06 02:28:29 -0500259 if (data[0] != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
261 goto exit;
262 }
263
264 input_regs(dev, regs);
Dmitry Torokhove5119882005-06-06 02:28:29 -0500265 if (data[1] & 0x04) {
Ping Chengebb6f372005-11-17 09:46:51 -0800266 input_report_key(dev, BTN_TOOL_RUBBER, (data[1] & 0x20) ? ERASER_DEVICE_ID : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
Dmitry Torokhove5119882005-06-06 02:28:29 -0500268 } else {
Ping Chengebb6f372005-11-17 09:46:51 -0800269 input_report_key(dev, BTN_TOOL_PEN, (data[1] & 0x20) ? STYLUS_DEVICE_ID : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
271 }
272 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[2]));
273 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[4]));
274 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
275 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
276 input_report_key(dev, BTN_STYLUS2, data[1] & 0x10);
277
278 input_sync(dev);
279
Dmitry Torokhove5119882005-06-06 02:28:29 -0500280 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 retval = usb_submit_urb (urb, GFP_ATOMIC);
282 if (retval)
283 err ("%s - usb_submit_urb failed with result %d",
284 __FUNCTION__, retval);
285}
286
287static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
288{
289 struct wacom *wacom = urb->context;
290 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500291 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 int retval;
293
294 switch (urb->status) {
295 case 0:
296 /* success */
297 break;
298 case -ECONNRESET:
299 case -ENOENT:
300 case -ESHUTDOWN:
301 /* this urb is terminated, clean up */
302 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
303 return;
304 default:
305 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
306 goto exit;
307 }
308
309 if (data[0] != 2) {
310 printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
311 goto exit;
312 }
313
314 input_regs(dev, regs);
Ping Chengebb6f372005-11-17 09:46:51 -0800315 input_report_key(dev, BTN_TOOL_PEN, STYLUS_DEVICE_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[1]));
317 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[3]));
318 input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127);
319 input_report_key(dev, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
320 input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
321 input_sync(dev);
322
Dmitry Torokhove5119882005-06-06 02:28:29 -0500323 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 retval = usb_submit_urb (urb, GFP_ATOMIC);
325 if (retval)
326 err ("%s - usb_submit_urb failed with result %d",
327 __FUNCTION__, retval);
328}
329
330static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
331{
332 struct wacom *wacom = urb->context;
333 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500334 struct input_dev *dev = wacom->dev;
Ping Chengebb6f372005-11-17 09:46:51 -0800335 int x, y, id, rw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 int retval;
337
338 switch (urb->status) {
339 case 0:
340 /* success */
341 break;
342 case -ECONNRESET:
343 case -ENOENT:
344 case -ESHUTDOWN:
345 /* this urb is terminated, clean up */
346 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
347 return;
348 default:
349 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
350 goto exit;
351 }
352
353 if (data[0] != 2) {
354 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
355 goto exit;
356 }
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 input_regs(dev, regs);
359
Ping Chengebb6f372005-11-17 09:46:51 -0800360 id = STYLUS_DEVICE_ID;
Dmitry Torokhove5119882005-06-06 02:28:29 -0500361 if (data[1] & 0x10) { /* in prox */
362
Ping Chengb2f86362005-06-06 02:25:50 -0500363 switch ((data[1] >> 5) & 3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Ping Chengb2f86362005-06-06 02:25:50 -0500365 case 0: /* Pen */
366 wacom->tool[0] = BTN_TOOL_PEN;
367 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Ping Chengb2f86362005-06-06 02:25:50 -0500369 case 1: /* Rubber */
370 wacom->tool[0] = BTN_TOOL_RUBBER;
Ping Chengebb6f372005-11-17 09:46:51 -0800371 id = ERASER_DEVICE_ID;
Ping Chengb2f86362005-06-06 02:25:50 -0500372 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Ping Chengb2f86362005-06-06 02:25:50 -0500374 case 2: /* Mouse with wheel */
375 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
Ping Chengebb6f372005-11-17 09:46:51 -0800376 if (wacom->features->type == G4) {
377 rw = data[7] & 0x04 ? -(data[7] & 0x03) : (data[7] & 0x03);
378 input_report_rel(dev, REL_WHEEL, rw);
379 } else
380 input_report_rel(dev, REL_WHEEL, (signed char) data[6]);
Ping Chengb2f86362005-06-06 02:25:50 -0500381 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Dmitry Torokhove5119882005-06-06 02:28:29 -0500383 case 3: /* Mouse without wheel */
Ping Chengb2f86362005-06-06 02:25:50 -0500384 wacom->tool[0] = BTN_TOOL_MOUSE;
Ping Chengebb6f372005-11-17 09:46:51 -0800385 id = CURSOR_DEVICE_ID;
Ping Chengb2f86362005-06-06 02:25:50 -0500386 input_report_key(dev, BTN_LEFT, data[1] & 0x01);
387 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
Ping Chengebb6f372005-11-17 09:46:51 -0800388 if (wacom->features->type == G4)
389 input_report_abs(dev, ABS_DISTANCE, data[6]);
390 else
391 input_report_abs(dev, ABS_DISTANCE, data[7]);
Ping Chengb2f86362005-06-06 02:25:50 -0500392 break;
393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 }
395
Ping Chengdc1d97e2005-08-16 15:16:32 -0700396 if (data[1] & 0x90) {
397 x = le16_to_cpu(*(__le16 *) &data[2]);
398 y = le16_to_cpu(*(__le16 *) &data[4]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 input_report_abs(dev, ABS_X, x);
400 input_report_abs(dev, ABS_Y, y);
Ping Chengdc1d97e2005-08-16 15:16:32 -0700401 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
Ping Chengebb6f372005-11-17 09:46:51 -0800402 input_report_abs(dev, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8));
Ping Chengdc1d97e2005-08-16 15:16:32 -0700403 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
404 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
405 input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
406 }
Ping Chengb2f86362005-06-06 02:25:50 -0500407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Ping Chengebb6f372005-11-17 09:46:51 -0800409 input_report_key(dev, wacom->tool[0], (data[1] & 0x10) ? id : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 input_sync(dev);
411
Ping Chengebb6f372005-11-17 09:46:51 -0800412 /* send pad data */
413 if (wacom->features->type == G4) {
414 /* fist time sending pad data */
415 if (wacom->tool[1] != BTN_TOOL_FINGER) {
416 wacom->id[1] = 0;
417 wacom->serial[1] = (data[7] & 0x38) >> 2;
418 }
419 if (data[7] & 0xf8) {
420 input_report_key(dev, BTN_0, (data[7] & 0x40));
421 input_report_key(dev, BTN_4, (data[7] & 0x80));
422 if (((data[7] & 0x38) >> 2) == (wacom->serial[1] & 0x0e))
423 /* alter REL_WHEEL value so X apps can get it */
424 wacom->serial[1] += (wacom->serial[1] & 0x01) ? -1 : 1;
425 else
426 wacom->serial[1] = (data[7] & 0x38 ) >> 2;
427
428 /* don't alter the value when there is no wheel event */
429 if (wacom->serial[1] == 1)
430 wacom->serial[1] = 0;
431 rw = wacom->serial[1];
432 rw = (rw & 0x08) ? -(rw & 0x07) : (rw & 0x07);
433 input_report_rel(dev, REL_WHEEL, rw);
434 wacom->tool[1] = BTN_TOOL_FINGER;
435 wacom->id[1] = data[7] & 0xf8;
436 input_report_key(dev, wacom->tool[1], 0xf0);
437 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
438 } else if (wacom->id[1]) {
439 wacom->id[1] = 0;
440 wacom->serial[1] = 0;
441 input_report_key(dev, wacom->tool[1], 0);
442 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
443 }
444 input_sync(dev);
445 }
Dmitry Torokhove5119882005-06-06 02:28:29 -0500446 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 retval = usb_submit_urb (urb, GFP_ATOMIC);
448 if (retval)
449 err ("%s - usb_submit_urb failed with result %d",
450 __FUNCTION__, retval);
451}
452
453static int wacom_intuos_inout(struct urb *urb)
454{
455 struct wacom *wacom = urb->context;
456 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500457 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 int idx;
459
460 /* tool number */
461 idx = data[1] & 0x01;
462
463 /* Enter report */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500464 if ((data[1] & 0xfc) == 0xc0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /* serial number of the tool */
Ping Chengb2f86362005-06-06 02:25:50 -0500466 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
467 (data[4] << 20) + (data[5] << 12) +
468 (data[6] << 4) + (data[7] >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Ping Chengebb6f372005-11-17 09:46:51 -0800470 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
471 switch (wacom->id[idx]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 case 0x812: /* Inking pen */
473 case 0x801: /* Intuos3 Inking pen */
474 case 0x012:
475 wacom->tool[idx] = BTN_TOOL_PENCIL;
476 break;
477 case 0x822: /* Pen */
478 case 0x842:
479 case 0x852:
480 case 0x823: /* Intuos3 Grip Pen */
481 case 0x813: /* Intuos3 Classic Pen */
482 case 0x885: /* Intuos3 Marker Pen */
483 case 0x022:
484 wacom->tool[idx] = BTN_TOOL_PEN;
485 break;
486 case 0x832: /* Stroke pen */
487 case 0x032:
488 wacom->tool[idx] = BTN_TOOL_BRUSH;
489 break;
490 case 0x007: /* Mouse 4D and 2D */
491 case 0x09c:
492 case 0x094:
493 case 0x017: /* Intuos3 2D Mouse */
494 wacom->tool[idx] = BTN_TOOL_MOUSE;
495 break;
496 case 0x096: /* Lens cursor */
497 case 0x097: /* Intuos3 Lens cursor */
498 wacom->tool[idx] = BTN_TOOL_LENS;
499 break;
500 case 0x82a: /* Eraser */
501 case 0x85a:
502 case 0x91a:
503 case 0xd1a:
504 case 0x0fa:
505 case 0x82b: /* Intuos3 Grip Pen Eraser */
506 case 0x81b: /* Intuos3 Classic Pen Eraser */
507 case 0x91b: /* Intuos3 Airbrush Eraser */
508 wacom->tool[idx] = BTN_TOOL_RUBBER;
509 break;
510 case 0xd12:
511 case 0x912:
512 case 0x112:
513 case 0x913: /* Intuos3 Airbrush */
514 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
Ping Chengb2f86362005-06-06 02:25:50 -0500515 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 default: /* Unknown tool */
517 wacom->tool[idx] = BTN_TOOL_PEN;
518 }
Ping Chengebb6f372005-11-17 09:46:51 -0800519 input_report_key(dev, wacom->tool[idx], wacom->id[idx]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
521 input_sync(dev);
522 return 1;
523 }
524
525 /* Exit report */
526 if ((data[1] & 0xfe) == 0x80) {
527 input_report_key(dev, wacom->tool[idx], 0);
528 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
529 input_sync(dev);
530 return 1;
531 }
532
533 return 0;
534}
535
536static void wacom_intuos_general(struct urb *urb)
537{
538 struct wacom *wacom = urb->context;
539 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500540 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 unsigned int t;
542
543 /* general pen packet */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500544 if ((data[1] & 0xb8) == 0xa0) {
Ping Chengb2f86362005-06-06 02:25:50 -0500545 t = (data[6] << 2) | ((data[7] >> 6) & 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 input_report_abs(dev, ABS_PRESSURE, t);
547 input_report_abs(dev, ABS_TILT_X,
548 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
549 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
550 input_report_key(dev, BTN_STYLUS, data[1] & 2);
551 input_report_key(dev, BTN_STYLUS2, data[1] & 4);
552 input_report_key(dev, BTN_TOUCH, t > 10);
553 }
554
555 /* airbrush second packet */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500556 if ((data[1] & 0xbc) == 0xb4) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 input_report_abs(dev, ABS_WHEEL,
Ping Chengb2f86362005-06-06 02:25:50 -0500558 (data[6] << 2) | ((data[7] >> 6) & 3));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 input_report_abs(dev, ABS_TILT_X,
560 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
561 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
562 }
563 return;
564}
565
566static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
567{
568 struct wacom *wacom = urb->context;
569 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500570 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 unsigned int t;
572 int idx;
573 int retval;
574
575 switch (urb->status) {
576 case 0:
577 /* success */
578 break;
579 case -ECONNRESET:
580 case -ENOENT:
581 case -ESHUTDOWN:
582 /* this urb is terminated, clean up */
583 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
584 return;
585 default:
586 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
587 goto exit;
588 }
589
Ping Chengb2f86362005-06-06 02:25:50 -0500590 if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
592 goto exit;
593 }
594
595 input_regs(dev, regs);
596
597 /* tool number */
598 idx = data[1] & 0x01;
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 /* pad packets. Works as a second tool and is always in prox */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500601 if (data[0] == 12) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /* initiate the pad as a device */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500603 if (wacom->tool[1] != BTN_TOOL_FINGER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 wacom->tool[1] = BTN_TOOL_FINGER;
605 input_report_key(dev, wacom->tool[1], 1);
606 }
607 input_report_key(dev, BTN_0, (data[5] & 0x01));
608 input_report_key(dev, BTN_1, (data[5] & 0x02));
609 input_report_key(dev, BTN_2, (data[5] & 0x04));
610 input_report_key(dev, BTN_3, (data[5] & 0x08));
611 input_report_key(dev, BTN_4, (data[6] & 0x01));
612 input_report_key(dev, BTN_5, (data[6] & 0x02));
613 input_report_key(dev, BTN_6, (data[6] & 0x04));
614 input_report_key(dev, BTN_7, (data[6] & 0x08));
615 input_report_abs(dev, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
616 input_report_abs(dev, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
617 input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff);
618 input_sync(dev);
619 goto exit;
620 }
621
622 /* process in/out prox events */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500623 if (wacom_intuos_inout(urb))
624 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Ping Chengb2f86362005-06-06 02:25:50 -0500626 /* Cintiq doesn't send data when RDY bit isn't set */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500627 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
Ping Chengdc1d97e2005-08-16 15:16:32 -0700628 goto exit;
Ping Chengb2f86362005-06-06 02:25:50 -0500629
Dmitry Torokhove5119882005-06-06 02:28:29 -0500630 if (wacom->features->type >= INTUOS3) {
Ping Chengb2f86362005-06-06 02:25:50 -0500631 input_report_abs(dev, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
632 input_report_abs(dev, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
633 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
Dmitry Torokhove5119882005-06-06 02:28:29 -0500634 } else {
Ping Chengb2f86362005-06-06 02:25:50 -0500635 input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
636 input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
637 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 /* process general packets */
641 wacom_intuos_general(urb);
642
Ping Chengb2f86362005-06-06 02:25:50 -0500643 /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
644 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
Dmitry Torokhove5119882005-06-06 02:28:29 -0500645
646 if (data[1] & 0x02) {
647 /* Rotation packet */
648 if (wacom->features->type >= INTUOS3) {
Ping Chengb2f86362005-06-06 02:25:50 -0500649 /* I3 marker pen rotation reported as wheel
650 * due to valuator limitation
651 */
652 t = (data[6] << 3) | ((data[7] >> 5) & 7);
653 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
654 ((t-1) / 2 + 450)) : (450 - t / 2) ;
655 input_report_abs(dev, ABS_WHEEL, t);
Dmitry Torokhove5119882005-06-06 02:28:29 -0500656 } else {
Ping Chengb2f86362005-06-06 02:25:50 -0500657 /* 4D mouse rotation packet */
658 t = (data[6] << 3) | ((data[7] >> 5) & 7);
659 input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ?
660 ((t - 1) / 2) : -t / 2);
661 }
Dmitry Torokhove5119882005-06-06 02:28:29 -0500662
663 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3) {
664 /* 4D mouse packet */
Ping Chengb2f86362005-06-06 02:25:50 -0500665 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
666 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
667 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Ping Chengb2f86362005-06-06 02:25:50 -0500669 input_report_key(dev, BTN_SIDE, data[8] & 0x20);
670 input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
671 t = (data[6] << 2) | ((data[7] >> 6) & 3);
672 input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
Dmitry Torokhove5119882005-06-06 02:28:29 -0500673
674 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
675 /* 2D mouse packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 input_report_key(dev, BTN_LEFT, data[8] & 0x04);
677 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
678 input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
Ping Chengb2f86362005-06-06 02:25:50 -0500679 input_report_rel(dev, REL_WHEEL, ((data[8] & 0x02) >> 1)
Dmitry Torokhove5119882005-06-06 02:28:29 -0500680 - (data[8] & 0x01));
Ping Chengb2f86362005-06-06 02:25:50 -0500681
682 /* I3 2D mouse side buttons */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500683 if (wacom->features->type == INTUOS3) {
Ping Chengb2f86362005-06-06 02:25:50 -0500684 input_report_key(dev, BTN_SIDE, data[8] & 0x40);
685 input_report_key(dev, BTN_EXTRA, data[8] & 0x20);
686 }
Dmitry Torokhove5119882005-06-06 02:28:29 -0500687
688 } else if (wacom->features->type < INTUOS3) {
689 /* Lens cursor packets */
Ping Chengb2f86362005-06-06 02:25:50 -0500690 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
691 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
692 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
693 input_report_key(dev, BTN_SIDE, data[8] & 0x10);
694 input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696 }
697
Ping Chengebb6f372005-11-17 09:46:51 -0800698 input_report_key(dev, wacom->tool[idx], wacom->id[idx]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
700 input_sync(dev);
701
702exit:
703 retval = usb_submit_urb (urb, GFP_ATOMIC);
704 if (retval)
705 err ("%s - usb_submit_urb failed with result %d",
706 __FUNCTION__, retval);
707}
708
709static struct wacom_features wacom_features[] = {
Dmitry Torokhove5119882005-06-06 02:28:29 -0500710 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, PENPARTNER, wacom_penpartner_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500711 { "Wacom Graphire", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
712 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
Dmitry Torokhove5119882005-06-06 02:28:29 -0500713 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500714 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq },
715 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq },
Ping Chengebb6f372005-11-17 09:46:51 -0800716 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 32, G4, wacom_graphire_irq },
717 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 32, G4, wacom_graphire_irq },
718 { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
719 { "Wacom PenStation2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
720 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
721 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 32, GRAPHIRE, wacom_graphire_irq },
722 { "Wacom PenPartner2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
Dmitry Torokhove5119882005-06-06 02:28:29 -0500723 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
724 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
725 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
726 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
727 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
728 { "Wacom PL400", 8, 5408, 4056, 255, 32, PL, wacom_pl_irq },
729 { "Wacom PL500", 8, 6144, 4608, 255, 32, PL, wacom_pl_irq },
730 { "Wacom PL600", 8, 6126, 4604, 255, 32, PL, wacom_pl_irq },
731 { "Wacom PL600SX", 8, 6260, 5016, 255, 32, PL, wacom_pl_irq },
732 { "Wacom PL550", 8, 6144, 4608, 511, 32, PL, wacom_pl_irq },
733 { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq },
Ping Chengebb6f372005-11-17 09:46:51 -0800734 { "Wacom PL700", 8, 6758, 5406, 511, 32, PL, wacom_pl_irq },
735 { "Wacom PL510", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
736 { "Wacom PL710", 8, 34080, 27660, 511, 32, PL, wacom_pl_irq },
737 { "Wacom DTF720", 8, 6858, 5506, 511, 32, PL, wacom_pl_irq },
738 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500739 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
740 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
741 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
742 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
743 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500744 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq },
745 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq },
746 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq },
Ping Chengebb6f372005-11-17 09:46:51 -0800747 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 15, INTUOS3, wacom_intuos_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500748 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq },
749 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500750 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751};
752
753static struct usb_device_id wacom_ids[] = {
754 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
755 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
756 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
757 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
758 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
759 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
Ping Chengebb6f372005-11-17 09:46:51 -0800760 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
761 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
762 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
763 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
764 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
765 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
766 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
768 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
769 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
770 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
771 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
772 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
773 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
774 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
775 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
776 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
777 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
Ping Chengebb6f372005-11-17 09:46:51 -0800778 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
779 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
780 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
781 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
782 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
784 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
785 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
786 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
787 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
789 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
790 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
Ping Chengebb6f372005-11-17 09:46:51 -0800791 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
Ping Chengb2f86362005-06-06 02:25:50 -0500792 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
794 { }
795};
796
797MODULE_DEVICE_TABLE(usb, wacom_ids);
798
799static int wacom_open(struct input_dev *dev)
800{
801 struct wacom *wacom = dev->private;
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 wacom->irq->dev = wacom->usbdev;
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500804 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 return 0;
808}
809
810static void wacom_close(struct input_dev *dev)
811{
812 struct wacom *wacom = dev->private;
813
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500814 usb_kill_urb(wacom->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815}
816
817static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
818{
819 struct usb_device *dev = interface_to_usbdev(intf);
820 struct usb_endpoint_descriptor *endpoint;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 struct wacom *wacom;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500822 struct input_dev *input_dev;
823 char rep_data[2] = {0x02, 0x02};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500825 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
826 input_dev = input_allocate_device();
827 if (!wacom || !input_dev)
828 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500831 if (!wacom->data)
832 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500835 if (!wacom->irq)
836 goto fail2;
837
838 wacom->usbdev = dev;
839 wacom->dev = input_dev;
840 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
841 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 wacom->features = wacom_features + (id - wacom_ids);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500844 if (wacom->features->pktlen > 10)
845 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500847 input_dev->name = wacom->features->name;
848 usb_to_input_id(dev, &input_dev->id);
849
850 input_dev->cdev.dev = &intf->dev;
851 input_dev->private = wacom;
852 input_dev->open = wacom_open;
853 input_dev->close = wacom_close;
854
855 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
856 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
Denny Priebe40c372132005-12-29 22:19:09 -0500857 input_set_abs_params(input_dev, ABS_X, 0, wacom->features->x_max, 4, 0);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500858 input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0);
859 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 switch (wacom->features->type) {
Ping Chengebb6f372005-11-17 09:46:51 -0800862 case G4:
863 input_dev->evbit[0] |= BIT(EV_MSC);
864 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
865 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
866 input_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);
867 /* fall through */
868
Ping Chengb2f86362005-06-06 02:25:50 -0500869 case GRAPHIRE:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500870 input_dev->evbit[0] |= BIT(EV_REL);
871 input_dev->relbit[0] |= BIT(REL_WHEEL);
872 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
873 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
874 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 break;
876
Ping Chengb2f86362005-06-06 02:25:50 -0500877 case INTUOS3:
878 case CINTIQ:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500879 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
880 input_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);
881 input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0);
882 input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 /* fall through */
884
Ping Chengb2f86362005-06-06 02:25:50 -0500885 case INTUOS:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500886 input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
887 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
888 input_dev->relbit[0] |= BIT(REL_WHEEL);
889 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
890 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500892 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
893 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
894 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
895 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
896 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
897 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 break;
899
Ping Chengb2f86362005-06-06 02:25:50 -0500900 case PL:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500901 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 break;
903 }
904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 endpoint = &intf->cur_altsetting->endpoint[0].desc;
906
907 if (wacom->features->pktlen > 10)
908 BUG();
909
910 usb_fill_int_urb(wacom->irq, dev,
911 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
912 wacom->data, wacom->features->pktlen,
913 wacom->features->irq, wacom, endpoint->bInterval);
914 wacom->irq->transfer_dma = wacom->data_dma;
915 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
916
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500917 input_register_device(wacom->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 /* ask the tablet to report tablet data */
920 usb_set_report(intf, 3, 2, rep_data, 2);
921 /* repeat once (not sure why the first call often fails) */
922 usb_set_report(intf, 3, 2, rep_data, 2);
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 usb_set_intfdata(intf, wacom);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 return 0;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500926
927fail2: usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
928fail1: input_free_device(input_dev);
929 kfree(wacom);
930 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
933static void wacom_disconnect(struct usb_interface *intf)
934{
935 struct wacom *wacom = usb_get_intfdata (intf);
936
937 usb_set_intfdata(intf, NULL);
938 if (wacom) {
939 usb_kill_urb(wacom->irq);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500940 input_unregister_device(wacom->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 usb_free_urb(wacom->irq);
942 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma);
943 kfree(wacom);
944 }
945}
946
947static struct usb_driver wacom_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 .name = "wacom",
949 .probe = wacom_probe,
950 .disconnect = wacom_disconnect,
951 .id_table = wacom_ids,
952};
953
954static int __init wacom_init(void)
955{
956 int result = usb_register(&wacom_driver);
957 if (result == 0)
958 info(DRIVER_VERSION ":" DRIVER_DESC);
959 return result;
960}
961
962static void __exit wacom_exit(void)
963{
964 usb_deregister(&wacom_driver);
965}
966
967module_init(wacom_init);
968module_exit(wacom_exit);