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

« back to all changes in this revision

Viewing changes to linuxwacom/src/2.6.9/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
 *  USB Wacom Graphire and Wacom Intuos tablet support
 
3
 *
 
4
 *  Copyright (c) 2000-2004 Vojtech Pavlik      <vojtech@ucw.cz>
 
5
 *  Copyright (c) 2000 Andreas Bach Aaen        <abach@stofanet.dk>
 
6
 *  Copyright (c) 2000 Clifford Wolf            <clifford@clifford.at>
 
7
 *  Copyright (c) 2000 Sam Mosel                <sam.mosel@computer.org>
 
8
 *  Copyright (c) 2000 James E. Blair           <corvus@gnu.org>
 
9
 *  Copyright (c) 2000 Daniel Egger             <egger@suse.de>
 
10
 *  Copyright (c) 2001 Frederic Lepied          <flepied@mandrakesoft.com>
 
11
 *  Copyright (c) 2004 Panagiotis Issaris       <panagiotis.issaris@mech.kuleuven.ac.be>
 
12
 *  Copyright (c) 2002-2004 Ping Cheng          <pingc@wacom.com>
 
13
 *
 
14
 *  ChangeLog:
 
15
 *      v0.1 (vp)  - Initial release
 
16
 *      v0.2 (aba) - Support for all buttons / combinations
 
17
 *      v0.3 (vp)  - Support for Intuos added
 
18
 *      v0.4 (sm)  - Support for more Intuos models, menustrip
 
19
 *                      relative mode, proximity.
 
20
 *      v0.5 (vp)  - Big cleanup, nifty features removed,
 
21
 *                      they belong in userspace
 
22
 *      v1.8 (vp)  - Submit URB only when operating, moved to CVS,
 
23
 *                      use input_report_key instead of report_btn and
 
24
 *                      other cleanups
 
25
 *      v1.11 (vp) - Add URB ->dev setting for new kernels
 
26
 *      v1.11 (jb) - Add support for the 4D Mouse & Lens
 
27
 *      v1.12 (de) - Add support for two more inking pen IDs
 
28
 *      v1.14 (vp) - Use new USB device id probing scheme.
 
29
 *                   Fix Wacom Graphire mouse wheel
 
30
 *      v1.18 (vp) - Fix mouse wheel direction
 
31
 *                   Make mouse relative
 
32
 *      v1.20 (fl) - Report tool id for Intuos devices
 
33
 *                 - Multi tools support
 
34
 *                 - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...)
 
35
 *                 - Add PL models support
 
36
 *                 - Fix Wacom Graphire mouse wheel again
 
37
 *      v1.21 (vp) - Removed protocol descriptions
 
38
 *                 - Added MISC_SERIAL for tool serial numbers
 
39
 *            (gb) - Identify version on module load.
 
40
 *    v1.21.1 (fl) - added Graphire2 support
 
41
 *    v1.21.2 (fl) - added Intuos2 support
 
42
 *                 - added all the PL ids
 
43
 *    v1.21.3 (fl) - added another eraser id from Neil Okamoto
 
44
 *                 - added smooth filter for Graphire from Peri Hankey
 
45
 *                 - added PenPartner support from Olaf van Es
 
46
 *                 - new tool ids from Ole Martin Bjoerndalen
 
47
 *      v1.29 (pc) - Add support for more tablets
 
48
 *                 - Fix pressure reporting
 
49
 *      v1.30 (vp) - Merge 2.4 and 2.5 drivers
 
50
 *                 - Since 2.5 now has input_sync(), remove MSC_SERIAL abuse
 
51
 *                 - Cleanups here and there
 
52
 *    v1.30.1 (pi) - Added Graphire3 support
 
53
 *      v1.40 (pc) - Add support for several new devices, fix eraser reporting, ...
 
54
 *
 
55
 *   WARNING: THIS IS NOT PART OF THE OFFICIAL KERNEL TREE
 
56
 *   THIS IS FOR TESTING PURPOSES
 
57
 *
 
58
 *    v1.40-2.6.9-pc-0.1 - incorporate with 2.6.9
 
59
 *    v1.40-2.6.9-pc-0.2 - linuxwacom-0.6.6
 
60
 */
 
61
 
 
62
/*
 
63
 * This program is free software; you can redistribute it and/or modify
 
64
 * it under the terms of the GNU General Public License as published by
 
65
 * the Free Software Foundation; either version 2 of the License, or
 
66
 * (at your option) any later version.
 
67
 */
 
68
 
 
69
#include <linux/kernel.h>
 
70
#include <linux/slab.h>
 
71
#include <linux/input.h>
 
72
#include <linux/module.h>
 
73
#include <linux/init.h>
 
74
#include <linux/usb.h>
 
75
#include <asm/unaligned.h>
 
76
#include <asm/byteorder.h>
 
77
 
 
78
/*
 
79
 * Version Information
 
80
 */
 
81
#define DRIVER_VERSION "v1.40 - 2.6.9-pc-0.2"
 
82
#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
 
83
#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
 
84
#define DRIVER_LICENSE "GPL"
 
