~ubuntu-branches/debian/lenny/wacom-tools/lenny

« back to all changes in this revision

Viewing changes to linuxwacom/src/2.4/wacom.c

  • Committer: Bazaar Package Importer
  • Author(s): Ron Lee
  • Date: 2004-12-10 16:12:07 UTC
  • Revision ID: james.westby@ubuntu.com-20041210161207-cw8urijtjsqvk2e3
Tags: upstream-0.6.6
ImportĀ upstreamĀ versionĀ 0.6.6

Show diffs side-by-side

added added

removed removed

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