~ubuntu-branches/ubuntu/raring/wacom-tools/raring

« back to all changes in this revision

Viewing changes to linuxwacom/src/2.4.30x86-64/wacom.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-05-22 12:04:32 UTC
  • mfrom: (1.12.2 upstream) (2.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090522120432-00suvwukj864ipib
Tags: 1:0.8.3.2-1ubuntu1
* Merge with Debian unstable, remaining changes:
  - Bump the epoch because of old Ubuntu packaging.
  - debian/control:
    - Change the Maintainer address.
    - Bump the epoch on Replaces/Conflicts.
    - Don't build wacom-kernel-source anymore (#71944).
  - debian/wacom.postinst:
    Remove old files.
  - debian/rules: Disable the scaling quirk.
  - Enable patch system (quilt).
    - Import debian/xsfbs/*
    - Add quilt to build-deps.
  - Include wacomcpl so the stylus can be calibrated. (#216347)
    - debian/rules: --enable-libwacomxi
    - debian/control: Add tcl-dev, tk-dev to Build-Depends, and tcl,
      tk to wacom-tools Depends.
  - Modify 10-linuxwacom.fdi to support WALTOP and N-Trig.
  - Add 104_revert-check.diff: Don't check the serial number, it breaks
    some devices. Disabled for now, needs testing because part of it
    is upstream now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (c) 2000-2002 Vojtech Pavlik  <vojtech@suse.cz>
3
 
 *  Copyright (c) 2000 Andreas Bach Aaen    <abach@stofanet.dk>
4
 
 *  Copyright (c) 2000 Clifford Wolf        <clifford@clifford.at>
5
 
 *  Copyright (c) 2000 Sam Mosel            <sam.mosel@computer.org>
6
 
 *  Copyright (c) 2000 James E. Blair       <corvus@gnu.org>
7
 
 *  Copyright (c) 2000 Daniel Egger         <egger@suse.de>
8
 
 *  Copyright (c) 2001 Frederic Lepied      <flepied@mandrakesoft.com>
9
 
 *  Copyright (c) 2002 Christer Nilsson     <christer.nilsson@kretskompaniet.se>
10
 
 *  Copyright (c) 2002-2008 Ping Cheng      <pingc@wacom.com>
11
 
 *  Copyright (c) 2002 John Joganic         <john@joganic.com>
12
 
 *
13
 
 *  USB Wacom Graphire and Intuos tablet support
14
 
 *
15
 
 *  Sponsored by SuSE
16
 
 *
17
 
 *  ChangeLog:
18
 
 *      v0.1 (vp)  - Initial release
19
 
 *      v0.2 (aba) - Support for all buttons / combinations
20
 
 *      v0.3 (vp)  - Support for Intuos added
21
 
 *      v0.4 (sm)  - Support for more Intuos models, menustrip
22
 
 *                      relative mode, proximity.
23
 
 *      v0.5 (vp)  - Big cleanup, nifty features removed,
24
 
 *                      they belong in userspace
25
 
 *      v1.8 (vp)  - Submit URB only when operating, moved to CVS,
26
 
 *                      use input_report_key instead of report_btn and
27
 
 *                      other cleanups
28
 
 *      v1.11 (vp) - Add URB ->dev setting for new kernels
29
 
 *      v1.11 (jb) - Add support for the 4D Mouse & Lens
30
 
 *      v1.12 (de) - Add support for two more inking pen IDs
31
 
 *      v1.14 (vp) - Use new USB device id probing scheme.
32
 
 *                   Fix Wacom Graphire mouse wheel
33
 
 *      v1.18 (vp) - Fix mouse wheel direction
34
 
 *                   Make mouse relative
35
 
 *      v1.20 (fl) - Report tool id for Intuos devices
36
 
 *                 - Multi tools support
37
 
 *                 - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...)
38
 
 *                 - Add PL models support
39
 
 *                 - Fix Wacom Graphire mouse wheel again
40
 
 *      v1.21 (vp) - Removed protocol descriptions
41
 
 *                 - Added MISC_SERIAL for tool serial numbers
42
 
 *            (gb) - Identify version on module load.
43
 
 *    v1.21.1 (fl) - added Graphire2 support
44
 
 *    v1.21.2 (fl) - added Intuos2 support
45
 
 *                 - added all the PL ids
46
 
 *    v1.21.3 (fl) - added another eraser id from Neil Okamoto
47
 
 *                 - added smooth filter for Graphire from Peri Hankey
48
 
 *                 - added PenPartner support from Olaf van Es
49
 
 *                 - new tool ids from Ole Martin Bjoerndalen
50
 
 *
51
 
 *   WARNING: THIS IS NOT PART OF THE OFFICIAL KERNEL TREE
52
 
 *   THIS IS FOR TESTING PURPOSES
53
 
 *
54
 
 *    v2.4.30-pc0.6.9   - Supports x86_64 systems
55
 
 *    v2.4.30-pc0.7.0   - Added Volito2 support
56
 
 *    v2.4.30-pc0.7.1   - Added DTF720, DTU 710, G4
57
 
 *    v2.4.30-pc0.7.3   - Added DTF 521, I3 12x12, and I3 12x19
58
 
 *    v2.4.30-pc0.7.5   - Support tablet buttons/keys  
59
 
 *    v2.4.30-pc0.7.7   - Support Intuos outbound tracking
60
 
 *    v2.4.30-pc0.7.8   - Added Bamboo
61
 
 *    v2.4.30-pc0.7.9   - Added Bamboo1, Bamboo Fun, and Hummingbird
62
 
 *    v2.4.30-pc0.7.9-8   - Added Cintiq 20WSX
63
 
 */
64
 
 
65
 
/*
66
 
 * This program is free software; you can redistribute it and/or modify
67
 
 * it under the terms of the GNU General Public License as published by
68
 
 * the Free Software Foundation; either version 2 of the License, or
69
 
 * (at your option) any later version.
70
 
 */
71
 
 
72
 
#include <linux/autoconf.h>
73
 
#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
74
 
#   define MODVERSIONS
75
 
#endif
76
 
 
77
 
#ifdef MODVERSIONS
78
 
#include <linux/modversions.h>
79
 
#endif
80
 
 
81
 
#include <linux/kernel.h>
82
 
#include <linux/slab.h>
83
 
#include <linux/input.h>
84
 
#include <linux/module.h>
85
 
#include <linux/init.h>
86
 
#include <linux/usb.h>
87
 
#include <linux/smp_lock.h>
88
 
#include <linux/list.h>
89
 
 
90
 
/*
91
 
 * Version Information
92
 
 */
93
 
#define DRIVER_VERSION "v2.4.30-pc0.8.2-1"
94
 
#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@suse.cz>"
95
 
#ifndef __JEJ_DEBUG
96
 
#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver (LINUXWACOM)"
97
 
#else
98
 
#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver (LINUXWACOM-DEBUG)"
99
 
#endif
100
 
 
101
 
MODULE_AUTHOR(DRIVER_AUTHOR);
102
 
MODULE_DESCRIPTION(DRIVER_DESC);
103
 
MODULE_LICENSE("GPL");
104
 
 
105
 
#define USB_VENDOR_ID_WACOM     0x056a
106
 
#define STYLUS_DEVICE_ID        0x02
107
 
#define CURSOR_DEVICE_ID        0x06
108
 
#define ERASER_DEVICE_ID        0x0A
109
 
#define PAD_DEVICE_ID           0x0F
110
 
 
111
 
struct wacom_features {
112
 
        char *name;
113
 
        int pktlen;
114
 
        int x_max;
115
 
        int y_max;
116
 
        int pressure_max;
117
 
        int distance_max;
118
 
        void (*irq)(struct urb *urb);
119
 
        unsigned long evbit;
120
 
        unsigned long absbit;
121
 
        unsigned long relbit;
122
 
        unsigned long btnbit;
123
 
        unsigned long digibit;
124
 
};
125
 
 
126
 
struct wacom {
127
 
        signed char data[10];
128
 
        struct input_dev dev;
129
 
        struct usb_device *usbdev;
130
 
        struct urb irq;
131
 
        struct wacom_features *features;
132
 
        int tool[2];
133
 
        int id[2];
134
 
        int open;
135
 
        __u32 serial[2];
136
 
        
137
 
        unsigned int ifnum;
138
 
};
139
 
 
140
 
static void wacom_pl_irq(struct urb *urb)
141
 
{
142
 
        struct wacom *wacom = urb->context;
143
 
        unsigned char *data = wacom->data;
144
 
        struct input_dev *dev = &wacom->dev;
145
 
        int prox, pressure;
146
 
 
147
 
        if (urb->status) return;
148
 
 
149
 
        if (data[0] != 2 && data[0] != 5)
150
 
        {
151
 
                printk(KERN_INFO "wacom_pl_irq: received unknown report #%d\n", data[0]);
152
 
                return;
153
 
        }
154
 
        
155
 
        /* proximity and pressure */
156
 
        prox = data[1] & 0x40;
157
 
                
158
 
        wacom->id[0] = ERASER_DEVICE_ID;
159
 
        if (prox) {
160
 
                pressure = (signed char) ((data[7] <<1 ) | ((data[4] >> 2) & 1));
161
 
                if ( wacom->features->pressure_max > 350 ) {
162
 
                    pressure = (pressure << 1) | ((data[4] >> 6) & 1);
163
 
                } 
164
 
                pressure += (( wacom->features->pressure_max + 1 )/ 2);
165
 
 
166
 
                /*
167
 
                 * if going from out of proximity into proximity select between the eraser
168
 
                 * and the pen based on the state of the stylus2 button, choose eraser if
169
 
                 * pressed else choose pen. if not a proximity change from out to in, send
170
 
                 * an out of proximity for previous tool then a in for new tool.
171
 
                 */
172
 
                if (!wacom->tool[0]) {
173
 
                        /* Eraser bit set for DTF */
174
 
                        if (data[1] & 0x10)
175
 
                                wacom->tool[1] = BTN_TOOL_RUBBER;
176
 
                        else
177
 
                        /* Going into proximity select tool */
178
 
                                wacom->tool[1] = (data[4] & 0x20)? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
179
 
                }
180
 
                else {
181
 
                        /* was entered with stylus2 pressed */
182
 
                        if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20) ) {
183
 
                                /* report out proximity for previous tool */
184
 
                                input_report_abs(dev, ABS_MISC, wacom->id[0]); /* report tool id */
185
 
                                input_report_key(dev, wacom->tool[1], 0);
186
 
                                input_event(dev, EV_MSC, MSC_SERIAL, wacom->id[0]);
187
 
                                wacom->tool[1] = BTN_TOOL_PEN;
188
 
                                return;
189
 
                        }
190
 
                }
191
 
                if (wacom->tool[1] != BTN_TOOL_RUBBER) {
192
 
                        /* Unknown tool selected default to pen tool */
193
 
                        wacom->tool[1] = BTN_TOOL_PEN;
194
 
                        wacom->id[0] = STYLUS_DEVICE_ID;
195
 
                }
196
 
                input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */
197
 
                input_report_abs(dev, ABS_MISC, wacom->id[0]); /* report tool id */
198
 
                input_report_abs(dev, ABS_X, data[3] | ((__u32)data[2] << 7) | ((__u32)(data[1] & 0x03) << 14));
199
 
                input_report_abs(dev, ABS_Y, data[6] | ((__u32)data[5] << 7) | ((__u32)(data[4] & 0x03) << 14));
200
 
                input_report_abs(dev, ABS_PRESSURE, pressure);
201
 
                input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
202
 
                input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
203
 
                /* Only allow the stylus2 button to be reported for the pen tool. */
204
 
                input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
205
 
        }