85
 
 
86
MODULE_AUTHOR(DRIVER_AUTHOR);
 
87
MODULE_DESCRIPTION(DRIVER_DESC);
 
88
MODULE_LICENSE(DRIVER_LICENSE);
 
89
 
 
90
#define USB_VENDOR_ID_WACOM     0x056a
 
91
 
 
92
struct wacom_features {
 
93
        char *name;
 
94
        int pktlen;
 
95
        int x_max;
 
96
        int y_max;
 
97
        int pressure_max;
 
98
        int distance_max;
 
99
        int type;
 
100
        usb_complete_t irq;
 
101
};
 
102
 
 
103
struct wacom {
 
104
        signed char *data;
 
105
        dma_addr_t data_dma;
 
106
        struct input_dev dev;
 
107
        struct usb_device *usbdev;
 
108
        struct urb *irq;
 
109
        struct wacom_features *features;
 
110
        int tool[2];
 
111
        int open;
 
112
        __u32 serial[2];
 
113
        char phys[32];
 
114
};
 
115
 
 
116
#define USB_REQ_SET_REPORT      0x09
 
117
static int usb_set_report(struct usb_interface *intf, unsigned char type,
 
118
                                unsigned char id, void *buf, int size)
 
119
{
 
120
        return usb_control_msg(interface_to_usbdev(intf),
 
121
                usb_sndctrlpipe(interface_to_usbdev(intf), 0),
 
122
                USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
 
123
                (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
 
124
                buf, size, HZ);
 
125
}
 
126
 
 
127
static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
 
128
{
 
129
        struct wacom *wacom = urb->context;
 
130
        unsigned char *data = wacom->data;
 
131
        struct input_dev *dev = &wacom->dev;
 
132
        int prox, pressure;
 
133
        int retval;
 
134
 
 
135
        switch (urb->status) {
 
136
        case 0:
 
137
                /* success */
 
138
                break;
 
139
        case -ECONNRESET:
 
140
        case -ENOENT:
 
141
        case -ESHUTDOWN:
 
142
                /* this urb is terminated, clean up */
 
143
                dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
 
144
                return;
 
145
        default:
 
146
                dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
 
147
                goto exit;
 
148
        }
 
149
 
 
150
        if (data[0] != 2) {
 
151
                dbg("wacom_pl_irq: received unknown report #%d", data[0]);
 
152
                return;
 
153
        }
 
154
 
 
155
        prox = data[1] & 0x40;
 
156
 
 
157
        input_regs(dev, regs);
 
158
        
 
159
        if (prox) {
 
160
 
 
161
                pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
 
162
                if (wacom->features->pressure_max > 255)
 
163
                        pressure = (pressure << 1) | ((data[4] >> 6) & 1);
 
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
                        /* Going into proximity select tool */
 
174
                        wacom->tool[1] = (data[4] & 0x20)? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
 
175
                }
 
176
                else {
 
177
                        /* was entered with stylus2 pressed */
 
178
                        if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20) ) {
 
179
                                /* report out proximity for previous tool */
 
180
                                input_report_key(dev, wacom->tool[1], 0);
 
181
                                input_sync(dev);
 
182
                                wacom->tool[1] = BTN_TOOL_PEN;
 
183
                                goto exit;
 
184
                        }
 
185
                }
 
186
                if (wacom->tool[1] != BTN_TOOL_RUBBER) {
 
187
                        /* Unknown tool selected default to pen tool */
 
188
                        wacom->tool[1] = BTN_TOOL_PEN;
 
189
                }
 
190
                input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */
 
191
                input_report_abs(dev, ABS_X, data[3] | ((__u32)data[2] << 7) | ((__u32)(data[1] & 0x03) << 14));
 
192
                input_report_abs(dev, ABS_Y, data[6] | ((__u32)data[5] << 7) | ((__u32)(data[4] & 0x03) << 14));
 
193
                input_report_abs(dev, ABS_PRESSURE, pressure);
 
194
 
 
195
                input_report_key(dev, BTN_TOUCH, data[4] & 0x08);
 
196
                input_report_key(dev, BTN_STYLUS, data[4] & 0x10);
 
197
                /* Only allow the stylus2 button to be reported for the pen tool. */
 
198
                input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
 
199
        }
 
200
        else {
 
201
                /* report proximity-out of a (valid) tool */
 
202
                if (wacom->tool[1] != BTN_TOOL_RUBBER) {
 
203
                        /* Unknown tool selected default to pen tool */
 
204
                        wacom->tool[1] = BTN_TOOL_PEN;
 
205
                }
 
206
                input_report_key(dev, wacom->tool[1], prox);
 
207
        }
 
208
 
 
209
        wacom->tool[0] = prox; /* Save proximity state */
 
210
        input_sync(dev);
 
211
 
 
212
exit:
 
213
        retval = usb_submit_urb (urb, GFP_ATOMIC);
 
214
        if (retval)
 
215
                err ("%s - usb_submit_urb failed with result %d",
 
216
                     __FUNCTION__, retval);
 
217
}
 
218
 
 
219
static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
 
