blob: c18287724a1ee4788b9061e7d8d9bb8bfa262ca9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Native support for the Aiptek HyperPen USB Tablets
3 * (4000U/5000U/6000U/8000U/12000U)
Dmitry Torokhov05f091a2005-05-29 02:29:01 -05004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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.
Dmitry Torokhov05f091a2005-05-29 02:29:01 -050034 * v1.2 - Reworked jitter timer as a kernel thread.
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 * 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
Dmitry Torokhov05f091a2005-05-29 02:29:01 -050052 * "Tablet Manager".
53 * These three products are highly interactive with one another,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * so therefore it's easier to document them all as one subsystem.
Dmitry Torokhov05f091a2005-05-29 02:29:01 -050055 * Please visit the project's "home page", located at,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include <linux/module.h>
77#include <linux/init.h>
David Brownellae0dadc2006-06-13 10:04:34 -070078#include <linux/usb/input.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <asm/uaccess.h>
80#include <asm/unaligned.h>
81
82/*
83 * Version Information
84 */
85#define DRIVER_VERSION "v1.5 (May-15-2004)"
86#define DRIVER_AUTHOR "Bryan W. Headley/Chris Atenasio"
87#define DRIVER_DESC "Aiptek HyperPen USB Tablet Driver (Linux 2.6.x)"
88
89/*
90 * Aiptek status packet:
91 *
92 * (returned as Report 1 - relative coordinates from mouse and stylus)
93 *
94 * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
95 * byte0 0 0 0 0 0 0 0 1
96 * byte1 0 0 0 0 0 BS2 BS Tip
97 * byte2 X7 X6 X5 X4 X3 X2 X1 X0
98 * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
99 *
100 * (returned as Report 2 - absolute coordinates from the stylus)
101 *
102 * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
103 * byte0 0 0 0 0 0 0 1 0
104 * byte1 X7 X6 X5 X4 X3 X2 X1 X0
105 * byte2 X15 X14 X13 X12 X11 X10 X9 X8
106 * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
107 * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
108 * byte5 * * * BS2 BS1 Tip IR DV
109 * byte6 P7 P6 P5 P4 P3 P2 P1 P0
110 * byte7 P15 P14 P13 P12 P11 P10 P9 P8
111 *
112 * (returned as Report 3 - absolute coordinates from the mouse)
113 *
114 * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
Rene van Paassen2fe57412007-05-21 00:18:24 -0400115 * byte0 0 0 0 0 0 0 1 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * byte1 X7 X6 X5 X4 X3 X2 X1 X0
117 * byte2 X15 X14 X13 X12 X11 X10 X9 X8
118 * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
119 * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
120 * byte5 * * * BS2 BS1 Tip IR DV
121 * byte6 P7 P6 P5 P4 P3 P2 P1 P0
122 * byte7 P15 P14 P13 P12 P11 P10 P9 P8
123 *
124 * (returned as Report 4 - macrokeys from the stylus)
125 *
126 * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
127 * byte0 0 0 0 0 0 1 0 0
128 * byte1 0 0 0 BS2 BS Tip IR DV
129 * byte2 0 0 0 0 0 0 1 0
130 * byte3 0 0 0 K4 K3 K2 K1 K0
131 * byte4 P7 P6 P5 P4 P3 P2 P1 P0
132 * byte5 P15 P14 P13 P12 P11 P10 P9 P8
133 *
134 * (returned as Report 5 - macrokeys from the mouse)
135 *
136 * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
Rene van Paassen2fe57412007-05-21 00:18:24 -0400137 * byte0 0 0 0 0 0 1 0 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 * byte1 0 0 0 BS2 BS Tip IR DV
139 * byte2 0 0 0 0 0 0 1 0
140 * byte3 0 0 0 K4 K3 K2 K1 K0
141 * byte4 P7 P6 P5 P4 P3 P2 P1 P0
142 * byte5 P15 P14 P13 P12 P11 P10 P9 P8
143 *
144 * IR: In Range = Proximity on
145 * DV = Data Valid
146 * BS = Barrel Switch (as in, macro keys)
147 * BS2 also referred to as Tablet Pick
148 *
149 * Command Summary:
150 *
151 * Use report_type CONTROL (3)
152 * Use report_id 2
153 *
154 * Command/Data Description Return Bytes Return Value
155 * 0x10/0x00 SwitchToMouse 0
156 * 0x10/0x01 SwitchToTablet 0
Dmitry Torokhov05f091a2005-05-29 02:29:01 -0500157 * 0x18/0x04 SetResolution 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 * 0x12/0xFF AutoGainOn 0
159 * 0x17/0x00 FilterOn 0
160 * 0x01/0x00 GetXExtension 2 MaxX
161 * 0x01/0x01 GetYExtension 2 MaxY
162 * 0x02/0x00 GetModelCode 2 ModelCode = LOBYTE
163 * 0x03/0x00 GetODMCode 2 ODMCode
164 * 0x08/0x00 GetPressureLevels 2 =512
165 * 0x04/0x00 GetFirmwareVersion 2 Firmware Version
166 * 0x11/0x02 EnableMacroKeys 0
167 *
168 * To initialize the tablet:
169 *
170 * (1) Send Resolution500LPI (Command)
171 * (2) Query for Model code (Option Report)
172 * (3) Query for ODM code (Option Report)
173 * (4) Query for firmware (Option Report)
174 * (5) Query for GetXExtension (Option Report)
175 * (6) Query for GetYExtension (Option Report)
176 * (7) Query for GetPressureLevels (Option Report)
177 * (8) SwitchToTablet for Absolute coordinates, or
178 * SwitchToMouse for Relative coordinates (Command)
179 * (9) EnableMacroKeys (Command)
180 * (10) FilterOn (Command)
181 * (11) AutoGainOn (Command)
182 *
183 * (Step 9 can be omitted, but you'll then have no function keys.)
184 */
185
186#define USB_VENDOR_ID_AIPTEK 0x08ca
187#define USB_REQ_GET_REPORT 0x01
188#define USB_REQ_SET_REPORT 0x09
189
190 /* PointerMode codes
191 */
192#define AIPTEK_POINTER_ONLY_MOUSE_MODE 0
193#define AIPTEK_POINTER_ONLY_STYLUS_MODE 1
194#define AIPTEK_POINTER_EITHER_MODE 2
195
196#define AIPTEK_POINTER_ALLOW_MOUSE_MODE(a) \
197 (a == AIPTEK_POINTER_ONLY_MOUSE_MODE || \
198 a == AIPTEK_POINTER_EITHER_MODE)
199#define AIPTEK_POINTER_ALLOW_STYLUS_MODE(a) \
200 (a == AIPTEK_POINTER_ONLY_STYLUS_MODE || \
201 a == AIPTEK_POINTER_EITHER_MODE)
202
203 /* CoordinateMode code
204 */
205#define AIPTEK_COORDINATE_RELATIVE_MODE 0
206#define AIPTEK_COORDINATE_ABSOLUTE_MODE 1
207
208 /* XTilt and YTilt values
209 */
210#define AIPTEK_TILT_MIN (-128)
211#define AIPTEK_TILT_MAX 127
212#define AIPTEK_TILT_DISABLE (-10101)
213
214 /* Wheel values
215 */
216#define AIPTEK_WHEEL_MIN 0
217#define AIPTEK_WHEEL_MAX 1024
218#define AIPTEK_WHEEL_DISABLE (-10101)
219
220 /* ToolCode values, which BTW are 0x140 .. 0x14f
221 * We have things set up such that if TOOL_BUTTON_FIRED_BIT is
222 * not set, we'll send one instance of AIPTEK_TOOL_BUTTON_xxx.
223 *
224 * Whenever the user resets the value, TOOL_BUTTON_FIRED_BIT will
225 * get reset.
226 */
227#define TOOL_BUTTON(x) ((x) & 0x14f)
228#define TOOL_BUTTON_FIRED(x) ((x) & 0x200)
229#define TOOL_BUTTON_FIRED_BIT 0x200
230 /* toolMode codes
231 */
232#define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
233#define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
234#define AIPTEK_TOOL_BUTTON_PENCIL_MODE BTN_TOOL_PENCIL
235#define AIPTEK_TOOL_BUTTON_BRUSH_MODE BTN_TOOL_BRUSH
236#define AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE BTN_TOOL_AIRBRUSH
237#define AIPTEK_TOOL_BUTTON_ERASER_MODE BTN_TOOL_RUBBER
238#define AIPTEK_TOOL_BUTTON_MOUSE_MODE BTN_TOOL_MOUSE
239#define AIPTEK_TOOL_BUTTON_LENS_MODE BTN_TOOL_LENS
240
241 /* Diagnostic message codes
242 */
243#define AIPTEK_DIAGNOSTIC_NA 0
244#define AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE 1
245#define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
246#define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
247
Dmitry Torokhov05f091a2005-05-29 02:29:01 -0500248 /* Time to wait (in ms) to help mask hand jittering
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 * when pressing the stylus buttons.
250 */
251#define AIPTEK_JITTER_DELAY_DEFAULT 50
252
253 /* Time to wait (in ms) in-between sending the tablet
254 * a command and beginning the process of reading the return
255 * sequence from the tablet.
256 */
257#define AIPTEK_PROGRAMMABLE_DELAY_25 25
258#define AIPTEK_PROGRAMMABLE_DELAY_50 50
259#define AIPTEK_PROGRAMMABLE_DELAY_100 100
260#define AIPTEK_PROGRAMMABLE_DELAY_200 200
261#define AIPTEK_PROGRAMMABLE_DELAY_300 300
262#define AIPTEK_PROGRAMMABLE_DELAY_400 400
263#define AIPTEK_PROGRAMMABLE_DELAY_DEFAULT AIPTEK_PROGRAMMABLE_DELAY_400
264
265 /* Mouse button programming
266 */
Rene van Paassence0982e2007-05-21 00:31:45 -0400267#define AIPTEK_MOUSE_LEFT_BUTTON 0x04
268#define AIPTEK_MOUSE_RIGHT_BUTTON 0x08
269#define AIPTEK_MOUSE_MIDDLE_BUTTON 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 /* Stylus button programming
272 */
273#define AIPTEK_STYLUS_LOWER_BUTTON 0x08
274#define AIPTEK_STYLUS_UPPER_BUTTON 0x10
275
276 /* Length of incoming packet from the tablet
277 */
278#define AIPTEK_PACKET_LENGTH 8
279
280 /* We report in EV_MISC both the proximity and
281 * whether the report came from the stylus, tablet mouse
282 * or "unknown" -- Unknown when the tablet is in relative
283 * mode, because we only get report 1's.
284 */
285#define AIPTEK_REPORT_TOOL_UNKNOWN 0x10
286#define AIPTEK_REPORT_TOOL_STYLUS 0x20
287#define AIPTEK_REPORT_TOOL_MOUSE 0x40
288
289static int programmableDelay = AIPTEK_PROGRAMMABLE_DELAY_DEFAULT;
290static int jitterDelay = AIPTEK_JITTER_DELAY_DEFAULT;
291
292struct aiptek_features {
293 int odmCode; /* Tablet manufacturer code */
294 int modelCode; /* Tablet model code (not unique) */
295 int firmwareCode; /* prom/eeprom version */
296 char usbPath[64 + 1]; /* device's physical usb path */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297};
298
299struct aiptek_settings {
300 int pointerMode; /* stylus-, mouse-only or either */
301 int coordinateMode; /* absolute/relative coords */
302 int toolMode; /* pen, pencil, brush, etc. tool */
303 int xTilt; /* synthetic xTilt amount */
304 int yTilt; /* synthetic yTilt amount */
305 int wheel; /* synthetic wheel amount */
306 int stylusButtonUpper; /* stylus upper btn delivers... */
307 int stylusButtonLower; /* stylus lower btn delivers... */
308 int mouseButtonLeft; /* mouse left btn delivers... */
309 int mouseButtonMiddle; /* mouse middle btn delivers... */
310 int mouseButtonRight; /* mouse right btn delivers... */
311 int programmableDelay; /* delay for tablet programming */
312 int jitterDelay; /* delay for hand jittering */
313};
314
315struct aiptek {
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500316 struct input_dev *inputdev; /* input device struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 struct usb_device *usbdev; /* usb device struct */
318 struct urb *urb; /* urb for incoming reports */
319 dma_addr_t data_dma; /* our dma stuffage */
320 struct aiptek_features features; /* tablet's array of features */
321 struct aiptek_settings curSetting; /* tablet's current programmable */
322 struct aiptek_settings newSetting; /* ... and new param settings */
323 unsigned int ifnum; /* interface number for IO */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 int diagnostic; /* tablet diagnostic codes */
325 unsigned long eventCount; /* event count */
326 int inDelay; /* jitter: in jitter delay? */
327 unsigned long endDelay; /* jitter: time when delay ends */
328 int previousJitterable; /* jitterable prev value */
329 unsigned char *data; /* incoming packet data */
330};
331
Dmitry Torokhov33936fa2007-05-21 00:18:15 -0400332static const int buttonEvents[] = {
333 BTN_LEFT, BTN_RIGHT, BTN_MIDDLE,
334 BTN_TOOL_PEN, BTN_TOOL_RUBBER, BTN_TOOL_PENCIL, BTN_TOOL_AIRBRUSH,
335 BTN_TOOL_BRUSH, BTN_TOOL_MOUSE, BTN_TOOL_LENS, BTN_TOUCH,
336 BTN_STYLUS, BTN_STYLUS2,
337};
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/*
340 * Permit easy lookup of keyboard events to send, versus
341 * the bitmap which comes from the tablet. This hides the
342 * issue that the F_keys are not sequentially numbered.
343 */
Arjan van de Ven4c4c9432005-11-29 09:43:42 +0100344static const int macroKeyEvents[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
346 KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
347 KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17,
348 KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23,
349 KEY_F24, KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO,
350 KEY_FRONT, KEY_COPY, KEY_OPEN, KEY_PASTE, 0
351};
352
353/***********************************************************************
Dmitry Torokhovcd438a52007-05-21 00:17:57 -0400354 * Map values to strings and back. Every map shoudl have the following
355 * as its last element: { NULL, AIPTEK_INVALID_VALUE }.
356 */
357#define AIPTEK_INVALID_VALUE -1
358
359struct aiptek_map {
360 const char *string;
361 int value;
362};
363
364static int map_str_to_val(const struct aiptek_map *map, const char *str, size_t count)
365{
366 const struct aiptek_map *p;
367
368 for (p = map; p->string; p++)
369 if (!strncmp(str, p->string, count))
370 return p->value;
371
372 return AIPTEK_INVALID_VALUE;
373}
374
375static const char *map_val_to_str(const struct aiptek_map *map, int val)
376{
377 const struct aiptek_map *p;
378
379 for (p = map; p->value != AIPTEK_INVALID_VALUE; p++)
380 if (val == p->value)
381 return p->string;
382
383 return "unknown";
384}
385
386/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 * aiptek_irq can receive one of six potential reports.
388 * The documentation for each is in the body of the function.
389 *
390 * The tablet reports on several attributes per invocation of
391 * aiptek_irq. Because the Linux Input Event system allows the
392 * transmission of ONE attribute per input_report_xxx() call,
393 * collation has to be done on the other end to reconstitute
394 * a complete tablet report. Further, the number of Input Event reports
395 * submitted varies, depending on what USB report type, and circumstance.
396 * To deal with this, EV_MSC is used to indicate an 'end-of-report'
397 * message. This has been an undocumented convention understood by the kernel
398 * tablet driver and clients such as gpm and XFree86's tablet drivers.
399 *
400 * Of the information received from the tablet, the one piece I
401 * cannot transmit is the proximity bit (without resorting to an EV_MSC
402 * convention above.) I therefore have taken over REL_MISC and ABS_MISC
403 * (for relative and absolute reports, respectively) for communicating
404 * Proximity. Why two events? I thought it interesting to know if the
Steven Cole093cf722005-05-03 19:07:24 -0600405 * Proximity event occurred while the tablet was in absolute or relative
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 * mode.
407 *
408 * Other tablets use the notion of a certain minimum stylus pressure
409 * to infer proximity. While that could have been done, that is yet
410 * another 'by convention' behavior, the documentation for which
411 * would be spread between two (or more) pieces of software.
412 *
413 * EV_MSC usage was terminated for this purpose in Linux 2.5.x, and
414 * replaced with the input_sync() method (which emits EV_SYN.)
415 */
416
David Howells7d12e782006-10-05 14:55:46 +0100417static void aiptek_irq(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
419 struct aiptek *aiptek = urb->context;
420 unsigned char *data = aiptek->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500421 struct input_dev *inputdev = aiptek->inputdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 int jitterable = 0;
423 int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
424
425 switch (urb->status) {
426 case 0:
427 /* Success */
428 break;
429
430 case -ECONNRESET:
431 case -ENOENT:
432 case -ESHUTDOWN:
433 /* This urb is terminated, clean up */
434 dbg("%s - urb shutting down with status: %d",
435 __FUNCTION__, urb->status);
436 return;
437
438 default:
439 dbg("%s - nonzero urb status received: %d",
440 __FUNCTION__, urb->status);
441 goto exit;
442 }
443
444 /* See if we are in a delay loop -- throw out report if true.
445 */
446 if (aiptek->inDelay == 1 && time_after(aiptek->endDelay, jiffies)) {
447 goto exit;
448 }
449
450 aiptek->inDelay = 0;
451 aiptek->eventCount++;
452
453 /* Report 1 delivers relative coordinates with either a stylus
454 * or the mouse. You do not know, however, which input
455 * tool generated the event.
456 */
457 if (data[0] == 1) {
458 if (aiptek->curSetting.coordinateMode ==
459 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
460 aiptek->diagnostic =
461 AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
462 } else {
Dmitry Torokhov37767b62007-05-21 00:18:08 -0400463 x = (signed char) data[2];
464 y = (signed char) data[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 /* jitterable keeps track of whether any button has been pressed.
467 * We're also using it to remap the physical mouse button mask
468 * to pseudo-settings. (We don't specifically care about it's
469 * value after moving/transposing mouse button bitmasks, except
470 * that a non-zero value indicates that one or more
471 * mouse button was pressed.)
472 */
Mark Vytlacil0038cae2007-05-21 00:31:50 -0400473 jitterable = data[1] & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Mark Vytlacil0038cae2007-05-21 00:31:50 -0400475 left = (data[1] & aiptek->curSetting.mouseButtonLeft >> 2) != 0 ? 1 : 0;
476 right = (data[1] & aiptek->curSetting.mouseButtonRight >> 2) != 0 ? 1 : 0;
477 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle >> 2) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 input_report_key(inputdev, BTN_LEFT, left);
480 input_report_key(inputdev, BTN_MIDDLE, middle);
481 input_report_key(inputdev, BTN_RIGHT, right);
Mark Vytlacil0038cae2007-05-21 00:31:50 -0400482
483 input_report_abs(inputdev, ABS_MISC,
484 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 input_report_rel(inputdev, REL_X, x);
486 input_report_rel(inputdev, REL_Y, y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 /* Wheel support is in the form of a single-event
489 * firing.
490 */
491 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
492 input_report_rel(inputdev, REL_WHEEL,
493 aiptek->curSetting.wheel);
494 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
495 }
496 input_sync(inputdev);
497 }
498 }
499 /* Report 2 is delivered only by the stylus, and delivers
500 * absolute coordinates.
501 */
502 else if (data[0] == 2) {
503 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
504 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
505 } else if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE
506 (aiptek->curSetting.pointerMode)) {
507 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
508 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
510 y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
511 z = le16_to_cpu(get_unaligned((__le16 *) (data + 6)));
512
Rene van Paassenfe981f22007-05-21 00:31:24 -0400513 dv = (data[5] & 0x01) != 0 ? 1 : 0;
514 p = (data[5] & 0x02) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 tip = (data[5] & 0x04) != 0 ? 1 : 0;
516
517 /* Use jitterable to re-arrange button masks
518 */
519 jitterable = data[5] & 0x18;
520
521 bs = (data[5] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
522 pck = (data[5] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
523
524 /* dv indicates 'data valid' (e.g., the tablet is in sync
525 * and has delivered a "correct" report) We will ignore
526 * all 'bad' reports...
527 */
528 if (dv != 0) {
529 /* If we've not already sent a tool_button_?? code, do
530 * so now. Then set FIRED_BIT so it won't be resent unless
531 * the user forces FIRED_BIT off.
532 */
533 if (TOOL_BUTTON_FIRED
534 (aiptek->curSetting.toolMode) == 0) {
535 input_report_key(inputdev,
536 TOOL_BUTTON(aiptek->curSetting.toolMode),
537 1);
538 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
539 }
540
541 if (p != 0) {
542 input_report_abs(inputdev, ABS_X, x);
543 input_report_abs(inputdev, ABS_Y, y);
544 input_report_abs(inputdev, ABS_PRESSURE, z);
545
546 input_report_key(inputdev, BTN_TOUCH, tip);
547 input_report_key(inputdev, BTN_STYLUS, bs);
548 input_report_key(inputdev, BTN_STYLUS2, pck);
549
550 if (aiptek->curSetting.xTilt !=
551 AIPTEK_TILT_DISABLE) {
552 input_report_abs(inputdev,
553 ABS_TILT_X,
554 aiptek->curSetting.xTilt);
555 }
556 if (aiptek->curSetting.yTilt != AIPTEK_TILT_DISABLE) {
557 input_report_abs(inputdev,
558 ABS_TILT_Y,
559 aiptek->curSetting.yTilt);
560 }
561
562 /* Wheel support is in the form of a single-event
563 * firing.
564 */
565 if (aiptek->curSetting.wheel !=
566 AIPTEK_WHEEL_DISABLE) {
567 input_report_abs(inputdev,
568 ABS_WHEEL,
569 aiptek->curSetting.wheel);
570 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
571 }
572 }
573 input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_STYLUS);
574 input_sync(inputdev);
575 }
576 }
577 }
578 /* Report 3's come from the mouse in absolute mode.
579 */
580 else if (data[0] == 3) {
581 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
582 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
583 } else if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE
584 (aiptek->curSetting.pointerMode)) {
585 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
586 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
588 y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
589
590 jitterable = data[5] & 0x1c;
591
Rene van Paassenfe981f22007-05-21 00:31:24 -0400592 dv = (data[5] & 0x01) != 0 ? 1 : 0;
593 p = (data[5] & 0x02) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
595 right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
596 middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
597
598 if (dv != 0) {
599 /* If we've not already sent a tool_button_?? code, do
600 * so now. Then set FIRED_BIT so it won't be resent unless
601 * the user forces FIRED_BIT off.
602 */
603 if (TOOL_BUTTON_FIRED
604 (aiptek->curSetting.toolMode) == 0) {
605 input_report_key(inputdev,
606 TOOL_BUTTON(aiptek->curSetting.toolMode),
607 1);
608 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
609 }
610
611 if (p != 0) {
612 input_report_abs(inputdev, ABS_X, x);
613 input_report_abs(inputdev, ABS_Y, y);
614
615 input_report_key(inputdev, BTN_LEFT, left);
616 input_report_key(inputdev, BTN_MIDDLE, middle);
617 input_report_key(inputdev, BTN_RIGHT, right);
618
619 /* Wheel support is in the form of a single-event
620 * firing.
621 */
622 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
623 input_report_abs(inputdev,
624 ABS_WHEEL,
625 aiptek->curSetting.wheel);
626 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
627 }
628 }
629 input_report_rel(inputdev, REL_MISC, p | AIPTEK_REPORT_TOOL_MOUSE);
630 input_sync(inputdev);
631 }
632 }
633 }
634 /* Report 4s come from the macro keys when pressed by stylus
635 */
636 else if (data[0] == 4) {
637 jitterable = data[1] & 0x18;
638
Rene van Paassenfe981f22007-05-21 00:31:24 -0400639 dv = (data[1] & 0x01) != 0 ? 1 : 0;
640 p = (data[1] & 0x02) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 tip = (data[1] & 0x04) != 0 ? 1 : 0;
642 bs = (data[1] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
643 pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
644
645 macro = data[3];
646 z = le16_to_cpu(get_unaligned((__le16 *) (data + 4)));
647
648 if (dv != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 /* If we've not already sent a tool_button_?? code, do
650 * so now. Then set FIRED_BIT so it won't be resent unless
651 * the user forces FIRED_BIT off.
652 */
653 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
654 input_report_key(inputdev,
655 TOOL_BUTTON(aiptek->curSetting.toolMode),
656 1);
657 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
658 }
659
660 if (p != 0) {
661 input_report_key(inputdev, BTN_TOUCH, tip);
662 input_report_key(inputdev, BTN_STYLUS, bs);
663 input_report_key(inputdev, BTN_STYLUS2, pck);
664 input_report_abs(inputdev, ABS_PRESSURE, z);
665 }
666
667 /* For safety, we're sending key 'break' codes for the
668 * neighboring macro keys.
669 */
670 if (macro > 0) {
671 input_report_key(inputdev,
672 macroKeyEvents[macro - 1], 0);
673 }
674 if (macro < 25) {
675 input_report_key(inputdev,
676 macroKeyEvents[macro + 1], 0);
677 }
678 input_report_key(inputdev, macroKeyEvents[macro], p);
679 input_report_abs(inputdev, ABS_MISC,
680 p | AIPTEK_REPORT_TOOL_STYLUS);
681 input_sync(inputdev);
682 }
683 }
684 /* Report 5s come from the macro keys when pressed by mouse
685 */
686 else if (data[0] == 5) {
687 jitterable = data[1] & 0x1c;
688
Rene van Paassenfe981f22007-05-21 00:31:24 -0400689 dv = (data[1] & 0x01) != 0 ? 1 : 0;
690 p = (data[1] & 0x02) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
692 right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
693 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
694 macro = data[3];
695
696 if (dv != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 /* If we've not already sent a tool_button_?? code, do
698 * so now. Then set FIRED_BIT so it won't be resent unless
699 * the user forces FIRED_BIT off.
700 */
701 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
702 input_report_key(inputdev,
703 TOOL_BUTTON(aiptek->curSetting.toolMode),
704 1);
705 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
706 }
707
708 if (p != 0) {
709 input_report_key(inputdev, BTN_LEFT, left);
710 input_report_key(inputdev, BTN_MIDDLE, middle);
711 input_report_key(inputdev, BTN_RIGHT, right);
712 }
713
714 /* For safety, we're sending key 'break' codes for the
715 * neighboring macro keys.
716 */
717 if (macro > 0) {
718 input_report_key(inputdev,
719 macroKeyEvents[macro - 1], 0);
720 }
721 if (macro < 25) {
722 input_report_key(inputdev,
723 macroKeyEvents[macro + 1], 0);
724 }
725
726 input_report_key(inputdev, macroKeyEvents[macro], 1);
727 input_report_rel(inputdev, ABS_MISC,
728 p | AIPTEK_REPORT_TOOL_MOUSE);
729 input_sync(inputdev);
730 }
731 }
732 /* We have no idea which tool can generate a report 6. Theoretically,
733 * neither need to, having been given reports 4 & 5 for such use.
734 * However, report 6 is the 'official-looking' report for macroKeys;
735 * reports 4 & 5 supposively are used to support unnamed, unknown
736 * hat switches (which just so happen to be the macroKeys.)
737 */
738 else if (data[0] == 6) {
739 macro = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 if (macro > 0) {
741 input_report_key(inputdev, macroKeyEvents[macro - 1],
742 0);
743 }
744 if (macro < 25) {
745 input_report_key(inputdev, macroKeyEvents[macro + 1],
746 0);
747 }
748
749 /* If we've not already sent a tool_button_?? code, do
750 * so now. Then set FIRED_BIT so it won't be resent unless
751 * the user forces FIRED_BIT off.
752 */
753 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
754 input_report_key(inputdev,
755 TOOL_BUTTON(aiptek->curSetting.
756 toolMode), 1);
757 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
758 }
759
760 input_report_key(inputdev, macroKeyEvents[macro], 1);
761 input_report_abs(inputdev, ABS_MISC,
762 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
763 input_sync(inputdev);
764 } else {
765 dbg("Unknown report %d", data[0]);
766 }
767
768 /* Jitter may occur when the user presses a button on the stlyus
769 * or the mouse. What we do to prevent that is wait 'x' milliseconds
770 * following a 'jitterable' event, which should give the hand some time
771 * stabilize itself.
772 *
773 * We just introduced aiptek->previousJitterable to carry forth the
774 * notion that jitter occurs when the button state changes from on to off:
775 * a person drawing, holding a button down is not subject to jittering.
776 * With that in mind, changing from upper button depressed to lower button
777 * WILL transition through a jitter delay.
778 */
779
780 if (aiptek->previousJitterable != jitterable &&
781 aiptek->curSetting.jitterDelay != 0 && aiptek->inDelay != 1) {
782 aiptek->endDelay = jiffies +
783 ((aiptek->curSetting.jitterDelay * HZ) / 1000);
784 aiptek->inDelay = 1;
785 }
786 aiptek->previousJitterable = jitterable;
787
788exit:
789 retval = usb_submit_urb(urb, GFP_ATOMIC);
790 if (retval != 0) {
791 err("%s - usb_submit_urb failed with result %d",
792 __FUNCTION__, retval);
793 }
794}
795
796/***********************************************************************
797 * These are the USB id's known so far. We do not identify them to
798 * specific Aiptek model numbers, because there has been overlaps,
799 * use, and reuse of id's in existing models. Certain models have
800 * been known to use more than one ID, indicative perhaps of
Dmitry Torokhov05f091a2005-05-29 02:29:01 -0500801 * manufacturing revisions. In any event, we consider these
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 * IDs to not be model-specific nor unique.
803 */
804static const struct usb_device_id aiptek_ids[] = {
805 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01)},
806 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10)},
807 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20)},
808 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21)},
809 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
810 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
811 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
812 {}
813};
814
815MODULE_DEVICE_TABLE(usb, aiptek_ids);
816
817/***********************************************************************
818 * Open an instance of the tablet driver.
819 */
820static int aiptek_open(struct input_dev *inputdev)
821{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400822 struct aiptek *aiptek = input_get_drvdata(inputdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 aiptek->urb->dev = aiptek->usbdev;
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500825 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828 return 0;
829}
830
831/***********************************************************************
832 * Close an instance of the tablet driver.
833 */
834static void aiptek_close(struct input_dev *inputdev)
835{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400836 struct aiptek *aiptek = input_get_drvdata(inputdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500838 usb_kill_urb(aiptek->urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839}
840
841/***********************************************************************
Dmitry Torokhov05f091a2005-05-29 02:29:01 -0500842 * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 * where they were known as usb_set_report and usb_get_report.
844 */
845static int
846aiptek_set_report(struct aiptek *aiptek,
847 unsigned char report_type,
848 unsigned char report_id, void *buffer, int size)
849{
850 return usb_control_msg(aiptek->usbdev,
851 usb_sndctrlpipe(aiptek->usbdev, 0),
852 USB_REQ_SET_REPORT,
853 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
854 USB_DIR_OUT, (report_type << 8) + report_id,
855 aiptek->ifnum, buffer, size, 5000);
856}
857
858static int
859aiptek_get_report(struct aiptek *aiptek,
860 unsigned char report_type,
861 unsigned char report_id, void *buffer, int size)
862{
863 return usb_control_msg(aiptek->usbdev,
864 usb_rcvctrlpipe(aiptek->usbdev, 0),
865 USB_REQ_GET_REPORT,
866 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
867 USB_DIR_IN, (report_type << 8) + report_id,
868 aiptek->ifnum, buffer, size, 5000);
869}
870
871/***********************************************************************
872 * Send a command to the tablet.
873 */
874static int
875aiptek_command(struct aiptek *aiptek, unsigned char command, unsigned char data)
876{
877 const int sizeof_buf = 3 * sizeof(u8);
878 int ret;
879 u8 *buf;
880
881 buf = kmalloc(sizeof_buf, GFP_KERNEL);
882 if (!buf)
883 return -ENOMEM;
884
885 buf[0] = 2;
886 buf[1] = command;
887 buf[2] = data;
888
889 if ((ret =
890 aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
891 dbg("aiptek_program: failed, tried to send: 0x%02x 0x%02x",
892 command, data);
893 }
894 kfree(buf);
895 return ret < 0 ? ret : 0;
896}
897
898/***********************************************************************
899 * Retrieve information from the tablet. Querying info is defined as first
900 * sending the {command,data} sequence as a command, followed by a wait
901 * (aka, "programmaticDelay") and then a "read" request.
902 */
903static int
904aiptek_query(struct aiptek *aiptek, unsigned char command, unsigned char data)
905{
906 const int sizeof_buf = 3 * sizeof(u8);
907 int ret;
908 u8 *buf;
909
910 buf = kmalloc(sizeof_buf, GFP_KERNEL);
911 if (!buf)
912 return -ENOMEM;
913
914 buf[0] = 2;
915 buf[1] = command;
916 buf[2] = data;
917
918 if (aiptek_command(aiptek, command, data) != 0) {
919 kfree(buf);
920 return -EIO;
921 }
922 msleep(aiptek->curSetting.programmableDelay);
923
924 if ((ret =
925 aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
926 dbg("aiptek_query failed: returned 0x%02x 0x%02x 0x%02x",
927 buf[0], buf[1], buf[2]);
928 ret = -EIO;
929 } else {
930 ret = le16_to_cpu(get_unaligned((__le16 *) (buf + 1)));
931 }
932 kfree(buf);
933 return ret;
934}
935
936/***********************************************************************
937 * Program the tablet into either absolute or relative mode.
938 * We also get information about the tablet's size.
939 */
940static int aiptek_program_tablet(struct aiptek *aiptek)
941{
942 int ret;
943 /* Execute Resolution500LPI */
944 if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
945 return ret;
946
947 /* Query getModelCode */
948 if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
949 return ret;
950 aiptek->features.modelCode = ret & 0xff;
951
952 /* Query getODMCode */
953 if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
954 return ret;
955 aiptek->features.odmCode = ret;
956
957 /* Query getFirmwareCode */
958 if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
959 return ret;
960 aiptek->features.firmwareCode = ret;
961
962 /* Query getXextension */
963 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
964 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500965 aiptek->inputdev->absmin[ABS_X] = 0;
966 aiptek->inputdev->absmax[ABS_X] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 /* Query getYextension */
969 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
970 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500971 aiptek->inputdev->absmin[ABS_Y] = 0;
972 aiptek->inputdev->absmax[ABS_Y] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
974 /* Query getPressureLevels */
975 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
976 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500977 aiptek->inputdev->absmin[ABS_PRESSURE] = 0;
978 aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 /* Depending on whether we are in absolute or relative mode, we will
981 * do a switchToTablet(absolute) or switchToMouse(relative) command.
982 */
983 if (aiptek->curSetting.coordinateMode ==
984 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
985 /* Execute switchToTablet */
986 if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
987 return ret;
988 }
989 } else {
990 /* Execute switchToMouse */
991 if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
992 return ret;
993 }
994 }
995
996 /* Enable the macro keys */
997 if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
998 return ret;
999#if 0
1000 /* Execute FilterOn */
1001 if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
1002 return ret;
1003#endif
1004
1005 /* Execute AutoGainOn */
1006 if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
1007 return ret;
1008
1009 /* Reset the eventCount, so we track events from last (re)programming
1010 */
1011 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
1012 aiptek->eventCount = 0;
1013
1014 return 0;
1015}
1016
1017/***********************************************************************
1018 * Sysfs functions. Sysfs prefers that individually-tunable parameters
1019 * exist in their separate pseudo-files. Summary data that is immutable
1020 * may exist in a singular file so long as you don't define a writeable
1021 * interface.
1022 */
1023
1024/***********************************************************************
1025 * support the 'size' file -- display support
1026 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001027static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
1029 struct aiptek *aiptek = dev_get_drvdata(dev);
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 return snprintf(buf, PAGE_SIZE, "%dx%d\n",
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001032 aiptek->inputdev->absmax[ABS_X] + 1,
1033 aiptek->inputdev->absmax[ABS_Y] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034}
1035
1036/* These structs define the sysfs files, param #1 is the name of the
1037 * file, param 2 is the file permissions, param 3 & 4 are to the
1038 * output generator and input parser routines. Absence of a routine is
1039 * permitted -- it only means can't either 'cat' the file, or send data
1040 * to it.
1041 */
1042static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
1043
1044/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 * support routines for the 'pointer_mode' file. Note that this file
1046 * both displays current setting and allows reprogramming.
1047 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001048static struct aiptek_map pointer_mode_map[] = {
1049 { "stylus", AIPTEK_POINTER_ONLY_STYLUS_MODE },
1050 { "mouse", AIPTEK_POINTER_ONLY_MOUSE_MODE },
1051 { "either", AIPTEK_POINTER_EITHER_MODE },
1052 { NULL, AIPTEK_INVALID_VALUE }
1053};
1054
Yani Ioannou060b8842005-05-17 06:44:04 -04001055static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056{
1057 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001059 return snprintf(buf, PAGE_SIZE, "%s\n",
1060 map_val_to_str(pointer_mode_map,
1061 aiptek->curSetting.pointerMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062}
1063
1064static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001065store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
1067 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001068 int new_mode = map_str_to_val(pointer_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001070 if (new_mode == AIPTEK_INVALID_VALUE)
1071 return -EINVAL;
1072
1073 aiptek->newSetting.pointerMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 return count;
1075}
1076
1077static DEVICE_ATTR(pointer_mode,
1078 S_IRUGO | S_IWUGO,
1079 show_tabletPointerMode, store_tabletPointerMode);
1080
1081/***********************************************************************
1082 * support routines for the 'coordinate_mode' file. Note that this file
1083 * both displays current setting and allows reprogramming.
1084 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001085
1086static struct aiptek_map coordinate_mode_map[] = {
1087 { "absolute", AIPTEK_COORDINATE_ABSOLUTE_MODE },
1088 { "relative", AIPTEK_COORDINATE_RELATIVE_MODE },
1089 { NULL, AIPTEK_INVALID_VALUE }
1090};
1091
Yani Ioannou060b8842005-05-17 06:44:04 -04001092static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
1094 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001096 return snprintf(buf, PAGE_SIZE, "%s\n",
1097 map_val_to_str(coordinate_mode_map,
1098 aiptek->curSetting.coordinateMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
1101static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001102store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
1104 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001105 int new_mode = map_str_to_val(coordinate_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001107 if (new_mode == AIPTEK_INVALID_VALUE)
1108 return -EINVAL;
1109
1110 aiptek->newSetting.coordinateMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 return count;
1112}
1113
1114static DEVICE_ATTR(coordinate_mode,
1115 S_IRUGO | S_IWUGO,
1116 show_tabletCoordinateMode, store_tabletCoordinateMode);
1117
1118/***********************************************************************
1119 * support routines for the 'tool_mode' file. Note that this file
1120 * both displays current setting and allows reprogramming.
1121 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001122
1123static struct aiptek_map tool_mode_map[] = {
1124 { "mouse", AIPTEK_TOOL_BUTTON_MOUSE_MODE },
1125 { "eraser", AIPTEK_TOOL_BUTTON_ERASER_MODE },
1126 { "pencil", AIPTEK_TOOL_BUTTON_PENCIL_MODE },
1127 { "pen", AIPTEK_TOOL_BUTTON_PEN_MODE },
1128 { "brush", AIPTEK_TOOL_BUTTON_BRUSH_MODE },
1129 { "airbrush", AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE },
1130 { "lens", AIPTEK_TOOL_BUTTON_LENS_MODE },
1131 { NULL, AIPTEK_INVALID_VALUE }
1132};
1133
Yani Ioannou060b8842005-05-17 06:44:04 -04001134static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
1136 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001138 return snprintf(buf, PAGE_SIZE, "%s\n",
1139 map_val_to_str(tool_mode_map,
1140 aiptek->curSetting.toolMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
1143static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001144store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
1146 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001147 int new_mode = map_str_to_val(tool_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001149 if (new_mode == AIPTEK_INVALID_VALUE)
1150 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001152 aiptek->newSetting.toolMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 return count;
1154}
1155
1156static DEVICE_ATTR(tool_mode,
1157 S_IRUGO | S_IWUGO,
1158 show_tabletToolMode, store_tabletToolMode);
1159
1160/***********************************************************************
1161 * support routines for the 'xtilt' file. Note that this file
1162 * both displays current setting and allows reprogramming.
1163 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001164static ssize_t show_tabletXtilt(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
1166 struct aiptek *aiptek = dev_get_drvdata(dev);
1167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
1169 return snprintf(buf, PAGE_SIZE, "disable\n");
1170 } else {
1171 return snprintf(buf, PAGE_SIZE, "%d\n",
1172 aiptek->curSetting.xTilt);
1173 }
1174}
1175
1176static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001177store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178{
1179 struct aiptek *aiptek = dev_get_drvdata(dev);
1180 int x;
1181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 if (strcmp(buf, "disable") == 0) {
1183 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
1184 } else {
1185 x = (int)simple_strtol(buf, NULL, 10);
1186 if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
1187 aiptek->newSetting.xTilt = x;
1188 }
1189 }
1190 return count;
1191}
1192
1193static DEVICE_ATTR(xtilt,
1194 S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt);
1195
1196/***********************************************************************
1197 * support routines for the 'ytilt' file. Note that this file
1198 * both displays current setting and allows reprogramming.
1199 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001200static ssize_t show_tabletYtilt(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
1202 struct aiptek *aiptek = dev_get_drvdata(dev);
1203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
1205 return snprintf(buf, PAGE_SIZE, "disable\n");
1206 } else {
1207 return snprintf(buf, PAGE_SIZE, "%d\n",
1208 aiptek->curSetting.yTilt);
1209 }
1210}
1211
1212static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001213store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214{
1215 struct aiptek *aiptek = dev_get_drvdata(dev);
1216 int y;
1217
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 if (strcmp(buf, "disable") == 0) {
1219 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
1220 } else {
1221 y = (int)simple_strtol(buf, NULL, 10);
1222 if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
1223 aiptek->newSetting.yTilt = y;
1224 }
1225 }
1226 return count;
1227}
1228
1229static DEVICE_ATTR(ytilt,
1230 S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt);
1231
1232/***********************************************************************
1233 * support routines for the 'jitter' file. Note that this file
1234 * both displays current setting and allows reprogramming.
1235 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001236static ssize_t show_tabletJitterDelay(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237{
1238 struct aiptek *aiptek = dev_get_drvdata(dev);
1239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
1241}
1242
1243static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001244store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
1246 struct aiptek *aiptek = dev_get_drvdata(dev);
1247
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10);
1249 return count;
1250}
1251
1252static DEVICE_ATTR(jitter,
1253 S_IRUGO | S_IWUGO,
1254 show_tabletJitterDelay, store_tabletJitterDelay);
1255
1256/***********************************************************************
1257 * support routines for the 'delay' file. Note that this file
1258 * both displays current setting and allows reprogramming.
1259 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001260static ssize_t show_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
1262 struct aiptek *aiptek = dev_get_drvdata(dev);
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 return snprintf(buf, PAGE_SIZE, "%d\n",
1265 aiptek->curSetting.programmableDelay);
1266}
1267
1268static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001269store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
1271 struct aiptek *aiptek = dev_get_drvdata(dev);
1272
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10);
1274 return count;
1275}
1276
1277static DEVICE_ATTR(delay,
1278 S_IRUGO | S_IWUGO,
1279 show_tabletProgrammableDelay, store_tabletProgrammableDelay);
1280
1281/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 * support routines for the 'event_count' file. Note that this file
1283 * only displays current setting.
1284 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001285static ssize_t show_tabletEventsReceived(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
1287 struct aiptek *aiptek = dev_get_drvdata(dev);
1288
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
1290}
1291
1292static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
1293
1294/***********************************************************************
1295 * support routines for the 'diagnostic' file. Note that this file
1296 * only displays current setting.
1297 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001298static ssize_t show_tabletDiagnosticMessage(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
1300 struct aiptek *aiptek = dev_get_drvdata(dev);
1301 char *retMsg;
1302
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 switch (aiptek->diagnostic) {
1304 case AIPTEK_DIAGNOSTIC_NA:
1305 retMsg = "no errors\n";
1306 break;
1307
1308 case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
1309 retMsg = "Error: receiving relative reports\n";
1310 break;
1311
1312 case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
1313 retMsg = "Error: receiving absolute reports\n";
1314 break;
1315
1316 case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
1317 if (aiptek->curSetting.pointerMode ==
1318 AIPTEK_POINTER_ONLY_MOUSE_MODE) {
1319 retMsg = "Error: receiving stylus reports\n";
1320 } else {
1321 retMsg = "Error: receiving mouse reports\n";
1322 }
1323 break;
1324
1325 default:
1326 return 0;
1327 }
1328 return snprintf(buf, PAGE_SIZE, retMsg);
1329}
1330
1331static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
1332
1333/***********************************************************************
1334 * support routines for the 'stylus_upper' file. Note that this file
1335 * both displays current setting and allows for setting changing.
1336 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001337
1338static struct aiptek_map stylus_button_map[] = {
1339 { "upper", AIPTEK_STYLUS_UPPER_BUTTON },
1340 { "lower", AIPTEK_STYLUS_LOWER_BUTTON },
1341 { NULL, AIPTEK_INVALID_VALUE }
1342};
1343
Yani Ioannou060b8842005-05-17 06:44:04 -04001344static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345{
1346 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001348 return snprintf(buf, PAGE_SIZE, "%s\n",
1349 map_val_to_str(stylus_button_map,
1350 aiptek->curSetting.stylusButtonUpper));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351}
1352
1353static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001354store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
1356 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001357 int new_button = map_str_to_val(stylus_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001359 if (new_button == AIPTEK_INVALID_VALUE)
1360 return -EINVAL;
1361
1362 aiptek->newSetting.stylusButtonUpper = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 return count;
1364}
1365
1366static DEVICE_ATTR(stylus_upper,
1367 S_IRUGO | S_IWUGO,
1368 show_tabletStylusUpper, store_tabletStylusUpper);
1369
1370/***********************************************************************
1371 * support routines for the 'stylus_lower' file. Note that this file
1372 * both displays current setting and allows for setting changing.
1373 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001374
Yani Ioannou060b8842005-05-17 06:44:04 -04001375static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
1377 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001379 return snprintf(buf, PAGE_SIZE, "%s\n",
1380 map_val_to_str(stylus_button_map,
1381 aiptek->curSetting.stylusButtonLower));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
1384static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001385store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
1387 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001388 int new_button = map_str_to_val(stylus_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001390 if (new_button == AIPTEK_INVALID_VALUE)
1391 return -EINVAL;
1392
1393 aiptek->newSetting.stylusButtonLower = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 return count;
1395}
1396
1397static DEVICE_ATTR(stylus_lower,
1398 S_IRUGO | S_IWUGO,
1399 show_tabletStylusLower, store_tabletStylusLower);
1400
1401/***********************************************************************
1402 * support routines for the 'mouse_left' file. Note that this file
1403 * both displays current setting and allows for setting changing.
1404 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001405
1406static struct aiptek_map mouse_button_map[] = {
1407 { "left", AIPTEK_MOUSE_LEFT_BUTTON },
1408 { "middle", AIPTEK_MOUSE_MIDDLE_BUTTON },
1409 { "right", AIPTEK_MOUSE_RIGHT_BUTTON },
1410 { NULL, AIPTEK_INVALID_VALUE }
1411};
1412
Yani Ioannou060b8842005-05-17 06:44:04 -04001413static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414{
1415 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001417 return snprintf(buf, PAGE_SIZE, "%s\n",
1418 map_val_to_str(mouse_button_map,
1419 aiptek->curSetting.mouseButtonLeft));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
1422static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001423store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
1425 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001426 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001428 if (new_button == AIPTEK_INVALID_VALUE)
1429 return -EINVAL;
1430
1431 aiptek->newSetting.mouseButtonLeft = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 return count;
1433}
1434
1435static DEVICE_ATTR(mouse_left,
1436 S_IRUGO | S_IWUGO,
1437 show_tabletMouseLeft, store_tabletMouseLeft);
1438
1439/***********************************************************************
1440 * support routines for the 'mouse_middle' file. Note that this file
1441 * both displays current setting and allows for setting changing.
1442 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001443static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
1445 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001447 return snprintf(buf, PAGE_SIZE, "%s\n",
1448 map_val_to_str(mouse_button_map,
1449 aiptek->curSetting.mouseButtonMiddle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450}
1451
1452static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001453store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
1455 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001456 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001458 if (new_button == AIPTEK_INVALID_VALUE)
1459 return -EINVAL;
1460
1461 aiptek->newSetting.mouseButtonMiddle = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 return count;
1463}
1464
1465static DEVICE_ATTR(mouse_middle,
1466 S_IRUGO | S_IWUGO,
1467 show_tabletMouseMiddle, store_tabletMouseMiddle);
1468
1469/***********************************************************************
1470 * support routines for the 'mouse_right' file. Note that this file
1471 * both displays current setting and allows for setting changing.
1472 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001473static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001477 return snprintf(buf, PAGE_SIZE, "%s\n",
1478 map_val_to_str(mouse_button_map,
1479 aiptek->curSetting.mouseButtonRight));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
1481
1482static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001483store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
1485 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001486 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001488 if (new_button == AIPTEK_INVALID_VALUE)
1489 return -EINVAL;
1490
1491 aiptek->newSetting.mouseButtonRight = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 return count;
1493}
1494
1495static DEVICE_ATTR(mouse_right,
1496 S_IRUGO | S_IWUGO,
1497 show_tabletMouseRight, store_tabletMouseRight);
1498
1499/***********************************************************************
1500 * support routines for the 'wheel' file. Note that this file
1501 * both displays current setting and allows for setting changing.
1502 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001503static ssize_t show_tabletWheel(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
1505 struct aiptek *aiptek = dev_get_drvdata(dev);
1506
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
1508 return snprintf(buf, PAGE_SIZE, "disable\n");
1509 } else {
1510 return snprintf(buf, PAGE_SIZE, "%d\n",
1511 aiptek->curSetting.wheel);
1512 }
1513}
1514
1515static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001516store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517{
1518 struct aiptek *aiptek = dev_get_drvdata(dev);
1519
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10);
1521 return count;
1522}
1523
1524static DEVICE_ATTR(wheel,
1525 S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel);
1526
1527/***********************************************************************
1528 * support routines for the 'execute' file. Note that this file
1529 * both displays current setting and allows for setting changing.
1530 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001531static ssize_t show_tabletExecute(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 /* There is nothing useful to display, so a one-line manual
1534 * is in order...
1535 */
1536 return snprintf(buf, PAGE_SIZE,
1537 "Write anything to this file to program your tablet.\n");
1538}
1539
1540static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001541store_tabletExecute(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542{
1543 struct aiptek *aiptek = dev_get_drvdata(dev);
1544
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 /* We do not care what you write to this file. Merely the action
1546 * of writing to this file triggers a tablet reprogramming.
1547 */
1548 memcpy(&aiptek->curSetting, &aiptek->newSetting,
1549 sizeof(struct aiptek_settings));
1550
1551 if (aiptek_program_tablet(aiptek) < 0)
1552 return -EIO;
1553
1554 return count;
1555}
1556
1557static DEVICE_ATTR(execute,
1558 S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute);
1559
1560/***********************************************************************
1561 * support routines for the 'odm_code' file. Note that this file
1562 * only displays current setting.
1563 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001564static ssize_t show_tabletODMCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
1566 struct aiptek *aiptek = dev_get_drvdata(dev);
1567
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
1569}
1570
1571static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
1572
1573/***********************************************************************
1574 * support routines for the 'model_code' file. Note that this file
1575 * only displays current setting.
1576 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001577static ssize_t show_tabletModelCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578{
1579 struct aiptek *aiptek = dev_get_drvdata(dev);
1580
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
1582}
1583
1584static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
1585
1586/***********************************************************************
1587 * support routines for the 'firmware_code' file. Note that this file
1588 * only displays current setting.
1589 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001590static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591{
1592 struct aiptek *aiptek = dev_get_drvdata(dev);
1593
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 return snprintf(buf, PAGE_SIZE, "%04x\n",
1595 aiptek->features.firmwareCode);
1596}
1597
1598static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
1599
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001600static struct attribute *aiptek_attributes[] = {
1601 &dev_attr_size.attr,
1602 &dev_attr_pointer_mode.attr,
1603 &dev_attr_coordinate_mode.attr,
1604 &dev_attr_tool_mode.attr,
1605 &dev_attr_xtilt.attr,
1606 &dev_attr_ytilt.attr,
1607 &dev_attr_jitter.attr,
1608 &dev_attr_delay.attr,
1609 &dev_attr_event_count.attr,
1610 &dev_attr_diagnostic.attr,
1611 &dev_attr_odm_code.attr,
1612 &dev_attr_model_code.attr,
1613 &dev_attr_firmware_code.attr,
1614 &dev_attr_stylus_lower.attr,
1615 &dev_attr_stylus_upper.attr,
1616 &dev_attr_mouse_left.attr,
1617 &dev_attr_mouse_middle.attr,
1618 &dev_attr_mouse_right.attr,
1619 &dev_attr_wheel.attr,
1620 &dev_attr_execute.attr,
1621 NULL
1622};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001624static struct attribute_group aiptek_attribute_group = {
1625 .attrs = aiptek_attributes,
1626};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628/***********************************************************************
1629 * This routine is called when a tablet has been identified. It basically
1630 * sets up the tablet and the driver's internal structures.
1631 */
1632static int
1633aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1634{
1635 struct usb_device *usbdev = interface_to_usbdev(intf);
1636 struct usb_endpoint_descriptor *endpoint;
1637 struct aiptek *aiptek;
1638 struct input_dev *inputdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 int i;
1640 int speeds[] = { 0,
1641 AIPTEK_PROGRAMMABLE_DELAY_50,
1642 AIPTEK_PROGRAMMABLE_DELAY_400,
1643 AIPTEK_PROGRAMMABLE_DELAY_25,
1644 AIPTEK_PROGRAMMABLE_DELAY_100,
1645 AIPTEK_PROGRAMMABLE_DELAY_200,
1646 AIPTEK_PROGRAMMABLE_DELAY_300
1647 };
Dmitry Torokhov50141862007-04-12 01:33:39 -04001648 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 /* programmableDelay is where the command-line specified
1651 * delay is kept. We make it the first element of speeds[],
1652 * so therefore, your override speed is tried first, then the
1653 * remainder. Note that the default value of 400ms will be tried
1654 * if you do not specify any command line parameter.
1655 */
1656 speeds[0] = programmableDelay;
1657
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001658 aiptek = kzalloc(sizeof(struct aiptek), GFP_KERNEL);
1659 inputdev = input_allocate_device();
1660 if (!aiptek || !inputdev)
1661 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663 aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
Christoph Lameter54e6ecb2006-12-06 20:33:16 -08001664 GFP_ATOMIC, &aiptek->data_dma);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001665 if (!aiptek->data)
1666 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668 aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001669 if (!aiptek->urb)
1670 goto fail2;
1671
1672 aiptek->inputdev = inputdev;
1673 aiptek->usbdev = usbdev;
1674 aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
1675 aiptek->inDelay = 0;
1676 aiptek->endDelay = 0;
1677 aiptek->previousJitterable = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 /* Set up the curSettings struct. Said struct contains the current
1680 * programmable parameters. The newSetting struct contains changes
1681 * the user makes to the settings via the sysfs interface. Those
1682 * changes are not "committed" to curSettings until the user
1683 * writes to the sysfs/.../execute file.
1684 */
1685 aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
1686 aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
1687 aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
1688 aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
1689 aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
1690 aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
1691 aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
1692 aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
1693 aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
1694 aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
1695 aiptek->curSetting.jitterDelay = jitterDelay;
1696 aiptek->curSetting.programmableDelay = programmableDelay;
1697
1698 /* Both structs should have equivalent settings
1699 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001700 aiptek->newSetting = aiptek->curSetting;
1701
1702 /* Determine the usb devices' physical path.
1703 * Asketh not why we always pretend we're using "../input0",
1704 * but I suspect this will have to be refactored one
1705 * day if a single USB device can be a keyboard & a mouse
1706 * & a tablet, and the inputX number actually will tell
1707 * us something...
1708 */
1709 usb_make_path(usbdev, aiptek->features.usbPath,
1710 sizeof(aiptek->features.usbPath));
1711 strlcat(aiptek->features.usbPath, "/input0",
1712 sizeof(aiptek->features.usbPath));
1713
1714 /* Set up client data, pointers to open and close routines
1715 * for the input device.
1716 */
1717 inputdev->name = "Aiptek";
1718 inputdev->phys = aiptek->features.usbPath;
1719 usb_to_input_id(usbdev, &inputdev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -04001720 inputdev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001721
1722 input_set_drvdata(inputdev, aiptek);
1723
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001724 inputdev->open = aiptek_open;
1725 inputdev->close = aiptek_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
1727 /* Now program the capacities of the tablet, in terms of being
1728 * an input device.
1729 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001730 inputdev->evbit[0] |= BIT(EV_KEY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 | BIT(EV_ABS)
1732 | BIT(EV_REL)
1733 | BIT(EV_MSC);
1734
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001735 inputdev->absbit[0] |= BIT(ABS_MISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001737 inputdev->relbit[0] |=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC));
1739
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001740 inputdev->mscbit[0] = BIT(MSC_SERIAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Dmitry Torokhov33936fa2007-05-21 00:18:15 -04001742 /* Set up key and button codes */
1743 for (i = 0; i < ARRAY_SIZE(buttonEvents); ++i)
1744 __set_bit(buttonEvents[i], inputdev->keybit);
1745
Tobias Klauser52950ed2005-12-11 16:20:08 +01001746 for (i = 0; i < ARRAY_SIZE(macroKeyEvents); ++i)
Dmitry Torokhov33936fa2007-05-21 00:18:15 -04001747 __set_bit(macroKeyEvents[i], inputdev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001749 /*
1750 * Program the input device coordinate capacities. We do not yet
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 * know what maximum X, Y, and Z values are, so we're putting fake
1752 * values in. Later, we'll ask the tablet to put in the correct
1753 * values.
1754 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001755 input_set_abs_params(inputdev, ABS_X, 0, 2999, 0, 0);
Riccardo Magliocchettif873e3e2005-12-28 20:44:48 -05001756 input_set_abs_params(inputdev, ABS_Y, 0, 2249, 0, 0);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001757 input_set_abs_params(inputdev, ABS_PRESSURE, 0, 511, 0, 0);
1758 input_set_abs_params(inputdev, ABS_TILT_X, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
1759 input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
1760 input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
1762 endpoint = &intf->altsetting[0].endpoint[0].desc;
1763
1764 /* Go set up our URB, which is called when the tablet receives
1765 * input.
1766 */
1767 usb_fill_int_urb(aiptek->urb,
1768 aiptek->usbdev,
1769 usb_rcvintpipe(aiptek->usbdev,
1770 endpoint->bEndpointAddress),
1771 aiptek->data, 8, aiptek_irq, aiptek,
1772 endpoint->bInterval);
1773
1774 aiptek->urb->transfer_dma = aiptek->data_dma;
1775 aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1776
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 /* Program the tablet. This sets the tablet up in the mode
1778 * specified in newSetting, and also queries the tablet's
1779 * physical capacities.
1780 *
1781 * Sanity check: if a tablet doesn't like the slow programmatic
1782 * delay, we often get sizes of 0x0. Let's use that as an indicator
1783 * to try faster delays, up to 25 ms. If that logic fails, well, you'll
1784 * have to explain to us how your tablet thinks it's 0x0, and yet that's
1785 * not an error :-)
1786 */
1787
Tobias Klauser52950ed2005-12-11 16:20:08 +01001788 for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 aiptek->curSetting.programmableDelay = speeds[i];
1790 (void)aiptek_program_tablet(aiptek);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001791 if (aiptek->inputdev->absmax[ABS_X] > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 info("input: Aiptek using %d ms programming speed\n",
1793 aiptek->curSetting.programmableDelay);
1794 break;
1795 }
1796 }
1797
1798 /* Associate this driver's struct with the usb interface.
1799 */
1800 usb_set_intfdata(intf, aiptek);
1801
1802 /* Set up the sysfs files
1803 */
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001804 err = sysfs_create_group(&intf->dev.kobj, &aiptek_attribute_group);
1805 if (err)
1806 goto fail3;
1807
1808 /* Register the tablet as an Input Device
1809 */
1810 err = input_register_device(aiptek->inputdev);
1811 if (err)
1812 goto fail4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 return 0;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001815
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001816 fail4: sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
1817 fail3: usb_free_urb(aiptek->urb);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001818 fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001819 aiptek->data_dma);
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001820 fail1: usb_set_intfdata(intf, NULL);
1821 input_free_device(inputdev);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001822 kfree(aiptek);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001823 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824}
1825
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826/***********************************************************************
1827 * Deal with tablet disconnecting from the system.
1828 */
1829static void aiptek_disconnect(struct usb_interface *intf)
1830{
1831 struct aiptek *aiptek = usb_get_intfdata(intf);
1832
1833 /* Disassociate driver's struct with usb interface
1834 */
1835 usb_set_intfdata(intf, NULL);
1836 if (aiptek != NULL) {
1837 /* Free & unhook everything from the system.
1838 */
1839 usb_kill_urb(aiptek->urb);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001840 input_unregister_device(aiptek->inputdev);
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001841 sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 usb_free_urb(aiptek->urb);
1843 usb_buffer_free(interface_to_usbdev(intf),
1844 AIPTEK_PACKET_LENGTH,
1845 aiptek->data, aiptek->data_dma);
1846 kfree(aiptek);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 }
1848}
1849
Dmitry Torokhov50141862007-04-12 01:33:39 -04001850static struct usb_driver aiptek_driver = {
1851 .name = "aiptek",
1852 .probe = aiptek_probe,
1853 .disconnect = aiptek_disconnect,
1854 .id_table = aiptek_ids,
1855};
1856
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857static int __init aiptek_init(void)
1858{
1859 int result = usb_register(&aiptek_driver);
1860 if (result == 0) {
1861 info(DRIVER_VERSION ": " DRIVER_AUTHOR);
1862 info(DRIVER_DESC);
1863 }
1864 return result;
1865}
1866
1867static void __exit aiptek_exit(void)
1868{
1869 usb_deregister(&aiptek_driver);
1870}
1871
1872MODULE_AUTHOR(DRIVER_AUTHOR);
1873MODULE_DESCRIPTION(DRIVER_DESC);
1874MODULE_LICENSE("GPL");
1875
1876module_param(programmableDelay, int, 0);
1877MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
1878module_param(jitterDelay, int, 0);
1879MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
1880
1881module_init(aiptek_init);
1882module_exit(aiptek_exit);