patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / usb / input / aiptek.c
1 /*
2  *  Native support for the Aiptek HyperPen USB Tablets
3  *  (4000U/5000U/6000U/8000U/12000U)
4  *  
5  *  Copyright (c) 2001      Chris Atenasio   <chris@crud.net>
6  *  Copyright (c) 2002-2004 Bryan W. Headley <bwheadley@earthlink.net>
7  *
8  *  based on wacom.c by
9  *     Vojtech Pavlik      <vojtech@suse.cz>
10  *     Andreas Bach Aaen   <abach@stofanet.dk>
11  *     Clifford Wolf       <clifford@clifford.at>
12  *     Sam Mosel           <sam.mosel@computer.org>
13  *     James E. Blair      <corvus@gnu.org>
14  *     Daniel Egger        <egger@suse.de>
15  *
16  *  Many thanks to Oliver Kuechemann for his support.
17  *
18  *  ChangeLog:
19  *      v0.1 - Initial release
20  *      v0.2 - Hack to get around fake event 28's. (Bryan W. Headley)
21  *      v0.3 - Make URB dynamic (Bryan W. Headley, Jun-8-2002)
22  *             Released to Linux 2.4.19 and 2.5.x
23  *      v0.4 - Rewrote substantial portions of the code to deal with
24  *             corrected control sequences, timing, dynamic configuration,
25  *             support of 6000U - 12000U, procfs, and macro key support
26  *             (Jan-1-2003 - Feb-5-2003, Bryan W. Headley)
27  *      v1.0 - Added support for diagnostic messages, count of messages
28  *             received from URB - Mar-8-2003, Bryan W. Headley
29  *      v1.1 - added support for tablet resolution, changed DV and proximity
30  *             some corrections - Jun-22-2003, martin schneebacher
31  *           - Added support for the sysfs interface, deprecating the
32  *             procfs interface for 2.5.x kernel. Also added support for
33  *             Wheel command. Bryan W. Headley July-15-2003.
34  *      v1.2 - Reworked jitter timer as a kernel thread. 
35  *             Bryan W. Headley November-28-2003/Jan-10-2004.
36  *      v1.3 - Repaired issue of kernel thread going nuts on single-processor
37  *             machines, introduced programmableDelay as a command line
38  *             parameter. Feb 7 2004, Bryan W. Headley.
39  *      v1.4 - Re-wire jitter so it does not require a thread. Courtesy of
40  *             Rene van Paassen. Added reporting of physical pointer device
41  *             (e.g., stylus, mouse in reports 2, 3, 4, 5. We don't know
42  *             for reports 1, 6.)
43  *             what physical device reports for reports 1, 6.) Also enabled
44  *             MOUSE and LENS tool button modes. Renamed "rubber" to "eraser".
45  *             Feb 20, 2004, Bryan W. Headley.
46  *      v1.5 - Added previousJitterable, so we don't do jitter delay when the
47  *             user is holding a button down for periods of time.
48  *
49  * NOTE:
50  *      This kernel driver is augmented by the "Aiptek" XFree86 input
51  *      driver for your X server, as well as the Gaiptek GUI Front-end
52  *      "Tablet Manager". 
53  *      These three products are highly interactive with one another, 
54  *      so therefore it's easier to document them all as one subsystem.
55  *      Please visit the project's "home page", located at, 
56  *      http://aiptektablet.sourceforge.net.
57  *
58  * This program is free software; you can redistribute it and/or modify
59  * it under the terms of the GNU General Public License as published by
60  * the Free Software Foundation; either version 2 of the License, or
61  * (at your option) any later version.
62  *
63  * This program is distributed in the hope that it will be useful,
64  * but WITHOUT ANY WARRANTY; without even the implied warranty of
65  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
66  * GNU General Public License for more details.
67  *
68  * You should have received a copy of the GNU General Public License
69  * along with this program; if not, write to the Free Software
70  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
71  */
72
73 #include <linux/jiffies.h>
74 #include <linux/kernel.h>
75 #include <linux/slab.h>
76 #include <linux/input.h>
77 #include <linux/module.h>
78 #include <linux/init.h>
79 #include <linux/usb.h>
80 #include <linux/sched.h>
81 #include <asm/uaccess.h>
82 #include <asm/unaligned.h>
83
84 /*
85  * Version Information
86  */
87 #define DRIVER_VERSION "v1.5 (May-15-2004)"
88 #define DRIVER_AUTHOR  "Bryan W. Headley/Chris Atenasio"
89 #define DRIVER_DESC    "Aiptek HyperPen USB Tablet Driver (Linux 2.6.x)"
90
91 /*
92  * Aiptek status packet:
93  *
94  * (returned as Report 1 - relative coordinates from mouse and stylus)
95  *
96  *        bit7  bit6  bit5  bit4  bit3  bit2  bit1  bit0
97  * byte0   0     0     0     0     0     0     0     1
98  * byte1   0     0     0     0     0    BS2   BS    Tip
99  * byte2  X7    X6    X5    X4    X3    X2    X1    X0
100  * byte3  Y7    Y6    Y5    Y4    Y3    Y2    Y1    Y0
101  *
102  * (returned as Report 2 - absolute coordinates from the stylus)
103  *
104  *        bit7  bit6  bit5  bit4  bit3  bit2  bit1  bit0
105  * byte0   0     0     0     0     0     0     1     0
106  * byte1  X7    X6    X5    X4    X3    X2    X1    X0
107  * byte2  X15   X14   X13   X12   X11   X10   X9    X8
108  * byte3  Y7    Y6    Y5    Y4    Y3    Y2    Y1    Y0
109  * byte4  Y15   Y14   Y13   Y12   Y11   Y10   Y9    Y8
110  * byte5   *     *     *    BS2   BS1   Tip   IR    DV
111  * byte6  P7    P6    P5    P4    P3    P2    P1    P0
112  * byte7  P15   P14   P13   P12   P11   P10   P9    P8
113  *
114  * (returned as Report 3 - absolute coordinates from the mouse)
115  *
116  *        bit7  bit6  bit5  bit4  bit3  bit2  bit1  bit0
117  * byte0   0     0     0     0     0     0     1     0
118  * byte1  X7    X6    X5    X4    X3    X2    X1    X0
119  * byte2  X15   X14   X13   X12   X11   X10   X9    X8
120  * byte3  Y7    Y6    Y5    Y4    Y3    Y2    Y1    Y0
121  * byte4  Y15   Y14   Y13   Y12   Y11   Y10   Y9    Y8
122  * byte5   *     *     *    BS2   BS1   Tip   IR    DV
123  * byte6  P7    P6    P5    P4    P3    P2    P1    P0
124  * byte7  P15   P14   P13   P12   P11   P10   P9    P8
125  *
126  * (returned as Report 4 - macrokeys from the stylus)
127  *
128  *        bit7  bit6  bit5  bit4  bit3  bit2  bit1  bit0
129  * byte0   0     0     0     0     0     1     0     0
130  * byte1   0     0     0    BS2   BS    Tip   IR    DV
131  * byte2   0     0     0     0     0     0     1     0
132  * byte3   0     0     0    K4    K3    K2    K1    K0
133  * byte4  P7    P6    P5    P4    P3    P2    P1    P0
134  * byte5  P15   P14   P13   P12   P11   P10   P9    P8
135  *
136  * (returned as Report 5 - macrokeys from the mouse)
137  *
138  *        bit7  bit6  bit5  bit4  bit3  bit2  bit1  bit0
139  * byte0   0     0     0     0     0     1     0     0
140  * byte1   0     0     0    BS2   BS    Tip   IR    DV
141  * byte2   0     0     0     0     0     0     1     0
142  * byte3   0     0     0    K4    K3    K2    K1    K0
143  * byte4  P7    P6    P5    P4    P3    P2    P1    P0
144  * byte5  P15   P14   P13   P12   P11   P10   P9    P8
145  *
146  * IR: In Range = Proximity on
147  * DV = Data Valid
148  * BS = Barrel Switch (as in, macro keys)
149  * BS2 also referred to as Tablet Pick
150  *
151  * Command Summary:
152  *
153  * Use report_type CONTROL (3)
154  * Use report_id   2
155  *
156  * Command/Data    Description     Return Bytes    Return Value
157  * 0x10/0x00       SwitchToMouse       0
158  * 0x10/0x01       SwitchToTablet      0
159  * 0x18/0x04       SetResolution       0 
160  * 0x12/0xFF       AutoGainOn          0
161  * 0x17/0x00       FilterOn            0
162  * 0x01/0x00       GetXExtension       2           MaxX
163  * 0x01/0x01       GetYExtension       2           MaxY
164  * 0x02/0x00       GetModelCode        2           ModelCode = LOBYTE
165  * 0x03/0x00       GetODMCode          2           ODMCode
166  * 0x08/0x00       GetPressureLevels   2           =512
167  * 0x04/0x00       GetFirmwareVersion  2           Firmware Version
168  * 0x11/0x02       EnableMacroKeys     0
169  *
170  * To initialize the tablet:
171  *
172  * (1) Send Resolution500LPI (Command)
173  * (2) Query for Model code (Option Report)
174  * (3) Query for ODM code (Option Report)
175  * (4) Query for firmware (Option Report)
176  * (5) Query for GetXExtension (Option Report)
177  * (6) Query for GetYExtension (Option Report)
178  * (7) Query for GetPressureLevels (Option Report)
179  * (8) SwitchToTablet for Absolute coordinates, or
180  *     SwitchToMouse for Relative coordinates (Command)
181  * (9) EnableMacroKeys (Command)
182  * (10) FilterOn (Command)
183  * (11) AutoGainOn (Command)
184  *
185  * (Step 9 can be omitted, but you'll then have no function keys.)
186  */
187
188 #define USB_VENDOR_ID_AIPTEK                            0x08ca
189 #define USB_REQ_GET_REPORT                              0x01
190 #define USB_REQ_SET_REPORT                              0x09
191
192         /* PointerMode codes
193          */
194 #define AIPTEK_POINTER_ONLY_MOUSE_MODE                  0
195 #define AIPTEK_POINTER_ONLY_STYLUS_MODE                 1
196 #define AIPTEK_POINTER_EITHER_MODE                      2
197
198 #define AIPTEK_POINTER_ALLOW_MOUSE_MODE(a)              \
199         (a == AIPTEK_POINTER_ONLY_MOUSE_MODE ||         \
200          a == AIPTEK_POINTER_EITHER_MODE)
201 #define AIPTEK_POINTER_ALLOW_STYLUS_MODE(a)             \
202         (a == AIPTEK_POINTER_ONLY_STYLUS_MODE ||        \
203          a == AIPTEK_POINTER_EITHER_MODE)
204
205         /* CoordinateMode code
206          */
207 #define AIPTEK_COORDINATE_RELATIVE_MODE                 0
208 #define AIPTEK_COORDINATE_ABSOLUTE_MODE                 1
209
210        /* XTilt and YTilt values
211         */
212 #define AIPTEK_TILT_MIN                                 (-128)
213 #define AIPTEK_TILT_MAX                                 127
214 #define AIPTEK_TILT_DISABLE                             (-10101)
215
216         /* Wheel values
217          */
218 #define AIPTEK_WHEEL_MIN                                0
219 #define AIPTEK_WHEEL_MAX                                1024
220 #define AIPTEK_WHEEL_DISABLE                            (-10101)
221
222         /* ToolCode values, which BTW are 0x140 .. 0x14f
223          * We have things set up such that if TOOL_BUTTON_FIRED_BIT is
224          * not set, we'll send one instance of AIPTEK_TOOL_BUTTON_xxx.
225          *
226          * Whenever the user resets the value, TOOL_BUTTON_FIRED_BIT will
227          * get reset.
228          */
229 #define TOOL_BUTTON(x)                                  ((x) & 0x14f)
230 #define TOOL_BUTTON_FIRED(x)                            ((x) & 0x200)
231 #define TOOL_BUTTON_FIRED_BIT                           0x200
232         /* toolMode codes
233          */
234 #define AIPTEK_TOOL_BUTTON_PEN_MODE                     BTN_TOOL_PEN
235 #define AIPTEK_TOOL_BUTTON_PEN_MODE                     BTN_TOOL_PEN
236 #define AIPTEK_TOOL_BUTTON_PENCIL_MODE                  BTN_TOOL_PENCIL
237 #define AIPTEK_TOOL_BUTTON_BRUSH_MODE                   BTN_TOOL_BRUSH
238 #define AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE                BTN_TOOL_AIRBRUSH
239 #define AIPTEK_TOOL_BUTTON_ERASER_MODE                  BTN_TOOL_RUBBER
240 #define AIPTEK_TOOL_BUTTON_MOUSE_MODE                   BTN_TOOL_MOUSE
241 #define AIPTEK_TOOL_BUTTON_LENS_MODE                    BTN_TOOL_LENS
242
243         /* Diagnostic message codes
244          */
245 #define AIPTEK_DIAGNOSTIC_NA                            0
246 #define AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE  1
247 #define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE  2
248 #define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED               3
249
250         /* Time to wait (in ms) to help mask hand jittering 
251          * when pressing the stylus buttons.
252          */
253 #define AIPTEK_JITTER_DELAY_DEFAULT                     50
254
255         /* Time to wait (in ms) in-between sending the tablet
256          * a command and beginning the process of reading the return
257          * sequence from the tablet.
258          */
259 #define AIPTEK_PROGRAMMABLE_DELAY_25            25
260 #define AIPTEK_PROGRAMMABLE_DELAY_50            50
261 #define AIPTEK_PROGRAMMABLE_DELAY_100           100
262 #define AIPTEK_PROGRAMMABLE_DELAY_200           200
263 #define AIPTEK_PROGRAMMABLE_DELAY_300           300
264 #define AIPTEK_PROGRAMMABLE_DELAY_400           400
265 #define AIPTEK_PROGRAMMABLE_DELAY_DEFAULT       AIPTEK_PROGRAMMABLE_DELAY_400
266
267         /* Mouse button programming
268          */
269 #define AIPTEK_MOUSE_LEFT_BUTTON                0x01
270 #define AIPTEK_MOUSE_RIGHT_BUTTON               0x02
271 #define AIPTEK_MOUSE_MIDDLE_BUTTON              0x04
272
273         /* Stylus button programming
274          */
275 #define AIPTEK_STYLUS_LOWER_BUTTON              0x08
276 #define AIPTEK_STYLUS_UPPER_BUTTON              0x10
277
278         /* Length of incoming packet from the tablet
279          */
280 #define AIPTEK_PACKET_LENGTH                    8
281
282         /* We report in EV_MISC both the proximity and
283          * whether the report came from the stylus, tablet mouse
284          * or "unknown" -- Unknown when the tablet is in relative
285          * mode, because we only get report 1's.
286          */
287 #define AIPTEK_REPORT_TOOL_UNKNOWN              0x10
288 #define AIPTEK_REPORT_TOOL_STYLUS               0x20
289 #define AIPTEK_REPORT_TOOL_MOUSE                0x40
290
291 static int programmableDelay = AIPTEK_PROGRAMMABLE_DELAY_DEFAULT;
292 static int jitterDelay = AIPTEK_JITTER_DELAY_DEFAULT;
293
294 struct aiptek_features {
295         int odmCode;            /* Tablet manufacturer code       */
296         int modelCode;          /* Tablet model code (not unique) */
297         int firmwareCode;       /* prom/eeprom version            */
298         char usbPath[64 + 1];   /* device's physical usb path     */
299         char inputPath[64 + 1]; /* input device path              */
300         char manuName[64 + 1];  /* manufacturer name              */
301         char prodName[64 + 1];  /* product name                   */
302 };
303
304 struct aiptek_settings {
305         int pointerMode;        /* stylus-, mouse-only or either */
306         int coordinateMode;     /* absolute/relative coords      */
307         int toolMode;           /* pen, pencil, brush, etc. tool */
308         int xTilt;              /* synthetic xTilt amount        */
309         int yTilt;              /* synthetic yTilt amount        */
310         int wheel;              /* synthetic wheel amount        */
311         int stylusButtonUpper;  /* stylus upper btn delivers...  */
312         int stylusButtonLower;  /* stylus lower btn delivers...  */
313         int mouseButtonLeft;    /* mouse left btn delivers...    */
314         int mouseButtonMiddle;  /* mouse middle btn delivers...  */
315         int mouseButtonRight;   /* mouse right btn delivers...   */
316         int programmableDelay;  /* delay for tablet programming  */
317         int jitterDelay;        /* delay for hand jittering      */
318 };
319
320 struct aiptek {
321         struct input_dev inputdev;              /* input device struct           */
322         struct usb_device *usbdev;              /* usb device struct             */
323         struct urb *urb;                        /* urb for incoming reports      */
324         dma_addr_t data_dma;                    /* our dma stuffage              */
325         struct aiptek_features features;        /* tablet's array of features    */
326         struct aiptek_settings curSetting;      /* tablet's current programmable */
327         struct aiptek_settings newSetting;      /* ... and new param settings    */
328         unsigned int ifnum;                     /* interface number for IO       */
329         int openCount;                          /* module use counter            */
330         int diagnostic;                         /* tablet diagnostic codes       */
331         unsigned long eventCount;               /* event count                   */
332         int inDelay;                            /* jitter: in jitter delay?      */
333         unsigned long endDelay;                 /* jitter: time when delay ends  */
334         int previousJitterable;                 /* jitterable prev value     */
335         unsigned char *data;                    /* incoming packet data          */
336 };
337
338 /*
339  * Permit easy lookup of keyboard events to send, versus
340  * the bitmap which comes from the tablet. This hides the
341  * issue that the F_keys are not sequentially numbered.
342  */
343 static int macroKeyEvents[] = {
344         KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
345         KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
346         KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17,
347         KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23,
348         KEY_F24, KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO,
349         KEY_FRONT, KEY_COPY, KEY_OPEN, KEY_PASTE, 0
350 };
351
352 /***********************************************************************
353  * Relative reports deliver values in 2's complement format to
354  * deal with negative offsets.
355  */
356 static int aiptek_convert_from_2s_complement(unsigned char c)
357 {
358         int ret;
359         unsigned char b = c;
360         int negate = 0;
361
362         if ((b & 0x80) != 0) {
363                 b = ~b;
364                 b--;
365                 negate = 1;
366         }
367         ret = b;
368         ret = (negate == 1) ? -ret : ret;
369         return ret;
370 }
371
372 /***********************************************************************
373  * aiptek_irq can receive one of six potential reports.
374  * The documentation for each is in the body of the function.
375  *
376  * The tablet reports on several attributes per invocation of
377  * aiptek_irq. Because the Linux Input Event system allows the
378  * transmission of ONE attribute per input_report_xxx() call,
379  * collation has to be done on the other end to reconstitute
380  * a complete tablet report. Further, the number of Input Event reports
381  * submitted varies, depending on what USB report type, and circumstance.
382  * To deal with this, EV_MSC is used to indicate an 'end-of-report'
383  * message. This has been an undocumented convention understood by the kernel
384  * tablet driver and clients such as gpm and XFree86's tablet drivers.
385  *
386  * Of the information received from the tablet, the one piece I
387  * cannot transmit is the proximity bit (without resorting to an EV_MSC
388  * convention above.) I therefore have taken over REL_MISC and ABS_MISC
389  * (for relative and absolute reports, respectively) for communicating
390  * Proximity. Why two events? I thought it interesting to know if the
391  * Proximity event occured while the tablet was in absolute or relative
392  * mode.
393  *
394  * Other tablets use the notion of a certain minimum stylus pressure
395  * to infer proximity. While that could have been done, that is yet
396  * another 'by convention' behavior, the documentation for which
397  * would be spread between two (or more) pieces of software.
398  *
399  * EV_MSC usage was terminated for this purpose in Linux 2.5.x, and
400  * replaced with the input_sync() method (which emits EV_SYN.)
401  */
402
403 static void aiptek_irq(struct urb *urb, struct pt_regs *regs)
404 {
405         struct aiptek *aiptek = urb->context;
406         unsigned char *data = aiptek->data;
407         struct input_dev *inputdev = &aiptek->inputdev;
408         int jitterable = 0;
409         int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
410
411         switch (urb->status) {
412         case 0:
413                 /* Success */
414                 break;
415
416         case -ECONNRESET:
417         case -ENOENT:
418         case -ESHUTDOWN:
419                 /* This urb is terminated, clean up */
420                 dbg("%s - urb shutting down with status: %d",
421                     __FUNCTION__, urb->status);
422                 return;
423
424         default:
425                 dbg("%s - nonzero urb status received: %d",
426                     __FUNCTION__, urb->status);
427                 goto exit;
428         }
429
430         /* See if we are in a delay loop -- throw out report if true.
431          */
432         if (aiptek->inDelay == 1 && time_after(aiptek->endDelay, jiffies)) {
433                 goto exit;
434         }
435
436         aiptek->inDelay = 0;
437         aiptek->eventCount++;
438
439         /* Report 1 delivers relative coordinates with either a stylus
440          * or the mouse. You do not know, however, which input
441          * tool generated the event.
442          */
443         if (data[0] == 1) {
444                 if (aiptek->curSetting.coordinateMode ==
445                     AIPTEK_COORDINATE_ABSOLUTE_MODE) {
446                         aiptek->diagnostic =
447                             AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
448                 } else {
449                         input_regs(inputdev, regs);
450
451                         x = aiptek_convert_from_2s_complement(data[2]);
452                         y = aiptek_convert_from_2s_complement(data[3]);
453
454                         /* jitterable keeps track of whether any button has been pressed.
455                          * We're also using it to remap the physical mouse button mask
456                          * to pseudo-settings. (We don't specifically care about it's
457                          * value after moving/transposing mouse button bitmasks, except
458                          * that a non-zero value indicates that one or more
459                          * mouse button was pressed.)
460                          */
461                         jitterable = data[5] & 0x07;
462
463                         left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
464                         right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
465                         middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
466
467                         input_report_key(inputdev, BTN_LEFT, left);
468                         input_report_key(inputdev, BTN_MIDDLE, middle);
469                         input_report_key(inputdev, BTN_RIGHT, right);
470                         input_report_rel(inputdev, REL_X, x);
471                         input_report_rel(inputdev, REL_Y, y);
472                         input_report_rel(inputdev, REL_MISC, 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
473
474                         /* Wheel support is in the form of a single-event
475                          * firing.
476                          */
477                         if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
478                                 input_report_rel(inputdev, REL_WHEEL,
479                                                  aiptek->curSetting.wheel);
480                                 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
481                         }
482                         input_sync(inputdev);
483                 }
484         }
485         /* Report 2 is delivered only by the stylus, and delivers
486          * absolute coordinates.
487          */
488         else if (data[0] == 2) {
489                 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
490                         aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
491                 } else if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE
492                             (aiptek->curSetting.pointerMode)) {
493                                 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
494                 } else {
495                         input_regs(inputdev, regs);
496
497                         x = le16_to_cpu(get_unaligned((__u16 *) (data + 1)));
498                         y = le16_to_cpu(get_unaligned((__u16 *) (data + 3)));
499                         z = le16_to_cpu(get_unaligned((__u16 *) (data + 6)));
500
501                         p = (data[5] & 0x01) != 0 ? 1 : 0;
502                         dv = (data[5] & 0x02) != 0 ? 1 : 0;
503                         tip = (data[5] & 0x04) != 0 ? 1 : 0;
504
505                         /* Use jitterable to re-arrange button masks
506                          */
507                         jitterable = data[5] & 0x18;
508
509                         bs = (data[5] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
510                         pck = (data[5] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
511
512                         /* dv indicates 'data valid' (e.g., the tablet is in sync
513                          * and has delivered a "correct" report) We will ignore
514                          * all 'bad' reports...
515                          */
516                         if (dv != 0) {
517                                 /* If we've not already sent a tool_button_?? code, do
518                                  * so now. Then set FIRED_BIT so it won't be resent unless
519                                  * the user forces FIRED_BIT off.
520                                  */
521                                 if (TOOL_BUTTON_FIRED
522                                     (aiptek->curSetting.toolMode) == 0) {
523                                         input_report_key(inputdev,
524                                                          TOOL_BUTTON(aiptek->curSetting.toolMode),
525                                                          1);
526                                         aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
527                                 }
528
529                                 if (p != 0) {
530                                         input_report_abs(inputdev, ABS_X, x);
531                                         input_report_abs(inputdev, ABS_Y, y);
532                                         input_report_abs(inputdev, ABS_PRESSURE, z);
533
534                                         input_report_key(inputdev, BTN_TOUCH, tip);
535                                         input_report_key(inputdev, BTN_STYLUS, bs);
536                                         input_report_key(inputdev, BTN_STYLUS2, pck);
537
538                                         if (aiptek->curSetting.xTilt !=
539                                             AIPTEK_TILT_DISABLE) {
540                                                 input_report_abs(inputdev,
541                                                                  ABS_TILT_X,
542                                                                  aiptek->curSetting.xTilt);
543                                         }
544                                         if (aiptek->curSetting.yTilt != AIPTEK_TILT_DISABLE) {
545                                                 input_report_abs(inputdev,
546                                                                  ABS_TILT_Y,
547                                                                  aiptek->curSetting.yTilt);
548                                         }
549
550                                         /* Wheel support is in the form of a single-event
551                                          * firing.
552                                          */
553                                         if (aiptek->curSetting.wheel !=
554                                             AIPTEK_WHEEL_DISABLE) {
555                                                 input_report_abs(inputdev,
556                                                                  ABS_WHEEL,
557                                                                  aiptek->curSetting.wheel);
558                                                 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
559                                         }
560                                 }
561                                 input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_STYLUS);
562                                 input_sync(inputdev);
563                         }
564                 }
565         }
566         /* Report 3's come from the mouse in absolute mode.
567          */
568         else if (data[0] == 3) {
569                 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
570                         aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
571                 } else if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE
572                         (aiptek->curSetting.pointerMode)) {
573                         aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
574                 } else {
575                         input_regs(inputdev, regs);
576                         x = le16_to_cpu(get_unaligned((__u16 *) (data + 1)));
577                         y = le16_to_cpu(get_unaligned((__u16 *) (data + 3)));
578
579                         jitterable = data[5] & 0x1c;
580
581                         p = (data[5] & 0x01) != 0 ? 1 : 0;
582                         dv = (data[5] & 0x02) != 0 ? 1 : 0;
583                         left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
584                         right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
585                         middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
586
587                         if (dv != 0) {
588                                 /* If we've not already sent a tool_button_?? code, do
589                                  * so now. Then set FIRED_BIT so it won't be resent unless
590                                  * the user forces FIRED_BIT off.
591                                  */
592                                 if (TOOL_BUTTON_FIRED
593                                     (aiptek->curSetting.toolMode) == 0) {
594                                         input_report_key(inputdev,
595                                                          TOOL_BUTTON(aiptek->curSetting.toolMode),
596                                                          1);
597                                         aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
598                                 }
599
600                                 if (p != 0) {
601                                         input_report_abs(inputdev, ABS_X, x);
602                                         input_report_abs(inputdev, ABS_Y, y);
603
604                                         input_report_key(inputdev, BTN_LEFT, left);
605                                         input_report_key(inputdev, BTN_MIDDLE, middle);
606                                         input_report_key(inputdev, BTN_RIGHT, right);
607
608                                         /* Wheel support is in the form of a single-event
609                                          * firing.
610                                          */
611                                         if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
612                                                 input_report_abs(inputdev,
613                                                                  ABS_WHEEL,
614                                                                  aiptek->curSetting.wheel);
615                                                 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
616                                         }
617                                 }
618                                 input_report_rel(inputdev, REL_MISC, p | AIPTEK_REPORT_TOOL_MOUSE);
619                                 input_sync(inputdev);
620                         }
621                 }
622         }
623         /* Report 4s come from the macro keys when pressed by stylus
624          */
625         else if (data[0] == 4) {
626                 jitterable = data[1] & 0x18;
627
628                 p = (data[1] & 0x01) != 0 ? 1 : 0;
629                 dv = (data[1] & 0x02) != 0 ? 1 : 0;
630                 tip = (data[1] & 0x04) != 0 ? 1 : 0;
631                 bs = (data[1] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
632                 pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
633
634                 macro = data[3];
635                 z = le16_to_cpu(get_unaligned((__u16 *) (data + 4)));
636
637                 if (dv != 0) {
638                         input_regs(inputdev, regs);
639
640                         /* If we've not already sent a tool_button_?? code, do
641                          * so now. Then set FIRED_BIT so it won't be resent unless
642                          * the user forces FIRED_BIT off.
643                          */
644                         if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
645                                 input_report_key(inputdev,
646                                                  TOOL_BUTTON(aiptek->curSetting.toolMode),
647                                                  1);
648                                 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
649                         }
650
651                         if (p != 0) {
652                                 input_report_key(inputdev, BTN_TOUCH, tip);
653                                 input_report_key(inputdev, BTN_STYLUS, bs);
654                                 input_report_key(inputdev, BTN_STYLUS2, pck);
655                                 input_report_abs(inputdev, ABS_PRESSURE, z);
656                         }
657
658                         /* For safety, we're sending key 'break' codes for the
659                          * neighboring macro keys.
660                          */
661                         if (macro > 0) {
662                                 input_report_key(inputdev,
663                                                  macroKeyEvents[macro - 1], 0);
664                         }
665                         if (macro < 25) {
666                                 input_report_key(inputdev,
667                                                  macroKeyEvents[macro + 1], 0);
668                         }
669                         input_report_key(inputdev, macroKeyEvents[macro], p);
670                         input_report_abs(inputdev, ABS_MISC,
671                                          p | AIPTEK_REPORT_TOOL_STYLUS);
672                         input_sync(inputdev);
673                 }
674         }
675         /* Report 5s come from the macro keys when pressed by mouse
676          */
677         else if (data[0] == 5) {
678                 jitterable = data[1] & 0x1c;
679
680                 p = (data[1] & 0x01) != 0 ? 1 : 0;
681                 dv = (data[1] & 0x02) != 0 ? 1 : 0;
682                 left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
683                 right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
684                 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
685                 macro = data[3];
686
687                 if (dv != 0) {
688                         input_regs(inputdev, regs);
689
690                         /* If we've not already sent a tool_button_?? code, do
691                          * so now. Then set FIRED_BIT so it won't be resent unless
692                          * the user forces FIRED_BIT off.
693                          */
694                         if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
695                                 input_report_key(inputdev,
696                                                  TOOL_BUTTON(aiptek->curSetting.toolMode),
697                                                  1);
698                                 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
699                         }
700
701                         if (p != 0) {
702                                 input_report_key(inputdev, BTN_LEFT, left);
703                                 input_report_key(inputdev, BTN_MIDDLE, middle);
704                                 input_report_key(inputdev, BTN_RIGHT, right);
705                         }
706
707                         /* For safety, we're sending key 'break' codes for the
708                          * neighboring macro keys.
709                          */
710                         if (macro > 0) {
711                                 input_report_key(inputdev,
712                                                  macroKeyEvents[macro - 1], 0);
713                         }
714                         if (macro < 25) {
715                                 input_report_key(inputdev,
716                                                  macroKeyEvents[macro + 1], 0);
717                         }
718
719                         input_report_key(inputdev, macroKeyEvents[macro], 1);
720                         input_report_rel(inputdev, ABS_MISC,
721                                          p | AIPTEK_REPORT_TOOL_MOUSE);
722                         input_sync(inputdev);
723                 }
724         }
725         /* We have no idea which tool can generate a report 6. Theoretically,
726          * neither need to, having been given reports 4 & 5 for such use.
727          * However, report 6 is the 'official-looking' report for macroKeys;
728          * reports 4 & 5 supposively are used to support unnamed, unknown
729          * hat switches (which just so happen to be the macroKeys.)
730          */
731         else if (data[0] == 6) {
732                 macro = le16_to_cpu(get_unaligned((__u16 *) (data + 1)));
733                 input_regs(inputdev, regs);
734
735                 if (macro > 0) {
736                         input_report_key(inputdev, macroKeyEvents[macro - 1],
737                                          0);
738                 }
739                 if (macro < 25) {
740                         input_report_key(inputdev, macroKeyEvents[macro + 1],
741                                          0);
742                 }
743
744                 /* If we've not already sent a tool_button_?? code, do
745                  * so now. Then set FIRED_BIT so it won't be resent unless
746                  * the user forces FIRED_BIT off.
747                  */
748                 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
749                         input_report_key(inputdev,
750                                          TOOL_BUTTON(aiptek->curSetting.
751                                                      toolMode), 1);
752                         aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
753                 }
754
755                 input_report_key(inputdev, macroKeyEvents[macro], 1);
756                 input_report_abs(inputdev, ABS_MISC,
757                                  1 | AIPTEK_REPORT_TOOL_UNKNOWN);
758                 input_sync(inputdev);
759         } else {
760                 dbg("Unknown report %d", data[0]);
761         }
762
763         /* Jitter may occur when the user presses a button on the stlyus
764          * or the mouse. What we do to prevent that is wait 'x' milliseconds
765          * following a 'jitterable' event, which should give the hand some time
766          * stabilize itself.
767          *
768          * We just introduced aiptek->previousJitterable to carry forth the
769          * notion that jitter occurs when the button state changes from on to off:
770          * a person drawing, holding a button down is not subject to jittering.
771          * With that in mind, changing from upper button depressed to lower button
772          * WILL transition through a jitter delay.
773          */
774
775         if (aiptek->previousJitterable != jitterable &&
776             aiptek->curSetting.jitterDelay != 0 && aiptek->inDelay != 1) {
777                 aiptek->endDelay = jiffies +
778                     ((aiptek->curSetting.jitterDelay * HZ) / 1000);
779                 aiptek->inDelay = 1;
780         }
781         aiptek->previousJitterable = jitterable;
782
783 exit:
784         retval = usb_submit_urb(urb, GFP_ATOMIC);
785         if (retval != 0) {
786                 err("%s - usb_submit_urb failed with result %d",
787                     __FUNCTION__, retval);
788         }
789 }
790
791 /***********************************************************************
792  * These are the USB id's known so far. We do not identify them to
793  * specific Aiptek model numbers, because there has been overlaps,
794  * use, and reuse of id's in existing models. Certain models have
795  * been known to use more than one ID, indicative perhaps of
796  * manufacturing revisions. In any event, we consider these 
797  * IDs to not be model-specific nor unique.
798  */
799 struct usb_device_id aiptek_ids[] = {
800         {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01)},
801         {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10)},
802         {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20)},
803         {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21)},
804         {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
805         {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
806         {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
807         {}
808 };
809
810 MODULE_DEVICE_TABLE(usb, aiptek_ids);
811
812 /***********************************************************************
813  * Open an instance of the tablet driver.
814  */
815 static int aiptek_open(struct input_dev *inputdev)
816 {
817         struct aiptek *aiptek = inputdev->private;
818
819         if (aiptek->openCount++ > 0) {
820                 return 0;
821         }
822
823         aiptek->urb->dev = aiptek->usbdev;
824         if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0) {
825                 aiptek->openCount--;
826                 return -EIO;
827         }
828
829         return 0;
830 }
831
832 /***********************************************************************
833  * Close an instance of the tablet driver.
834  */
835 static void aiptek_close(struct input_dev *inputdev)
836 {
837         struct aiptek *aiptek = inputdev->private;
838
839         if (--aiptek->openCount == 0) {
840                 usb_unlink_urb(aiptek->urb);
841         }
842 }
843
844 /***********************************************************************
845  * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x, 
846  * where they were known as usb_set_report and usb_get_report.
847  */
848 static int
849 aiptek_set_report(struct aiptek *aiptek,
850                   unsigned char report_type,
851                   unsigned char report_id, void *buffer, int size)
852 {
853         return usb_control_msg(aiptek->usbdev,
854                                usb_sndctrlpipe(aiptek->usbdev, 0),
855                                USB_REQ_SET_REPORT,
856                                USB_TYPE_CLASS | USB_RECIP_INTERFACE |
857                                USB_DIR_OUT, (report_type << 8) + report_id,
858                                aiptek->ifnum, buffer, size, 5 * HZ);
859 }
860
861 static int
862 aiptek_get_report(struct aiptek *aiptek,
863                   unsigned char report_type,
864                   unsigned char report_id, void *buffer, int size)
865 {
866         return usb_control_msg(aiptek->usbdev,
867                                usb_rcvctrlpipe(aiptek->usbdev, 0),
868                                USB_REQ_GET_REPORT,
869                                USB_TYPE_CLASS | USB_RECIP_INTERFACE |
870                                USB_DIR_IN, (report_type << 8) + report_id,
871                                aiptek->ifnum, buffer, size, 5 * HZ);
872 }
873
874 /***********************************************************************
875  * Send a command to the tablet.
876  */
877 static int
878 aiptek_command(struct aiptek *aiptek, unsigned char command, unsigned char data)
879 {
880         const int sizeof_buf = 3 * sizeof(u8);
881         int ret;
882         u8 *buf;
883
884         buf = kmalloc(sizeof_buf, GFP_KERNEL);
885         if (!buf)
886                 return -ENOMEM;
887
888         buf[0] = 2;
889         buf[1] = command;
890         buf[2] = data;
891
892         if ((ret =
893              aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
894                 dbg("aiptek_program: failed, tried to send: 0x%02x 0x%02x",
895                     command, data);
896         }
897         kfree(buf);
898         return ret < 0 ? ret : 0;
899 }
900
901 /***********************************************************************
902  * Retrieve information from the tablet. Querying info is defined as first
903  * sending the {command,data} sequence as a command, followed by a wait
904  * (aka, "programmaticDelay") and then a "read" request.
905  */
906 static int
907 aiptek_query(struct aiptek *aiptek, unsigned char command, unsigned char data)
908 {
909         const int sizeof_buf = 3 * sizeof(u8);
910         int ret;
911         u8 *buf;
912
913         buf = kmalloc(sizeof_buf, GFP_KERNEL);
914         if (!buf)
915                 return -ENOMEM;
916
917         buf[0] = 2;
918         buf[1] = command;
919         buf[2] = data;
920
921         if (aiptek_command(aiptek, command, data) != 0) {
922                 kfree(buf);
923                 return -EIO;
924         }
925         msleep(aiptek->curSetting.programmableDelay);
926
927         if ((ret =
928              aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
929                 dbg("aiptek_query failed: returned 0x%02x 0x%02x 0x%02x",
930                     buf[0], buf[1], buf[2]);
931                 ret = -EIO;
932         } else {
933                 ret = le16_to_cpu(get_unaligned((__u16 *) (buf + 1)));
934         }
935         kfree(buf);
936         return ret;
937 }
938
939 /***********************************************************************
940  * Program the tablet into either absolute or relative mode.
941  * We also get information about the tablet's size.
942  */
943 static int aiptek_program_tablet(struct aiptek *aiptek)
944 {
945         int ret;
946         /* Execute Resolution500LPI */
947         if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
948                 return ret;
949
950         /* Query getModelCode */
951         if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
952                 return ret;
953         aiptek->features.modelCode = ret & 0xff;
954
955         /* Query getODMCode */
956         if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
957                 return ret;
958         aiptek->features.odmCode = ret;
959
960         /* Query getFirmwareCode */
961         if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
962                 return ret;
963         aiptek->features.firmwareCode = ret;
964
965         /* Query getXextension */
966         if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
967                 return ret;
968         aiptek->inputdev.absmin[ABS_X] = 0;
969         aiptek->inputdev.absmax[ABS_X] = ret - 1;
970
971         /* Query getYextension */
972         if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
973                 return ret;
974         aiptek->inputdev.absmin[ABS_Y] = 0;
975         aiptek->inputdev.absmax[ABS_Y] = ret - 1;
976
977         /* Query getPressureLevels */
978         if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
979                 return ret;
980         aiptek->inputdev.absmin[ABS_PRESSURE] = 0;
981         aiptek->inputdev.absmax[ABS_PRESSURE] = ret - 1;
982
983         /* Depending on whether we are in absolute or relative mode, we will
984          * do a switchToTablet(absolute) or switchToMouse(relative) command.
985          */
986         if (aiptek->curSetting.coordinateMode ==
987             AIPTEK_COORDINATE_ABSOLUTE_MODE) {
988                 /* Execute switchToTablet */
989                 if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
990                         return ret;
991                 }
992         } else {
993                 /* Execute switchToMouse */
994                 if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
995                         return ret;
996                 }
997         }
998
999         /* Enable the macro keys */
1000         if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
1001                 return ret;
1002 #if 0
1003         /* Execute FilterOn */
1004         if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
1005                 return ret;
1006 #endif
1007
1008         /* Execute AutoGainOn */
1009         if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
1010                 return ret;
1011
1012         /* Reset the eventCount, so we track events from last (re)programming
1013          */
1014         aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
1015         aiptek->eventCount = 0;
1016
1017         return 0;
1018 }
1019
1020 /***********************************************************************
1021  * Sysfs functions. Sysfs prefers that individually-tunable parameters
1022  * exist in their separate pseudo-files. Summary data that is immutable
1023  * may exist in a singular file so long as you don't define a writeable
1024  * interface.
1025  */
1026
1027 /***********************************************************************
1028  * support the 'size' file -- display support
1029  */
1030 static ssize_t show_tabletSize(struct device *dev, char *buf)
1031 {
1032         struct aiptek *aiptek = dev_get_drvdata(dev);
1033
1034         if (aiptek == NULL)
1035                 return 0;
1036
1037         return snprintf(buf, PAGE_SIZE, "%dx%d\n",
1038                         aiptek->inputdev.absmax[ABS_X] + 1,
1039                         aiptek->inputdev.absmax[ABS_Y] + 1);
1040 }
1041
1042 /* These structs define the sysfs files, param #1 is the name of the
1043  * file, param 2 is the file permissions, param 3 & 4 are to the
1044  * output generator and input parser routines. Absence of a routine is
1045  * permitted -- it only means can't either 'cat' the file, or send data
1046  * to it.
1047  */
1048 static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
1049
1050 /***********************************************************************
1051  * support routines for the 'product_id' file
1052  */
1053 static ssize_t show_tabletProductId(struct device *dev, char *buf)
1054 {
1055         struct aiptek *aiptek = dev_get_drvdata(dev);
1056
1057         if (aiptek == NULL)
1058                 return 0;
1059
1060         return snprintf(buf, PAGE_SIZE, "0x%04x\n",
1061                         aiptek->inputdev.id.product);
1062 }
1063
1064 static DEVICE_ATTR(product_id, S_IRUGO, show_tabletProductId, NULL);
1065
1066 /***********************************************************************
1067  * support routines for the 'vendor_id' file
1068  */
1069 static ssize_t show_tabletVendorId(struct device *dev, char *buf)
1070 {
1071         struct aiptek *aiptek = dev_get_drvdata(dev);
1072
1073         if (aiptek == NULL)
1074                 return 0;
1075
1076         return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->inputdev.id.vendor);
1077 }
1078
1079 static DEVICE_ATTR(vendor_id, S_IRUGO, show_tabletVendorId, NULL);
1080
1081 /***********************************************************************
1082  * support routines for the 'vendor' file
1083  */
1084 static ssize_t show_tabletManufacturer(struct device *dev, char *buf)
1085 {
1086         struct aiptek *aiptek = dev_get_drvdata(dev);
1087         int retval;
1088
1089         if (aiptek == NULL)
1090                 return 0;
1091
1092         retval = snprintf(buf, PAGE_SIZE, "%s\n", aiptek->features.manuName);
1093         return retval;
1094 }
1095
1096 static DEVICE_ATTR(vendor, S_IRUGO, show_tabletManufacturer, NULL);
1097
1098 /***********************************************************************
1099  * support routines for the 'product' file
1100  */
1101 static ssize_t show_tabletProduct(struct device *dev, char *buf)
1102 {
1103         struct aiptek *aiptek = dev_get_drvdata(dev);
1104         int retval;
1105
1106         if (aiptek == NULL)
1107                 return 0;
1108
1109         retval = snprintf(buf, PAGE_SIZE, "%s\n", aiptek->features.prodName);
1110         return retval;
1111 }
1112
1113 static DEVICE_ATTR(product, S_IRUGO, show_tabletProduct, NULL);
1114
1115 /***********************************************************************
1116  * support routines for the 'pointer_mode' file. Note that this file
1117  * both displays current setting and allows reprogramming.
1118  */
1119 static ssize_t show_tabletPointerMode(struct device *dev, char *buf)
1120 {
1121         struct aiptek *aiptek = dev_get_drvdata(dev);
1122         char *s;
1123
1124         if (aiptek == NULL)
1125                 return 0;
1126
1127         switch (aiptek->curSetting.pointerMode) {
1128         case AIPTEK_POINTER_ONLY_STYLUS_MODE:
1129                 s = "stylus";
1130                 break;
1131
1132         case AIPTEK_POINTER_ONLY_MOUSE_MODE:
1133                 s = "mouse";
1134                 break;
1135
1136         case AIPTEK_POINTER_EITHER_MODE:
1137                 s = "either";
1138                 break;
1139
1140         default:
1141                 s = "unknown";
1142                 break;
1143         }
1144         return snprintf(buf, PAGE_SIZE, "%s\n", s);
1145 }
1146
1147 static ssize_t
1148 store_tabletPointerMode(struct device *dev, const char *buf, size_t count)
1149 {
1150         struct aiptek *aiptek = dev_get_drvdata(dev);
1151         if (aiptek == NULL)
1152                 return 0;
1153
1154         if (strcmp(buf, "stylus") == 0) {
1155                 aiptek->newSetting.pointerMode =
1156                     AIPTEK_POINTER_ONLY_STYLUS_MODE;
1157         } else if (strcmp(buf, "mouse") == 0) {
1158                 aiptek->newSetting.pointerMode = AIPTEK_POINTER_ONLY_MOUSE_MODE;
1159         } else if (strcmp(buf, "either") == 0) {
1160                 aiptek->newSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
1161         }
1162         return count;
1163 }
1164
1165 static DEVICE_ATTR(pointer_mode,
1166                    S_IRUGO | S_IWUGO,
1167                    show_tabletPointerMode, store_tabletPointerMode);
1168
1169 /***********************************************************************
1170  * support routines for the 'coordinate_mode' file. Note that this file
1171  * both displays current setting and allows reprogramming.
1172  */
1173 static ssize_t show_tabletCoordinateMode(struct device *dev, char *buf)
1174 {
1175         struct aiptek *aiptek = dev_get_drvdata(dev);
1176         char *s;
1177
1178         if (aiptek == NULL)
1179                 return 0;
1180
1181         switch (aiptek->curSetting.coordinateMode) {
1182         case AIPTEK_COORDINATE_ABSOLUTE_MODE:
1183                 s = "absolute";
1184                 break;
1185
1186         case AIPTEK_COORDINATE_RELATIVE_MODE:
1187                 s = "relative";
1188                 break;
1189
1190         default:
1191                 s = "unknown";
1192                 break;
1193         }
1194         return snprintf(buf, PAGE_SIZE, "%s\n", s);
1195 }
1196
1197 static ssize_t
1198 store_tabletCoordinateMode(struct device *dev, const char *buf, size_t count)
1199 {
1200         struct aiptek *aiptek = dev_get_drvdata(dev);
1201         if (aiptek == NULL)
1202                 return 0;
1203
1204         if (strcmp(buf, "absolute") == 0) {
1205                 aiptek->newSetting.pointerMode =
1206                     AIPTEK_COORDINATE_ABSOLUTE_MODE;
1207         } else if (strcmp(buf, "relative") == 0) {
1208                 aiptek->newSetting.pointerMode =
1209                     AIPTEK_COORDINATE_RELATIVE_MODE;
1210         }
1211         return count;
1212 }
1213
1214 static DEVICE_ATTR(coordinate_mode,
1215                    S_IRUGO | S_IWUGO,
1216                    show_tabletCoordinateMode, store_tabletCoordinateMode);
1217
1218 /***********************************************************************
1219  * support routines for the 'tool_mode' file. Note that this file
1220  * both displays current setting and allows reprogramming.
1221  */
1222 static ssize_t show_tabletToolMode(struct device *dev, char *buf)
1223 {
1224         struct aiptek *aiptek = dev_get_drvdata(dev);
1225         char *s;
1226
1227         if (aiptek == NULL)
1228                 return 0;
1229
1230         switch (TOOL_BUTTON(aiptek->curSetting.toolMode)) {
1231         case AIPTEK_TOOL_BUTTON_MOUSE_MODE:
1232                 s = "mouse";
1233                 break;
1234
1235         case AIPTEK_TOOL_BUTTON_ERASER_MODE:
1236                 s = "eraser";
1237                 break;
1238
1239         case AIPTEK_TOOL_BUTTON_PENCIL_MODE:
1240                 s = "pencil";
1241                 break;
1242
1243         case AIPTEK_TOOL_BUTTON_PEN_MODE:
1244                 s = "pen";
1245                 break;
1246
1247         case AIPTEK_TOOL_BUTTON_BRUSH_MODE:
1248                 s = "brush";
1249                 break;
1250
1251         case AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE:
1252                 s = "airbrush";
1253                 break;
1254
1255         case AIPTEK_TOOL_BUTTON_LENS_MODE:
1256                 s = "lens";
1257                 break;
1258
1259         default:
1260                 s = "unknown";
1261                 break;
1262         }
1263         return snprintf(buf, PAGE_SIZE, "%s\n", s);
1264 }
1265
1266 static ssize_t
1267 store_tabletToolMode(struct device *dev, const char *buf, size_t count)
1268 {
1269         struct aiptek *aiptek = dev_get_drvdata(dev);
1270         if (aiptek == NULL)
1271                 return 0;
1272
1273         if (strcmp(buf, "mouse") == 0) {
1274                 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_MOUSE_MODE;
1275         } else if (strcmp(buf, "eraser") == 0) {
1276                 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_ERASER_MODE;
1277         } else if (strcmp(buf, "pencil") == 0) {
1278                 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PENCIL_MODE;
1279         } else if (strcmp(buf, "pen") == 0) {
1280                 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
1281         } else if (strcmp(buf, "brush") == 0) {
1282                 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_BRUSH_MODE;
1283         } else if (strcmp(buf, "airbrush") == 0) {
1284                 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE;
1285         } else if (strcmp(buf, "lens") == 0) {
1286                 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_LENS_MODE;
1287         }
1288
1289         return count;
1290 }
1291
1292 static DEVICE_ATTR(tool_mode,
1293                    S_IRUGO | S_IWUGO,
1294                    show_tabletToolMode, store_tabletToolMode);
1295
1296 /***********************************************************************
1297  * support routines for the 'xtilt' file. Note that this file
1298  * both displays current setting and allows reprogramming.
1299  */
1300 static ssize_t show_tabletXtilt(struct device *dev, char *buf)
1301 {
1302         struct aiptek *aiptek = dev_get_drvdata(dev);
1303
1304         if (aiptek == NULL)
1305                 return 0;
1306
1307         if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
1308                 return snprintf(buf, PAGE_SIZE, "disable\n");
1309         } else {
1310                 return snprintf(buf, PAGE_SIZE, "%d\n",
1311                                 aiptek->curSetting.xTilt);
1312         }
1313 }
1314
1315 static ssize_t
1316 store_tabletXtilt(struct device *dev, const char *buf, size_t count)
1317 {
1318         struct aiptek *aiptek = dev_get_drvdata(dev);
1319         int x;
1320
1321         if (aiptek == NULL)
1322                 return 0;
1323
1324         if (strcmp(buf, "disable") == 0) {
1325                 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
1326         } else {
1327                 x = (int)simple_strtol(buf, 0, 10);
1328                 if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
1329                         aiptek->newSetting.xTilt = x;
1330                 }
1331         }
1332         return count;
1333 }
1334
1335 static DEVICE_ATTR(xtilt,
1336                    S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt);
1337
1338 /***********************************************************************
1339  * support routines for the 'ytilt' file. Note that this file
1340  * both displays current setting and allows reprogramming.
1341  */
1342 static ssize_t show_tabletYtilt(struct device *dev, char *buf)
1343 {
1344         struct aiptek *aiptek = dev_get_drvdata(dev);
1345
1346         if (aiptek == NULL)
1347                 return 0;
1348
1349         if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
1350                 return snprintf(buf, PAGE_SIZE, "disable\n");
1351         } else {
1352                 return snprintf(buf, PAGE_SIZE, "%d\n",
1353                                 aiptek->curSetting.yTilt);
1354         }
1355 }
1356
1357 static ssize_t
1358 store_tabletYtilt(struct device *dev, const char *buf, size_t count)
1359 {
1360         struct aiptek *aiptek = dev_get_drvdata(dev);
1361         int y;
1362
1363         if (aiptek == NULL)
1364                 return 0;
1365
1366         if (strcmp(buf, "disable") == 0) {
1367                 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
1368         } else {
1369                 y = (int)simple_strtol(buf, 0, 10);
1370                 if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
1371                         aiptek->newSetting.yTilt = y;
1372                 }
1373         }
1374         return count;
1375 }
1376
1377 static DEVICE_ATTR(ytilt,
1378                    S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt);
1379
1380 /***********************************************************************
1381  * support routines for the 'jitter' file. Note that this file
1382  * both displays current setting and allows reprogramming.
1383  */
1384 static ssize_t show_tabletJitterDelay(struct device *dev, char *buf)
1385 {
1386         struct aiptek *aiptek = dev_get_drvdata(dev);
1387
1388         if (aiptek == NULL)
1389                 return 0;
1390
1391         return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
1392 }
1393
1394 static ssize_t
1395 store_tabletJitterDelay(struct device *dev, const char *buf, size_t count)
1396 {
1397         struct aiptek *aiptek = dev_get_drvdata(dev);
1398
1399         if (aiptek == NULL)
1400                 return 0;
1401
1402         aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, 0, 10);
1403         return count;
1404 }
1405
1406 static DEVICE_ATTR(jitter,
1407                    S_IRUGO | S_IWUGO,
1408                    show_tabletJitterDelay, store_tabletJitterDelay);
1409
1410 /***********************************************************************
1411  * support routines for the 'delay' file. Note that this file
1412  * both displays current setting and allows reprogramming.
1413  */
1414 static ssize_t show_tabletProgrammableDelay(struct device *dev, char *buf)
1415 {
1416         struct aiptek *aiptek = dev_get_drvdata(dev);
1417
1418         if (aiptek == NULL)
1419                 return 0;
1420
1421         return snprintf(buf, PAGE_SIZE, "%d\n",
1422                         aiptek->curSetting.programmableDelay);
1423 }
1424
1425 static ssize_t
1426 store_tabletProgrammableDelay(struct device *dev, const char *buf, size_t count)
1427 {
1428         struct aiptek *aiptek = dev_get_drvdata(dev);
1429
1430         if (aiptek == NULL)
1431                 return 0;
1432
1433         aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, 0, 10);
1434         return count;
1435 }
1436
1437 static DEVICE_ATTR(delay,
1438                    S_IRUGO | S_IWUGO,
1439                    show_tabletProgrammableDelay, store_tabletProgrammableDelay);
1440
1441 /***********************************************************************
1442  * support routines for the 'input_path' file. Note that this file
1443  * only displays current setting.
1444  */
1445 static ssize_t show_tabletInputDevice(struct device *dev, char *buf)
1446 {
1447         struct aiptek *aiptek = dev_get_drvdata(dev);
1448
1449         if (aiptek == NULL)
1450                 return 0;
1451
1452         return snprintf(buf, PAGE_SIZE, "/dev/input/%s\n",
1453                         aiptek->features.inputPath);
1454 }
1455
1456 static DEVICE_ATTR(input_path, S_IRUGO, show_tabletInputDevice, NULL);
1457
1458 /***********************************************************************
1459  * support routines for the 'event_count' file. Note that this file
1460  * only displays current setting.
1461  */
1462 static ssize_t show_tabletEventsReceived(struct device *dev, char *buf)
1463 {
1464         struct aiptek *aiptek = dev_get_drvdata(dev);
1465
1466         if (aiptek == NULL)
1467                 return 0;
1468
1469         return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
1470 }
1471
1472 static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
1473
1474 /***********************************************************************
1475  * support routines for the 'diagnostic' file. Note that this file
1476  * only displays current setting.
1477  */
1478 static ssize_t show_tabletDiagnosticMessage(struct device *dev, char *buf)
1479 {
1480         struct aiptek *aiptek = dev_get_drvdata(dev);
1481         char *retMsg;
1482
1483         if (aiptek == NULL)
1484                 return 0;
1485
1486         switch (aiptek->diagnostic) {
1487         case AIPTEK_DIAGNOSTIC_NA:
1488                 retMsg = "no errors\n";
1489                 break;
1490
1491         case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
1492                 retMsg = "Error: receiving relative reports\n";
1493                 break;
1494
1495         case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
1496                 retMsg = "Error: receiving absolute reports\n";
1497                 break;
1498
1499         case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
1500                 if (aiptek->curSetting.pointerMode ==
1501                     AIPTEK_POINTER_ONLY_MOUSE_MODE) {
1502                         retMsg = "Error: receiving stylus reports\n";
1503                 } else {
1504                         retMsg = "Error: receiving mouse reports\n";
1505                 }
1506                 break;
1507
1508         default:
1509                 return 0;
1510         }
1511         return snprintf(buf, PAGE_SIZE, retMsg);
1512 }
1513
1514 static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
1515
1516 /***********************************************************************
1517  * support routines for the 'stylus_upper' file. Note that this file
1518  * both displays current setting and allows for setting changing.
1519  */
1520 static ssize_t show_tabletStylusUpper(struct device *dev, char *buf)
1521 {
1522         struct aiptek *aiptek = dev_get_drvdata(dev);
1523         char *s;
1524
1525         if (aiptek == NULL)
1526                 return 0;
1527
1528         switch (aiptek->curSetting.stylusButtonUpper) {
1529         case AIPTEK_STYLUS_UPPER_BUTTON:
1530                 s = "upper";
1531                 break;
1532
1533         case AIPTEK_STYLUS_LOWER_BUTTON:
1534                 s = "lower";
1535                 break;
1536
1537         default:
1538                 s = "unknown";
1539                 break;
1540         }
1541         return snprintf(buf, PAGE_SIZE, "%s\n", s);
1542 }
1543
1544 static ssize_t
1545 store_tabletStylusUpper(struct device *dev, const char *buf, size_t count)
1546 {
1547         struct aiptek *aiptek = dev_get_drvdata(dev);
1548
1549         if (aiptek == NULL)
1550                 return 0;
1551
1552         if (strcmp(buf, "upper") == 0) {
1553                 aiptek->newSetting.stylusButtonUpper =
1554                     AIPTEK_STYLUS_UPPER_BUTTON;
1555         } else if (strcmp(buf, "lower") == 0) {
1556                 aiptek->newSetting.stylusButtonUpper =
1557                     AIPTEK_STYLUS_LOWER_BUTTON;
1558         }
1559         return count;
1560 }
1561
1562 static DEVICE_ATTR(stylus_upper,
1563                    S_IRUGO | S_IWUGO,
1564                    show_tabletStylusUpper, store_tabletStylusUpper);
1565
1566 /***********************************************************************
1567  * support routines for the 'stylus_lower' file. Note that this file
1568  * both displays current setting and allows for setting changing.
1569  */
1570 static ssize_t show_tabletStylusLower(struct device *dev, char *buf)
1571 {
1572         struct aiptek *aiptek = dev_get_drvdata(dev);
1573         char *s;
1574
1575         if (aiptek == NULL)
1576                 return 0;
1577
1578         switch (aiptek->curSetting.stylusButtonLower) {
1579         case AIPTEK_STYLUS_UPPER_BUTTON:
1580                 s = "upper";
1581                 break;
1582
1583         case AIPTEK_STYLUS_LOWER_BUTTON:
1584                 s = "lower";
1585                 break;
1586
1587         default:
1588                 s = "unknown";
1589                 break;
1590         }
1591         return snprintf(buf, PAGE_SIZE, "%s\n", s);
1592 }
1593
1594 static ssize_t
1595 store_tabletStylusLower(struct device *dev, const char *buf, size_t count)
1596 {
1597         struct aiptek *aiptek = dev_get_drvdata(dev);
1598
1599         if (aiptek == NULL)
1600                 return 0;
1601
1602         if (strcmp(buf, "upper") == 0) {
1603                 aiptek->newSetting.stylusButtonLower =
1604                     AIPTEK_STYLUS_UPPER_BUTTON;
1605         } else if (strcmp(buf, "lower") == 0) {
1606                 aiptek->newSetting.stylusButtonLower =
1607                     AIPTEK_STYLUS_LOWER_BUTTON;
1608         }
1609         return count;
1610 }
1611
1612 static DEVICE_ATTR(stylus_lower,
1613                    S_IRUGO | S_IWUGO,
1614                    show_tabletStylusLower, store_tabletStylusLower);
1615
1616 /***********************************************************************
1617  * support routines for the 'mouse_left' file. Note that this file
1618  * both displays current setting and allows for setting changing.
1619  */
1620 static ssize_t show_tabletMouseLeft(struct device *dev, char *buf)
1621 {
1622         struct aiptek *aiptek = dev_get_drvdata(dev);
1623         char *s;
1624
1625         if (aiptek == NULL)
1626                 return 0;
1627
1628         switch (aiptek->curSetting.mouseButtonLeft) {
1629         case AIPTEK_MOUSE_LEFT_BUTTON:
1630                 s = "left";
1631                 break;
1632
1633         case AIPTEK_MOUSE_MIDDLE_BUTTON:
1634                 s = "middle";
1635                 break;
1636
1637         case AIPTEK_MOUSE_RIGHT_BUTTON:
1638                 s = "right";
1639                 break;
1640
1641         default:
1642                 s = "unknown";
1643                 break;
1644         }
1645         return snprintf(buf, PAGE_SIZE, "%s\n", s);
1646 }
1647
1648 static ssize_t
1649 store_tabletMouseLeft(struct device *dev, const char *buf, size_t count)
1650 {
1651         struct aiptek *aiptek = dev_get_drvdata(dev);
1652
1653         if (aiptek == NULL)
1654                 return 0;
1655
1656         if (strcmp(buf, "left") == 0) {
1657                 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
1658         } else if (strcmp(buf, "middle") == 0) {
1659                 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_MIDDLE_BUTTON;
1660         } else if (strcmp(buf, "right") == 0) {
1661                 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_RIGHT_BUTTON;
1662         }
1663         return count;
1664 }
1665
1666 static DEVICE_ATTR(mouse_left,
1667                    S_IRUGO | S_IWUGO,
1668                    show_tabletMouseLeft, store_tabletMouseLeft);
1669
1670 /***********************************************************************
1671  * support routines for the 'mouse_middle' file. Note that this file
1672  * both displays current setting and allows for setting changing.
1673  */
1674 static ssize_t show_tabletMouseMiddle(struct device *dev, char *buf)
1675 {
1676         struct aiptek *aiptek = dev_get_drvdata(dev);
1677         char *s;
1678
1679         if (aiptek == NULL)
1680                 return 0;
1681
1682         switch (aiptek->curSetting.mouseButtonMiddle) {
1683         case AIPTEK_MOUSE_LEFT_BUTTON:
1684                 s = "left";
1685                 break;
1686
1687         case AIPTEK_MOUSE_MIDDLE_BUTTON:
1688                 s = "middle";
1689                 break;
1690
1691         case AIPTEK_MOUSE_RIGHT_BUTTON:
1692                 s = "right";
1693                 break;
1694
1695         default:
1696                 s = "unknown";
1697                 break;
1698         }
1699         return snprintf(buf, PAGE_SIZE, "%s\n", s);
1700 }
1701
1702 static ssize_t
1703 store_tabletMouseMiddle(struct device *dev, const char *buf, size_t count)
1704 {
1705         struct aiptek *aiptek = dev_get_drvdata(dev);
1706
1707         if (aiptek == NULL)
1708                 return 0;
1709
1710         if (strcmp(buf, "left") == 0) {
1711                 aiptek->newSetting.mouseButtonMiddle = AIPTEK_MOUSE_LEFT_BUTTON;
1712         } else if (strcmp(buf, "middle") == 0) {
1713                 aiptek->newSetting.mouseButtonMiddle =
1714                     AIPTEK_MOUSE_MIDDLE_BUTTON;
1715         } else if (strcmp(buf, "right") == 0) {
1716                 aiptek->newSetting.mouseButtonMiddle =
1717                     AIPTEK_MOUSE_RIGHT_BUTTON;
1718         }
1719         return count;
1720 }
1721
1722 static DEVICE_ATTR(mouse_middle,
1723                    S_IRUGO | S_IWUGO,
1724                    show_tabletMouseMiddle, store_tabletMouseMiddle);
1725
1726 /***********************************************************************
1727  * support routines for the 'mouse_right' file. Note that this file
1728  * both displays current setting and allows for setting changing.
1729  */
1730 static ssize_t show_tabletMouseRight(struct device *dev, char *buf)
1731 {
1732         struct aiptek *aiptek = dev_get_drvdata(dev);
1733         char *s;
1734
1735         if (aiptek == NULL)
1736                 return 0;
1737
1738         switch (aiptek->curSetting.mouseButtonRight) {
1739         case AIPTEK_MOUSE_LEFT_BUTTON:
1740                 s = "left";
1741                 break;
1742
1743         case AIPTEK_MOUSE_MIDDLE_BUTTON:
1744                 s = "middle";
1745                 break;
1746
1747         case AIPTEK_MOUSE_RIGHT_BUTTON:
1748                 s = "right";
1749                 break;
1750
1751         default:
1752                 s = "unknown";
1753                 break;
1754         }
1755         return snprintf(buf, PAGE_SIZE, "%s\n", s);
1756 }
1757
1758 static ssize_t
1759 store_tabletMouseRight(struct device *dev, const char *buf, size_t count)
1760 {
1761         struct aiptek *aiptek = dev_get_drvdata(dev);
1762
1763         if (aiptek == NULL)
1764                 return 0;
1765
1766         if (strcmp(buf, "left") == 0) {
1767                 aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_LEFT_BUTTON;
1768         } else if (strcmp(buf, "middle") == 0) {
1769                 aiptek->newSetting.mouseButtonRight =
1770                     AIPTEK_MOUSE_MIDDLE_BUTTON;
1771         } else if (strcmp(buf, "right") == 0) {
1772                 aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
1773         }
1774         return count;
1775 }
1776
1777 static DEVICE_ATTR(mouse_right,
1778                    S_IRUGO | S_IWUGO,
1779                    show_tabletMouseRight, store_tabletMouseRight);
1780
1781 /***********************************************************************
1782  * support routines for the 'wheel' file. Note that this file
1783  * both displays current setting and allows for setting changing.
1784  */
1785 static ssize_t show_tabletWheel(struct device *dev, char *buf)
1786 {
1787         struct aiptek *aiptek = dev_get_drvdata(dev);
1788
1789         if (aiptek == NULL)
1790                 return 0;
1791
1792         if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
1793                 return snprintf(buf, PAGE_SIZE, "disable\n");
1794         } else {
1795                 return snprintf(buf, PAGE_SIZE, "%d\n",
1796                                 aiptek->curSetting.wheel);
1797         }
1798 }
1799
1800 static ssize_t
1801 store_tabletWheel(struct device *dev, const char *buf, size_t count)
1802 {
1803         struct aiptek *aiptek = dev_get_drvdata(dev);
1804
1805         if (aiptek == NULL)
1806                 return 0;
1807
1808         aiptek->newSetting.wheel = (int)simple_strtol(buf, 0, 10);
1809         return count;
1810 }
1811
1812 static DEVICE_ATTR(wheel,
1813                    S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel);
1814
1815 /***********************************************************************
1816  * support routines for the 'execute' file. Note that this file
1817  * both displays current setting and allows for setting changing.
1818  */
1819 static ssize_t show_tabletExecute(struct device *dev, char *buf)
1820 {
1821         struct aiptek *aiptek = dev_get_drvdata(dev);
1822
1823         if (aiptek == NULL)
1824                 return 0;
1825
1826         /* There is nothing useful to display, so a one-line manual
1827          * is in order...
1828          */
1829         return snprintf(buf, PAGE_SIZE,
1830                         "Write anything to this file to program your tablet.\n");
1831 }
1832
1833 static ssize_t
1834 store_tabletExecute(struct device *dev, const char *buf, size_t count)
1835 {
1836         struct aiptek *aiptek = dev_get_drvdata(dev);
1837
1838         if (aiptek == NULL)
1839                 return 0;
1840
1841         /* We do not care what you write to this file. Merely the action
1842          * of writing to this file triggers a tablet reprogramming.
1843          */
1844         memcpy(&aiptek->curSetting, &aiptek->newSetting,
1845                sizeof(struct aiptek_settings));
1846
1847         if (aiptek_program_tablet(aiptek) < 0)
1848                 return -EIO;
1849
1850         return count;
1851 }
1852
1853 static DEVICE_ATTR(execute,
1854                    S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute);
1855
1856 /***********************************************************************
1857  * support routines for the 'odm_code' file. Note that this file
1858  * only displays current setting.
1859  */
1860 static ssize_t show_tabletODMCode(struct device *dev, char *buf)
1861 {
1862         struct aiptek *aiptek = dev_get_drvdata(dev);
1863
1864         if (aiptek == NULL)
1865                 return 0;
1866
1867         return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
1868 }
1869
1870 static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
1871
1872 /***********************************************************************
1873  * support routines for the 'model_code' file. Note that this file
1874  * only displays current setting.
1875  */
1876 static ssize_t show_tabletModelCode(struct device *dev, char *buf)
1877 {
1878         struct aiptek *aiptek = dev_get_drvdata(dev);
1879
1880         if (aiptek == NULL)
1881                 return 0;
1882
1883         return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
1884 }
1885
1886 static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
1887
1888 /***********************************************************************
1889  * support routines for the 'firmware_code' file. Note that this file
1890  * only displays current setting.
1891  */
1892 static ssize_t show_firmwareCode(struct device *dev, char *buf)
1893 {
1894         struct aiptek *aiptek = dev_get_drvdata(dev);
1895
1896         if (aiptek == NULL)
1897                 return 0;
1898
1899         return snprintf(buf, PAGE_SIZE, "%04x\n",
1900                         aiptek->features.firmwareCode);
1901 }
1902
1903 static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
1904
1905 /***********************************************************************
1906  * This routine removes all existing sysfs files managed by this device
1907  * driver.
1908  */
1909 static void aiptek_delete_files(struct device *dev)
1910 {
1911         device_remove_file(dev, &dev_attr_size);
1912         device_remove_file(dev, &dev_attr_product_id);
1913         device_remove_file(dev, &dev_attr_vendor_id);
1914         device_remove_file(dev, &dev_attr_vendor);
1915         device_remove_file(dev, &dev_attr_product);
1916         device_remove_file(dev, &dev_attr_pointer_mode);
1917         device_remove_file(dev, &dev_attr_coordinate_mode);
1918         device_remove_file(dev, &dev_attr_tool_mode);
1919         device_remove_file(dev, &dev_attr_xtilt);
1920         device_remove_file(dev, &dev_attr_ytilt);
1921         device_remove_file(dev, &dev_attr_jitter);
1922         device_remove_file(dev, &dev_attr_delay);
1923         device_remove_file(dev, &dev_attr_input_path);
1924         device_remove_file(dev, &dev_attr_event_count);
1925         device_remove_file(dev, &dev_attr_diagnostic);
1926         device_remove_file(dev, &dev_attr_odm_code);
1927         device_remove_file(dev, &dev_attr_model_code);
1928         device_remove_file(dev, &dev_attr_firmware_code);
1929         device_remove_file(dev, &dev_attr_stylus_lower);
1930         device_remove_file(dev, &dev_attr_stylus_upper);
1931         device_remove_file(dev, &dev_attr_mouse_left);
1932         device_remove_file(dev, &dev_attr_mouse_middle);
1933         device_remove_file(dev, &dev_attr_mouse_right);
1934         device_remove_file(dev, &dev_attr_wheel);
1935         device_remove_file(dev, &dev_attr_execute);
1936 }
1937
1938 /***********************************************************************
1939  * This routine creates the sysfs files managed by this device
1940  * driver.
1941  */
1942 static int aiptek_add_files(struct device *dev)
1943 {
1944         int ret;
1945
1946         if ((ret = device_create_file(dev, &dev_attr_size)) ||
1947             (ret = device_create_file(dev, &dev_attr_product_id)) ||
1948             (ret = device_create_file(dev, &dev_attr_vendor_id)) ||
1949             (ret = device_create_file(dev, &dev_attr_vendor)) ||
1950             (ret = device_create_file(dev, &dev_attr_product)) ||
1951             (ret = device_create_file(dev, &dev_attr_pointer_mode)) ||
1952             (ret = device_create_file(dev, &dev_attr_coordinate_mode)) ||
1953             (ret = device_create_file(dev, &dev_attr_tool_mode)) ||
1954             (ret = device_create_file(dev, &dev_attr_xtilt)) ||
1955             (ret = device_create_file(dev, &dev_attr_ytilt)) ||
1956             (ret = device_create_file(dev, &dev_attr_jitter)) ||
1957             (ret = device_create_file(dev, &dev_attr_delay)) ||
1958             (ret = device_create_file(dev, &dev_attr_input_path)) ||
1959             (ret = device_create_file(dev, &dev_attr_event_count)) ||
1960             (ret = device_create_file(dev, &dev_attr_diagnostic)) ||
1961             (ret = device_create_file(dev, &dev_attr_odm_code)) ||
1962             (ret = device_create_file(dev, &dev_attr_model_code)) ||
1963             (ret = device_create_file(dev, &dev_attr_firmware_code)) ||
1964             (ret = device_create_file(dev, &dev_attr_stylus_lower)) ||
1965             (ret = device_create_file(dev, &dev_attr_stylus_upper)) ||
1966             (ret = device_create_file(dev, &dev_attr_mouse_left)) ||
1967             (ret = device_create_file(dev, &dev_attr_mouse_middle)) ||
1968             (ret = device_create_file(dev, &dev_attr_mouse_right)) ||
1969             (ret = device_create_file(dev, &dev_attr_wheel)) ||
1970             (ret = device_create_file(dev, &dev_attr_execute))) {
1971                 err("aiptek: killing own sysfs device files\n");
1972                 aiptek_delete_files(dev);
1973         }
1974         return ret;
1975 }
1976
1977 /***********************************************************************
1978  * This routine is called when a tablet has been identified. It basically
1979  * sets up the tablet and the driver's internal structures.
1980  */
1981 static int
1982 aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1983 {
1984         struct usb_device *usbdev = interface_to_usbdev(intf);
1985         struct usb_endpoint_descriptor *endpoint;
1986         struct aiptek *aiptek;
1987         struct input_dev *inputdev;
1988         struct input_handle *inputhandle;
1989         struct list_head *node, *next;
1990         char path[64 + 1];
1991         int i;
1992         int speeds[] = { 0,
1993                 AIPTEK_PROGRAMMABLE_DELAY_50,
1994                 AIPTEK_PROGRAMMABLE_DELAY_400,
1995                 AIPTEK_PROGRAMMABLE_DELAY_25,
1996                 AIPTEK_PROGRAMMABLE_DELAY_100,
1997                 AIPTEK_PROGRAMMABLE_DELAY_200,
1998                 AIPTEK_PROGRAMMABLE_DELAY_300
1999         };
2000
2001         /* programmableDelay is where the command-line specified
2002          * delay is kept. We make it the first element of speeds[],
2003          * so therefore, your override speed is tried first, then the
2004          * remainder. Note that the default value of 400ms will be tried
2005          * if you do not specify any command line parameter.
2006          */
2007         speeds[0] = programmableDelay;
2008
2009         if ((aiptek = kmalloc(sizeof(struct aiptek), GFP_KERNEL)) == NULL)
2010                 return -ENOMEM;
2011         memset(aiptek, 0, sizeof(struct aiptek));
2012
2013         aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
2014                                         SLAB_ATOMIC, &aiptek->data_dma);
2015         if (aiptek->data == NULL) {
2016                 kfree(aiptek);
2017                 return -ENOMEM;
2018         }
2019
2020         aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
2021         if (aiptek->urb == NULL) {
2022                 usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
2023                                 aiptek->data_dma);
2024                 kfree(aiptek);
2025                 return -ENOMEM;
2026         }
2027
2028         /* Set up the curSettings struct. Said struct contains the current
2029          * programmable parameters. The newSetting struct contains changes
2030          * the user makes to the settings via the sysfs interface. Those
2031          * changes are not "committed" to curSettings until the user
2032          * writes to the sysfs/.../execute file.
2033          */
2034         aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
2035         aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
2036         aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
2037         aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
2038         aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
2039         aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
2040         aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
2041         aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
2042         aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
2043         aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
2044         aiptek->curSetting.jitterDelay = jitterDelay;
2045         aiptek->curSetting.programmableDelay = programmableDelay;
2046
2047         /* Both structs should have equivalent settings
2048          */
2049         memcpy(&aiptek->newSetting, &aiptek->curSetting,
2050                sizeof(struct aiptek_settings));
2051
2052         /* Now program the capacities of the tablet, in terms of being
2053          * an input device.
2054          */
2055         aiptek->inputdev.evbit[0] |= BIT(EV_KEY)
2056             | BIT(EV_ABS)
2057             | BIT(EV_REL)
2058             | BIT(EV_MSC);
2059
2060         aiptek->inputdev.absbit[0] |=
2061             (BIT(ABS_X) |
2062              BIT(ABS_Y) |
2063              BIT(ABS_PRESSURE) |
2064              BIT(ABS_TILT_X) |
2065              BIT(ABS_TILT_Y) | BIT(ABS_WHEEL) | BIT(ABS_MISC));
2066
2067         aiptek->inputdev.relbit[0] |=
2068             (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC));
2069
2070         aiptek->inputdev.keybit[LONG(BTN_LEFT)] |=
2071             (BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE));
2072
2073         aiptek->inputdev.keybit[LONG(BTN_DIGI)] |=
2074             (BIT(BTN_TOOL_PEN) |
2075              BIT(BTN_TOOL_RUBBER) |
2076              BIT(BTN_TOOL_PENCIL) |
2077              BIT(BTN_TOOL_AIRBRUSH) |
2078              BIT(BTN_TOOL_BRUSH) |
2079              BIT(BTN_TOOL_MOUSE) |
2080              BIT(BTN_TOOL_LENS) |
2081              BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2));
2082
2083         aiptek->inputdev.mscbit[0] = BIT(MSC_SERIAL);
2084
2085         /* Programming the tablet macro keys needs to be done with a for loop
2086          * as the keycodes are discontiguous.
2087          */
2088         for (i = 0; i < sizeof(macroKeyEvents) / sizeof(macroKeyEvents[0]); ++i)
2089                 set_bit(macroKeyEvents[i], aiptek->inputdev.keybit);
2090
2091         /* Set up client data, pointers to open and close routines
2092          * for the input device.
2093          */
2094         aiptek->inputdev.private = aiptek;
2095         aiptek->inputdev.open = aiptek_open;
2096         aiptek->inputdev.close = aiptek_close;
2097
2098         /* Determine the usb devices' physical path.
2099          * Asketh not why we always pretend we're using "../input0",
2100          * but I suspect this will have to be refactored one
2101          * day if a single USB device can be a keyboard & a mouse
2102          * & a tablet, and the inputX number actually will tell
2103          * us something...
2104          */
2105         if (usb_make_path(usbdev, path, 64) > 0)
2106                 sprintf(aiptek->features.usbPath, "%s/input0", path);
2107
2108         /* Program the input device coordinate capacities. We do not yet
2109          * know what maximum X, Y, and Z values are, so we're putting fake
2110          * values in. Later, we'll ask the tablet to put in the correct
2111          * values.
2112          */
2113         aiptek->inputdev.absmin[ABS_X] = 0;
2114         aiptek->inputdev.absmax[ABS_X] = 2999;
2115         aiptek->inputdev.absmin[ABS_Y] = 0;
2116         aiptek->inputdev.absmax[ABS_Y] = 2249;
2117         aiptek->inputdev.absmin[ABS_PRESSURE] = 0;
2118         aiptek->inputdev.absmax[ABS_PRESSURE] = 511;
2119         aiptek->inputdev.absmin[ABS_TILT_X] = AIPTEK_TILT_MIN;
2120         aiptek->inputdev.absmax[ABS_TILT_X] = AIPTEK_TILT_MAX;
2121         aiptek->inputdev.absmin[ABS_TILT_Y] = AIPTEK_TILT_MIN;
2122         aiptek->inputdev.absmax[ABS_TILT_Y] = AIPTEK_TILT_MAX;
2123         aiptek->inputdev.absmin[ABS_WHEEL] = AIPTEK_WHEEL_MIN;
2124         aiptek->inputdev.absmax[ABS_WHEEL] = AIPTEK_WHEEL_MAX - 1;
2125         aiptek->inputdev.absfuzz[ABS_X] = 0;
2126         aiptek->inputdev.absfuzz[ABS_Y] = 0;
2127         aiptek->inputdev.absfuzz[ABS_PRESSURE] = 0;
2128         aiptek->inputdev.absfuzz[ABS_TILT_X] = 0;
2129         aiptek->inputdev.absfuzz[ABS_TILT_Y] = 0;
2130         aiptek->inputdev.absfuzz[ABS_WHEEL] = 0;
2131         aiptek->inputdev.absflat[ABS_X] = 0;
2132         aiptek->inputdev.absflat[ABS_Y] = 0;
2133         aiptek->inputdev.absflat[ABS_PRESSURE] = 0;
2134         aiptek->inputdev.absflat[ABS_TILT_X] = 0;
2135         aiptek->inputdev.absflat[ABS_TILT_Y] = 0;
2136         aiptek->inputdev.absflat[ABS_WHEEL] = 0;
2137         aiptek->inputdev.name = "Aiptek";
2138         aiptek->inputdev.phys = aiptek->features.usbPath;
2139         aiptek->inputdev.id.bustype = BUS_USB;
2140         aiptek->inputdev.id.vendor = usbdev->descriptor.idVendor;
2141         aiptek->inputdev.id.product = usbdev->descriptor.idProduct;
2142         aiptek->inputdev.id.version = usbdev->descriptor.bcdDevice;
2143
2144         aiptek->usbdev = usbdev;
2145         aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
2146         aiptek->inDelay = 0;
2147         aiptek->endDelay = 0;
2148         aiptek->previousJitterable = 0;
2149
2150         endpoint = &intf->altsetting[0].endpoint[0].desc;
2151
2152         /* Go set up our URB, which is called when the tablet receives
2153          * input.
2154          */
2155         usb_fill_int_urb(aiptek->urb,
2156                          aiptek->usbdev,
2157                          usb_rcvintpipe(aiptek->usbdev,
2158                                         endpoint->bEndpointAddress),
2159                          aiptek->data, 8, aiptek_irq, aiptek,
2160                          endpoint->bInterval);
2161
2162         aiptek->urb->transfer_dma = aiptek->data_dma;
2163         aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2164
2165         /* Register the tablet as an Input Device
2166          */
2167         input_register_device(&aiptek->inputdev);
2168
2169         /* Go and decode the USB representation of the tablet's manufacturer
2170          * name and product name. They only change once every hotplug event,
2171          * which is why we put it here instead of in the sysfs interface.
2172          */
2173         usb_string(usbdev,
2174                    usbdev->descriptor.iManufacturer,
2175                    aiptek->features.manuName,
2176                    sizeof(aiptek->features.manuName));
2177         usb_string(usbdev,
2178                    usbdev->descriptor.iProduct,
2179                    aiptek->features.prodName,
2180                    sizeof(aiptek->features.prodName));
2181
2182         /* We now will look for the evdev device which is mapped to
2183          * the tablet. The partial name is kept in the link list of
2184          * input_handles associated with this input device.
2185          * What identifies an evdev input_handler is that it begins
2186          * with 'event', continues with a digit, and that in turn
2187          * is mapped to /{devfs}/input/eventN.
2188          */
2189         inputdev = &aiptek->inputdev;
2190         list_for_each_safe(node, next, &inputdev->h_list) {
2191                 inputhandle = to_handle(node);
2192                 if (strncmp(inputhandle->name, "event", 5) == 0) {
2193                         strcpy(aiptek->features.inputPath, inputhandle->name);
2194                         break;
2195                 }
2196         }
2197
2198         info("input: Aiptek on %s (%s)\n", path, aiptek->features.inputPath);
2199
2200         /* Program the tablet. This sets the tablet up in the mode
2201          * specified in newSetting, and also queries the tablet's
2202          * physical capacities.
2203          *
2204          * Sanity check: if a tablet doesn't like the slow programmatic
2205          * delay, we often get sizes of 0x0. Let's use that as an indicator
2206          * to try faster delays, up to 25 ms. If that logic fails, well, you'll
2207          * have to explain to us how your tablet thinks it's 0x0, and yet that's
2208          * not an error :-)
2209          */
2210
2211         for (i = 0; i < sizeof(speeds) / sizeof(speeds[0]); ++i) {
2212                 aiptek->curSetting.programmableDelay = speeds[i];
2213                 (void)aiptek_program_tablet(aiptek);
2214                 if (aiptek->inputdev.absmax[ABS_X] > 0) {
2215                         info("input: Aiptek using %d ms programming speed\n",
2216                              aiptek->curSetting.programmableDelay);
2217                         break;
2218                 }
2219         }
2220
2221         /* Associate this driver's struct with the usb interface.
2222          */
2223         usb_set_intfdata(intf, aiptek);
2224
2225         /* Set up the sysfs files
2226          */
2227         aiptek_add_files(&intf->dev);
2228
2229         /* Make sure the evdev module is loaded. Assuming evdev IS a module :-)
2230          */
2231         if (request_module("evdev") != 0)
2232                 info("aiptek: error loading 'evdev' module");
2233
2234         return 0;
2235 }
2236
2237 /* Forward declaration */
2238 static void aiptek_disconnect(struct usb_interface *intf);
2239
2240 static struct usb_driver aiptek_driver = {
2241         .owner = THIS_MODULE,
2242         .name = "aiptek",
2243         .probe = aiptek_probe,
2244         .disconnect = aiptek_disconnect,
2245         .id_table = aiptek_ids,
2246 };
2247
2248 /***********************************************************************
2249  * Deal with tablet disconnecting from the system.
2250  */
2251 static void aiptek_disconnect(struct usb_interface *intf)
2252 {
2253         struct aiptek *aiptek = usb_get_intfdata(intf);
2254
2255         /* Disassociate driver's struct with usb interface
2256          */
2257         usb_set_intfdata(intf, NULL);
2258         if (aiptek != NULL) {
2259                 /* Free & unhook everything from the system.
2260                  */
2261                 usb_unlink_urb(aiptek->urb);
2262                 input_unregister_device(&aiptek->inputdev);
2263                 aiptek_delete_files(&intf->dev);
2264                 usb_free_urb(aiptek->urb);
2265                 usb_buffer_free(interface_to_usbdev(intf),
2266                                 AIPTEK_PACKET_LENGTH,
2267                                 aiptek->data, aiptek->data_dma);
2268                 kfree(aiptek);
2269                 aiptek = NULL;
2270         }
2271 }
2272
2273 static int __init aiptek_init(void)
2274 {
2275         int result = usb_register(&aiptek_driver);
2276         if (result == 0) {
2277                 info(DRIVER_VERSION ": " DRIVER_AUTHOR);
2278                 info(DRIVER_DESC);
2279         }
2280         return result;
2281 }
2282
2283 static void __exit aiptek_exit(void)
2284 {
2285         usb_deregister(&aiptek_driver);
2286 }
2287
2288 MODULE_AUTHOR(DRIVER_AUTHOR);
2289 MODULE_DESCRIPTION(DRIVER_DESC);
2290 MODULE_LICENSE("GPL");
2291
2292 MODULE_PARM(programmableDelay, "i");
2293 MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
2294 MODULE_PARM(jitterDelay, "i");
2295 MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
2296
2297 module_init(aiptek_init);
2298 module_exit(aiptek_exit);