206
 
        else {
207
 
                /* report proximity-out of a (valid) tool */
208
 
                if (wacom->tool[1] != BTN_TOOL_RUBBER) {
209
 
                        /* Unknown tool selected default to pen tool */
210
 
                        wacom->tool[1] = BTN_TOOL_PEN;
211
 
                }
212
 
                input_report_key(dev, wacom->tool[1], prox);
213
 
                input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
214
 
        }
215
 
 
216
 
        wacom->tool[0] = prox; /* Save proximity state */
217
 
        /* end of proximity code */
218
 
        
219
 
        input_event(dev, EV_MSC, MSC_SERIAL, wacom->id[0]);
220
 
}
221
 
 
222
 
static void wacom_ptu_irq(struct urb *urb)
223
 
{
224
 
        struct wacom *wacom = urb->context;
225
 
        unsigned char *data = wacom->data;
226
 
        struct input_dev *dev = &wacom->dev;
227
 
 
228
 
        if (urb->status) return;
229
 
 
230
 
        if (data[0] != 2 && data[0] != 5)
231
 
        {
232
 
                printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
233
 
                return;
234
 
        }
235
 
        
236
 
        if (data[1] & 0x04) 
237
 
        {
238
 
                input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20);
239
 
                input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
240
 
                wacom->id[0] = ERASER_DEVICE_ID;
241
 
        }
242
 
        else
243
 
        {
244
 
                input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20);
245
 
                input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
246
 
                wacom->id[0] = STYLUS_DEVICE_ID;
247
 
        }
248
 
        input_report_abs(dev, ABS_MISC, wacom->id[0]); /* report tool id */
249
 
        input_report_abs(dev, ABS_X, data[3] << 8 | data[2]);
250
 
        input_report_abs(dev, ABS_Y, data[5] << 8 | data[4]);
251
 
        input_report_abs(dev, ABS_PRESSURE, (data[6]|data[7] << 8));
252
 
        input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
253
 
        input_report_key(dev, BTN_STYLUS2, data[1] & 0x10);
254
 
 
255
 
        input_event(dev, EV_MSC, MSC_SERIAL, wacom->id[0]);
256
 
}
257
 
 
258
 
 
259
 
static void wacom_penpartner_irq(struct urb *urb)
260
 