220
{
 
221
        struct wacom *wacom = urb->context;
 
222
        unsigned char *data = wacom->data;
 
223
        struct input_dev *dev = &wacom->dev;
 
224
        int retval;
 
225
 
 
226
        switch (urb->status) {
 
227
        case 0:
 
228
                /* success */
 
229
                break;
 
230
        case -ECONNRESET:
 
231
        case -ENOENT:
 
232
        case -ESHUTDOWN:
 
233
                /* this urb is terminated, clean up */
 
234
                dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
 
235
                return;
 
236
        default:
 
237
                dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
 
238
                goto exit;
 
239
        }
 
240
 
 
241
        if (data[0] != 2)
 
242
        {
 
243
                printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
 
244
                return;
 
245
        }
 
246
 
 
247
        input_regs(dev, regs);
 
248
        if (data[1] & 0x04)
 
249
        {
 
250
                input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20);
 
251
                input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
 
252
        }
 
253
        else
 
254
        {
 
255
                input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20);
 
256
                input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
 
257
        }
 
258
        input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[2]));
 
259
        input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[4]));
 
260
        input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
 
261
        input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
 
262
        input_report_key(dev, BTN_STYLUS2, data[1] & 0x10);
 
263
 
 
264
        input_sync(dev);
 
265
 
 
266
exit:
 
267
        retval = usb_submit_urb (urb, GFP_ATOMIC);
 
268
        if (retval)
 
269
                err ("%s - usb_submit_urb failed with result %d",
 
270
                     __FUNCTION__, retval);
 
271
}
 
272
 
 
273
static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
 
274
{
 
275
        struct wacom *wacom = urb->context;
 
276
        unsigned char *data = wacom->data;
 
277
        struct input_dev *dev = &wacom->dev;
 
278
        int retval;
 
279
 
 
280
        switch (urb->status) {
 
281
        case 0:
 
282
                /* success */
 
283
                break;
 
284
        case -ECONNRESET:
 
285
        case -ENOENT:
 
286
        case -ESHUTDOWN:
 
287
                /* this urb is terminated, clean up */
 
288
                dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
 
289
                return;
 
290
        default:
 
291
                dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
 
292
                goto exit;
 
293
        }
 
294
 
 
295
        if (data[0] != 2) {
 
296
                printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
 
297
                return;
 
298
        }
 
299
 
 
300
        input_regs(dev, regs);
 
301
        input_report_key(dev, BTN_TOOL_PEN, 1);
 
302
        input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[1]));
 
303
        input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[3]));
 
304
        input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127);
 
305
        input_report_key(dev, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
 
306
        input_report_key(dev, BTN_STYLUS, (data[5] & 0x40));
 
307
        input_sync(dev);
 
308
 
 
309
exit:
 
310
        retval = usb_submit_urb (urb, GFP_ATOMIC);
 
311
        if (retval)
 
312
                err ("%s - usb_submit_urb failed with result %d",
 
313
                     __FUNCTION__, retval);
 
314
}
 
315
 
 
316
static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
 
317
{
 
318
        struct wacom *wacom = urb->context;
 
319
        unsigned char *data = wacom->data;
 
320
        struct input_dev *dev = &wacom->dev;
 
321
        int x, y;
 
322
        int retval;
 
323
 
 
324
        switch (urb->status) {
 
325
        case 0:
 
326
                /* success */
 
327
                break;
 
328
        case -ECONNRESET:
 
329
        case -ENOENT:
 
330
        case -ESHUTDOWN:
 
331
                /* this urb is terminated, clean up */
 
332
                dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
 
333
                return;
 
334
        default:
 
335
                dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
 
336
                goto exit;
 
337
        }
 
338
 
 
339
        if (data[0] != 2) {
 
340
                dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
 
341
                return;
 
342
        }
 
343
 
 
344
        x = le16_to_cpu(*(__le16 *) &data[2]);
 
345
        y = le16_to_cpu(*(__le16 *) &data[4]);
 
346
 
 
347
        input_regs(dev, regs);
 
348
 
 
349
        switch ((data[1] >> 5) & 3) {
 
350
 
 
351
                case 0: /* Pen */
 
352
                        input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x80);
 
353
                        break;
 
354
 
 
355
                case 1: /* Rubber */
 
356
                        input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x80);
 
357
                        break;
 
358
 
 
359
                case 2: /* Mouse with wheel */
 
360
                        input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
 
361
                        input_report_rel(dev, REL_WHEEL, (signed char) data[6]);
 
362
                        /* fall through */
 
363
 
 
364
                case 3: /* Mouse without wheel */
 
365
                        input_report_key(dev, BTN_TOOL_MOUSE, data[7] > 24);
 
366
                        input_report_key(dev, BTN_LEFT, data[1] & 0x01);
 
367
                        input_report_key(dev, BTN_RIGHT, data[1] & 0x02);
 
368
                        input_report_abs(dev, ABS_DISTANCE, data[7]);
 
369
 
 
370
                        input_report_abs(dev, ABS_X, x);
 
371
                        input_report_abs(dev, ABS_Y, y);
 
372
 
 
373
                        input_sync(dev);
 
