blob: cf84c6096f299721be8c24cb66d8baa9d43aad45 [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 Cheng7d3fe0852006-03-29 16:33:49 -080012 * Copyright (c) 2002-2006 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
Ping Cheng7d3fe0852006-03-29 16:33:49 -080059 * v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19
60 * - Minor data report fix
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 */
62
63/*
64 * This program is free software; you can redistribute it and/or modify
65 * it under the terms of the GNU General Public License as published by
66 * the Free Software Foundation; either version 2 of the License, or
67 * (at your option) any later version.
68 */
69
70#include <linux/kernel.h>
71#include <linux/slab.h>
72#include <linux/input.h>
73#include <linux/module.h>
74#include <linux/init.h>
75#include <linux/usb.h>
Dmitry Torokhov16a334c2005-06-30 00:49:08 -050076#include <linux/usb_input.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include <asm/unaligned.h>
78#include <asm/byteorder.h>
79
80/*
81 * Version Information
82 */
Ping Cheng7d3fe0852006-03-29 16:33:49 -080083#define DRIVER_VERSION "v1.45"
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
85#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
86#define DRIVER_LICENSE "GPL"
87
88MODULE_AUTHOR(DRIVER_AUTHOR);
89MODULE_DESCRIPTION(DRIVER_DESC);
90MODULE_LICENSE(DRIVER_LICENSE);
91
92#define USB_VENDOR_ID_WACOM 0x056a
Ping Chengebb6f372005-11-17 09:46:51 -080093#define STYLUS_DEVICE_ID 0x02
94#define CURSOR_DEVICE_ID 0x06
95#define ERASER_DEVICE_ID 0x0A
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Ping Chengb2f86362005-06-06 02:25:50 -050097enum {
98 PENPARTNER = 0,
99 GRAPHIRE,
Dmitry Torokhov1e27ffd2006-01-14 00:28:04 -0500100 WACOM_G4,
Ping Chengb2f86362005-06-06 02:25:50 -0500101 PL,
102 INTUOS,
103 INTUOS3,
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800104 INTUOS312,
105 INTUOS319,
Ping Chengb2f86362005-06-06 02:25:50 -0500106 CINTIQ,
107 MAX_TYPE
108};
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110struct wacom_features {
111 char *name;
112 int pktlen;
113 int x_max;
114 int y_max;
115 int pressure_max;
116 int distance_max;
117 int type;
118 usb_complete_t irq;
119};
120
121struct wacom {
122 signed char *data;
123 dma_addr_t data_dma;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500124 struct input_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 struct usb_device *usbdev;
126 struct urb *irq;
127 struct wacom_features *features;
128 int tool[2];
Ping Chengebb6f372005-11-17 09:46:51 -0800129 int id[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 __u32 serial[2];
131 char phys[32];
132};
133
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800134#define USB_REQ_GET_REPORT 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#define USB_REQ_SET_REPORT 0x09
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800136
137static int usb_get_report(struct usb_interface *intf, unsigned char type,
138 unsigned char id, void *buf, int size)
139{
140 return usb_control_msg(interface_to_usbdev(intf),
141 usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
142 USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
143 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
144 buf, size, 100);
145}
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147static int usb_set_report(struct usb_interface *intf, unsigned char type,
148 unsigned char id, void *buf, int size)
149{
150 return usb_control_msg(interface_to_usbdev(intf),
151 usb_sndctrlpipe(interface_to_usbdev(intf), 0),
152 USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
153 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
154 buf, size, 1000);
155}
156
157static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
158{
159 struct wacom *wacom = urb->context;
160 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500161 struct input_dev *dev = wacom->dev;
Ping Chengebb6f372005-11-17 09:46:51 -0800162 int prox, pressure, id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 int retval;
164
165 switch (urb->status) {
166 case 0:
167 /* success */
168 break;
169 case -ECONNRESET:
170 case -ENOENT:
171 case -ESHUTDOWN:
172 /* this urb is terminated, clean up */
173 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
174 return;
175 default:
176 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
177 goto exit;
178 }
179
180 if (data[0] != 2) {
181 dbg("wacom_pl_irq: received unknown report #%d", data[0]);
182 goto exit;
183 }
184
185 prox = data[1] & 0x40;
186
187 input_regs(dev, regs);
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500188
Ping Chengebb6f372005-11-17 09:46:51 -0800189 id = ERASER_DEVICE_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (prox) {
191
192 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
193 if (wacom->features->pressure_max > 255)
194 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
195 pressure += (wacom->features->pressure_max + 1) / 2;
196
197 /*
198 * if going from out of proximity into proximity select between the eraser
199 * and the pen based on the state of the stylus2 button, choose eraser if
200 * pressed else choose pen. if not a proximity change from out to in, send
201 * an out of proximity for previous tool then a in for new tool.
202 */
203 if (!wacom->tool[0]) {
Ping Chengebb6f372005-11-17 09:46:51 -0800204 /* Eraser bit set for DTF */
205 if (data[1] & 0x10)
206 wacom->tool[1] = BTN_TOOL_RUBBER;
207 else
208 /* Going into proximity select tool */
209 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
Dmitry Torokhove5119882005-06-06 02:28:29 -0500210 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /* was entered with stylus2 pressed */
Ping Chengebb6f372005-11-17 09:46:51 -0800212 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 /* report out proximity for previous tool */
214 input_report_key(dev, wacom->tool[1], 0);
215 input_sync(dev);
216 wacom->tool[1] = BTN_TOOL_PEN;
217 goto exit;
218 }
219 }
220 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
221 /* Unknown tool selected default to pen tool */
222 wacom->tool[1] = BTN_TOOL_PEN;
Ping Chengebb6f372005-11-17 09:46:51 -0800223 id = STYLUS_DEVICE_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800225 input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */
226 input_report_abs(dev, ABS_MISC, id); /* report tool id */
Ping Chengb2f86362005-06-06 02:25:50 -0500227 input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
228 input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 input_report_abs(dev, ABS_PRESSURE, pressure);
230
231 input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
232 input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
233 /* Only allow the stylus2 button to be reported for the pen tool. */
234 input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
Dmitry Torokhove5119882005-06-06 02:28:29 -0500235 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 /* report proximity-out of a (valid) tool */
237 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
238 /* Unknown tool selected default to pen tool */
239 wacom->tool[1] = BTN_TOOL_PEN;
240 }
241 input_report_key(dev, wacom->tool[1], prox);
242 }
243
244 wacom->tool[0] = prox; /* Save proximity state */
245 input_sync(dev);
246
Dmitry Torokhove5119882005-06-06 02:28:29 -0500247 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 retval = usb_submit_urb (urb, GFP_ATOMIC);
249 if (retval)
250 err ("%s - usb_submit_urb failed with result %d",
251 __FUNCTION__, retval);
252}
253
254static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
255{
256 struct wacom *wacom = urb->context;
257 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500258 struct input_dev *dev = wacom->dev;
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800259 int retval, id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 switch (urb->status) {
262 case 0:
263 /* success */
264 break;
265 case -ECONNRESET:
266 case -ENOENT:
267 case -ESHUTDOWN:
268 /* this urb is terminated, clean up */
269 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
270 return;
271 default:
272 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
273 goto exit;
274 }
275
Dmitry Torokhove5119882005-06-06 02:28:29 -0500276 if (data[0] != 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
278 goto exit;
279 }
280
281 input_regs(dev, regs);
Dmitry Torokhove5119882005-06-06 02:28:29 -0500282 if (data[1] & 0x04) {
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800283 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800285 id = ERASER_DEVICE_ID;
Dmitry Torokhove5119882005-06-06 02:28:29 -0500286 } else {
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800287 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800289 id = STYLUS_DEVICE_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800291 input_report_abs(dev, ABS_MISC, id); /* report tool id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[2]));
293 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[4]));
294 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
295 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
296 input_report_key(dev, BTN_STYLUS2, data[1] & 0x10);
297
298 input_sync(dev);
299
Dmitry Torokhove5119882005-06-06 02:28:29 -0500300 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 retval = usb_submit_urb (urb, GFP_ATOMIC);
302 if (retval)
303 err ("%s - usb_submit_urb failed with result %d",
304 __FUNCTION__, retval);
305}
306
307static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
308{
309 struct wacom *wacom = urb->context;
310 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500311 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 int retval;
313
314 switch (urb->status) {
315 case 0:
316 /* success */
317 break;
318 case -ECONNRESET:
319 case -ENOENT:
320 case -ESHUTDOWN:
321 /* this urb is terminated, clean up */
322 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
323 return;
324 default:
325 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
326 goto exit;
327 }
328
329 if (data[0] != 2) {
330 printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
331 goto exit;
332 }
333
334 input_regs(dev, regs);
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800335 input_report_key(dev, BTN_TOOL_PEN, 1);
336 input_report_abs(dev, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[1]));
338 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[3]));
339 input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127);
340 input_report_key(dev, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
341 input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
342 input_sync(dev);
343
Dmitry Torokhove5119882005-06-06 02:28:29 -0500344 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 retval = usb_submit_urb (urb, GFP_ATOMIC);
346 if (retval)
347 err ("%s - usb_submit_urb failed with result %d",
348 __FUNCTION__, retval);
349}
350
351static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
352{
353 struct wacom *wacom = urb->context;
354 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500355 struct input_dev *dev = wacom->dev;
Ping Chengebb6f372005-11-17 09:46:51 -0800356 int x, y, id, rw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 int retval;
358
359 switch (urb->status) {
360 case 0:
361 /* success */
362 break;
363 case -ECONNRESET:
364 case -ENOENT:
365 case -ESHUTDOWN:
366 /* this urb is terminated, clean up */
367 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
368 return;
369 default:
370 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
371 goto exit;
372 }
373
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800374 if (data[0] == 99) return; /* for Volito tablets */
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 if (data[0] != 2) {
377 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
378 goto exit;
379 }
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 input_regs(dev, regs);
382
Ping Chengebb6f372005-11-17 09:46:51 -0800383 id = STYLUS_DEVICE_ID;
Dmitry Torokhove5119882005-06-06 02:28:29 -0500384 if (data[1] & 0x10) { /* in prox */
385
Ping Chengb2f86362005-06-06 02:25:50 -0500386 switch ((data[1] >> 5) & 3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Ping Chengb2f86362005-06-06 02:25:50 -0500388 case 0: /* Pen */
389 wacom->tool[0] = BTN_TOOL_PEN;
390 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Ping Chengb2f86362005-06-06 02:25:50 -0500392 case 1: /* Rubber */
393 wacom->tool[0] = BTN_TOOL_RUBBER;
Ping Chengebb6f372005-11-17 09:46:51 -0800394 id = ERASER_DEVICE_ID;
Ping Chengb2f86362005-06-06 02:25:50 -0500395 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Ping Chengb2f86362005-06-06 02:25:50 -0500397 case 2: /* Mouse with wheel */
398 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
Dmitry Torokhov1e27ffd2006-01-14 00:28:04 -0500399 if (wacom->features->type == WACOM_G4) {
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800400 rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
401 input_report_rel(dev, REL_WHEEL, -rw);
Ping Chengebb6f372005-11-17 09:46:51 -0800402 } else
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800403 input_report_rel(dev, REL_WHEEL, -(signed char) data[6]);
Ping Chengb2f86362005-06-06 02:25:50 -0500404 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Dmitry Torokhove5119882005-06-06 02:28:29 -0500406 case 3: /* Mouse without wheel */
Ping Chengb2f86362005-06-06 02:25:50 -0500407 wacom->tool[0] = BTN_TOOL_MOUSE;
Ping Chengebb6f372005-11-17 09:46:51 -0800408 id = CURSOR_DEVICE_ID;
Ping Chengb2f86362005-06-06 02:25:50 -0500409 input_report_key(dev, BTN_LEFT, data[1] & 0x01);
410 input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
Dmitry Torokhov1e27ffd2006-01-14 00:28:04 -0500411 if (wacom->features->type == WACOM_G4)
Ping Chengebb6f372005-11-17 09:46:51 -0800412 input_report_abs(dev, ABS_DISTANCE, data[6]);
413 else
414 input_report_abs(dev, ABS_DISTANCE, data[7]);
Ping Chengb2f86362005-06-06 02:25:50 -0500415 break;
416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
418
Ping Chengdc1d97e2005-08-16 15:16:32 -0700419 if (data[1] & 0x90) {
420 x = le16_to_cpu(*(__le16 *) &data[2]);
421 y = le16_to_cpu(*(__le16 *) &data[4]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 input_report_abs(dev, ABS_X, x);
423 input_report_abs(dev, ABS_Y, y);
Ping Chengdc1d97e2005-08-16 15:16:32 -0700424 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
Ping Chengebb6f372005-11-17 09:46:51 -0800425 input_report_abs(dev, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8));
Ping Chengdc1d97e2005-08-16 15:16:32 -0700426 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
427 input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
428 input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
429 }
Ping Chengb2f86362005-06-06 02:25:50 -0500430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800432 if (data[1] & 0x10)
433 input_report_abs(dev, ABS_MISC, id); /* report tool id */
434 else
435 input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
436 input_report_key(dev, wacom->tool[0], data[1] & 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 input_sync(dev);
438
Ping Chengebb6f372005-11-17 09:46:51 -0800439 /* send pad data */
Dmitry Torokhov1e27ffd2006-01-14 00:28:04 -0500440 if (wacom->features->type == WACOM_G4) {
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800441 if ((wacom->serial[1] & 0xc0) != (data[7] & 0xf8)) {
442 wacom->id[1] = 1;
443 wacom->serial[1] = (data[7] & 0xf8);
Ping Chengebb6f372005-11-17 09:46:51 -0800444 input_report_key(dev, BTN_0, (data[7] & 0x40));
445 input_report_key(dev, BTN_4, (data[7] & 0x80));
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800446 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
Ping Chengebb6f372005-11-17 09:46:51 -0800447 input_report_rel(dev, REL_WHEEL, rw);
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800448 input_report_key(dev, BTN_TOOL_FINGER, 0xf0);
Ping Chengebb6f372005-11-17 09:46:51 -0800449 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
450 } else if (wacom->id[1]) {
451 wacom->id[1] = 0;
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800452 input_report_key(dev, BTN_TOOL_FINGER, 0);
Ping Chengebb6f372005-11-17 09:46:51 -0800453 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
454 }
455 input_sync(dev);
456 }
Dmitry Torokhove5119882005-06-06 02:28:29 -0500457 exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 retval = usb_submit_urb (urb, GFP_ATOMIC);
459 if (retval)
460 err ("%s - usb_submit_urb failed with result %d",
461 __FUNCTION__, retval);
462}
463
464static int wacom_intuos_inout(struct urb *urb)
465{
466 struct wacom *wacom = urb->context;
467 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500468 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 int idx;
470
471 /* tool number */
472 idx = data[1] & 0x01;
473
474 /* Enter report */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500475 if ((data[1] & 0xfc) == 0xc0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 /* serial number of the tool */
Ping Chengb2f86362005-06-06 02:25:50 -0500477 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
478 (data[4] << 20) + (data[5] << 12) +
479 (data[6] << 4) + (data[7] >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Ping Chengebb6f372005-11-17 09:46:51 -0800481 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
482 switch (wacom->id[idx]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 case 0x812: /* Inking pen */
484 case 0x801: /* Intuos3 Inking pen */
485 case 0x012:
486 wacom->tool[idx] = BTN_TOOL_PENCIL;
487 break;
488 case 0x822: /* Pen */
489 case 0x842:
490 case 0x852:
491 case 0x823: /* Intuos3 Grip Pen */
492 case 0x813: /* Intuos3 Classic Pen */
493 case 0x885: /* Intuos3 Marker Pen */
494 case 0x022:
495 wacom->tool[idx] = BTN_TOOL_PEN;
496 break;
497 case 0x832: /* Stroke pen */
498 case 0x032:
499 wacom->tool[idx] = BTN_TOOL_BRUSH;
500 break;
501 case 0x007: /* Mouse 4D and 2D */
502 case 0x09c:
503 case 0x094:
504 case 0x017: /* Intuos3 2D Mouse */
505 wacom->tool[idx] = BTN_TOOL_MOUSE;
506 break;
507 case 0x096: /* Lens cursor */
508 case 0x097: /* Intuos3 Lens cursor */
509 wacom->tool[idx] = BTN_TOOL_LENS;
510 break;
511 case 0x82a: /* Eraser */
512 case 0x85a:
513 case 0x91a:
514 case 0xd1a:
515 case 0x0fa:
516 case 0x82b: /* Intuos3 Grip Pen Eraser */
517 case 0x81b: /* Intuos3 Classic Pen Eraser */
518 case 0x91b: /* Intuos3 Airbrush Eraser */
519 wacom->tool[idx] = BTN_TOOL_RUBBER;
520 break;
521 case 0xd12:
522 case 0x912:
523 case 0x112:
524 case 0x913: /* Intuos3 Airbrush */
525 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
Ping Chengb2f86362005-06-06 02:25:50 -0500526 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 default: /* Unknown tool */
528 wacom->tool[idx] = BTN_TOOL_PEN;
529 }
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800530 if(!((wacom->tool[idx] == BTN_TOOL_LENS) &&
531 ((wacom->features->type == INTUOS312)
532 || (wacom->features->type == INTUOS319)))) {
533 input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
534 input_report_key(dev, wacom->tool[idx], 1);
535 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
536 input_sync(dev);
537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 return 1;
539 }
540
541 /* Exit report */
542 if ((data[1] & 0xfe) == 0x80) {
543 input_report_key(dev, wacom->tool[idx], 0);
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800544 input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
546 input_sync(dev);
547 return 1;
548 }
549
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800550 if((wacom->tool[idx] == BTN_TOOL_LENS) && ((wacom->features->type == INTUOS312)
551 || (wacom->features->type == INTUOS319)))
552 return 1;
553 else
554 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
557static void wacom_intuos_general(struct urb *urb)
558{
559 struct wacom *wacom = urb->context;
560 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500561 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 unsigned int t;
563
564 /* general pen packet */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500565 if ((data[1] & 0xb8) == 0xa0) {
Ping Chengb2f86362005-06-06 02:25:50 -0500566 t = (data[6] << 2) | ((data[7] >> 6) & 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 input_report_abs(dev, ABS_PRESSURE, t);
568 input_report_abs(dev, ABS_TILT_X,
569 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
570 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
571 input_report_key(dev, BTN_STYLUS, data[1] & 2);
572 input_report_key(dev, BTN_STYLUS2, data[1] & 4);
573 input_report_key(dev, BTN_TOUCH, t > 10);
574 }
575
576 /* airbrush second packet */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500577 if ((data[1] & 0xbc) == 0xb4) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 input_report_abs(dev, ABS_WHEEL,
Ping Chengb2f86362005-06-06 02:25:50 -0500579 (data[6] << 2) | ((data[7] >> 6) & 3));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 input_report_abs(dev, ABS_TILT_X,
581 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
582 input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
583 }
584 return;
585}
586
587static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
588{
589 struct wacom *wacom = urb->context;
590 unsigned char *data = wacom->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500591 struct input_dev *dev = wacom->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 unsigned int t;
593 int idx;
594 int retval;
595
596 switch (urb->status) {
597 case 0:
598 /* success */
599 break;
600 case -ECONNRESET:
601 case -ENOENT:
602 case -ESHUTDOWN:
603 /* this urb is terminated, clean up */
604 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
605 return;
606 default:
607 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
608 goto exit;
609 }
610
Ping Chengb2f86362005-06-06 02:25:50 -0500611 if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
613 goto exit;
614 }
615
616 input_regs(dev, regs);
617
618 /* tool number */
619 idx = data[1] & 0x01;
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 /* pad packets. Works as a second tool and is always in prox */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500622 if (data[0] == 12) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 /* initiate the pad as a device */
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800624 if (wacom->tool[1] != BTN_TOOL_FINGER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 wacom->tool[1] = BTN_TOOL_FINGER;
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 input_report_key(dev, BTN_0, (data[5] & 0x01));
628 input_report_key(dev, BTN_1, (data[5] & 0x02));
629 input_report_key(dev, BTN_2, (data[5] & 0x04));
630 input_report_key(dev, BTN_3, (data[5] & 0x08));
631 input_report_key(dev, BTN_4, (data[6] & 0x01));
632 input_report_key(dev, BTN_5, (data[6] & 0x02));
633 input_report_key(dev, BTN_6, (data[6] & 0x04));
634 input_report_key(dev, BTN_7, (data[6] & 0x08));
635 input_report_abs(dev, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
636 input_report_abs(dev, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800637
638 if((data[5] & 0x0f) | (data[6] & 0x0f) | (data[1] & 0x1f) | data[2])
639 input_report_key(dev, wacom->tool[1], 1);
640 else
641 input_report_key(dev, wacom->tool[1], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff);
643 input_sync(dev);
644 goto exit;
645 }
646
647 /* process in/out prox events */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500648 if (wacom_intuos_inout(urb))
649 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Ping Chengb2f86362005-06-06 02:25:50 -0500651 /* Cintiq doesn't send data when RDY bit isn't set */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500652 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
Ping Chengdc1d97e2005-08-16 15:16:32 -0700653 goto exit;
Ping Chengb2f86362005-06-06 02:25:50 -0500654
Dmitry Torokhove5119882005-06-06 02:28:29 -0500655 if (wacom->features->type >= INTUOS3) {
Ping Chengb2f86362005-06-06 02:25:50 -0500656 input_report_abs(dev, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
657 input_report_abs(dev, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
658 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
Dmitry Torokhove5119882005-06-06 02:28:29 -0500659 } else {
Ping Chengb2f86362005-06-06 02:25:50 -0500660 input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
661 input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
662 input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
663 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 /* process general packets */
666 wacom_intuos_general(urb);
667
Ping Chengb2f86362005-06-06 02:25:50 -0500668 /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
669 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
Dmitry Torokhove5119882005-06-06 02:28:29 -0500670
671 if (data[1] & 0x02) {
672 /* Rotation packet */
673 if (wacom->features->type >= INTUOS3) {
Ping Chengb2f86362005-06-06 02:25:50 -0500674 /* I3 marker pen rotation reported as wheel
675 * due to valuator limitation
676 */
677 t = (data[6] << 3) | ((data[7] >> 5) & 7);
678 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
679 ((t-1) / 2 + 450)) : (450 - t / 2) ;
680 input_report_abs(dev, ABS_WHEEL, t);
Dmitry Torokhove5119882005-06-06 02:28:29 -0500681 } else {
Ping Chengb2f86362005-06-06 02:25:50 -0500682 /* 4D mouse rotation packet */
683 t = (data[6] << 3) | ((data[7] >> 5) & 7);
684 input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ?
685 ((t - 1) / 2) : -t / 2);
686 }
Dmitry Torokhove5119882005-06-06 02:28:29 -0500687
688 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3) {
689 /* 4D mouse packet */
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Ping Chengb2f86362005-06-06 02:25:50 -0500694 input_report_key(dev, BTN_SIDE, data[8] & 0x20);
695 input_report_key(dev, BTN_EXTRA, data[8] & 0x10);
696 t = (data[6] << 2) | ((data[7] >> 6) & 3);
697 input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
Dmitry Torokhove5119882005-06-06 02:28:29 -0500698
699 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
700 /* 2D mouse packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 input_report_key(dev, BTN_LEFT, data[8] & 0x04);
702 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
703 input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800704 input_report_rel(dev, REL_WHEEL, (data[8] & 0x01)
705 - ((data[8] & 0x02) >> 1));
Ping Chengb2f86362005-06-06 02:25:50 -0500706
707 /* I3 2D mouse side buttons */
Dmitry Torokhove5119882005-06-06 02:28:29 -0500708 if (wacom->features->type == INTUOS3) {
Ping Chengb2f86362005-06-06 02:25:50 -0500709 input_report_key(dev, BTN_SIDE, data[8] & 0x40);
710 input_report_key(dev, BTN_EXTRA, data[8] & 0x20);
711 }
Dmitry Torokhove5119882005-06-06 02:28:29 -0500712
713 } else if (wacom->features->type < INTUOS3) {
714 /* Lens cursor packets */
Ping Chengb2f86362005-06-06 02:25:50 -0500715 input_report_key(dev, BTN_LEFT, data[8] & 0x01);
716 input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
717 input_report_key(dev, BTN_RIGHT, data[8] & 0x04);
718 input_report_key(dev, BTN_SIDE, data[8] & 0x10);
719 input_report_key(dev, BTN_EXTRA, data[8] & 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721 }
722
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800723 input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
724 input_report_key(dev, wacom->tool[idx], 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
726 input_sync(dev);
727
728exit:
729 retval = usb_submit_urb (urb, GFP_ATOMIC);
730 if (retval)
731 err ("%s - usb_submit_urb failed with result %d",
732 __FUNCTION__, retval);
733}
734
735static struct wacom_features wacom_features[] = {
Dmitry Torokhove5119882005-06-06 02:28:29 -0500736 { "Wacom Penpartner", 7, 5040, 3780, 255, 32, PENPARTNER, wacom_penpartner_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500737 { "Wacom Graphire", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
738 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq },
Dmitry Torokhove5119882005-06-06 02:28:29 -0500739 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500740 { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq },
741 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq },
Dmitry Torokhov1e27ffd2006-01-14 00:28:04 -0500742 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 32, WACOM_G4, wacom_graphire_irq },
743 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 32, WACOM_G4, wacom_graphire_irq },
Ping Chengebb6f372005-11-17 09:46:51 -0800744 { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
745 { "Wacom PenStation2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
746 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq },
747 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 32, GRAPHIRE, wacom_graphire_irq },
748 { "Wacom PenPartner2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq },
Dmitry Torokhove5119882005-06-06 02:28:29 -0500749 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
750 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
751 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
752 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
753 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
754 { "Wacom PL400", 8, 5408, 4056, 255, 32, PL, wacom_pl_irq },
755 { "Wacom PL500", 8, 6144, 4608, 255, 32, PL, wacom_pl_irq },
756 { "Wacom PL600", 8, 6126, 4604, 255, 32, PL, wacom_pl_irq },
757 { "Wacom PL600SX", 8, 6260, 5016, 255, 32, PL, wacom_pl_irq },
758 { "Wacom PL550", 8, 6144, 4608, 511, 32, PL, wacom_pl_irq },
759 { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq },
Ping Chengebb6f372005-11-17 09:46:51 -0800760 { "Wacom PL700", 8, 6758, 5406, 511, 32, PL, wacom_pl_irq },
761 { "Wacom PL510", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800762 { "Wacom DTU710", 8, 34080, 27660, 511, 32, PL, wacom_pl_irq },
763 { "Wacom DTF521", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
Ping Chengebb6f372005-11-17 09:46:51 -0800764 { "Wacom DTF720", 8, 6858, 5506, 511, 32, PL, wacom_pl_irq },
765 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500766 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
767 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
768 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq },
769 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
770 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500771 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq },
772 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq },
773 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq },
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800774 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 15, INTUOS312, wacom_intuos_irq },
775 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 15, INTUOS319, wacom_intuos_irq },
Ping Chengebb6f372005-11-17 09:46:51 -0800776 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 15, INTUOS3, wacom_intuos_irq },
Ping Chengb2f86362005-06-06 02:25:50 -0500777 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq },
778 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500779 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780};
781
782static struct usb_device_id wacom_ids[] = {
783 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
784 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
785 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
786 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
787 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
788 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
Ping Chengebb6f372005-11-17 09:46:51 -0800789 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
790 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
791 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
792 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
793 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
794 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
795 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
797 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
798 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
799 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
800 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
801 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
802 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
803 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
804 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
805 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
806 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
Ping Chengebb6f372005-11-17 09:46:51 -0800807 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
808 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
809 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
810 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800811 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC3) },
Ping Chengebb6f372005-11-17 09:46:51 -0800812 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
814 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
815 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
816 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
817 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
819 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
820 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800821 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
822 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
Ping Chengebb6f372005-11-17 09:46:51 -0800823 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
Ping Chengb2f86362005-06-06 02:25:50 -0500824 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
826 { }
827};
828
829MODULE_DEVICE_TABLE(usb, wacom_ids);
830
831static int wacom_open(struct input_dev *dev)
832{
833 struct wacom *wacom = dev->private;
834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 wacom->irq->dev = wacom->usbdev;
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500836 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 return 0;
840}
841
842static void wacom_close(struct input_dev *dev)
843{
844 struct wacom *wacom = dev->private;
845
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500846 usb_kill_urb(wacom->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
849static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
850{
851 struct usb_device *dev = interface_to_usbdev(intf);
852 struct usb_endpoint_descriptor *endpoint;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 struct wacom *wacom;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500854 struct input_dev *input_dev;
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800855 char rep_data[2], limit = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500857 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
858 input_dev = input_allocate_device();
859 if (!wacom || !input_dev)
860 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500863 if (!wacom->data)
864 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500867 if (!wacom->irq)
868 goto fail2;
869
870 wacom->usbdev = dev;
871 wacom->dev = input_dev;
872 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
873 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 wacom->features = wacom_features + (id - wacom_ids);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500876 if (wacom->features->pktlen > 10)
877 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500879 input_dev->name = wacom->features->name;
880 usb_to_input_id(dev, &input_dev->id);
881
882 input_dev->cdev.dev = &intf->dev;
883 input_dev->private = wacom;
884 input_dev->open = wacom_open;
885 input_dev->close = wacom_close;
886
887 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
888 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
Denny Priebe40c372132005-12-29 22:19:09 -0500889 input_set_abs_params(input_dev, ABS_X, 0, wacom->features->x_max, 4, 0);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500890 input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0);
891 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0);
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800892 input_dev->absbit[LONG(ABS_MISC)] |= BIT(ABS_MISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 switch (wacom->features->type) {
Dmitry Torokhov1e27ffd2006-01-14 00:28:04 -0500895 case WACOM_G4:
Ping Chengebb6f372005-11-17 09:46:51 -0800896 input_dev->evbit[0] |= BIT(EV_MSC);
897 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
898 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
899 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);
900 /* fall through */
901
Ping Chengb2f86362005-06-06 02:25:50 -0500902 case GRAPHIRE:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500903 input_dev->evbit[0] |= BIT(EV_REL);
904 input_dev->relbit[0] |= BIT(REL_WHEEL);
905 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
906 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
907 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 break;
909
Ping Chengb2f86362005-06-06 02:25:50 -0500910 case INTUOS3:
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800911 case INTUOS312:
912 case INTUOS319:
Ping Chengb2f86362005-06-06 02:25:50 -0500913 case CINTIQ:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500914 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
915 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);
916 input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0);
917 input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 /* fall through */
919
Ping Chengb2f86362005-06-06 02:25:50 -0500920 case INTUOS:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500921 input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
922 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
923 input_dev->relbit[0] |= BIT(REL_WHEEL);
924 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
925 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 -0700926 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500927 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
928 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
929 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
930 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
931 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
932 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 break;
934
Ping Chengb2f86362005-06-06 02:25:50 -0500935 case PL:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500936 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 break;
938 }
939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 endpoint = &intf->cur_altsetting->endpoint[0].desc;
941
942 if (wacom->features->pktlen > 10)
943 BUG();
944
945 usb_fill_int_urb(wacom->irq, dev,
946 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
947 wacom->data, wacom->features->pktlen,
948 wacom->features->irq, wacom, endpoint->bInterval);
949 wacom->irq->transfer_dma = wacom->data_dma;
950 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
951
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500952 input_register_device(wacom->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Ping Cheng7d3fe0852006-03-29 16:33:49 -0800954 /* Ask the tablet to report tablet data. Repeat until it succeeds */
955 do {
956 rep_data[0] = 2;
957 rep_data[1] = 2;
958 usb_set_report(intf, 3, 2, rep_data, 2);
959 usb_get_report(intf, 3, 2, rep_data, 2);
960 } while (rep_data[1] != 2 && limit++ < 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 usb_set_intfdata(intf, wacom);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return 0;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500964
965fail2: usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
966fail1: input_free_device(input_dev);
967 kfree(wacom);
968 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
971static void wacom_disconnect(struct usb_interface *intf)
972{
973 struct wacom *wacom = usb_get_intfdata (intf);
974
975 usb_set_intfdata(intf, NULL);
976 if (wacom) {
977 usb_kill_urb(wacom->irq);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500978 input_unregister_device(wacom->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 usb_free_urb(wacom->irq);
980 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma);
981 kfree(wacom);
982 }
983}
984
985static struct usb_driver wacom_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .name = "wacom",
987 .probe = wacom_probe,
988 .disconnect = wacom_disconnect,
989 .id_table = wacom_ids,
990};
991
992static int __init wacom_init(void)
993{
994 int result = usb_register(&wacom_driver);
995 if (result == 0)
996 info(DRIVER_VERSION ":" DRIVER_DESC);
997 return result;
998}
999
1000static void __exit wacom_exit(void)
1001{
1002 usb_deregister(&wacom_driver);
1003}
1004
1005module_init(wacom_init);
1006module_exit(wacom_exit);