{
261
 
        struct wacom *wacom = urb->context;
262
 
        unsigned char *data = wacom->data;
263
 
        struct input_dev *dev = &wacom->dev;
264
 
 
265
 
        if (urb->status) return;
266
 
 
267
 
        switch (data[0]) {
268
 
                case 1:
269
 
                        if (data[5] & 0x80) {
270
 
                                wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
271
 
                                wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
272
 
                                input_report_key(dev, wacom->tool[0], 1);
273
 
                                input_report_abs(dev, ABS_MISC, wacom->id[0]); /* report tool id */
274
 
                                input_report_abs(dev, ABS_X, data[2] << 8 | data[1]);
275
 
                                input_report_abs(dev, ABS_Y, data[4] << 8 | data[3]);
276
 
                                input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127);
277
 
                                input_report_key(dev, BTN_TOUCH, ((signed char)data[6] > -127));
278
 
                                input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
279
 
                        } else {
280
 
                                input_report_key(dev, wacom->tool[0], 0);
281
 
                                input_report_abs(dev, ABS_MISC, 0); /* report tool id */
282
 
                                input_report_abs(dev, ABS_PRESSURE, -1);
283
 
                                input_report_key(dev, BTN_TOUCH, 0);
284
 
                        }
285
 
                        input_event(dev, EV_MSC, MSC_SERIAL, data[5] & 0x80);
286
 
                        break;
287
 
                case 2:
288
 
                        input_report_key(dev, BTN_TOOL_PEN, 1);
289
 
                        input_report_abs(dev, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
290
 
                        input_report_abs(dev, ABS_X, data[2] << 8 | data[1]);
291
 
                        input_report_abs(dev, ABS_Y, data[4] << 8 | data[3]);
292
 
                        input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127);
293
 
                        input_report_key(dev, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
294
 
                        input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
295
 
                        input_event(dev, EV_MSC, MSC_SERIAL, ((signed char)data[6] > -80) && !(data[5] & 0x20));
296
 
                        break;
297
 
                default:
298
 
                        printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
299
 
                        wacom_request_reset(wacom);
300
 
                        return;
301
 
        }
302
 
}
303
 
 
304
 
static void wacom_graphire_irq(struct urb *urb)
305
 
{
306
 
        struct wacom *wacom = urb->context;
307
 
        unsigned char *data = wacom->data;
308
 
        struct input_dev *dev = &wacom->dev;
309
 
        int x, y, rw;
310
 
 
311
 
        if (urb->status) return;
312
 
 
313
 
        /* 2 Volito1 and 2 users say this is wrong
314
 
        if (data[0] == 99) return; */
315
 
 
316
 
        if (data[0] != 2)
317
 
        {
318
 
                printk(KERN_INFO "wacom_graphire_irq: received unknown report #%d\n", data[0]);
319
 
                return;
320
 
        }
321
 
 
322
 
        if (data[1] & 0x80) {
323
 
                /* in prox and not a pad data */
324
 
 
325
 
                switch ((data[1] >> 5) & 3) {
326
 
 
327
 
                        case 0: /* Pen */
328
 
                                wacom->tool[0] = BTN_TOOL_PEN;
329
 
                                wacom->id[0] = STYLUS_DEVICE_ID;
330
 
                                break;
331
 
 
332
 
                        case 1: /* Rubber */
333
 
                                wacom->tool[0] = BTN_TOOL_RUBBER;
334
 
                                wacom->id[0] = ERASER_DEVICE_ID;
335
 
                                break;
336
 
 
337
 
                        case 2: /* Mouse with wheel */
338
 
                                input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
339
 
                                if ( strstr(wacom->features->name, "Graphire4") || 
340
 
                                                strstr(wacom->features->name, "Bamboo") ) {
341
 
                                        rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : data[7] & 0x03;
342
 
                                        input_report_rel(dev, REL_WHEEL, -rw);
343
 
                                } else
344
 
                                        input_report_rel(dev, REL_WHEEL, -(signed char) data[6]);
345
 
                                /* fall through */
346
 
 
347
 
                        case 3: /* Mouse without wheel */
348
 
                                wacom->tool[0] = BTN_TOOL_MOUSE;
349
 
                                wacom->id[0] = CURSOR_DEVICE_ID;
350
 
                                input_report_key(dev, BTN_LEFT, data[1] & 0x01);
351
 
                                input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
352
 
                                if ( strstr(wacom->features->name, "Graphire4") || 
353
 
                                                strstr(wacom->features->name, "Bamboo") )
354
 
                                        input_report_abs(dev, ABS_DISTANCE, data[6]);
355
 
                                else
356
 
                                        input_report_abs(dev, ABS_DISTANCE, data[7]);
357
 
                                break;
358
 
                }
359
 
                x = data[2] | ((__u32)data[3] << 8);
360
 
                y = data[4] | ((__u32)data[5] << 8);
361
 
                input_report_abs(dev, ABS_X, x);
362
 
                input_report_abs(dev, ABS_Y, y);
363
 
 
364
 
                if (wacom->tool[0] != BTN_TOOL_MOUSE) {
365
 
                        input_report_abs(dev, ABS_PRESSURE, data[6] | ((__u32)data[7] << 8));
366
 
                        input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
367
 
                        input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
368
 
                        input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
369
 
                }
370
 
                input_report_abs(dev, ABS_MISC, wacom->id[0]); /* report tool id */
371
 
                input_report_key(dev, wacom->tool[0], 1);
372
 
        } else if (wacom->id[0]) {
373
 
                input_report_abs(dev, ABS_X, 0);
374
 
                input_report_abs(dev, ABS_Y, 0);
375
 
                if (wacom->tool[0] == BTN_TOOL_MOUSE) {
376
 
                        input_report_key(dev, BTN_LEFT, 0);
377
 
                        input_report_key(dev, BTN_RIGHT, 0);
378
 
                        input_report_abs(dev, ABS_DISTANCE, 0);
379
 
                } else {
380
 
                        input_report_abs(dev, ABS_PRESSURE, 0);
381
 
                        input_report_key(dev, BTN_TOUCH, 0);
382
 
                        input_report_key(dev, BTN_STYLUS, 0);
383
 
                        input_report_key(dev, BTN_STYLUS2, 0);
384
 
                }
385
 
                wacom->id[0] = 0;
386
 
                input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
387
 
                input_report_key(dev, wacom->tool[0], 0);
388
 
        }
389
 
        input_event(dev, EV_MSC, MSC_SERIAL,wacom->id[0]);
390
 
 
391
 
        /* send pad data */
392
 
        if ( strstr(wacom->features->name, "Graphire4") ) {
393
 
                if (data[7] & 0xf8) {
394
 
                        wacom->id[1] = PAD_DEVICE_ID;
395
 
                        input_report_key(dev, BTN_0, (data[7] & 0x40));
396
 
                        input_report_key(dev, BTN_4, (data[7] & 0x80));
397
 
                        rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
398
 
                        input_report_rel(dev, REL_WHEEL, rw);
399
 
                        input_report_key(dev, BTN_TOOL_FINGER, 0xf0);
400
 
                        input_report_abs(dev, ABS_MISC, wacom->id[1]);
401
 
                        input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
402
 
                } else if ( wacom->id[1] ) {
403
 
                        wacom->id[1] = 0;
404
 
                        input_report_key(dev, BTN_0, (data[7] & 0x40));
405
 
                        input_report_key(dev, BTN_4, (data[7] & 0x80));
406
 
                        input_report_rel(dev, REL_WHEEL, 0);
407
 
                        input_report_key(dev, BTN_TOOL_FINGER, 0);
408
 
                        input_report_abs(dev, ABS_MISC, 0);
409
 
                        input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
410
 
                }
411
 
        }
412
 
        if ( strstr(wacom->features->name, "Bamboo") ) {
413
 
                if ((data[7] & 0xf8) || (data[8] & 0xff)) {
414
 
                        wacom->id[1] = PAD_DEVICE_ID;
415
 
                        input_report_key(dev, BTN_0, (data[7] & 0x08));
416
 
                        input_report_key(dev, BTN_1, (data[7] & 0x20));
417
 
                        input_report_key(dev, BTN_4, (data[7] & 0x10));
418
 
                        input_report_key(dev, BTN_5, (data[7] & 0x40));
419
 
                        input_report_abs(dev, ABS_WHEEL, (data[8] & 0x7f));
420
 
                        input_report_key(dev, BTN_TOOL_FINGER, 0xf0);
421
 
                        input_report_abs(dev, ABS_MISC, wacom->id[1]);
422
 
                        input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
423
 
                } else if (wacom->id[1]) {
424
 
                        wacom->id[1] = 0;
425
 
                        input_report_key(dev, BTN_0, (data[7] & 0x08));
426
 
                        input_report_key(dev, BTN_1, (data[7] & 0x20));
427
 
                        input_report_key(dev, BTN_4, (data[7] & 0x10));
428
 
                        input_report_key(dev, BTN_5, (data[7] & 0x40));
429
 
                        input_report_abs(dev, ABS_WHEEL, (data[8] & 0x7f));
430
 
                        input_report_key(dev, BTN_TOOL_FINGER, 0);
431
 
                        input_report_abs(dev, ABS_MISC, 0); 
432
 
                        input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
433
 
                }
434
 
        }
435
 
}
436
 
 
437
 