374
                        goto exit;
 
375
        }
 
376
 
 
377
        if (data[1] & 0x80) {
 
378
                input_report_abs(dev, ABS_X, x);
 
379
                input_report_abs(dev, ABS_Y, y);
 
380
        }
 
381
 
 
382
        input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
 
383
        input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
 
384
        input_report_key(dev, BTN_STYLUS, data[1] & 0x02);
 
385
        input_report_key(dev, BTN_STYLUS2, data[1] & 0x04);
 
386
 
 
387
        input_sync(dev);
 
388
 
 
389
exit:
 
390
        retval = usb_submit_urb (urb, GFP_ATOMIC);
 
391
        if (retval)
 
392
                err ("%s - usb_submit_urb failed with result %d",
 
393
                     __FUNCTION__, retval);
 
394
}
 
395
 
 
396
static int wacom_intuos_inout(struct urb *urb)
 
397
{
 
398
        struct wacom *wacom = urb->context;
 
399
        unsigned char *data = wacom->data;
 
400
        struct input_dev *dev = &wacom->dev;
 
401
        int idx;
 
402
 
 
403
        /* tool number */
 
404
        idx = data[1] & 0x01;
 
405
 
 
406
        /* Enter report */
 
407
        if ((data[1] & 0xfc) == 0xc0) 
 
408
        {       
 
409
                /* serial number of the tool */
 
410
                wacom->serial[idx] = ((__u32)(data[3] & 0x0f) << 28) +  
 
411
                        ((__u32)data[4] << 20) + ((__u32)data[5] << 12) +
 
412
                        ((__u32)data[6] << 4) + (data[7] >> 4);
 
413
 
 
414
                switch (((__u32)data[2] << 4) | (data[3] >> 4)) {
 
415
                        case 0x812: /* Inking pen */
 
416
                        case 0x801: /* Intuos3 Inking pen */
 
417
                        case 0x012: 
 
418
                                wacom->tool[idx] = BTN_TOOL_PENCIL;
 
419
                                break;  
 
420
                        case 0x822: /* Pen */
 
421
                        case 0x842:
 
422
                        case 0x852:
 
423
                        case 0x823: /* Intuos3 Grip Pen */
 
424
                        case 0x813: /* Intuos3 Classic Pen */
 
425
                        case 0x885: /* Intuos3 Marker Pen */
 
426
                        case 0x022: 
 
427
                                wacom->tool[idx] = BTN_TOOL_PEN;
 
428
                                break;
 
429
                        case 0x832: /* Stroke pen */
 
430
                        case 0x032: 
 
431
                                wacom->tool[idx] = BTN_TOOL_BRUSH;
 
432
                                break;
 
433
                        case 0x007: /* Mouse 4D and 2D */
 
434
                        case 0x09c:
 
435
                        case 0x094:
 
436
                        case 0x017: /* Intuos3 2D Mouse */
 
437
                                wacom->tool[idx] = BTN_TOOL_MOUSE;
 
438
                                break;
 
439
                        case 0x096: /* Lens cursor */
 
440
                        case 0x097: /* Intuos3 Lens cursor */
 
441
                                wacom->tool[idx] = BTN_TOOL_LENS;
 
442
                                break;
 
443
                        case 0x82a: /* Eraser */
 
444
                        case 0x85a:
 
445
                        case 0x91a:
 
446
                        case 0xd1a:
 
447
                        case 0x0fa: 
 
448
                        case 0x82b: /* Intuos3 Grip Pen Eraser */
 
449
                        case 0x81b: /* Intuos3 Classic Pen Eraser */
 
450
                        case 0x91b: /* Intuos3 Airbrush Eraser */
 
451
                                wacom->tool[idx] = BTN_TOOL_RUBBER;
 
452
                                break;
 
453
                        case 0xd12: /* Airbrush */
 
454
                        case 0x912:
 
455
                        case 0x112: 
 
456
                        case 0x913: /* Intuos3 Airbrush */
 
457
                                wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
 
458
                                break;
 
459
                        default: /* Unknown tool */
 
460
                                wacom->tool[idx] = BTN_TOOL_PEN;
 
461
                }
 
462
                input_report_key(dev, wacom->tool[idx], 1);
 
463
                input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
 
464
                input_sync(dev);
 
465
                return 1;
 
466
        }
 
467
 
 
468
        /* Exit report */
 
469
        if ((data[1] & 0xfe) == 0x80) {
 
470
                input_report_key(dev, wacom->tool[idx], 0);
 
471
                input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
 
472
                input_sync(dev);
 
473
                return 1;
 
474
        }
 
475
 
 
476
        return 0;
 
477
}
 
478
 
 
479
static void wacom_intuos_general(struct urb *urb)
 
