blob: 0c990e61ed731b1d6803bb17554671cde1971b4d [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 Torokhov05f091ab2005-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 Torokhov05f091ab2005-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 Torokhov05f091ab2005-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 Torokhov05f091ab2005-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
115 * byte0 0 0 0 0 0 0 1 0
116 * 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
137 * byte0 0 0 0 0 0 1 0 0
138 * 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 Torokhov05f091ab2005-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 Torokhov05f091ab2005-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 */
267#define AIPTEK_MOUSE_LEFT_BUTTON 0x01
268#define AIPTEK_MOUSE_RIGHT_BUTTON 0x02
269#define AIPTEK_MOUSE_MIDDLE_BUTTON 0x04
270
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
332/*
333 * Permit easy lookup of keyboard events to send, versus
334 * the bitmap which comes from the tablet. This hides the
335 * issue that the F_keys are not sequentially numbered.
336 */
Arjan van de Ven4c4c9432005-11-29 09:43:42 +0100337static const int macroKeyEvents[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
339 KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
340 KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17,
341 KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23,
342 KEY_F24, KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO,
343 KEY_FRONT, KEY_COPY, KEY_OPEN, KEY_PASTE, 0
344};
345
346/***********************************************************************
Dmitry Torokhovcd438a52007-05-21 00:17:57 -0400347 * Map values to strings and back. Every map shoudl have the following
348 * as its last element: { NULL, AIPTEK_INVALID_VALUE }.
349 */
350#define AIPTEK_INVALID_VALUE -1
351
352struct aiptek_map {
353 const char *string;
354 int value;
355};
356
357static int map_str_to_val(const struct aiptek_map *map, const char *str, size_t count)
358{
359 const struct aiptek_map *p;
360
361 for (p = map; p->string; p++)
362 if (!strncmp(str, p->string, count))
363 return p->value;
364
365 return AIPTEK_INVALID_VALUE;
366}
367
368static const char *map_val_to_str(const struct aiptek_map *map, int val)
369{
370 const struct aiptek_map *p;
371
372 for (p = map; p->value != AIPTEK_INVALID_VALUE; p++)
373 if (val == p->value)
374 return p->string;
375
376 return "unknown";
377}
378
379/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 * Relative reports deliver values in 2's complement format to
381 * deal with negative offsets.
382 */
383static int aiptek_convert_from_2s_complement(unsigned char c)
384{
385 int ret;
386 unsigned char b = c;
387 int negate = 0;
388
389 if ((b & 0x80) != 0) {
390 b = ~b;
391 b--;
392 negate = 1;
393 }
394 ret = b;
395 ret = (negate == 1) ? -ret : ret;
396 return ret;
397}
398
399/***********************************************************************
400 * aiptek_irq can receive one of six potential reports.
401 * The documentation for each is in the body of the function.
402 *
403 * The tablet reports on several attributes per invocation of
404 * aiptek_irq. Because the Linux Input Event system allows the
405 * transmission of ONE attribute per input_report_xxx() call,
406 * collation has to be done on the other end to reconstitute
407 * a complete tablet report. Further, the number of Input Event reports
408 * submitted varies, depending on what USB report type, and circumstance.
409 * To deal with this, EV_MSC is used to indicate an 'end-of-report'
410 * message. This has been an undocumented convention understood by the kernel
411 * tablet driver and clients such as gpm and XFree86's tablet drivers.
412 *
413 * Of the information received from the tablet, the one piece I
414 * cannot transmit is the proximity bit (without resorting to an EV_MSC
415 * convention above.) I therefore have taken over REL_MISC and ABS_MISC
416 * (for relative and absolute reports, respectively) for communicating
417 * Proximity. Why two events? I thought it interesting to know if the
Steven Cole093cf722005-05-03 19:07:24 -0600418 * Proximity event occurred while the tablet was in absolute or relative
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 * mode.
420 *
421 * Other tablets use the notion of a certain minimum stylus pressure
422 * to infer proximity. While that could have been done, that is yet
423 * another 'by convention' behavior, the documentation for which
424 * would be spread between two (or more) pieces of software.
425 *
426 * EV_MSC usage was terminated for this purpose in Linux 2.5.x, and
427 * replaced with the input_sync() method (which emits EV_SYN.)
428 */
429
David Howells7d12e782006-10-05 14:55:46 +0100430static void aiptek_irq(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
432 struct aiptek *aiptek = urb->context;
433 unsigned char *data = aiptek->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500434 struct input_dev *inputdev = aiptek->inputdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 int jitterable = 0;
436 int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
437
438 switch (urb->status) {
439 case 0:
440 /* Success */
441 break;
442
443 case -ECONNRESET:
444 case -ENOENT:
445 case -ESHUTDOWN:
446 /* This urb is terminated, clean up */
447 dbg("%s - urb shutting down with status: %d",
448 __FUNCTION__, urb->status);
449 return;
450
451 default:
452 dbg("%s - nonzero urb status received: %d",
453 __FUNCTION__, urb->status);
454 goto exit;
455 }
456
457 /* See if we are in a delay loop -- throw out report if true.
458 */
459 if (aiptek->inDelay == 1 && time_after(aiptek->endDelay, jiffies)) {
460 goto exit;
461 }
462
463 aiptek->inDelay = 0;
464 aiptek->eventCount++;
465
466 /* Report 1 delivers relative coordinates with either a stylus
467 * or the mouse. You do not know, however, which input
468 * tool generated the event.
469 */
470 if (data[0] == 1) {
471 if (aiptek->curSetting.coordinateMode ==
472 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
473 aiptek->diagnostic =
474 AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
475 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 x = aiptek_convert_from_2s_complement(data[2]);
477 y = aiptek_convert_from_2s_complement(data[3]);
478
479 /* jitterable keeps track of whether any button has been pressed.
480 * We're also using it to remap the physical mouse button mask
481 * to pseudo-settings. (We don't specifically care about it's
482 * value after moving/transposing mouse button bitmasks, except
483 * that a non-zero value indicates that one or more
484 * mouse button was pressed.)
485 */
486 jitterable = data[5] & 0x07;
487
488 left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
489 right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
490 middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
491
492 input_report_key(inputdev, BTN_LEFT, left);
493 input_report_key(inputdev, BTN_MIDDLE, middle);
494 input_report_key(inputdev, BTN_RIGHT, right);
495 input_report_rel(inputdev, REL_X, x);
496 input_report_rel(inputdev, REL_Y, y);
497 input_report_rel(inputdev, REL_MISC, 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
498
499 /* Wheel support is in the form of a single-event
500 * firing.
501 */
502 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
503 input_report_rel(inputdev, REL_WHEEL,
504 aiptek->curSetting.wheel);
505 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
506 }
507 input_sync(inputdev);
508 }
509 }
510 /* Report 2 is delivered only by the stylus, and delivers
511 * absolute coordinates.
512 */
513 else if (data[0] == 2) {
514 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
515 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
516 } else if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE
517 (aiptek->curSetting.pointerMode)) {
518 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
519 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
521 y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
522 z = le16_to_cpu(get_unaligned((__le16 *) (data + 6)));
523
524 p = (data[5] & 0x01) != 0 ? 1 : 0;
525 dv = (data[5] & 0x02) != 0 ? 1 : 0;
526 tip = (data[5] & 0x04) != 0 ? 1 : 0;
527
528 /* Use jitterable to re-arrange button masks
529 */
530 jitterable = data[5] & 0x18;
531
532 bs = (data[5] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
533 pck = (data[5] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
534
535 /* dv indicates 'data valid' (e.g., the tablet is in sync
536 * and has delivered a "correct" report) We will ignore
537 * all 'bad' reports...
538 */
539 if (dv != 0) {
540 /* If we've not already sent a tool_button_?? code, do
541 * so now. Then set FIRED_BIT so it won't be resent unless
542 * the user forces FIRED_BIT off.
543 */
544 if (TOOL_BUTTON_FIRED
545 (aiptek->curSetting.toolMode) == 0) {
546 input_report_key(inputdev,
547 TOOL_BUTTON(aiptek->curSetting.toolMode),
548 1);
549 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
550 }
551
552 if (p != 0) {
553 input_report_abs(inputdev, ABS_X, x);
554 input_report_abs(inputdev, ABS_Y, y);
555 input_report_abs(inputdev, ABS_PRESSURE, z);
556
557 input_report_key(inputdev, BTN_TOUCH, tip);
558 input_report_key(inputdev, BTN_STYLUS, bs);
559 input_report_key(inputdev, BTN_STYLUS2, pck);
560
561 if (aiptek->curSetting.xTilt !=
562 AIPTEK_TILT_DISABLE) {
563 input_report_abs(inputdev,
564 ABS_TILT_X,
565 aiptek->curSetting.xTilt);
566 }
567 if (aiptek->curSetting.yTilt != AIPTEK_TILT_DISABLE) {
568 input_report_abs(inputdev,
569 ABS_TILT_Y,
570 aiptek->curSetting.yTilt);
571 }
572
573 /* Wheel support is in the form of a single-event
574 * firing.
575 */
576 if (aiptek->curSetting.wheel !=
577 AIPTEK_WHEEL_DISABLE) {
578 input_report_abs(inputdev,
579 ABS_WHEEL,
580 aiptek->curSetting.wheel);
581 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
582 }
583 }
584 input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_STYLUS);
585 input_sync(inputdev);
586 }
587 }
588 }
589 /* Report 3's come from the mouse in absolute mode.
590 */
591 else if (data[0] == 3) {
592 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
593 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
594 } else if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE
595 (aiptek->curSetting.pointerMode)) {
596 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
597 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
599 y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
600
601 jitterable = data[5] & 0x1c;
602
603 p = (data[5] & 0x01) != 0 ? 1 : 0;
604 dv = (data[5] & 0x02) != 0 ? 1 : 0;
605 left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
606 right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
607 middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
608
609 if (dv != 0) {
610 /* If we've not already sent a tool_button_?? code, do
611 * so now. Then set FIRED_BIT so it won't be resent unless
612 * the user forces FIRED_BIT off.
613 */
614 if (TOOL_BUTTON_FIRED
615 (aiptek->curSetting.toolMode) == 0) {
616 input_report_key(inputdev,
617 TOOL_BUTTON(aiptek->curSetting.toolMode),
618 1);
619 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
620 }
621
622 if (p != 0) {
623 input_report_abs(inputdev, ABS_X, x);
624 input_report_abs(inputdev, ABS_Y, y);
625
626 input_report_key(inputdev, BTN_LEFT, left);
627 input_report_key(inputdev, BTN_MIDDLE, middle);
628 input_report_key(inputdev, BTN_RIGHT, right);
629
630 /* Wheel support is in the form of a single-event
631 * firing.
632 */
633 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
634 input_report_abs(inputdev,
635 ABS_WHEEL,
636 aiptek->curSetting.wheel);
637 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
638 }
639 }
640 input_report_rel(inputdev, REL_MISC, p | AIPTEK_REPORT_TOOL_MOUSE);
641 input_sync(inputdev);
642 }
643 }
644 }
645 /* Report 4s come from the macro keys when pressed by stylus
646 */
647 else if (data[0] == 4) {
648 jitterable = data[1] & 0x18;
649
650 p = (data[1] & 0x01) != 0 ? 1 : 0;
651 dv = (data[1] & 0x02) != 0 ? 1 : 0;
652 tip = (data[1] & 0x04) != 0 ? 1 : 0;
653 bs = (data[1] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
654 pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
655
656 macro = data[3];
657 z = le16_to_cpu(get_unaligned((__le16 *) (data + 4)));
658
659 if (dv != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 /* If we've not already sent a tool_button_?? code, do
661 * so now. Then set FIRED_BIT so it won't be resent unless
662 * the user forces FIRED_BIT off.
663 */
664 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
665 input_report_key(inputdev,
666 TOOL_BUTTON(aiptek->curSetting.toolMode),
667 1);
668 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
669 }
670
671 if (p != 0) {
672 input_report_key(inputdev, BTN_TOUCH, tip);
673 input_report_key(inputdev, BTN_STYLUS, bs);
674 input_report_key(inputdev, BTN_STYLUS2, pck);
675 input_report_abs(inputdev, ABS_PRESSURE, z);
676 }
677
678 /* For safety, we're sending key 'break' codes for the
679 * neighboring macro keys.
680 */
681 if (macro > 0) {
682 input_report_key(inputdev,
683 macroKeyEvents[macro - 1], 0);
684 }
685 if (macro < 25) {
686 input_report_key(inputdev,
687 macroKeyEvents[macro + 1], 0);
688 }
689 input_report_key(inputdev, macroKeyEvents[macro], p);
690 input_report_abs(inputdev, ABS_MISC,
691 p | AIPTEK_REPORT_TOOL_STYLUS);
692 input_sync(inputdev);
693 }
694 }
695 /* Report 5s come from the macro keys when pressed by mouse
696 */
697 else if (data[0] == 5) {
698 jitterable = data[1] & 0x1c;
699
700 p = (data[1] & 0x01) != 0 ? 1 : 0;
701 dv = (data[1] & 0x02) != 0 ? 1 : 0;
702 left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
703 right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
704 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
705 macro = data[3];
706
707 if (dv != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 /* If we've not already sent a tool_button_?? code, do
709 * so now. Then set FIRED_BIT so it won't be resent unless
710 * the user forces FIRED_BIT off.
711 */
712 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
713 input_report_key(inputdev,
714 TOOL_BUTTON(aiptek->curSetting.toolMode),
715 1);
716 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
717 }
718
719 if (p != 0) {
720 input_report_key(inputdev, BTN_LEFT, left);
721 input_report_key(inputdev, BTN_MIDDLE, middle);
722 input_report_key(inputdev, BTN_RIGHT, right);
723 }
724
725 /* For safety, we're sending key 'break' codes for the
726 * neighboring macro keys.
727 */
728 if (macro > 0) {
729 input_report_key(inputdev,
730 macroKeyEvents[macro - 1], 0);
731 }
732 if (macro < 25) {
733 input_report_key(inputdev,
734 macroKeyEvents[macro + 1], 0);
735 }
736
737 input_report_key(inputdev, macroKeyEvents[macro], 1);
738 input_report_rel(inputdev, ABS_MISC,
739 p | AIPTEK_REPORT_TOOL_MOUSE);
740 input_sync(inputdev);
741 }
742 }
743 /* We have no idea which tool can generate a report 6. Theoretically,
744 * neither need to, having been given reports 4 & 5 for such use.
745 * However, report 6 is the 'official-looking' report for macroKeys;
746 * reports 4 & 5 supposively are used to support unnamed, unknown
747 * hat switches (which just so happen to be the macroKeys.)
748 */
749 else if (data[0] == 6) {
750 macro = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 if (macro > 0) {
752 input_report_key(inputdev, macroKeyEvents[macro - 1],
753 0);
754 }
755 if (macro < 25) {
756 input_report_key(inputdev, macroKeyEvents[macro + 1],
757 0);
758 }
759
760 /* If we've not already sent a tool_button_?? code, do
761 * so now. Then set FIRED_BIT so it won't be resent unless
762 * the user forces FIRED_BIT off.
763 */
764 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
765 input_report_key(inputdev,
766 TOOL_BUTTON(aiptek->curSetting.
767 toolMode), 1);
768 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
769 }
770
771 input_report_key(inputdev, macroKeyEvents[macro], 1);
772 input_report_abs(inputdev, ABS_MISC,
773 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
774 input_sync(inputdev);
775 } else {
776 dbg("Unknown report %d", data[0]);
777 }
778
779 /* Jitter may occur when the user presses a button on the stlyus
780 * or the mouse. What we do to prevent that is wait 'x' milliseconds
781 * following a 'jitterable' event, which should give the hand some time
782 * stabilize itself.
783 *
784 * We just introduced aiptek->previousJitterable to carry forth the
785 * notion that jitter occurs when the button state changes from on to off:
786 * a person drawing, holding a button down is not subject to jittering.
787 * With that in mind, changing from upper button depressed to lower button
788 * WILL transition through a jitter delay.
789 */
790
791 if (aiptek->previousJitterable != jitterable &&
792 aiptek->curSetting.jitterDelay != 0 && aiptek->inDelay != 1) {
793 aiptek->endDelay = jiffies +
794 ((aiptek->curSetting.jitterDelay * HZ) / 1000);
795 aiptek->inDelay = 1;
796 }
797 aiptek->previousJitterable = jitterable;
798
799exit:
800 retval = usb_submit_urb(urb, GFP_ATOMIC);
801 if (retval != 0) {
802 err("%s - usb_submit_urb failed with result %d",
803 __FUNCTION__, retval);
804 }
805}
806
807/***********************************************************************
808 * These are the USB id's known so far. We do not identify them to
809 * specific Aiptek model numbers, because there has been overlaps,
810 * use, and reuse of id's in existing models. Certain models have
811 * been known to use more than one ID, indicative perhaps of
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500812 * manufacturing revisions. In any event, we consider these
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 * IDs to not be model-specific nor unique.
814 */
815static const struct usb_device_id aiptek_ids[] = {
816 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01)},
817 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10)},
818 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20)},
819 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21)},
820 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
821 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
822 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
823 {}
824};
825
826MODULE_DEVICE_TABLE(usb, aiptek_ids);
827
828/***********************************************************************
829 * Open an instance of the tablet driver.
830 */
831static int aiptek_open(struct input_dev *inputdev)
832{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400833 struct aiptek *aiptek = input_get_drvdata(inputdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 aiptek->urb->dev = aiptek->usbdev;
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500836 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 return 0;
840}
841
842/***********************************************************************
843 * Close an instance of the tablet driver.
844 */
845static void aiptek_close(struct input_dev *inputdev)
846{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400847 struct aiptek *aiptek = input_get_drvdata(inputdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500849 usb_kill_urb(aiptek->urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850}
851
852/***********************************************************************
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500853 * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 * where they were known as usb_set_report and usb_get_report.
855 */
856static int
857aiptek_set_report(struct aiptek *aiptek,
858 unsigned char report_type,
859 unsigned char report_id, void *buffer, int size)
860{
861 return usb_control_msg(aiptek->usbdev,
862 usb_sndctrlpipe(aiptek->usbdev, 0),
863 USB_REQ_SET_REPORT,
864 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
865 USB_DIR_OUT, (report_type << 8) + report_id,
866 aiptek->ifnum, buffer, size, 5000);
867}
868
869static int
870aiptek_get_report(struct aiptek *aiptek,
871 unsigned char report_type,
872 unsigned char report_id, void *buffer, int size)
873{
874 return usb_control_msg(aiptek->usbdev,
875 usb_rcvctrlpipe(aiptek->usbdev, 0),
876 USB_REQ_GET_REPORT,
877 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
878 USB_DIR_IN, (report_type << 8) + report_id,
879 aiptek->ifnum, buffer, size, 5000);
880}
881
882/***********************************************************************
883 * Send a command to the tablet.
884 */
885static int
886aiptek_command(struct aiptek *aiptek, unsigned char command, unsigned char data)
887{
888 const int sizeof_buf = 3 * sizeof(u8);
889 int ret;
890 u8 *buf;
891
892 buf = kmalloc(sizeof_buf, GFP_KERNEL);
893 if (!buf)
894 return -ENOMEM;
895
896 buf[0] = 2;
897 buf[1] = command;
898 buf[2] = data;
899
900 if ((ret =
901 aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
902 dbg("aiptek_program: failed, tried to send: 0x%02x 0x%02x",
903 command, data);
904 }
905 kfree(buf);
906 return ret < 0 ? ret : 0;
907}
908
909/***********************************************************************
910 * Retrieve information from the tablet. Querying info is defined as first
911 * sending the {command,data} sequence as a command, followed by a wait
912 * (aka, "programmaticDelay") and then a "read" request.
913 */
914static int
915aiptek_query(struct aiptek *aiptek, unsigned char command, unsigned char data)
916{
917 const int sizeof_buf = 3 * sizeof(u8);
918 int ret;
919 u8 *buf;
920
921 buf = kmalloc(sizeof_buf, GFP_KERNEL);
922 if (!buf)
923 return -ENOMEM;
924
925 buf[0] = 2;
926 buf[1] = command;
927 buf[2] = data;
928
929 if (aiptek_command(aiptek, command, data) != 0) {
930 kfree(buf);
931 return -EIO;
932 }
933 msleep(aiptek->curSetting.programmableDelay);
934
935 if ((ret =
936 aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
937 dbg("aiptek_query failed: returned 0x%02x 0x%02x 0x%02x",
938 buf[0], buf[1], buf[2]);
939 ret = -EIO;
940 } else {
941 ret = le16_to_cpu(get_unaligned((__le16 *) (buf + 1)));
942 }
943 kfree(buf);
944 return ret;
945}
946
947/***********************************************************************
948 * Program the tablet into either absolute or relative mode.
949 * We also get information about the tablet's size.
950 */
951static int aiptek_program_tablet(struct aiptek *aiptek)
952{
953 int ret;
954 /* Execute Resolution500LPI */
955 if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
956 return ret;
957
958 /* Query getModelCode */
959 if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
960 return ret;
961 aiptek->features.modelCode = ret & 0xff;
962
963 /* Query getODMCode */
964 if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
965 return ret;
966 aiptek->features.odmCode = ret;
967
968 /* Query getFirmwareCode */
969 if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
970 return ret;
971 aiptek->features.firmwareCode = ret;
972
973 /* Query getXextension */
974 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
975 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500976 aiptek->inputdev->absmin[ABS_X] = 0;
977 aiptek->inputdev->absmax[ABS_X] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 /* Query getYextension */
980 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
981 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500982 aiptek->inputdev->absmin[ABS_Y] = 0;
983 aiptek->inputdev->absmax[ABS_Y] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 /* Query getPressureLevels */
986 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
987 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500988 aiptek->inputdev->absmin[ABS_PRESSURE] = 0;
989 aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 /* Depending on whether we are in absolute or relative mode, we will
992 * do a switchToTablet(absolute) or switchToMouse(relative) command.
993 */
994 if (aiptek->curSetting.coordinateMode ==
995 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
996 /* Execute switchToTablet */
997 if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
998 return ret;
999 }
1000 } else {
1001 /* Execute switchToMouse */
1002 if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
1003 return ret;
1004 }
1005 }
1006
1007 /* Enable the macro keys */
1008 if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
1009 return ret;
1010#if 0
1011 /* Execute FilterOn */
1012 if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
1013 return ret;
1014#endif
1015
1016 /* Execute AutoGainOn */
1017 if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
1018 return ret;
1019
1020 /* Reset the eventCount, so we track events from last (re)programming
1021 */
1022 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
1023 aiptek->eventCount = 0;
1024
1025 return 0;
1026}
1027
1028/***********************************************************************
1029 * Sysfs functions. Sysfs prefers that individually-tunable parameters
1030 * exist in their separate pseudo-files. Summary data that is immutable
1031 * may exist in a singular file so long as you don't define a writeable
1032 * interface.
1033 */
1034
1035/***********************************************************************
1036 * support the 'size' file -- display support
1037 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001038static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
1040 struct aiptek *aiptek = dev_get_drvdata(dev);
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 return snprintf(buf, PAGE_SIZE, "%dx%d\n",
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001043 aiptek->inputdev->absmax[ABS_X] + 1,
1044 aiptek->inputdev->absmax[ABS_Y] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045}
1046
1047/* These structs define the sysfs files, param #1 is the name of the
1048 * file, param 2 is the file permissions, param 3 & 4 are to the
1049 * output generator and input parser routines. Absence of a routine is
1050 * permitted -- it only means can't either 'cat' the file, or send data
1051 * to it.
1052 */
1053static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
1054
1055/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 * support routines for the 'pointer_mode' file. Note that this file
1057 * both displays current setting and allows reprogramming.
1058 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001059static struct aiptek_map pointer_mode_map[] = {
1060 { "stylus", AIPTEK_POINTER_ONLY_STYLUS_MODE },
1061 { "mouse", AIPTEK_POINTER_ONLY_MOUSE_MODE },
1062 { "either", AIPTEK_POINTER_EITHER_MODE },
1063 { NULL, AIPTEK_INVALID_VALUE }
1064};
1065
Yani Ioannou060b8842005-05-17 06:44:04 -04001066static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
1068 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001070 return snprintf(buf, PAGE_SIZE, "%s\n",
1071 map_val_to_str(pointer_mode_map,
1072 aiptek->curSetting.pointerMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073}
1074
1075static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001076store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077{
1078 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001079 int new_mode = map_str_to_val(pointer_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001081 if (new_mode == AIPTEK_INVALID_VALUE)
1082 return -EINVAL;
1083
1084 aiptek->newSetting.pointerMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return count;
1086}
1087
1088static DEVICE_ATTR(pointer_mode,
1089 S_IRUGO | S_IWUGO,
1090 show_tabletPointerMode, store_tabletPointerMode);
1091
1092/***********************************************************************
1093 * support routines for the 'coordinate_mode' file. Note that this file
1094 * both displays current setting and allows reprogramming.
1095 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001096
1097static struct aiptek_map coordinate_mode_map[] = {
1098 { "absolute", AIPTEK_COORDINATE_ABSOLUTE_MODE },
1099 { "relative", AIPTEK_COORDINATE_RELATIVE_MODE },
1100 { NULL, AIPTEK_INVALID_VALUE }
1101};
1102
Yani Ioannou060b8842005-05-17 06:44:04 -04001103static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
1105 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001107 return snprintf(buf, PAGE_SIZE, "%s\n",
1108 map_val_to_str(coordinate_mode_map,
1109 aiptek->curSetting.coordinateMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
1112static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001113store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
1115 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001116 int new_mode = map_str_to_val(coordinate_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001118 if (new_mode == AIPTEK_INVALID_VALUE)
1119 return -EINVAL;
1120
1121 aiptek->newSetting.coordinateMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 return count;
1123}
1124
1125static DEVICE_ATTR(coordinate_mode,
1126 S_IRUGO | S_IWUGO,
1127 show_tabletCoordinateMode, store_tabletCoordinateMode);
1128
1129/***********************************************************************
1130 * support routines for the 'tool_mode' file. Note that this file
1131 * both displays current setting and allows reprogramming.
1132 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001133
1134static struct aiptek_map tool_mode_map[] = {
1135 { "mouse", AIPTEK_TOOL_BUTTON_MOUSE_MODE },
1136 { "eraser", AIPTEK_TOOL_BUTTON_ERASER_MODE },
1137 { "pencil", AIPTEK_TOOL_BUTTON_PENCIL_MODE },
1138 { "pen", AIPTEK_TOOL_BUTTON_PEN_MODE },
1139 { "brush", AIPTEK_TOOL_BUTTON_BRUSH_MODE },
1140 { "airbrush", AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE },
1141 { "lens", AIPTEK_TOOL_BUTTON_LENS_MODE },
1142 { NULL, AIPTEK_INVALID_VALUE }
1143};
1144
Yani Ioannou060b8842005-05-17 06:44:04 -04001145static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146{
1147 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001149 return snprintf(buf, PAGE_SIZE, "%s\n",
1150 map_val_to_str(tool_mode_map,
1151 aiptek->curSetting.toolMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
1154static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001155store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{
1157 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001158 int new_mode = map_str_to_val(tool_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001160 if (new_mode == AIPTEK_INVALID_VALUE)
1161 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001163 aiptek->newSetting.toolMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 return count;
1165}
1166
1167static DEVICE_ATTR(tool_mode,
1168 S_IRUGO | S_IWUGO,
1169 show_tabletToolMode, store_tabletToolMode);
1170
1171/***********************************************************************
1172 * support routines for the 'xtilt' file. Note that this file
1173 * both displays current setting and allows reprogramming.
1174 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001175static ssize_t show_tabletXtilt(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
1177 struct aiptek *aiptek = dev_get_drvdata(dev);
1178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
1180 return snprintf(buf, PAGE_SIZE, "disable\n");
1181 } else {
1182 return snprintf(buf, PAGE_SIZE, "%d\n",
1183 aiptek->curSetting.xTilt);
1184 }
1185}
1186
1187static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001188store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
1190 struct aiptek *aiptek = dev_get_drvdata(dev);
1191 int x;
1192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 if (strcmp(buf, "disable") == 0) {
1194 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
1195 } else {
1196 x = (int)simple_strtol(buf, NULL, 10);
1197 if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
1198 aiptek->newSetting.xTilt = x;
1199 }
1200 }
1201 return count;
1202}
1203
1204static DEVICE_ATTR(xtilt,
1205 S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt);
1206
1207/***********************************************************************
1208 * support routines for the 'ytilt' file. Note that this file
1209 * both displays current setting and allows reprogramming.
1210 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001211static ssize_t show_tabletYtilt(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
1213 struct aiptek *aiptek = dev_get_drvdata(dev);
1214
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
1216 return snprintf(buf, PAGE_SIZE, "disable\n");
1217 } else {
1218 return snprintf(buf, PAGE_SIZE, "%d\n",
1219 aiptek->curSetting.yTilt);
1220 }
1221}
1222
1223static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001224store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225{
1226 struct aiptek *aiptek = dev_get_drvdata(dev);
1227 int y;
1228
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 if (strcmp(buf, "disable") == 0) {
1230 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
1231 } else {
1232 y = (int)simple_strtol(buf, NULL, 10);
1233 if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
1234 aiptek->newSetting.yTilt = y;
1235 }
1236 }
1237 return count;
1238}
1239
1240static DEVICE_ATTR(ytilt,
1241 S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt);
1242
1243/***********************************************************************
1244 * support routines for the 'jitter' file. Note that this file
1245 * both displays current setting and allows reprogramming.
1246 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001247static ssize_t show_tabletJitterDelay(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248{
1249 struct aiptek *aiptek = dev_get_drvdata(dev);
1250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
1252}
1253
1254static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001255store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
1257 struct aiptek *aiptek = dev_get_drvdata(dev);
1258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10);
1260 return count;
1261}
1262
1263static DEVICE_ATTR(jitter,
1264 S_IRUGO | S_IWUGO,
1265 show_tabletJitterDelay, store_tabletJitterDelay);
1266
1267/***********************************************************************
1268 * support routines for the 'delay' file. Note that this file
1269 * both displays current setting and allows reprogramming.
1270 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001271static ssize_t show_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272{
1273 struct aiptek *aiptek = dev_get_drvdata(dev);
1274
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 return snprintf(buf, PAGE_SIZE, "%d\n",
1276 aiptek->curSetting.programmableDelay);
1277}
1278
1279static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001280store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281{
1282 struct aiptek *aiptek = dev_get_drvdata(dev);
1283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10);
1285 return count;
1286}
1287
1288static DEVICE_ATTR(delay,
1289 S_IRUGO | S_IWUGO,
1290 show_tabletProgrammableDelay, store_tabletProgrammableDelay);
1291
1292/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 * support routines for the 'event_count' file. Note that this file
1294 * only displays current setting.
1295 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001296static ssize_t show_tabletEventsReceived(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
1298 struct aiptek *aiptek = dev_get_drvdata(dev);
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
1301}
1302
1303static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
1304
1305/***********************************************************************
1306 * support routines for the 'diagnostic' file. Note that this file
1307 * only displays current setting.
1308 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001309static ssize_t show_tabletDiagnosticMessage(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
1311 struct aiptek *aiptek = dev_get_drvdata(dev);
1312 char *retMsg;
1313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 switch (aiptek->diagnostic) {
1315 case AIPTEK_DIAGNOSTIC_NA:
1316 retMsg = "no errors\n";
1317 break;
1318
1319 case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
1320 retMsg = "Error: receiving relative reports\n";
1321 break;
1322
1323 case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
1324 retMsg = "Error: receiving absolute reports\n";
1325 break;
1326
1327 case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
1328 if (aiptek->curSetting.pointerMode ==
1329 AIPTEK_POINTER_ONLY_MOUSE_MODE) {
1330 retMsg = "Error: receiving stylus reports\n";
1331 } else {
1332 retMsg = "Error: receiving mouse reports\n";
1333 }
1334 break;
1335
1336 default:
1337 return 0;
1338 }
1339 return snprintf(buf, PAGE_SIZE, retMsg);
1340}
1341
1342static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
1343
1344/***********************************************************************
1345 * support routines for the 'stylus_upper' file. Note that this file
1346 * both displays current setting and allows for setting changing.
1347 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001348
1349static struct aiptek_map stylus_button_map[] = {
1350 { "upper", AIPTEK_STYLUS_UPPER_BUTTON },
1351 { "lower", AIPTEK_STYLUS_LOWER_BUTTON },
1352 { NULL, AIPTEK_INVALID_VALUE }
1353};
1354
Yani Ioannou060b8842005-05-17 06:44:04 -04001355static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
1357 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001359 return snprintf(buf, PAGE_SIZE, "%s\n",
1360 map_val_to_str(stylus_button_map,
1361 aiptek->curSetting.stylusButtonUpper));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
1364static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001365store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
1367 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001368 int new_button = map_str_to_val(stylus_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001370 if (new_button == AIPTEK_INVALID_VALUE)
1371 return -EINVAL;
1372
1373 aiptek->newSetting.stylusButtonUpper = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 return count;
1375}
1376
1377static DEVICE_ATTR(stylus_upper,
1378 S_IRUGO | S_IWUGO,
1379 show_tabletStylusUpper, store_tabletStylusUpper);
1380
1381/***********************************************************************
1382 * support routines for the 'stylus_lower' file. Note that this file
1383 * both displays current setting and allows for setting changing.
1384 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001385
Yani Ioannou060b8842005-05-17 06:44:04 -04001386static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
1388 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001390 return snprintf(buf, PAGE_SIZE, "%s\n",
1391 map_val_to_str(stylus_button_map,
1392 aiptek->curSetting.stylusButtonLower));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393}
1394
1395static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001396store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397{
1398 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001399 int new_button = map_str_to_val(stylus_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001401 if (new_button == AIPTEK_INVALID_VALUE)
1402 return -EINVAL;
1403
1404 aiptek->newSetting.stylusButtonLower = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 return count;
1406}
1407
1408static DEVICE_ATTR(stylus_lower,
1409 S_IRUGO | S_IWUGO,
1410 show_tabletStylusLower, store_tabletStylusLower);
1411
1412/***********************************************************************
1413 * support routines for the 'mouse_left' file. Note that this file
1414 * both displays current setting and allows for setting changing.
1415 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001416
1417static struct aiptek_map mouse_button_map[] = {
1418 { "left", AIPTEK_MOUSE_LEFT_BUTTON },
1419 { "middle", AIPTEK_MOUSE_MIDDLE_BUTTON },
1420 { "right", AIPTEK_MOUSE_RIGHT_BUTTON },
1421 { NULL, AIPTEK_INVALID_VALUE }
1422};
1423
Yani Ioannou060b8842005-05-17 06:44:04 -04001424static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
1426 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001428 return snprintf(buf, PAGE_SIZE, "%s\n",
1429 map_val_to_str(mouse_button_map,
1430 aiptek->curSetting.mouseButtonLeft));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
1433static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001434store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435{
1436 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001437 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001439 if (new_button == AIPTEK_INVALID_VALUE)
1440 return -EINVAL;
1441
1442 aiptek->newSetting.mouseButtonLeft = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 return count;
1444}
1445
1446static DEVICE_ATTR(mouse_left,
1447 S_IRUGO | S_IWUGO,
1448 show_tabletMouseLeft, store_tabletMouseLeft);
1449
1450/***********************************************************************
1451 * support routines for the 'mouse_middle' file. Note that this file
1452 * both displays current setting and allows for setting changing.
1453 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001454static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
1456 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001458 return snprintf(buf, PAGE_SIZE, "%s\n",
1459 map_val_to_str(mouse_button_map,
1460 aiptek->curSetting.mouseButtonMiddle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
1463static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001464store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
1466 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001467 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001469 if (new_button == AIPTEK_INVALID_VALUE)
1470 return -EINVAL;
1471
1472 aiptek->newSetting.mouseButtonMiddle = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 return count;
1474}
1475
1476static DEVICE_ATTR(mouse_middle,
1477 S_IRUGO | S_IWUGO,
1478 show_tabletMouseMiddle, store_tabletMouseMiddle);
1479
1480/***********************************************************************
1481 * support routines for the 'mouse_right' file. Note that this file
1482 * both displays current setting and allows for setting changing.
1483 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001484static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
1486 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001488 return snprintf(buf, PAGE_SIZE, "%s\n",
1489 map_val_to_str(mouse_button_map,
1490 aiptek->curSetting.mouseButtonRight));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491}
1492
1493static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001494store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495{
1496 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001497 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001499 if (new_button == AIPTEK_INVALID_VALUE)
1500 return -EINVAL;
1501
1502 aiptek->newSetting.mouseButtonRight = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 return count;
1504}
1505
1506static DEVICE_ATTR(mouse_right,
1507 S_IRUGO | S_IWUGO,
1508 show_tabletMouseRight, store_tabletMouseRight);
1509
1510/***********************************************************************
1511 * support routines for the 'wheel' file. Note that this file
1512 * both displays current setting and allows for setting changing.
1513 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001514static ssize_t show_tabletWheel(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
1516 struct aiptek *aiptek = dev_get_drvdata(dev);
1517
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
1519 return snprintf(buf, PAGE_SIZE, "disable\n");
1520 } else {
1521 return snprintf(buf, PAGE_SIZE, "%d\n",
1522 aiptek->curSetting.wheel);
1523 }
1524}
1525
1526static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001527store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
1529 struct aiptek *aiptek = dev_get_drvdata(dev);
1530
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10);
1532 return count;
1533}
1534
1535static DEVICE_ATTR(wheel,
1536 S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel);
1537
1538/***********************************************************************
1539 * support routines for the 'execute' file. Note that this file
1540 * both displays current setting and allows for setting changing.
1541 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001542static ssize_t show_tabletExecute(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 /* There is nothing useful to display, so a one-line manual
1545 * is in order...
1546 */
1547 return snprintf(buf, PAGE_SIZE,
1548 "Write anything to this file to program your tablet.\n");
1549}
1550
1551static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001552store_tabletExecute(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553{
1554 struct aiptek *aiptek = dev_get_drvdata(dev);
1555
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 /* We do not care what you write to this file. Merely the action
1557 * of writing to this file triggers a tablet reprogramming.
1558 */
1559 memcpy(&aiptek->curSetting, &aiptek->newSetting,
1560 sizeof(struct aiptek_settings));
1561
1562 if (aiptek_program_tablet(aiptek) < 0)
1563 return -EIO;
1564
1565 return count;
1566}
1567
1568static DEVICE_ATTR(execute,
1569 S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute);
1570
1571/***********************************************************************
1572 * support routines for the 'odm_code' file. Note that this file
1573 * only displays current setting.
1574 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001575static ssize_t show_tabletODMCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576{
1577 struct aiptek *aiptek = dev_get_drvdata(dev);
1578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
1580}
1581
1582static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
1583
1584/***********************************************************************
1585 * support routines for the 'model_code' file. Note that this file
1586 * only displays current setting.
1587 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001588static ssize_t show_tabletModelCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589{
1590 struct aiptek *aiptek = dev_get_drvdata(dev);
1591
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
1593}
1594
1595static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
1596
1597/***********************************************************************
1598 * support routines for the 'firmware_code' file. Note that this file
1599 * only displays current setting.
1600 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001601static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602{
1603 struct aiptek *aiptek = dev_get_drvdata(dev);
1604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 return snprintf(buf, PAGE_SIZE, "%04x\n",
1606 aiptek->features.firmwareCode);
1607}
1608
1609static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
1610
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001611static struct attribute *aiptek_attributes[] = {
1612 &dev_attr_size.attr,
1613 &dev_attr_pointer_mode.attr,
1614 &dev_attr_coordinate_mode.attr,
1615 &dev_attr_tool_mode.attr,
1616 &dev_attr_xtilt.attr,
1617 &dev_attr_ytilt.attr,
1618 &dev_attr_jitter.attr,
1619 &dev_attr_delay.attr,
1620 &dev_attr_event_count.attr,
1621 &dev_attr_diagnostic.attr,
1622 &dev_attr_odm_code.attr,
1623 &dev_attr_model_code.attr,
1624 &dev_attr_firmware_code.attr,
1625 &dev_attr_stylus_lower.attr,
1626 &dev_attr_stylus_upper.attr,
1627 &dev_attr_mouse_left.attr,
1628 &dev_attr_mouse_middle.attr,
1629 &dev_attr_mouse_right.attr,
1630 &dev_attr_wheel.attr,
1631 &dev_attr_execute.attr,
1632 NULL
1633};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001635static struct attribute_group aiptek_attribute_group = {
1636 .attrs = aiptek_attributes,
1637};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
1639/***********************************************************************
1640 * This routine is called when a tablet has been identified. It basically
1641 * sets up the tablet and the driver's internal structures.
1642 */
1643static int
1644aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1645{
1646 struct usb_device *usbdev = interface_to_usbdev(intf);
1647 struct usb_endpoint_descriptor *endpoint;
1648 struct aiptek *aiptek;
1649 struct input_dev *inputdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 int i;
1651 int speeds[] = { 0,
1652 AIPTEK_PROGRAMMABLE_DELAY_50,
1653 AIPTEK_PROGRAMMABLE_DELAY_400,
1654 AIPTEK_PROGRAMMABLE_DELAY_25,
1655 AIPTEK_PROGRAMMABLE_DELAY_100,
1656 AIPTEK_PROGRAMMABLE_DELAY_200,
1657 AIPTEK_PROGRAMMABLE_DELAY_300
1658 };
Dmitry Torokhov50141862007-04-12 01:33:39 -04001659 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661 /* programmableDelay is where the command-line specified
1662 * delay is kept. We make it the first element of speeds[],
1663 * so therefore, your override speed is tried first, then the
1664 * remainder. Note that the default value of 400ms will be tried
1665 * if you do not specify any command line parameter.
1666 */
1667 speeds[0] = programmableDelay;
1668
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001669 aiptek = kzalloc(sizeof(struct aiptek), GFP_KERNEL);
1670 inputdev = input_allocate_device();
1671 if (!aiptek || !inputdev)
1672 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674 aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
Christoph Lameter54e6ecb2006-12-06 20:33:16 -08001675 GFP_ATOMIC, &aiptek->data_dma);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001676 if (!aiptek->data)
1677 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001680 if (!aiptek->urb)
1681 goto fail2;
1682
1683 aiptek->inputdev = inputdev;
1684 aiptek->usbdev = usbdev;
1685 aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
1686 aiptek->inDelay = 0;
1687 aiptek->endDelay = 0;
1688 aiptek->previousJitterable = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
1690 /* Set up the curSettings struct. Said struct contains the current
1691 * programmable parameters. The newSetting struct contains changes
1692 * the user makes to the settings via the sysfs interface. Those
1693 * changes are not "committed" to curSettings until the user
1694 * writes to the sysfs/.../execute file.
1695 */
1696 aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
1697 aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
1698 aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
1699 aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
1700 aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
1701 aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
1702 aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
1703 aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
1704 aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
1705 aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
1706 aiptek->curSetting.jitterDelay = jitterDelay;
1707 aiptek->curSetting.programmableDelay = programmableDelay;
1708
1709 /* Both structs should have equivalent settings
1710 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001711 aiptek->newSetting = aiptek->curSetting;
1712
1713 /* Determine the usb devices' physical path.
1714 * Asketh not why we always pretend we're using "../input0",
1715 * but I suspect this will have to be refactored one
1716 * day if a single USB device can be a keyboard & a mouse
1717 * & a tablet, and the inputX number actually will tell
1718 * us something...
1719 */
1720 usb_make_path(usbdev, aiptek->features.usbPath,
1721 sizeof(aiptek->features.usbPath));
1722 strlcat(aiptek->features.usbPath, "/input0",
1723 sizeof(aiptek->features.usbPath));
1724
1725 /* Set up client data, pointers to open and close routines
1726 * for the input device.
1727 */
1728 inputdev->name = "Aiptek";
1729 inputdev->phys = aiptek->features.usbPath;
1730 usb_to_input_id(usbdev, &inputdev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -04001731 inputdev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001732
1733 input_set_drvdata(inputdev, aiptek);
1734
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001735 inputdev->open = aiptek_open;
1736 inputdev->close = aiptek_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 /* Now program the capacities of the tablet, in terms of being
1739 * an input device.
1740 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001741 inputdev->evbit[0] |= BIT(EV_KEY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 | BIT(EV_ABS)
1743 | BIT(EV_REL)
1744 | BIT(EV_MSC);
1745
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001746 inputdev->absbit[0] |= BIT(ABS_MISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001748 inputdev->relbit[0] |=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC));
1750
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001751 inputdev->keybit[LONG(BTN_LEFT)] |=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 (BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE));
1753
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001754 inputdev->keybit[LONG(BTN_DIGI)] |=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 (BIT(BTN_TOOL_PEN) |
1756 BIT(BTN_TOOL_RUBBER) |
1757 BIT(BTN_TOOL_PENCIL) |
1758 BIT(BTN_TOOL_AIRBRUSH) |
1759 BIT(BTN_TOOL_BRUSH) |
1760 BIT(BTN_TOOL_MOUSE) |
1761 BIT(BTN_TOOL_LENS) |
1762 BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2));
1763
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001764 inputdev->mscbit[0] = BIT(MSC_SERIAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
1766 /* Programming the tablet macro keys needs to be done with a for loop
1767 * as the keycodes are discontiguous.
1768 */
Tobias Klauser52950ed2005-12-11 16:20:08 +01001769 for (i = 0; i < ARRAY_SIZE(macroKeyEvents); ++i)
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001770 set_bit(macroKeyEvents[i], inputdev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001772 /*
1773 * Program the input device coordinate capacities. We do not yet
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 * know what maximum X, Y, and Z values are, so we're putting fake
1775 * values in. Later, we'll ask the tablet to put in the correct
1776 * values.
1777 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001778 input_set_abs_params(inputdev, ABS_X, 0, 2999, 0, 0);
Riccardo Magliocchettif873e3e2005-12-28 20:44:48 -05001779 input_set_abs_params(inputdev, ABS_Y, 0, 2249, 0, 0);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001780 input_set_abs_params(inputdev, ABS_PRESSURE, 0, 511, 0, 0);
1781 input_set_abs_params(inputdev, ABS_TILT_X, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
1782 input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
1783 input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
1785 endpoint = &intf->altsetting[0].endpoint[0].desc;
1786
1787 /* Go set up our URB, which is called when the tablet receives
1788 * input.
1789 */
1790 usb_fill_int_urb(aiptek->urb,
1791 aiptek->usbdev,
1792 usb_rcvintpipe(aiptek->usbdev,
1793 endpoint->bEndpointAddress),
1794 aiptek->data, 8, aiptek_irq, aiptek,
1795 endpoint->bInterval);
1796
1797 aiptek->urb->transfer_dma = aiptek->data_dma;
1798 aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1799
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 /* Program the tablet. This sets the tablet up in the mode
1801 * specified in newSetting, and also queries the tablet's
1802 * physical capacities.
1803 *
1804 * Sanity check: if a tablet doesn't like the slow programmatic
1805 * delay, we often get sizes of 0x0. Let's use that as an indicator
1806 * to try faster delays, up to 25 ms. If that logic fails, well, you'll
1807 * have to explain to us how your tablet thinks it's 0x0, and yet that's
1808 * not an error :-)
1809 */
1810
Tobias Klauser52950ed2005-12-11 16:20:08 +01001811 for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 aiptek->curSetting.programmableDelay = speeds[i];
1813 (void)aiptek_program_tablet(aiptek);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001814 if (aiptek->inputdev->absmax[ABS_X] > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 info("input: Aiptek using %d ms programming speed\n",
1816 aiptek->curSetting.programmableDelay);
1817 break;
1818 }
1819 }
1820
1821 /* Associate this driver's struct with the usb interface.
1822 */
1823 usb_set_intfdata(intf, aiptek);
1824
1825 /* Set up the sysfs files
1826 */
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001827 err = sysfs_create_group(&intf->dev.kobj, &aiptek_attribute_group);
1828 if (err)
1829 goto fail3;
1830
1831 /* Register the tablet as an Input Device
1832 */
1833 err = input_register_device(aiptek->inputdev);
1834 if (err)
1835 goto fail4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 return 0;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001838
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001839 fail4: sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
1840 fail3: usb_free_urb(aiptek->urb);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001841 fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001842 aiptek->data_dma);
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001843 fail1: usb_set_intfdata(intf, NULL);
1844 input_free_device(inputdev);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001845 kfree(aiptek);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001846 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847}
1848
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849/***********************************************************************
1850 * Deal with tablet disconnecting from the system.
1851 */
1852static void aiptek_disconnect(struct usb_interface *intf)
1853{
1854 struct aiptek *aiptek = usb_get_intfdata(intf);
1855
1856 /* Disassociate driver's struct with usb interface
1857 */
1858 usb_set_intfdata(intf, NULL);
1859 if (aiptek != NULL) {
1860 /* Free & unhook everything from the system.
1861 */
1862 usb_kill_urb(aiptek->urb);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001863 input_unregister_device(aiptek->inputdev);
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001864 sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 usb_free_urb(aiptek->urb);
1866 usb_buffer_free(interface_to_usbdev(intf),
1867 AIPTEK_PACKET_LENGTH,
1868 aiptek->data, aiptek->data_dma);
1869 kfree(aiptek);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 }
1871}
1872
Dmitry Torokhov50141862007-04-12 01:33:39 -04001873static struct usb_driver aiptek_driver = {
1874 .name = "aiptek",
1875 .probe = aiptek_probe,
1876 .disconnect = aiptek_disconnect,
1877 .id_table = aiptek_ids,
1878};
1879
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880static int __init aiptek_init(void)
1881{
1882 int result = usb_register(&aiptek_driver);
1883 if (result == 0) {
1884 info(DRIVER_VERSION ": " DRIVER_AUTHOR);
1885 info(DRIVER_DESC);
1886 }
1887 return result;
1888}
1889
1890static void __exit aiptek_exit(void)
1891{
1892 usb_deregister(&aiptek_driver);
1893}
1894
1895MODULE_AUTHOR(DRIVER_AUTHOR);
1896MODULE_DESCRIPTION(DRIVER_DESC);
1897MODULE_LICENSE("GPL");
1898
1899module_param(programmableDelay, int, 0);
1900MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
1901module_param(jitterDelay, int, 0);
1902MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
1903
1904module_init(aiptek_init);
1905module_exit(aiptek_exit);