static int wacom_intuos_inout(struct urb *urb)
438
 
{
439
 
        struct wacom *wacom = urb->context;
440
 
        unsigned char *data = wacom->data;
441
 
        struct input_dev *dev = &wacom->dev;
442
 
        int idx;
443
 
 
444
 
        /* tool number */
445
 
        idx = data[1] & 0x01;
446
 
 
447
 
        /* Enter report */
448
 
        if ((data[1] & 0xfc) == 0xc0)
449
 
        {
450
 
                /* serial number of the tool */
451
 
                wacom->serial[idx] = ((__u32)(data[3] & 0x0f) << 28) +
452
 
                                ((__u32)data[4] << 20) + ((__u32)data[5] << 12) +
453
 
                                ((__u32)data[6] << 4) + ((__u32)data[7] >> 4);
454
 
 
455
 
                #ifdef __JEJ_DEBUG
456
 
                printk(KERN_INFO "wacom_intuos_irq: tool change 0x%03X\n",
457
 
                                (((__u32)data[2] << 4) | (data[3] >> 4)));
458
 
                #endif
459
 
 
460
 
                wacom->id[idx] = ((__u32)data[2] << 4) | (data[3] >> 4);
461
 
                switch (wacom->id[idx])
462
 
                {
463
 
                        case 0x812: /* Intuos2 ink pen XP-110-00A */
464
 
                        case 0x801: /* Intuos3 Inking pen */
465
 
                        case 0x012: /* Inking pen */
466
 
                                wacom->tool[idx] = BTN_TOOL_PENCIL; break;
467
 
 
468
 
                        case 0x822: /* Intuos Pen GP-300E-01H */
469
 
                        case 0x852: /* Intuos2 Grip Pen XP-501E-00A */
470
 
                        case 0x842: /* Designer Pen */
471
 
                        case 0x823: /* Intuos3 Grip Pen */
472
 
                        case 0x813: /* Intuos3 Classic Pen */
473
 
                        case 0x885: /* Intuos3 Marker Pen */
474
 
                        case 0x022:
475
 
                                wacom->tool[idx] = BTN_TOOL_PEN; break;
476
 
 
477
 
                        case 0x832: /* Intuos2 stroke pen XP-120-00A */
478
 
                        case 0x032: /* Stroke pen */
479
 
                                wacom->tool[idx] = BTN_TOOL_BRUSH; break;
480
 
 
481
 
                        case 0x007: /* 2D Mouse */
482
 
                        case 0x09C: /* ?? Mouse - not a valid code according to Wacom */
483
 
                        case 0x094: /* 4D Mouse */
484
 
                        case 0x017: /* Intuos3 2D Mouse */
485
 
                                wacom->tool[idx] = BTN_TOOL_MOUSE; break;
486
 
 
487
 
                        case 0x096: /* Lens cursor */
488
 
                        case 0x097: /* Intuos3 Lens cursor */
489
 
                                wacom->tool[idx] = BTN_TOOL_LENS; break;
490
 
 
491
 
                        case 0x82A:
492
 
                        case 0x85A:
493
 
                        case 0x91A:
494
 
                        case 0xD1A:
495
 
                        case 0x0FA: /* Eraser */
496
 
                        case 0x82B: /* Intuos3 Grip Pen Eraser */
497
 
                        case 0x81B: /* Intuos3 Classic Pen Eraser */
498
 
                        case 0x91B: /* Intuos3 Airbrush Eraser */
499
 
                                wacom->tool[idx] = BTN_TOOL_RUBBER; break;
500
 
 
501
 
                        case 0x112: /* Airbrush */
502
 
                        case 0x912: /* Intuos2 Airbrush */
503
 
                        case 0xD12: /* Intuos Airbrush */
504
 
                        case 0x913: /* Intuos3 Airbrush */
505
 
                                wacom->tool[idx] = BTN_TOOL_AIRBRUSH; break;
506
 
 
507
 
                        default: /* Unknown tool */
508
 
                                wacom->tool[idx] = BTN_TOOL_PEN; break;
509
 
                }
510
 
                return 1;
511
 
        }
512
 
 
513
 
        /* Exit report */
514
 
        if ((data[1] & 0xfe) == 0x80)
515
 
        {
516
 
                input_report_abs(dev, ABS_X, 0);
517
 
                input_report_abs(dev, ABS_Y, 0);
518
 
                input_report_abs(dev, ABS_DISTANCE, 0);
519
 
                if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
520
 
                        input_report_key(dev, BTN_LEFT, 0);
521
 
                        input_report_key(dev, BTN_MIDDLE, 0);
522
 
                        input_report_key(dev, BTN_RIGHT, 0);
523
 
                        input_report_key(dev, BTN_SIDE, 0);
524
 
                        input_report_key(dev, BTN_EXTRA, 0);
525
 
                        input_report_abs(dev, ABS_THROTTLE, 0);
526
 
                        input_report_abs(dev, ABS_RZ, 0);
527
 
                } else {
528
 
                        input_report_abs(dev, ABS_PRESSURE, 0);
529
 
                        input_report_abs(dev, ABS_TILT_X, 0);
530
 
                        input_report_abs(dev, ABS_TILT_Y, 0);
531
 
                        input_report_key(dev, BTN_STYLUS, 0);
532
 
                        input_report_key(dev, BTN_STYLUS2, 0);
533
 
                        input_report_key(dev, BTN_TOUCH, 0);
534
 
                        input_report_abs(dev, ABS_WHEEL, 0);
535
 
                        input_report_abs(dev, ABS_Z, 0);
536
 
                }
537
 
                input_report_key(dev, wacom->tool[idx], 0);
538
 
                input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
539
 
                input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
540
 
                return 1;
541
 
        }
542
 
        return 0;
543
 
}
544
 
 
545
 
static void wacom_intuos_general(struct urb *urb)
546
 
{
547
 
        struct wacom *wacom = urb->context;
548
 
        unsigned char *data = wacom->data;
549
 
        struct input_dev *dev = &wacom->dev;
550
 
        unsigned int t;
551
 
 
552
 
        /* general pen packet */
553
 
        if ((data[1] & 0xb8) == 0xa0)
554
 
        {
555
 
                t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3);
556
 
                input_report_abs(dev, ABS_PRESSURE, t);
557
 
                input_report_abs(dev, ABS_TILT_X,
558
 
                                ((data[7] << 1) & 0x7e) | (data[8] >> 7));
559
 
                input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
560
 
                input_report_key(dev, BTN_STYLUS, data[1] & 2);
561
 
                input_report_key(dev, BTN_STYLUS2, data[1] & 4);
562
 
                input_report_key(dev, BTN_TOUCH, t > 10);
563
 
        }
564
 
 
565
 
        /* airbrush second packet */
566
 
        if ((data[1] & 0xbc) == 0xb4)