480
{
 
481
        struct wacom *wacom = urb->context;
 
482
        unsigned char *data = wacom->data;
 
483
        struct input_dev *dev = &wacom->dev;
 
484
        unsigned int t;
 
485
 
 
486
        /* general pen packet */
 
487
        if ((data[1] & 0xb8) == 0xa0)
 
488
        {
 
489
                t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3);
 
490
                input_report_abs(dev, ABS_PRESSURE, t);
 
491
                input_report_abs(dev, ABS_TILT_X,
 
492
                                ((data[7] << 1) & 0x7e) | (data[8] >> 7));
 
493
                input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
 
494
                input_report_key(dev, BTN_STYLUS, data[1] & 2);
 
495
                input_report_key(dev, BTN_STYLUS2, data[1] & 4);
 
496
                input_report_key(dev, BTN_TOUCH, t > 10);
 
497
        }
 
498
 
 
499
        /* airbrush second packet */
 
500
        if ((data[1] & 0xbc) == 0xb4)
 
501
        {
 
502
                input_report_abs(dev, ABS_WHEEL,
 
503
                                ((__u32)data[6] << 2) | ((data[7] >> 6) & 3));
 
504
                input_report_abs(dev, ABS_TILT_X,
 
505
                                ((data[7] << 1) & 0x7e) | (data[8] >> 7));
 
506
                input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f);
 
507
        }
 
508
        return;
 
509
}
 
510
 
 
511
static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
 
512
{
 
513
        struct wacom *wacom = urb->context;
 
514
        unsigned char *data = wacom->data;
 
515
        struct input_dev *dev = &wacom->dev;
 
516
        unsigned int t;
 
517
        int idx;
 
518
        int retval;
 
519
 
 
520
        switch (urb->status) {
 
521
        case 0:
 
522
                /* success */
 
523
                break;
 
524
        case -ECONNRESET:
 
525
        case -ENOENT:
 
526
        case -ESHUTDOWN:
 
527
                /* this urb is terminated, clean up */
 
528
                dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
 
529
                return;
 
530
        default:
 
531
                dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
 
532
                goto exit;
 
533
        }
 
534
 
 
535
        if (data[0] != 2 && data[0] != 5 && data[0] != 6) {
 
536
                dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
 
537
                return;
 
538
        }
 
539
 
 
540
        input_regs(dev, regs);
 
541
 
 
542
        /* tool number */
 
543
        idx = data[1] & 0x01;
 
544
 
 
545
        /* process in/out prox events */
 
546
        if (wacom_intuos_inout(urb)) goto exit;
 
547
 
 
548
        input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2]));
 
549
        input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4]));
 
550
        input_report_abs(dev, ABS_DISTANCE, data[9]);
 
551
 
 
552
        /* process general packets */
 
553
        wacom_intuos_general(urb);
 
554
        
 
555
        if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {             /* 4D mouse or Lens cursor packets */
 
556
 
 
557
                if (data[1] & 0x02) {                                           /* Rotation packet */
 
558
 
 
559
                        t = ((__u32)data[6] << 3) | ((data[7] >> 5) & 7);
 
560
                        input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ? ((t - 1) / 2) : -t / 2);
 
561
 
 
562
                } else {
 
563
 
 
564
                        if ((data[1] & 0x10) == 0) {                            /* 4D mouse packets */
 
565
 
 
566
                                input_report_key(dev, BTN_LEFT,   data[8] & 0x01);
 
567
                                input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
 
568
                                input_report_key(dev, BTN_RIGHT,  data[8] & 0x04);
 
569
 
 
570
                                input_report_key(dev, BTN_SIDE,   data[8] & 0x20);
 
571
                                input_report_key(dev, BTN_EXTRA,  data[8] & 0x10);
 
572
                                t = ((__u32)data[6] << 2) | ((data[7] >> 6) & 3);
 
573
                                input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
 
574
                        } else {
 
575
                                if (wacom->tool[idx] == BTN_TOOL_MOUSE) {       /* 2D mouse packets */  
 
576
                                        input_report_key(dev, BTN_LEFT,   data[8] & 0x04);
 
577
                                        input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
 
578
                                        input_report_key(dev, BTN_RIGHT,  data[8] & 0x10);
 
579
                                        input_report_rel(dev, REL_WHEEL, 
 
580
                                            (-(__u32)(data[8] & 0x01) + (__u32)((data[8] & 0x02) >> 1)));
 
581
                                }
 
582
                                else {     /* Lens cursor packets */
 
583
                                        input_report_key(dev, BTN_LEFT,   data[8] & 0x01);
 
584
                                        input_report_key(dev, BTN_MIDDLE, data[8] & 0x02);
 
585
                                        input_report_key(dev, BTN_RIGHT,  data[8] & 0x04);
 
586
                                        input_report_key(dev, BTN_SIDE,   data[8] & 0x10);
 
587
                                        input_report_key(dev, BTN_EXTRA,  data[8] & 0x08);
 
588
                                }
 
589
                        }
 
590
                }
 
591
        }
 
592
        
 
593
        input_report_key(dev, wacom->tool[idx], 1);
 
594
        input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
 
595
        input_sync(dev);
 
596
 
 
597
exit:
 
598
        retval = usb_submit_urb (urb, GFP_ATOMIC);
 
599
        if (retval)
 
600
                err ("%s - usb_submit_urb failed with result %d",
 
601
                     __FUNCTION__, retval);
 
602
}
 