567
 
        {
568
 
                input_report_abs(dev, ABS_WHEEL,
569
 
                                ((__u32)data[6] << 2) | ((data[7] >> 6) & 3));
570
 
                input_report_abs(dev, ABS_TILT_X,
571
 
                                ((data[7] << 1) & 0x7e) | (data[8] >> 7));
572
 
                input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
573
 
        }
574
 
        return;
575
 
}
576
 
 
577
 
static void wacom_intuos_irq(struct urb *urb)
578
 
{
579
 
        struct wacom *wacom = urb->context;
580
 
        unsigned char *data = wacom->data;
581
 
        struct input_dev *dev = &wacom->dev;
582
 
        unsigned int t;
583
 
        int idx;
584
 
 
585
 
        if (urb->status) return;
586
 
 
587
 
        /* check for valid report */
588
 
        if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12)
589
 
        {
590
 
                printk(KERN_INFO "wacom_intuos_irq: received unknown report #%d\n", data[0]);
591
 
                return;
592
 
        }
593
 
        
594
 
        /* tool index */
595
 
        idx = data[1] & 0x01;
596
 
 
597
 
        /* pad packets. Works as a second tool */
598
 
        if (data[0] == 12 && (strstr(wacom->features->name, "Intuos3") ||
599
 
                        strstr(wacom->features->name, "Cintiq")) )
600
 
        {
601
 
                /* initiate the pad as a device */
602
 
                if (wacom->tool[1] != BTN_TOOL_FINGER)
603
 
                        wacom->tool[1] = BTN_TOOL_FINGER;
604
 
 
605
 
                input_report_key(dev, BTN_0, (data[5] & 0x01));
606
 
                input_report_key(dev, BTN_1, (data[5] & 0x02));
607
 
                input_report_key(dev, BTN_2, (data[5] & 0x04));
608
 
                input_report_key(dev, BTN_3, (data[5] & 0x08));
609
 
                input_report_key(dev, BTN_4, (data[6] & 0x01));
610
 
                input_report_key(dev, BTN_5, (data[6] & 0x02));
611
 
                input_report_key(dev, BTN_6, (data[6] & 0x04));
612
 
                input_report_key(dev, BTN_7, (data[6] & 0x08));
613
 
                input_report_key(dev, BTN_8, (data[5] & 0x10));
614
 
                input_report_key(dev, BTN_9, (data[6] & 0x10));
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
 
 
618
 
                if((data[5] & 0x1f) | (data[6] & 0x1f) | (data[1] & 0x1f) | 
619
 
                        data[2] | (data[3] & 0x1f) | data[4]) {
620
 
                        input_report_key(dev, wacom->tool[1], 1);
621
 
                        input_report_abs(dev, ABS_MISC, PAD_DEVICE_ID);
622
 
                } else {
623
 
                        input_report_key(dev, wacom->tool[1], 0);
624
 
                        input_report_abs(dev, ABS_MISC, 0);
625
 
                }
626
 
                input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff);
627
 
                return;
628
 
        }
629
 
 
630
 
        /* process in/out prox events */
631
 
        if (wacom_intuos_inout(urb)) return;
632
 
 
633
 
        /* Only large I3 supports Lens Cursor */
634
 
        if((wacom->tool[idx] == BTN_TOOL_LENS) && strstr(wacom->features->name, "Intuos3"))
635
 
                if (!(strstr(wacom->features->name, "Intuos3 12x12") 
636
 
                        || strstr(wacom->features->name, "Intuos3 12x19")))
637
 
                        return;
638
 
 
639
 
        /* Cintiq doesn't send data when RDY bit isn't set */
640
 
        if (strstr(wacom->features->name, "Cintiq") && !(data[1] & 0x40)) return;
641
 
 
642
 
        if(strstr(wacom->features->name, "Intuos3") || strstr(wacom->features->name, "Cintiq"))
643
 
        {
644
 
                input_report_abs(dev, ABS_X, ((__u32)data[2] << 9) | ((__u32)data[3] << 1) | ((data[9] >> 1) & 1));
645
 
                input_report_abs(dev, ABS_Y, ((__u32)data[4] << 9) | ((__u32)data[5] << 1) | (data[9] & 1));
646
 
                input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
647
 
        }
648
 
        else
649
 
        {
650
 
                input_report_abs(dev, ABS_X, ((__u32)data[2] << 8) | data[3]);
651
 
                input_report_abs(dev, ABS_Y, ((__u32)data[4] << 8) | data[5]);
652
 
                input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
653
 
        }
654
 
 
655
 
        /* process general packets */
656
 
        wacom_intuos_general(urb);
657
 
        
658
 
        /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
659
 
        if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0)
660
 
        {
661
 
                /* Rotation packet */
662
 
                if (data[1] & 0x02)
663
 
                {
664
 
                        if(strstr(wacom->features->name, "Intuos3") ||
665
 
                                        strstr(wacom->features->name, "Cintiq"))
666
 
                        {
667
 
                                /* I3 marker pen rotation */
668
 
                                t = ((__u32)data[6] << 3) | ((data[7] >> 5) & 7);
669
 
                                t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
670
 
                                        ((t-1) / 2 + 450)) : (450 - t / 2) ;
671
 
                                input_report_abs(dev, ABS_Z, t);
672
 
                        }
673
 
                        else
674
 
                        {
675
 
                                /* 4D mouse rotation packet */
676
 
                                t = ((__u32)data[6] << 3) | ((data[7] >> 5) & 7);
677
 
                                input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ?
678
 
                                        ((t - 1) / 2) : -t / 2);
679
 
                        }
680
 
                }
681
 
 
682
 
                /* 4D mouse packets */
683
 
                else if ( !(data[1] & 0x10) && !strstr(wacom->features->name, "Intuos3"))
684
 
                {
685
 
                        input_report_key(dev, BTN_LEFT,   data[8] & 0x01);
686
 
                        input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
687
 
                        input_report_key(dev, BTN_RIGHT,  data[8] & 0x04);
688
 
                        input_report_key(dev, BTN_SIDE,   data[8] & 0x20);
689
 
                        input_report_key(dev, BTN_EXTRA,  data[8] & 0x10);
690
 
                        /* throttle is positive when rolled backwards */
691
 
                        t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3);
692
 
                        input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
693
 
                }
694
 
 
695
 
                /* 2D mouse packets */  
696
 
                else if (wacom->tool[idx] == BTN_TOOL_MOUSE)
697
 
                {
698
 
                        input_report_key(dev, BTN_LEFT,   data[8] & 0x04);
699
 
                        input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
700
 
                        input_report_key(dev, BTN_RIGHT,  data[8] & 0x10);
701
 
                        /* mouse wheel is positive when rolled backwards */
702
 
                        input_report_rel(dev, REL_WHEEL, (__u32)(data[8] & 0x01)
703
 
                                         - (__u32)((data[8] & 0x02) >> 1));
704
 
 
705
 
                        /* I3 2D mouse side buttons */  
706
 
                        if (strstr(wacom->features->name, "Intuos3"))
707
 
                        {
708
 
                                input_report_key(dev, BTN_SIDE,   data[8] & 0x40);
709
 
                                input_report_key(dev, BTN_EXTRA,  data[8] & 0x20);
710
 
                        }
711
 
                }
712
 
                /* lens cursor packets */
713
 
                else if ( !strstr(wacom->features->name, "Intuos3") )
714
 
                {
715
 
                        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);
720
 
                }
721
 
        }
722
 
 
723
 
        input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
724
 
        input_report_key(dev, wacom->tool[idx], 1);
725
 
        input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
726
 
}
727
 
 
728
 
#define WACOM_GRAPHIRE_BITS     (BIT(EV_REL))
729
 
#define WACOM_GRAPHIRE_REL      (BIT(REL_WHEEL))
730
 
#define WACOM_G4_TOOLS          (BIT(BTN_TOOL_FINGER))
731
 
#define WACOM_G4_BUTTONS        (BIT(BTN_0) | BIT(BTN_4))
732
 
#define WACOM_MO_BUTTONS        (WACOM_G4_BUTTONS | BIT(BTN_1) | BIT(BTN_5))
733
 
#define WACOM_MO_ABS            (BIT(ABS_WHEEL))
734
 
#define WACOM_INTUOS_TOOLS      (BIT(BTN_TOOL_BRUSH) | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS))
735
 
#define WACOM_INTUOS3_TOOLS     (WACOM_INTUOS_TOOLS | BIT(BTN_TOOL_FINGER))
736
 
#define WACOM_INTUOS_BUTTONS    (BIT(BTN_SIDE) | BIT(BTN_EXTRA))
737
 
#define WACOM_INTUOS3S_BUTTONS  (WACOM_INTUOS_BUTTONS | BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3))
738
 
#define WACOM_INTUOS3_BUTTONS   (WACOM_INTUOS3S_BUTTONS | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7))
739
 
#define WACOM_BEE_BUTTONS       (WACOM_INTUOS3_BUTTONS | BIT(BTN_8) | BIT(BTN_9))
740
 
#define WACOM_INTUOS_BITS       (BIT(EV_REL))
741
 
#define WACOM_INTUOS_REL        (BIT(REL_WHEEL))
742
 
#define WACOM_INTUOS_ABS        (BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE))
743
 
#define WACOM_INTUOS3S_ABS      (WACOM_INTUOS_ABS | BIT(ABS_RX) | BIT(ABS_Z))
744
 
#define WACOM_INTUOS3_ABS       (WACOM_INTUOS3S_ABS | BIT(ABS_RY))
745
 
 
746
 
struct wacom_features wacom_features[] = {
747
 
 
748
 
        /* PenPartner */
749
 
        /*  0 */ { "Wacom Penpartner",     7,   5040,  3780,   255, 0,
750
 
                        wacom_penpartner_irq, 0, 0, 0, 0 },
751
 
 
752
 
        /* Graphire */
753
 
        /*  1 */ { "Wacom Graphire",       8,  10206,  7422,   511, 63,
754
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, WACOM_GRAPHIRE_REL, 0 },
755
 
        /*  2 */ { "Wacom Graphire2 4x5",  8,  10206,  7422,   511, 63,
756
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, WACOM_GRAPHIRE_REL, 0 },
757
 
        /*  3 */ { "Wacom Graphire2 5x7",  8,  13918, 10206,   511, 63,
758
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, WACOM_GRAPHIRE_REL, 0 },
759
 
 
760
 
        /* Intuos */
761
 