603
 
 
604
static void wacom_intuos3_irq(struct urb *urb, struct pt_regs *regs)
 
605
{
 
606
        struct wacom *wacom = urb->context;
 
607
        unsigned char *data = wacom->data;
 
608
        struct input_dev *dev = &wacom->dev;
 
609
        unsigned int t;
 
610
        int idx, retval;
 
611
 
 
612
        switch (urb->status) {
 
613
        case 0:
 
614
                /* success */
 
615
                break;
 
616
        case -ECONNRESET:
 
617
        case -ENOENT:
 
618
        case -ESHUTDOWN:
 
619
                /* this urb is terminated, clean up */
 
620
                dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
 
621
                return;
 
622
        default:
 
623
                dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
 
624
                goto exit;
 
625
        }
 
626
 
 
627
        /* check for valid report */
 
628
        if (data[0] != 2 && data[0] != 5 && data[0] != 12)
 
629
        {
 
630
                printk(KERN_INFO "wacom_intuos3_irq: received unknown report #%d\n", data[0]);
 
631
                return;
 
632
        }
 
633
 
 
634
        input_regs(dev, regs);
 
635
 
 
636
        /* tool index is always 0 here since there is no dual input tool */
 
637
        idx = data[1] & 0x01;
 
638
 
 
639
        /* pad packets. Works as a second tool and is alway in prox */
 
640
        if (data[0] == 12)
 
641
        {
 
642
                /* initiate the pad as a device */
 
643
                if (wacom->tool[1] != BTN_TOOL_FINGER)
 
644
                {
 
645
                        wacom->tool[1] = BTN_TOOL_FINGER;
 
646
                        input_report_key(dev, wacom->tool[1], 1);
 
647
                }
 
648
                input_report_key(dev, BTN_0, (data[5] & 0x01));
 
649
                input_report_key(dev, BTN_1, (data[5] & 0x02));
 
650
                input_report_key(dev, BTN_2, (data[5] & 0x04));
 
651
                input_report_key(dev, BTN_3, (data[5] & 0x08));
 
652
                input_report_key(dev, BTN_4, (data[6] & 0x01));
 
653
                input_report_key(dev, BTN_5, (data[6] & 0x02));
 
654
                input_report_key(dev, BTN_6, (data[6] & 0x04));
 
655
                input_report_key(dev, BTN_7, (data[6] & 0x08));
 
656
                input_report_abs(dev, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
 
657
                input_report_abs(dev, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
 
658
                input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff);
 
659
                input_sync(dev);
 
660
                goto exit;
 
661
        }
 
662
 
 
663
        /* process in/out prox events */
 
664
        if (wacom_intuos_inout(urb)) goto exit;
 
665
 
 
666
        input_report_abs(dev, ABS_X, ((__u32)data[2] << 9) | ((__u32)data[3] << 1) | ((data[9] >> 1) & 1));
 
667
        input_report_abs(dev, ABS_Y, ((__u32)data[4] << 9) | ((__u32)data[5] << 1) | (data[9] & 1));
 
668
        input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
 
669
 
 
670
        /* process general packets */
 
671
        wacom_intuos_general(urb);
 
672
 
 
673
        if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0)
 
674
        {
 
675
                /* Marker pen rotation packet. Reported as wheel due to valuator limitation */
 
676
                if (data[1] & 0x02)
 
677
                {
 
678
                        t = ((__u32)data[6] << 3) | ((data[7] >> 5) & 7);
 
679
                        t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
 
680
                                ((t-1) / 2 + 450)) : (450 - t / 2) ;
 
681
                        input_report_abs(dev, ABS_WHEEL, t);
 
682
                }
 
683
 
 
684
                /* 2D mouse packets */
 
685
                if (wacom->tool[idx] == BTN_TOOL_MOUSE)
 
686
                {
 
687
                        input_report_key(dev, BTN_LEFT,   data[8] & 0x04);
 
688
                        input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
 
689
                        input_report_key(dev, BTN_RIGHT,  data[8] & 0x10);
 
690
                        input_report_key(dev, BTN_SIDE,   data[8] & 0x40);
 
691
                        input_report_key(dev, BTN_EXTRA,  data[8] & 0x20);
 
692
                        /* mouse wheel is positive when rolled backwards */
 
693
                        input_report_rel(dev, REL_WHEEL,  ((__u32)((data[8] & 0x02) >> 1)
 
694
                                         - (__u32)(data[8] & 0x01)));
 
695
                }
 
696
        }
 
697
 
 
698
        input_report_key(dev, wacom->tool[idx], 1);
 
699
        input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
 
700
        input_sync(dev);
 
701
 
 
702
exit:
 
703
        retval = usb_submit_urb (urb, GFP_ATOMIC);
 
704
        if (retval)
 
705
                err ("%s - usb_submit_urb failed with result %d",
 
706
                    __FUNCTION__, retval);
 
707
}
 
708
 
 
709
 
 
710
static struct wacom_features wacom_features[] = {
 
711
        { "Wacom Penpartner",    7,   5040,  3780,  255, 32, 0, wacom_penpartner_irq },
 
712
        { "Wacom Graphire",      8,  10206,  7422,  511, 32, 1, wacom_graphire_irq },
 
713
        { "Wacom Graphire2 4x5", 8,  10206,  7422,  511, 32, 1, wacom_graphire_irq },
 
714
        { "Wacom Graphire2 5x7", 8,  13918, 10206,  511, 32, 1, wacom_graphire_irq },
 
715
        { "Wacom Graphire3 4x5", 8,  10208,  7424,  511, 32, 1, wacom_graphire_irq },
 
716
        { "Wacom Graphire3 6x8", 8,  16704, 12064,  511, 32, 1, wacom_graphire_irq },
 
717
        { "Wacom Intuos 4x5",   10,  12700, 10600, 1023, 15, 2, wacom_intuos_irq },
 
718
        { "Wacom Intuos 6x8",   10,  20320, 16240, 1023, 15, 2, wacom_intuos_irq },
 
719
        { "Wacom Intuos 9x12",  10,  30480, 24060, 1023, 15, 2, wacom_intuos_irq },
 
720
        { "Wacom Intuos 12x12", 10,  30480, 31680, 1023, 15, 2, wacom_intuos_irq },
 
721
        { "Wacom Intuos 12x18", 10,  45720, 31680, 1023, 15, 2, wacom_intuos_irq },
 
722
        { "Wacom PL400",         8,   5408,  4056,  255, 32, 3, wacom_pl_irq },
 
723
        { "Wacom PL500",         8,   6144,  4608,  255, 32, 3, wacom_pl_irq },
 
724
        { "Wacom PL600",         8,   6126,  4604,  255, 32, 3, wacom_pl_irq },
 
725
        { "Wacom PL600SX",       8,   6260,  5016,  255, 32, 3, wacom_pl_irq },
 
726
        { "Wacom PL550",         8,   6144,  4608,  511, 32, 3, wacom_pl_irq },
 
727
        { "Wacom PL800",         8,   7220,  5780,  511, 32, 3, wacom_pl_irq },
 
728
        { "Wacom Intuos2 4x5",   10, 12700, 10600, 1023, 15, 2, wacom_intuos_irq },
 
729
        { "Wacom Intuos2 6x8",   10, 20320, 16240, 1023, 15, 2, wacom_intuos_irq },
 
730
        { "Wacom Intuos2 9x12",  10, 30480, 24060, 1023, 15, 2, wacom_intuos_irq },
 
731
        { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, 2, wacom_intuos_irq },
 
732
        { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, 2, wacom_intuos_irq },
 
733
        { "Wacom Volito",        8,   5104,  3712,  511, 32, 1, wacom_graphire_irq },
 
734
        { "Wacom Cintiq Partner",8,  20480, 15360,  511, 32, 3, wacom_ptu_irq },
 
735
        { "Wacom Intuos3 4x5",   10, 25400, 20320, 1023, 15, 4, wacom_intuos3_irq },
 
736
        { "Wacom Intuos3 6x8",   10, 40640, 30480, 1023, 15, 4, wacom_intuos3_irq },
 
737
        { "Wacom Intuos3 9x12",  10, 60960, 45720, 1023, 15, 4, wacom_intuos3_irq },
 
738
        { "Wacom Intuos2 6x8",   10, 20320, 16240, 1023, 15, 2, wacom_intuos_irq },
 
739
        { }
 
740
};
 
741
 
 
742
static struct usb_device_id wacom_ids[] = {
 
743
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
 
744
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
 
745
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
 
746
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
 
747
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
 
748
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
 
749
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
 
750
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
 
751
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
 
752
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
 
753
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
 
754
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
 
755
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
 
756
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
 
757
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
 
758
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
 
759
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
 
760
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
 
761
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
 
762
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
 
763
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
 
764
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
 
765
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
 
766
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
 
767
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
 
768
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
 
769
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
 
770
        { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
 
771
        { }
 
772
};
 
773
 
 
774
MODULE_DEVICE_TABLE(usb, wacom_ids);
 
775
 
 
776
static int wacom_open(struct input_dev *dev)
 
777
{
 
778
        struct wacom *wacom = dev->private;
 
779
 
 
780
        if (wacom->open++)
 
781
                return 0;
 
782
 
 
783
        wacom->irq->dev = wacom->usbdev;
 
784
        if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
 
785
                wacom->open--;
 
786
                return -EIO;
 
787
        }
 
788
 
 
789
        return 0;
 
790
}
 
791
 
 
792
static void wacom_close(struct input_dev *dev)
 
793
{
 
794
        struct wacom *wacom = dev->private;
 
795
 
 
796
        if (!--wacom->open)
 
797
                usb_unlink_urb(wacom->irq);
 
798
}
 
799
 
 
800
static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
 