        /*  4 */ { "Wacom Intuos 4x5",    10,  12700, 10600,  1023, 31,
762
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
763
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
764
 
        /* JEJ - confirmed X and Y range from test tablet */
765
 
        /*  5 */ { "Wacom Intuos 6x8",    10,  20320, 16240,  1023, 31,
766
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
767
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
768
 
        /*  6 */ { "Wacom Intuos 9x12",   10,  30480, 24060,  1023, 31,
769
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
770
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
771
 
        /*  7 */ { "Wacom Intuos 12x12",  10,  30480, 31680,  1023, 31,
772
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
773
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
774
 
        /*  8 */ { "Wacom Intuos 12x18",  10,  45720, 31680,  1023, 31,
775
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
776
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
777
 
 
778
 
        /* PL - Cintiq */
779
 
        /*  9 */ { "Wacom PL400",          8,   5408,  4056,   255, 0,
780
 
                        wacom_pl_irq, 0,  0, 0, 0 },
781
 
        /* 10 */ { "Wacom PL500",          8,   6144,  4608,   255, 0,
782
 
                        wacom_pl_irq, 0,  0, 0, 0 },
783
 
        /* 11 */ { "Wacom PL600",          8,   6126,  4604,   255, 0,
784
 
                        wacom_pl_irq, 0,  0, 0, 0 },
785
 
        /* 12 */ { "Wacom PL600SX",        8,   6260,  5016,   255, 0,
786
 
                        wacom_pl_irq, 0,  0, 0, 0 },
787
 
        /* 13 */ { "Wacom PL550",          8,   6144,  4608,   511, 0,
788
 
                        wacom_pl_irq, 0,  0, 0, 0 },
789
 
        /* 14 */ { "Wacom PL800",          8,   7220,  5780,   511, 0,
790
 
                        wacom_pl_irq, 0,  0, 0, 0 },
791
 
        /* 15 */ { "Wacom PL700",          8,   6758,  5406,   511, 0,
792
 
                        wacom_pl_irq, 0,  0, 0, 0 },
793
 
        /* 16 */ { "Wacom PL510",          8,   6282,  4762,   511, 0,
794
 
                        wacom_pl_irq, 0,  0, 0, 0 },
795
 
        /* 17 */ { "Wacom DTU710",         8,  34080, 27660,   511, 0,
796
 
                        wacom_pl_irq, 0,  0, 0, 0 },
797
 
 
798
 
        /* Intuos2 */
799
 
        /* JEJ - confirmed X and Y range from J.N. tablet */
800
 
        /* 18 */ { "Wacom Intuos2 4x5",   10,  12700, 10600,  1023, 31,
801
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
802
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
803
 
        /* JEJ - confirmed X and Y range from R.T. and J.S. tablets */
804
 
        /* 19 */ { "Wacom Intuos2 6x8",   10,  20320, 16240,  1023, 31,
805
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
806
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
807
 
        /* JEJ - values from serial 9x12 */
808
 
        /* 20 */ { "Wacom Intuos2 9x12",  10,  30480, 24060,  1023, 31,
809
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
810
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
811
 
        /* JEJ - confirmed X and Y range from J.J. tablet */
812
 
        /* 21 */ { "Wacom Intuos2 12x12", 10,  30480, 31680,  1023, 31,
813
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
814
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
815
 
        /* 22 */ { "Wacom Intuos2 12x18", 10,  45720, 31680,  1023, 31,
816
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
817
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
818
 
        /* Volito1 */
819
 
        /* 23 */ { "Wacom Volito1",        8,   5104,  3712,   511, 63,
820
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, 0, 0 },
821
 
        /* Volito2 - PenPartner - PenStation */
822
 
        /* 24 */ { "Wacom PenStation2",    8,   3250,  2320,   255, 63,
823
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, 0, 0 },
824
 
        /* 25 */ { "Wacom Volito2 4x5",    8,   5104,  3712,   511, 63,
825
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, 0, 0 },
826
 
        /* 26 */ { "Wacom Volito2 2x3",    8,   3250,  2320,   511, 63,
827
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, 0, 0 },
828
 
        /* 27 */ { "Wacom PenPartner2",    8,   3250,  2320,   511, 63,
829
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, 0, 0 },
830
 
        /* 28 */ { "Wacom Bamboo",         9,   14760, 9225,   511, 63,
831
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, WACOM_MO_ABS,
832
 
                        WACOM_GRAPHIRE_REL, WACOM_MO_BUTTONS, WACOM_G4_TOOLS },
833
 
        /* 29 */ { "Wacom Bamboo1",        8,   5104,  3712,   511, 63,
834
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, 0, 0 },
835
 
        /* 30 */ { "Wacom Graphire3 4x5",  8,   10208, 7424,   511, 63,
836
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, WACOM_GRAPHIRE_REL, 0 },
837
 
        /* 31 */ { "Wacom Graphire3 6x8",  8,   16704, 12064,  511, 63,
838
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, WACOM_GRAPHIRE_REL, 0 },
839
 
        /* 32 */ { "Wacom Graphire4 4x5",  8,   10208, 7424,   511, 63,
840
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, 
841
 
                        WACOM_GRAPHIRE_REL, WACOM_G4_BUTTONS, WACOM_G4_TOOLS },
842
 
        /* 33 */ { "Wacom Graphire4 6x8",  8,   16704, 12064,  511, 63,
843
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, 0, 
844
 
                        WACOM_GRAPHIRE_REL, WACOM_G4_BUTTONS, WACOM_G4_TOOLS },
845
 
        /* 34 */ { "Wacom BambooFun 4x5",  9,   14760, 9225,   511, 63,
846
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, WACOM_MO_ABS,
847
 
                        WACOM_GRAPHIRE_REL, WACOM_MO_BUTTONS, WACOM_G4_TOOLS },
848
 
        /* 35 */ { "Wacom BambooFun 6x8",  9,   21648,13530,   511, 63,
849
 
                        wacom_graphire_irq, WACOM_GRAPHIRE_BITS, WACOM_MO_ABS,
850
 
                        WACOM_GRAPHIRE_REL, WACOM_MO_BUTTONS, WACOM_G4_TOOLS },
851
 
        /* 36 */ { "Wacom Cintiq Partner", 8,   20480, 15360,  511, 31,
852
 
                        wacom_ptu_irq, 0, 0, 0, 0 },
853
 
        /* Intuos3 */
854
 
        /* 37 */ { "Wacom Intuos3 4x5",   10,  25400, 20320,  1023, 63,
855
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3S_ABS,
856
 
                        WACOM_INTUOS_REL, WACOM_INTUOS3S_BUTTONS, WACOM_INTUOS3_TOOLS },
857
 
        /* 38 */ { "Wacom Intuos3 6x8",   10,  40640, 30480,  1023, 63,
858
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3_ABS,
859
 
                        WACOM_INTUOS_REL, WACOM_INTUOS3_BUTTONS, WACOM_INTUOS3_TOOLS },
860
 
        /* 39 */ { "Wacom Intuos3 9x12",  10,  60960, 45720,  1023, 63,
861
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3_ABS,
862
 
                        WACOM_INTUOS_REL, WACOM_INTUOS3_BUTTONS, WACOM_INTUOS3_TOOLS },
863
 
        /* 40 */ { "Wacom Intuos3 12x12", 10,  60960, 60960,  1023, 63,
864
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3_ABS,
865
 
                        WACOM_INTUOS_REL, WACOM_INTUOS3_BUTTONS, WACOM_INTUOS3_TOOLS },
866
 
        /* 41 */ { "Wacom Intuos3 12x19", 10,  97536, 60960,  1023, 63,
867
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3_ABS,
868
 
                        WACOM_INTUOS_REL, WACOM_INTUOS3_BUTTONS, WACOM_INTUOS3_TOOLS },
869
 
        /* 42 */ { "Wacom Intuos3 6x11",  10,  54204, 31750,  1023, 63,
870
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3_ABS,
871
 
                        WACOM_INTUOS_REL, WACOM_INTUOS3_BUTTONS, WACOM_INTUOS3_TOOLS },
872
 
        /* 43 */ { "Wacom Intuos3 4x6",   10,  31496, 19685,  1023, 63,
873
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3S_ABS,
874
 
                        WACOM_INTUOS_REL, WACOM_INTUOS3S_BUTTONS, WACOM_INTUOS3_TOOLS },
875
 
        /* Protocol 5 Cintiq */
876
 
        /* 44 */ { "Wacom Cintiq 21UX",   10,  87200, 65600,  1023, 63,
877
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3_ABS,
878
 
                        0, WACOM_INTUOS3_BUTTONS, WACOM_INTUOS3_TOOLS },
879
 
        /* 45 */ { "Wacom Cintiq 20WSX",  10,  86680, 54180,  1023, 63, 
880
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3_ABS,
881
 
                        0, WACOM_BEE_BUTTONS, WACOM_INTUOS3_TOOLS },
882
 
        /* 46 */ { "Wacom Cintiq 12WX",   10,  53020, 33440,  1023, 63,
883
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS3_ABS,
884
 
                        0, WACOM_BEE_BUTTONS, WACOM_INTUOS3_TOOLS },
885
 
        /* 47 */ { "Wacom DTF720",         8,   6858,  5506,   511, 0,
886
 
                        wacom_pl_irq, 0,  0, 0, 0 },
887
 
        /* 48 */ { "Wacom DTF521",         8,   6282,  4762,   511, 0,
888
 
                        wacom_pl_irq, 0,  0, 0, 0 },
889
 
        /* 49 */ { "Wacom Intuos2 6x8",   10,  20320, 16240,  1023, 31,
890
 
                        wacom_intuos_irq, WACOM_INTUOS_BITS, WACOM_INTUOS_ABS,
891
 
                        WACOM_INTUOS_REL, WACOM_INTUOS_BUTTONS, WACOM_INTUOS_TOOLS },
892
 
        { NULL , 0 }
893
 
};
894
 
 
895
 
struct usb_device_id wacom_ids[] = {
896
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00), driver_info: 0 },
897
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10), driver_info: 1 },
898
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11), driver_info: 2 },
899
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12), driver_info: 3 },
900
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20), driver_info: 4 },
901
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21), driver_info: 5 },
902
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22), driver_info: 6 },
903
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23), driver_info: 7 },
904
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24), driver_info: 8 },
905
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30), driver_info: 9 },
906
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31), driver_info: 10 },
907
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32), driver_info: 11 },
908
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33), driver_info: 12 },
909
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34), driver_info: 13 },
910
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35), driver_info: 14 },
911
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37), driver_info: 15 },
912
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38), driver_info: 16 },
913
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39), driver_info: 17 },
914
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41), driver_info: 18 },
915
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42), driver_info: 19 },
916
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43), driver_info: 20 },
917
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44), driver_info: 21 },
918
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45), driver_info: 22 },
919
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60), driver_info: 23 },
920
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61), driver_info: 24 },
921
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62), driver_info: 25 },
922
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63), driver_info: 26 },
923
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64), driver_info: 27 },
924
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x65), driver_info: 28 },
925
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x69), driver_info: 29 },
926
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13), driver_info: 30 },
927
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14), driver_info: 31 },
928
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15), driver_info: 32 },
929
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16), driver_info: 33 },
930
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x17), driver_info: 34 },
931
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x18), driver_info: 35 },
932
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03), driver_info: 36 },
933
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0), driver_info: 37 },
934
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1), driver_info: 38 },
935
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2), driver_info: 39 },
936
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3), driver_info: 40 },
937
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4), driver_info: 41 },
938
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5), driver_info: 42 },
939
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7), driver_info: 43 },
940
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F), driver_info: 44 },
941
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC5), driver_info: 45 },
942
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC6), driver_info: 46 },
943
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0), driver_info: 47 },
944
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC4), driver_info: 48 },
945
 
 
946
 
        /* some Intuos2 6x8's erroneously report as 0x47;
947
 
         * multiple confirmed examples exist. */