801
{
 
802
        struct usb_device *dev = interface_to_usbdev(intf);
 
803
        struct usb_endpoint_descriptor *endpoint;
 
804
        char rep_data[2] = {0x02, 0x02};
 
805
        struct wacom *wacom;
 
806
        char path[64];
 
807
 
 
808
        if (!(wacom = kmalloc(sizeof(struct wacom), GFP_KERNEL)))
 
809
                return -ENOMEM;
 
810
        memset(wacom, 0, sizeof(struct wacom));
 
811
 
 
812
        wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
 
813
        if (!wacom->data) {
 
814
                kfree(wacom);
 
815
                return -ENOMEM;
 
816
        }
 
817
 
 
818
        wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
 
819
        if (!wacom->irq) {
 
820
                usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
 
821
                kfree(wacom);
 
822
                return -ENOMEM;
 
823
        }
 
824
 
 
825
        wacom->features = wacom_features + (id - wacom_ids);
 
826
 
 
827
        wacom->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
 
828
        wacom->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
 
829
        wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
 
830
 
 
831
        switch (wacom->features->type) {
 
832
                case 1:
 
833
                        wacom->dev.evbit[0] |= BIT(EV_REL);
 
834
                        wacom->dev.relbit[0] |= BIT(REL_WHEEL);
 
835
                        wacom->dev.absbit[0] |= BIT(ABS_DISTANCE);
 
836
                        wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
 
837
                        wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
 
838
                        break;
 
839
 
 
840
                case 4: /* new functions for Intuos3 */
 
841
                        wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
 
842
                        wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
 
843
                        wacom->dev.absbit[0] |= BIT(ABS_RX) | BIT(ABS_RY);
 
844
                        /* fall through */
 
845
 
 
846
                case 2:
 
847
                        wacom->dev.evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
 
848
                        wacom->dev.mscbit[0] |= BIT(MSC_SERIAL);
 
849
                        wacom->dev.relbit[0] |= BIT(REL_WHEEL);
 
850
                        wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
 
851
                        wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
 
852
                                                          | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
 
853
                        wacom->dev.absbit[0] |= BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) | BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE);
 
854
                        break;
 
855
 
 
856
                case 3:
 
857
                        wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
 
858
                        break;
 
859
        }
 
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
        usb_make_path(dev, path, 64);
 
884
        sprintf(wacom->phys, "%s/input0", path);
 
885
 
 
886
        wacom->dev.name = wacom->features->name;
 
887
        wacom->dev.phys = wacom->phys;
 
888
        wacom->dev.id.bustype = BUS_USB;
 
889
        wacom->dev.id.vendor = dev->descriptor.idVendor;
 
890
        wacom->dev.id.product = dev->descriptor.idProduct;
 
891
        wacom->dev.id.version = dev->descriptor.bcdDevice;
 
892
        wacom->dev.dev = &intf->dev;
 
893
        wacom->usbdev = dev;
 
894
 
 
895
        endpoint = &intf->cur_altsetting->endpoint[0].desc;
 
896
 
 
897
        if (wacom->features->pktlen > 10)
 
898
                BUG();
 
899
 
 
900
        usb_fill_int_urb(wacom->irq, dev,
 
901
                         usb_rcvintpipe(dev, endpoint->bEndpointAddress),
 
902
                         wacom->data, wacom->features->pktlen,
 
903
                         wacom->features->irq, wacom, endpoint->bInterval);
 
904
        wacom->irq->transfer_dma = wacom->data_dma;
 
905
        wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
906
 
 
907
        input_register_device(&wacom->dev);
 
908
 
 
909
        /* ask the tablet to report tablet data */
 
910
        usb_set_report(intf, 3, 2, rep_data, 2);
 
911
        /* repeat once (not sure why the first call often fails) */
 
912
        usb_set_report(intf, 3, 2, rep_data, 2);
 
913
 
 
914
        printk(KERN_INFO "input: %s on %s\n", wacom->features->name, path);
 
915
 
 
916
        usb_set_intfdata(intf, wacom);
 
917
 
 
918
        return 0;
 
919
}
 
920
 
 
921
static void wacom_disconnect(struct usb_interface *intf)
 
922
{
 
923
        struct wacom *wacom = usb_get_intfdata (intf);
 
924
 
 
925
        usb_set_intfdata(intf, NULL);
 
926
        if (wacom) {
 
927
                usb_unlink_urb(wacom->irq);
 
928
                input_unregister_device(&wacom->dev);
 
929
                usb_free_urb(wacom->irq);
 
930
                usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma);
 
931
                kfree(wacom);
 
932
        }
 
933
}
 
934
 
 
935
static struct usb_driver wacom_driver = {
 
936
        .owner =        THIS_MODULE,
 
937
        .name =         "wacom",
 
938
        .probe =        wacom_probe,
 
939
        .disconnect =   wacom_disconnect,
 
940
        .id_table =     wacom_ids,
 
941
};
 
942
 
 
943
static int __init wacom_init(void)
 
944
{
 
945
        int result = usb_register(&wacom_driver);
 
946
        if (result == 0)
 
947
                info(DRIVER_VERSION ":" DRIVER_DESC);
 
948
        return result;
 
949
}
 
950
 
 
951
static void __exit wacom_exit(void)
 
952
{
 
953
        usb_deregister(&wacom_driver);
 
954
}
 
955
 
 
956
module_init(wacom_init);
 
957
module_exit(wacom_exit);