948
 
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47), driver_info: 19 },
949
 
 
950
 
        { }
951
 
};
952
 
 
953
 
MODULE_DEVICE_TABLE(usb, wacom_ids);
954
 
 
955
 
static int wacom_open(struct input_dev *dev)
956
 
{
957
 
        struct wacom *wacom = dev->private;
958
 
        
959
 
        if (wacom->open++)
960
 
                return 0;
961
 
 
962
 
        wacom->irq.dev = wacom->usbdev;
963
 
        if (usb_submit_urb(&wacom->irq))
964
 
                return -EIO;
965
 
 
966
 
        return 0;
967
 
}
968
 
 
969
 
static void wacom_close(struct input_dev *dev)
970
 
{
971
 
        struct wacom *wacom = dev->private;
972
 
 
973
 
        if (!--wacom->open)
974
 
                usb_unlink_urb(&wacom->irq);
975
 
}
976
 
 
977
 
static void wacom_reset(struct wacom* wacom)
978
 
{
979
 
        unsigned char edata[2], limit=0;
980
 
        #ifdef __JEJ_DEBUG
981
 
        printk(KERN_INFO __FILE__ ": Setting tablet report for tablet data\n");
982
 
        #endif
983
 
 
984
 
        /* ask the tablet to report tablet data. repeats until it succeeds */
985
 
        do {
986
 
                edata[0] = 2;
987
 
                edata[1] = 2;
988
 
                usb_set_report(wacom->usbdev, wacom->ifnum, 3, 2, edata, 2);
989
 
                usb_get_report(wacom->usbdev, wacom->ifnum, 3, 2, edata, 2);
990
 
        } while (edata[1] != 2 && limit++ < 5);
991
 
}
992
 
 
993
 
static void *wacom_probe(struct usb_device *dev, unsigned int ifnum, const struct usb_device_id *id)
994
 
{
995
 
        struct usb_endpoint_descriptor *endpoint;
996
 
        struct wacom *wacom;
997
 
 
998
 
        if (!(wacom = kmalloc(sizeof(struct wacom), GFP_KERNEL))) return NULL;
999
 
        memset(wacom, 0, sizeof(struct wacom));
1000
 
 
1001
 
        wacom->features = wacom_features + id->driver_info;
1002
 
 
1003
 
        wacom->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC) |
1004
 
                        wacom->features->evbit;
1005
 
        wacom->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE) |
1006
 
                        BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) |
1007
 
                        wacom->features->absbit;
1008
 
        wacom->dev.absbit[LONG(ABS_MISC)] |= BIT(ABS_MISC);
1009
 
        wacom->dev.relbit[0] |= wacom->features->relbit;
1010
 
        wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) |
1011
 
                        BIT(BTN_MIDDLE) | wacom->features->btnbit;
1012
 
        wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | 
1013
 
                        BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | 
1014
 
                        BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2) |
1015
 
                        wacom->features->digibit;
1016
 
        wacom->dev.mscbit[0] |= BIT(MSC_SERIAL);
1017
 
 
1018
 
        #ifdef __JEJ_DEBUG
1019
 
        printk(KERN_INFO __FILE__ ": Reporting max %d, %d\n",
1020
 
                wacom->features->x_max, wacom->features->y_max);
1021
 
        #endif
1022
 
 
1023
 
        wacom->dev.absmax[ABS_X] = wacom->features->x_max;
1024
 
        wacom->dev.absmax[ABS_Y] = wacom->features->y_max;
1025
 
        wacom->dev.absmax[ABS_PRESSURE] = wacom->features->pressure_max;
1026
 
        wacom->dev.absmax[ABS_DISTANCE] = wacom->features->distance_max;
1027
 
        wacom->dev.absmax[ABS_TILT_X] = 127;
1028
 
        wacom->dev.absmax[ABS_TILT_Y] = 127;
1029
 
        wacom->dev.absmax[ABS_WHEEL] = 1023;
1030
 
 
1031
 
        wacom->dev.absmax[ABS_RX] = 4096;
1032
 
        wacom->dev.absmax[ABS_RY] = 4096;
1033
 
        wacom->dev.absmin[ABS_RZ] = -900;
1034
 
        wacom->dev.absmax[ABS_RZ] = 899;
1035
 
        wacom->dev.absmin[ABS_THROTTLE] = -1023;
1036
 
        wacom->dev.absmax[ABS_THROTTLE] = 1023;
1037
 
        wacom->dev.absmin[ABS_Z] = -900;
1038
 
        wacom->dev.absmax[ABS_Z] = 899;
1039
 
 
1040
 
        wacom->dev.absfuzz[ABS_X] = 4;
1041
 
        wacom->dev.absfuzz[ABS_Y] = 4;
1042
 
 
1043
 
        wacom->dev.private = wacom;
1044
 
        wacom->dev.open = wacom_open;
1045
 
        wacom->dev.close = wacom_close;
1046
 
 
1047
 
        wacom->dev.name = wacom->features->name;
1048
 
        wacom->dev.idbus = BUS_USB;
1049
 
        wacom->dev.idvendor = dev->descriptor.idVendor;
1050
 
        wacom->dev.idproduct = dev->descriptor.idProduct;
1051
 
        wacom->dev.idversion = dev->descriptor.bcdDevice;
1052
 
        wacom->usbdev = dev;
1053
 
        wacom->ifnum = ifnum;
1054
 
 
1055
 
        endpoint = dev->config[0].interface[ifnum].altsetting[0].endpoint + 0;
1056
 
 
1057
 
        usb_set_idle(dev, dev->config[0].interface[ifnum].altsetting[0].bInterfaceNumber, 0, 0);
1058
 
 
1059
 
        FILL_INT_URB(&wacom->irq, dev, usb_rcvintpipe(dev,
1060
 
                        endpoint->bEndpointAddress), wacom->data, wacom->features->pktlen,
1061
 
                        wacom->features->irq, wacom, endpoint->bInterval);
1062
 
 
1063
 
        input_register_device(&wacom->dev);
1064
 
 
1065
 
        wacom_reset(wacom);
1066
 
 
1067
 
        printk(KERN_INFO __FILE__ ": input%d: %s on usb%d:%d.%d\n",
1068
 
                        wacom->dev.number, wacom->features->name, dev->bus->busnum,
1069
 
                        dev->devnum, ifnum);
1070
 
 
1071
 
        return wacom;
1072
 
}
1073
 
 
1074
 
static void wacom_disconnect(struct usb_device *dev, void *ptr)
1075
 
{
1076
 
        struct wacom *wacom = ptr;
1077
 
 
1078
 
        usb_unlink_urb(&wacom->irq);
1079
 
        input_unregister_device(&wacom->dev);
1080
 
        kfree(wacom);
1081
 
}
1082
 
 
1083
 
static struct usb_driver wacom_driver = {
1084
 
        name:           "wacom",
1085
 
        probe:          wacom_probe,
1086
 
        disconnect:     wacom_disconnect,
1087
 
        id_table:       wacom_ids,
1088
 
};
1089
 
 
1090
 
static int __init wacom_init(void)
1091
 
{
1092
 
        usb_register(&wacom_driver);
1093
 
        info(DRIVER_VERSION " " DRIVER_AUTHOR);
1094
 
        info(DRIVER_DESC);
1095
 
        return 0;
1096
 
}
1097
 
 
1098
 
static void __exit wacom_exit(void)
1099
 
{
1100
 
        usb_deregister(&wacom_driver);
1101
 
}
1102
 
 
1103
 
module_init(wacom_init);
1104
 
module_exit(wacom_exit);