blob: 54c8d6f498330759810b1ce25d4603974b319c59 [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
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400221 * We have things set up such that if the tool button has changed,
222 * the tools get reset.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 /* toolMode codes
225 */
226#define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
227#define AIPTEK_TOOL_BUTTON_PEN_MODE BTN_TOOL_PEN
228#define AIPTEK_TOOL_BUTTON_PENCIL_MODE BTN_TOOL_PENCIL
229#define AIPTEK_TOOL_BUTTON_BRUSH_MODE BTN_TOOL_BRUSH
230#define AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE BTN_TOOL_AIRBRUSH
231#define AIPTEK_TOOL_BUTTON_ERASER_MODE BTN_TOOL_RUBBER
232#define AIPTEK_TOOL_BUTTON_MOUSE_MODE BTN_TOOL_MOUSE
233#define AIPTEK_TOOL_BUTTON_LENS_MODE BTN_TOOL_LENS
234
235 /* Diagnostic message codes
236 */
237#define AIPTEK_DIAGNOSTIC_NA 0
238#define AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE 1
239#define AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE 2
240#define AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED 3
241
Dmitry Torokhov05f091a2005-05-29 02:29:01 -0500242 /* Time to wait (in ms) to help mask hand jittering
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 * when pressing the stylus buttons.
244 */
245#define AIPTEK_JITTER_DELAY_DEFAULT 50
246
247 /* Time to wait (in ms) in-between sending the tablet
248 * a command and beginning the process of reading the return
249 * sequence from the tablet.
250 */
251#define AIPTEK_PROGRAMMABLE_DELAY_25 25
252#define AIPTEK_PROGRAMMABLE_DELAY_50 50
253#define AIPTEK_PROGRAMMABLE_DELAY_100 100
254#define AIPTEK_PROGRAMMABLE_DELAY_200 200
255#define AIPTEK_PROGRAMMABLE_DELAY_300 300
256#define AIPTEK_PROGRAMMABLE_DELAY_400 400
257#define AIPTEK_PROGRAMMABLE_DELAY_DEFAULT AIPTEK_PROGRAMMABLE_DELAY_400
258
259 /* Mouse button programming
260 */
Rene van Paassence0982e2007-05-21 00:31:45 -0400261#define AIPTEK_MOUSE_LEFT_BUTTON 0x04
262#define AIPTEK_MOUSE_RIGHT_BUTTON 0x08
263#define AIPTEK_MOUSE_MIDDLE_BUTTON 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 /* Stylus button programming
266 */
267#define AIPTEK_STYLUS_LOWER_BUTTON 0x08
268#define AIPTEK_STYLUS_UPPER_BUTTON 0x10
269
270 /* Length of incoming packet from the tablet
271 */
272#define AIPTEK_PACKET_LENGTH 8
273
274 /* We report in EV_MISC both the proximity and
275 * whether the report came from the stylus, tablet mouse
276 * or "unknown" -- Unknown when the tablet is in relative
277 * mode, because we only get report 1's.
278 */
279#define AIPTEK_REPORT_TOOL_UNKNOWN 0x10
280#define AIPTEK_REPORT_TOOL_STYLUS 0x20
281#define AIPTEK_REPORT_TOOL_MOUSE 0x40
282
283static int programmableDelay = AIPTEK_PROGRAMMABLE_DELAY_DEFAULT;
284static int jitterDelay = AIPTEK_JITTER_DELAY_DEFAULT;
285
286struct aiptek_features {
287 int odmCode; /* Tablet manufacturer code */
288 int modelCode; /* Tablet model code (not unique) */
289 int firmwareCode; /* prom/eeprom version */
290 char usbPath[64 + 1]; /* device's physical usb path */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291};
292
293struct aiptek_settings {
294 int pointerMode; /* stylus-, mouse-only or either */
295 int coordinateMode; /* absolute/relative coords */
296 int toolMode; /* pen, pencil, brush, etc. tool */
297 int xTilt; /* synthetic xTilt amount */
298 int yTilt; /* synthetic yTilt amount */
299 int wheel; /* synthetic wheel amount */
300 int stylusButtonUpper; /* stylus upper btn delivers... */
301 int stylusButtonLower; /* stylus lower btn delivers... */
302 int mouseButtonLeft; /* mouse left btn delivers... */
303 int mouseButtonMiddle; /* mouse middle btn delivers... */
304 int mouseButtonRight; /* mouse right btn delivers... */
305 int programmableDelay; /* delay for tablet programming */
306 int jitterDelay; /* delay for hand jittering */
307};
308
309struct aiptek {
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500310 struct input_dev *inputdev; /* input device struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 struct usb_device *usbdev; /* usb device struct */
312 struct urb *urb; /* urb for incoming reports */
313 dma_addr_t data_dma; /* our dma stuffage */
314 struct aiptek_features features; /* tablet's array of features */
315 struct aiptek_settings curSetting; /* tablet's current programmable */
316 struct aiptek_settings newSetting; /* ... and new param settings */
317 unsigned int ifnum; /* interface number for IO */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 int diagnostic; /* tablet diagnostic codes */
319 unsigned long eventCount; /* event count */
320 int inDelay; /* jitter: in jitter delay? */
321 unsigned long endDelay; /* jitter: time when delay ends */
322 int previousJitterable; /* jitterable prev value */
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400323
324 int lastMacro; /* macro key to reset */
325 int previousToolMode; /* pen, pencil, brush, etc. tool */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 unsigned char *data; /* incoming packet data */
327};
328
Rene van Paassen1a54f492007-05-21 00:31:55 -0400329static const int eventTypes[] = {
330 EV_KEY, EV_ABS, EV_REL, EV_MSC,
331};
332
333static const int absEvents[] = {
334 ABS_X, ABS_Y, ABS_PRESSURE, ABS_TILT_X, ABS_TILT_Y,
335 ABS_WHEEL, ABS_MISC,
336};
337
338static const int relEvents[] = {
339 REL_X, REL_Y, REL_WHEEL,
340};
341
Dmitry Torokhov33936fa2007-05-21 00:18:15 -0400342static const int buttonEvents[] = {
343 BTN_LEFT, BTN_RIGHT, BTN_MIDDLE,
344 BTN_TOOL_PEN, BTN_TOOL_RUBBER, BTN_TOOL_PENCIL, BTN_TOOL_AIRBRUSH,
345 BTN_TOOL_BRUSH, BTN_TOOL_MOUSE, BTN_TOOL_LENS, BTN_TOUCH,
346 BTN_STYLUS, BTN_STYLUS2,
347};
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349/*
350 * Permit easy lookup of keyboard events to send, versus
351 * the bitmap which comes from the tablet. This hides the
352 * issue that the F_keys are not sequentially numbered.
353 */
Arjan van de Ven4c4c9432005-11-29 09:43:42 +0100354static const int macroKeyEvents[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
356 KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
357 KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17,
358 KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23,
359 KEY_F24, KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO,
360 KEY_FRONT, KEY_COPY, KEY_OPEN, KEY_PASTE, 0
361};
362
363/***********************************************************************
Dmitry Torokhovcd438a52007-05-21 00:17:57 -0400364 * Map values to strings and back. Every map shoudl have the following
365 * as its last element: { NULL, AIPTEK_INVALID_VALUE }.
366 */
367#define AIPTEK_INVALID_VALUE -1
368
369struct aiptek_map {
370 const char *string;
371 int value;
372};
373
374static int map_str_to_val(const struct aiptek_map *map, const char *str, size_t count)
375{
376 const struct aiptek_map *p;
377
Rene van Paassen0112db32007-05-21 00:32:12 -0400378 if (str[count - 1] == '\n')
379 count--;
380
Dmitry Torokhovcd438a52007-05-21 00:17:57 -0400381 for (p = map; p->string; p++)
Rene van Paassen0112db32007-05-21 00:32:12 -0400382 if (!strncmp(str, p->string, count))
Dmitry Torokhovcd438a52007-05-21 00:17:57 -0400383 return p->value;
384
385 return AIPTEK_INVALID_VALUE;
386}
387
388static const char *map_val_to_str(const struct aiptek_map *map, int val)
389{
390 const struct aiptek_map *p;
391
392 for (p = map; p->value != AIPTEK_INVALID_VALUE; p++)
393 if (val == p->value)
394 return p->string;
395
396 return "unknown";
397}
398
399/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 * 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.
Rene van Paassenda9fda42007-05-21 00:32:03 -0400420 * Update: REL_MISC proved not to be such a good idea. With REL_MISC you
421 * get an event transmitted each time. ABS_MISC works better, since it
422 * can be set and re-set. Thus, only using ABS_MISC from now on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 *
424 * Other tablets use the notion of a certain minimum stylus pressure
425 * to infer proximity. While that could have been done, that is yet
426 * another 'by convention' behavior, the documentation for which
427 * would be spread between two (or more) pieces of software.
428 *
429 * EV_MSC usage was terminated for this purpose in Linux 2.5.x, and
430 * replaced with the input_sync() method (which emits EV_SYN.)
431 */
432
David Howells7d12e782006-10-05 14:55:46 +0100433static void aiptek_irq(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
435 struct aiptek *aiptek = urb->context;
436 unsigned char *data = aiptek->data;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500437 struct input_dev *inputdev = aiptek->inputdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 int jitterable = 0;
439 int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
440
441 switch (urb->status) {
442 case 0:
443 /* Success */
444 break;
445
446 case -ECONNRESET:
447 case -ENOENT:
448 case -ESHUTDOWN:
449 /* This urb is terminated, clean up */
450 dbg("%s - urb shutting down with status: %d",
451 __FUNCTION__, urb->status);
452 return;
453
454 default:
455 dbg("%s - nonzero urb status received: %d",
456 __FUNCTION__, urb->status);
457 goto exit;
458 }
459
460 /* See if we are in a delay loop -- throw out report if true.
461 */
462 if (aiptek->inDelay == 1 && time_after(aiptek->endDelay, jiffies)) {
463 goto exit;
464 }
465
466 aiptek->inDelay = 0;
467 aiptek->eventCount++;
468
469 /* Report 1 delivers relative coordinates with either a stylus
470 * or the mouse. You do not know, however, which input
471 * tool generated the event.
472 */
473 if (data[0] == 1) {
474 if (aiptek->curSetting.coordinateMode ==
475 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
476 aiptek->diagnostic =
477 AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
478 } else {
Dmitry Torokhov37767b62007-05-21 00:18:08 -0400479 x = (signed char) data[2];
480 y = (signed char) data[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 /* jitterable keeps track of whether any button has been pressed.
483 * We're also using it to remap the physical mouse button mask
484 * to pseudo-settings. (We don't specifically care about it's
485 * value after moving/transposing mouse button bitmasks, except
486 * that a non-zero value indicates that one or more
487 * mouse button was pressed.)
488 */
Mark Vytlacil0038cae2007-05-21 00:31:50 -0400489 jitterable = data[1] & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Mark Vytlacil0038cae2007-05-21 00:31:50 -0400491 left = (data[1] & aiptek->curSetting.mouseButtonLeft >> 2) != 0 ? 1 : 0;
492 right = (data[1] & aiptek->curSetting.mouseButtonRight >> 2) != 0 ? 1 : 0;
493 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle >> 2) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 input_report_key(inputdev, BTN_LEFT, left);
496 input_report_key(inputdev, BTN_MIDDLE, middle);
497 input_report_key(inputdev, BTN_RIGHT, right);
Mark Vytlacil0038cae2007-05-21 00:31:50 -0400498
499 input_report_abs(inputdev, ABS_MISC,
500 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 input_report_rel(inputdev, REL_X, x);
502 input_report_rel(inputdev, REL_Y, y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 /* Wheel support is in the form of a single-event
505 * firing.
506 */
507 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
508 input_report_rel(inputdev, REL_WHEEL,
509 aiptek->curSetting.wheel);
510 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
511 }
512 input_sync(inputdev);
513 }
514 }
515 /* Report 2 is delivered only by the stylus, and delivers
516 * absolute coordinates.
517 */
518 else if (data[0] == 2) {
519 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
520 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
521 } else if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE
522 (aiptek->curSetting.pointerMode)) {
523 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
524 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
526 y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
527 z = le16_to_cpu(get_unaligned((__le16 *) (data + 6)));
528
Rene van Paassenfe981f22007-05-21 00:31:24 -0400529 dv = (data[5] & 0x01) != 0 ? 1 : 0;
530 p = (data[5] & 0x02) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 tip = (data[5] & 0x04) != 0 ? 1 : 0;
532
533 /* Use jitterable to re-arrange button masks
534 */
535 jitterable = data[5] & 0x18;
536
537 bs = (data[5] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
538 pck = (data[5] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
539
540 /* dv indicates 'data valid' (e.g., the tablet is in sync
541 * and has delivered a "correct" report) We will ignore
542 * all 'bad' reports...
543 */
544 if (dv != 0) {
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400545 /* If the selected tool changed, reset the old
546 * tool key, and set the new one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 */
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400548 if (aiptek->previousToolMode !=
549 aiptek->curSetting.toolMode) {
550 input_report_key(inputdev,
551 aiptek->previousToolMode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 input_report_key(inputdev,
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400553 aiptek->curSetting.toolMode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 1);
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400555 aiptek->previousToolMode =
556 aiptek->curSetting.toolMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
559 if (p != 0) {
560 input_report_abs(inputdev, ABS_X, x);
561 input_report_abs(inputdev, ABS_Y, y);
562 input_report_abs(inputdev, ABS_PRESSURE, z);
563
564 input_report_key(inputdev, BTN_TOUCH, tip);
565 input_report_key(inputdev, BTN_STYLUS, bs);
566 input_report_key(inputdev, BTN_STYLUS2, pck);
567
568 if (aiptek->curSetting.xTilt !=
569 AIPTEK_TILT_DISABLE) {
570 input_report_abs(inputdev,
571 ABS_TILT_X,
572 aiptek->curSetting.xTilt);
573 }
574 if (aiptek->curSetting.yTilt != AIPTEK_TILT_DISABLE) {
575 input_report_abs(inputdev,
576 ABS_TILT_Y,
577 aiptek->curSetting.yTilt);
578 }
579
580 /* Wheel support is in the form of a single-event
581 * firing.
582 */
583 if (aiptek->curSetting.wheel !=
584 AIPTEK_WHEEL_DISABLE) {
585 input_report_abs(inputdev,
586 ABS_WHEEL,
587 aiptek->curSetting.wheel);
588 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
589 }
590 }
591 input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_STYLUS);
592 input_sync(inputdev);
593 }
594 }
595 }
596 /* Report 3's come from the mouse in absolute mode.
597 */
598 else if (data[0] == 3) {
599 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
600 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
601 } else if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE
602 (aiptek->curSetting.pointerMode)) {
603 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
604 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
606 y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
607
608 jitterable = data[5] & 0x1c;
609
Rene van Paassenfe981f22007-05-21 00:31:24 -0400610 dv = (data[5] & 0x01) != 0 ? 1 : 0;
611 p = (data[5] & 0x02) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
613 right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
614 middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
615
616 if (dv != 0) {
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400617 /* If the selected tool changed, reset the old
618 * tool key, and set the new one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 */
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400620 if (aiptek->previousToolMode !=
621 aiptek->curSetting.toolMode) {
622 input_report_key(inputdev,
623 aiptek->previousToolMode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 input_report_key(inputdev,
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400625 aiptek->curSetting.toolMode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 1);
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400627 aiptek->previousToolMode =
628 aiptek->curSetting.toolMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 }
630
631 if (p != 0) {
632 input_report_abs(inputdev, ABS_X, x);
633 input_report_abs(inputdev, ABS_Y, y);
634
635 input_report_key(inputdev, BTN_LEFT, left);
636 input_report_key(inputdev, BTN_MIDDLE, middle);
637 input_report_key(inputdev, BTN_RIGHT, right);
638
639 /* Wheel support is in the form of a single-event
640 * firing.
641 */
642 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
643 input_report_abs(inputdev,
644 ABS_WHEEL,
645 aiptek->curSetting.wheel);
646 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
647 }
648 }
Rene van Paassenda9fda42007-05-21 00:32:03 -0400649 input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_MOUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 input_sync(inputdev);
651 }
652 }
653 }
654 /* Report 4s come from the macro keys when pressed by stylus
655 */
656 else if (data[0] == 4) {
657 jitterable = data[1] & 0x18;
658
Rene van Paassenfe981f22007-05-21 00:31:24 -0400659 dv = (data[1] & 0x01) != 0 ? 1 : 0;
660 p = (data[1] & 0x02) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 tip = (data[1] & 0x04) != 0 ? 1 : 0;
662 bs = (data[1] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
663 pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
664
665 macro = data[3];
666 z = le16_to_cpu(get_unaligned((__le16 *) (data + 4)));
667
668 if (dv != 0) {
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400669 /* If the selected tool changed, reset the old
670 * tool key, and set the new one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 */
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400672 if (aiptek->previousToolMode !=
673 aiptek->curSetting.toolMode) {
674 input_report_key(inputdev,
675 aiptek->previousToolMode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 input_report_key(inputdev,
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400677 aiptek->curSetting.toolMode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 1);
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400679 aiptek->previousToolMode =
680 aiptek->curSetting.toolMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682
683 if (p != 0) {
684 input_report_key(inputdev, BTN_TOUCH, tip);
685 input_report_key(inputdev, BTN_STYLUS, bs);
686 input_report_key(inputdev, BTN_STYLUS2, pck);
687 input_report_abs(inputdev, ABS_PRESSURE, z);
688 }
689
690 /* For safety, we're sending key 'break' codes for the
691 * neighboring macro keys.
692 */
693 if (macro > 0) {
694 input_report_key(inputdev,
695 macroKeyEvents[macro - 1], 0);
696 }
697 if (macro < 25) {
698 input_report_key(inputdev,
699 macroKeyEvents[macro + 1], 0);
700 }
701 input_report_key(inputdev, macroKeyEvents[macro], p);
702 input_report_abs(inputdev, ABS_MISC,
703 p | AIPTEK_REPORT_TOOL_STYLUS);
704 input_sync(inputdev);
705 }
706 }
707 /* Report 5s come from the macro keys when pressed by mouse
708 */
709 else if (data[0] == 5) {
710 jitterable = data[1] & 0x1c;
711
Rene van Paassenfe981f22007-05-21 00:31:24 -0400712 dv = (data[1] & 0x01) != 0 ? 1 : 0;
713 p = (data[1] & 0x02) != 0 ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
715 right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
716 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
717 macro = data[3];
718
719 if (dv != 0) {
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400720 /* If the selected tool changed, reset the old
721 * tool key, and set the new one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 */
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400723 if (aiptek->previousToolMode !=
724 aiptek->curSetting.toolMode) {
725 input_report_key(inputdev,
726 aiptek->previousToolMode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 input_report_key(inputdev,
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400728 aiptek->curSetting.toolMode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 1);
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400730 aiptek->previousToolMode =
731 aiptek->curSetting.toolMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 }
733
734 if (p != 0) {
735 input_report_key(inputdev, BTN_LEFT, left);
736 input_report_key(inputdev, BTN_MIDDLE, middle);
737 input_report_key(inputdev, BTN_RIGHT, right);
738 }
739
740 /* For safety, we're sending key 'break' codes for the
741 * neighboring macro keys.
742 */
743 if (macro > 0) {
744 input_report_key(inputdev,
745 macroKeyEvents[macro - 1], 0);
746 }
747 if (macro < 25) {
748 input_report_key(inputdev,
749 macroKeyEvents[macro + 1], 0);
750 }
751
752 input_report_key(inputdev, macroKeyEvents[macro], 1);
753 input_report_rel(inputdev, ABS_MISC,
754 p | AIPTEK_REPORT_TOOL_MOUSE);
755 input_sync(inputdev);
756 }
757 }
758 /* We have no idea which tool can generate a report 6. Theoretically,
759 * neither need to, having been given reports 4 & 5 for such use.
760 * However, report 6 is the 'official-looking' report for macroKeys;
761 * reports 4 & 5 supposively are used to support unnamed, unknown
762 * hat switches (which just so happen to be the macroKeys.)
763 */
764 else if (data[0] == 6) {
765 macro = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 if (macro > 0) {
767 input_report_key(inputdev, macroKeyEvents[macro - 1],
768 0);
769 }
770 if (macro < 25) {
771 input_report_key(inputdev, macroKeyEvents[macro + 1],
772 0);
773 }
774
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400775 /* If the selected tool changed, reset the old
776 tool key, and set the new one.
777 */
778 if (aiptek->previousToolMode !=
779 aiptek->curSetting.toolMode) {
780 input_report_key(inputdev,
781 aiptek->previousToolMode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 input_report_key(inputdev,
Rene van Paassenb3b6cf12007-05-21 00:32:07 -0400783 aiptek->curSetting.toolMode,
784 1);
785 aiptek->previousToolMode =
786 aiptek->curSetting.toolMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 }
788
789 input_report_key(inputdev, macroKeyEvents[macro], 1);
790 input_report_abs(inputdev, ABS_MISC,
791 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
792 input_sync(inputdev);
793 } else {
794 dbg("Unknown report %d", data[0]);
795 }
796
797 /* Jitter may occur when the user presses a button on the stlyus
798 * or the mouse. What we do to prevent that is wait 'x' milliseconds
799 * following a 'jitterable' event, which should give the hand some time
800 * stabilize itself.
801 *
802 * We just introduced aiptek->previousJitterable to carry forth the
803 * notion that jitter occurs when the button state changes from on to off:
804 * a person drawing, holding a button down is not subject to jittering.
805 * With that in mind, changing from upper button depressed to lower button
806 * WILL transition through a jitter delay.
807 */
808
809 if (aiptek->previousJitterable != jitterable &&
810 aiptek->curSetting.jitterDelay != 0 && aiptek->inDelay != 1) {
811 aiptek->endDelay = jiffies +
812 ((aiptek->curSetting.jitterDelay * HZ) / 1000);
813 aiptek->inDelay = 1;
814 }
815 aiptek->previousJitterable = jitterable;
816
817exit:
818 retval = usb_submit_urb(urb, GFP_ATOMIC);
819 if (retval != 0) {
820 err("%s - usb_submit_urb failed with result %d",
821 __FUNCTION__, retval);
822 }
823}
824
825/***********************************************************************
826 * These are the USB id's known so far. We do not identify them to
827 * specific Aiptek model numbers, because there has been overlaps,
828 * use, and reuse of id's in existing models. Certain models have
829 * been known to use more than one ID, indicative perhaps of
Dmitry Torokhov05f091a2005-05-29 02:29:01 -0500830 * manufacturing revisions. In any event, we consider these
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 * IDs to not be model-specific nor unique.
832 */
833static const struct usb_device_id aiptek_ids[] = {
834 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01)},
835 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10)},
836 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20)},
837 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21)},
838 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
839 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
840 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
841 {}
842};
843
844MODULE_DEVICE_TABLE(usb, aiptek_ids);
845
846/***********************************************************************
847 * Open an instance of the tablet driver.
848 */
849static int aiptek_open(struct input_dev *inputdev)
850{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400851 struct aiptek *aiptek = input_get_drvdata(inputdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 aiptek->urb->dev = aiptek->usbdev;
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500854 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 return 0;
858}
859
860/***********************************************************************
861 * Close an instance of the tablet driver.
862 */
863static void aiptek_close(struct input_dev *inputdev)
864{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400865 struct aiptek *aiptek = input_get_drvdata(inputdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Dmitry Torokhov65cde542005-05-29 02:29:38 -0500867 usb_kill_urb(aiptek->urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
870/***********************************************************************
Dmitry Torokhov05f091a2005-05-29 02:29:01 -0500871 * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 * where they were known as usb_set_report and usb_get_report.
873 */
874static int
875aiptek_set_report(struct aiptek *aiptek,
876 unsigned char report_type,
877 unsigned char report_id, void *buffer, int size)
878{
879 return usb_control_msg(aiptek->usbdev,
880 usb_sndctrlpipe(aiptek->usbdev, 0),
881 USB_REQ_SET_REPORT,
882 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
883 USB_DIR_OUT, (report_type << 8) + report_id,
884 aiptek->ifnum, buffer, size, 5000);
885}
886
887static int
888aiptek_get_report(struct aiptek *aiptek,
889 unsigned char report_type,
890 unsigned char report_id, void *buffer, int size)
891{
892 return usb_control_msg(aiptek->usbdev,
893 usb_rcvctrlpipe(aiptek->usbdev, 0),
894 USB_REQ_GET_REPORT,
895 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
896 USB_DIR_IN, (report_type << 8) + report_id,
897 aiptek->ifnum, buffer, size, 5000);
898}
899
900/***********************************************************************
901 * Send a command to the tablet.
902 */
903static int
904aiptek_command(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 ((ret =
919 aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
920 dbg("aiptek_program: failed, tried to send: 0x%02x 0x%02x",
921 command, data);
922 }
923 kfree(buf);
924 return ret < 0 ? ret : 0;
925}
926
927/***********************************************************************
928 * Retrieve information from the tablet. Querying info is defined as first
929 * sending the {command,data} sequence as a command, followed by a wait
930 * (aka, "programmaticDelay") and then a "read" request.
931 */
932static int
933aiptek_query(struct aiptek *aiptek, unsigned char command, unsigned char data)
934{
935 const int sizeof_buf = 3 * sizeof(u8);
936 int ret;
937 u8 *buf;
938
939 buf = kmalloc(sizeof_buf, GFP_KERNEL);
940 if (!buf)
941 return -ENOMEM;
942
943 buf[0] = 2;
944 buf[1] = command;
945 buf[2] = data;
946
947 if (aiptek_command(aiptek, command, data) != 0) {
948 kfree(buf);
949 return -EIO;
950 }
951 msleep(aiptek->curSetting.programmableDelay);
952
953 if ((ret =
954 aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
955 dbg("aiptek_query failed: returned 0x%02x 0x%02x 0x%02x",
956 buf[0], buf[1], buf[2]);
957 ret = -EIO;
958 } else {
959 ret = le16_to_cpu(get_unaligned((__le16 *) (buf + 1)));
960 }
961 kfree(buf);
962 return ret;
963}
964
965/***********************************************************************
966 * Program the tablet into either absolute or relative mode.
967 * We also get information about the tablet's size.
968 */
969static int aiptek_program_tablet(struct aiptek *aiptek)
970{
971 int ret;
972 /* Execute Resolution500LPI */
973 if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
974 return ret;
975
976 /* Query getModelCode */
977 if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
978 return ret;
979 aiptek->features.modelCode = ret & 0xff;
980
981 /* Query getODMCode */
982 if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
983 return ret;
984 aiptek->features.odmCode = ret;
985
986 /* Query getFirmwareCode */
987 if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
988 return ret;
989 aiptek->features.firmwareCode = ret;
990
991 /* Query getXextension */
992 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
993 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500994 aiptek->inputdev->absmin[ABS_X] = 0;
995 aiptek->inputdev->absmax[ABS_X] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
997 /* Query getYextension */
998 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
999 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001000 aiptek->inputdev->absmin[ABS_Y] = 0;
1001 aiptek->inputdev->absmax[ABS_Y] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 /* Query getPressureLevels */
1004 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
1005 return ret;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001006 aiptek->inputdev->absmin[ABS_PRESSURE] = 0;
1007 aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 /* Depending on whether we are in absolute or relative mode, we will
1010 * do a switchToTablet(absolute) or switchToMouse(relative) command.
1011 */
1012 if (aiptek->curSetting.coordinateMode ==
1013 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
1014 /* Execute switchToTablet */
1015 if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
1016 return ret;
1017 }
1018 } else {
1019 /* Execute switchToMouse */
1020 if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
1021 return ret;
1022 }
1023 }
1024
1025 /* Enable the macro keys */
1026 if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
1027 return ret;
1028#if 0
1029 /* Execute FilterOn */
1030 if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
1031 return ret;
1032#endif
1033
1034 /* Execute AutoGainOn */
1035 if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
1036 return ret;
1037
1038 /* Reset the eventCount, so we track events from last (re)programming
1039 */
1040 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
1041 aiptek->eventCount = 0;
1042
1043 return 0;
1044}
1045
1046/***********************************************************************
1047 * Sysfs functions. Sysfs prefers that individually-tunable parameters
1048 * exist in their separate pseudo-files. Summary data that is immutable
1049 * may exist in a singular file so long as you don't define a writeable
1050 * interface.
1051 */
1052
1053/***********************************************************************
1054 * support the 'size' file -- display support
1055 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001056static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
1058 struct aiptek *aiptek = dev_get_drvdata(dev);
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 return snprintf(buf, PAGE_SIZE, "%dx%d\n",
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001061 aiptek->inputdev->absmax[ABS_X] + 1,
1062 aiptek->inputdev->absmax[ABS_Y] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
1064
1065/* These structs define the sysfs files, param #1 is the name of the
1066 * file, param 2 is the file permissions, param 3 & 4 are to the
1067 * output generator and input parser routines. Absence of a routine is
1068 * permitted -- it only means can't either 'cat' the file, or send data
1069 * to it.
1070 */
1071static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
1072
1073/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 * support routines for the 'pointer_mode' file. Note that this file
1075 * both displays current setting and allows reprogramming.
1076 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001077static struct aiptek_map pointer_mode_map[] = {
1078 { "stylus", AIPTEK_POINTER_ONLY_STYLUS_MODE },
1079 { "mouse", AIPTEK_POINTER_ONLY_MOUSE_MODE },
1080 { "either", AIPTEK_POINTER_EITHER_MODE },
1081 { NULL, AIPTEK_INVALID_VALUE }
1082};
1083
Yani Ioannou060b8842005-05-17 06:44:04 -04001084static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
1086 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001088 return snprintf(buf, PAGE_SIZE, "%s\n",
1089 map_val_to_str(pointer_mode_map,
1090 aiptek->curSetting.pointerMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
1093static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001094store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
1096 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001097 int new_mode = map_str_to_val(pointer_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001099 if (new_mode == AIPTEK_INVALID_VALUE)
1100 return -EINVAL;
1101
1102 aiptek->newSetting.pointerMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 return count;
1104}
1105
1106static DEVICE_ATTR(pointer_mode,
1107 S_IRUGO | S_IWUGO,
1108 show_tabletPointerMode, store_tabletPointerMode);
1109
1110/***********************************************************************
1111 * support routines for the 'coordinate_mode' file. Note that this file
1112 * both displays current setting and allows reprogramming.
1113 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001114
1115static struct aiptek_map coordinate_mode_map[] = {
1116 { "absolute", AIPTEK_COORDINATE_ABSOLUTE_MODE },
1117 { "relative", AIPTEK_COORDINATE_RELATIVE_MODE },
1118 { NULL, AIPTEK_INVALID_VALUE }
1119};
1120
Yani Ioannou060b8842005-05-17 06:44:04 -04001121static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
1123 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001125 return snprintf(buf, PAGE_SIZE, "%s\n",
1126 map_val_to_str(coordinate_mode_map,
1127 aiptek->curSetting.coordinateMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
1130static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001131store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
1133 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001134 int new_mode = map_str_to_val(coordinate_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001136 if (new_mode == AIPTEK_INVALID_VALUE)
1137 return -EINVAL;
1138
1139 aiptek->newSetting.coordinateMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 return count;
1141}
1142
1143static DEVICE_ATTR(coordinate_mode,
1144 S_IRUGO | S_IWUGO,
1145 show_tabletCoordinateMode, store_tabletCoordinateMode);
1146
1147/***********************************************************************
1148 * support routines for the 'tool_mode' file. Note that this file
1149 * both displays current setting and allows reprogramming.
1150 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001151
1152static struct aiptek_map tool_mode_map[] = {
1153 { "mouse", AIPTEK_TOOL_BUTTON_MOUSE_MODE },
1154 { "eraser", AIPTEK_TOOL_BUTTON_ERASER_MODE },
1155 { "pencil", AIPTEK_TOOL_BUTTON_PENCIL_MODE },
1156 { "pen", AIPTEK_TOOL_BUTTON_PEN_MODE },
1157 { "brush", AIPTEK_TOOL_BUTTON_BRUSH_MODE },
1158 { "airbrush", AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE },
1159 { "lens", AIPTEK_TOOL_BUTTON_LENS_MODE },
1160 { NULL, AIPTEK_INVALID_VALUE }
1161};
1162
Yani Ioannou060b8842005-05-17 06:44:04 -04001163static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164{
1165 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001167 return snprintf(buf, PAGE_SIZE, "%s\n",
1168 map_val_to_str(tool_mode_map,
1169 aiptek->curSetting.toolMode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
1172static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001173store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
1175 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001176 int new_mode = map_str_to_val(tool_mode_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001178 if (new_mode == AIPTEK_INVALID_VALUE)
1179 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001181 aiptek->newSetting.toolMode = new_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 return count;
1183}
1184
1185static DEVICE_ATTR(tool_mode,
1186 S_IRUGO | S_IWUGO,
1187 show_tabletToolMode, store_tabletToolMode);
1188
1189/***********************************************************************
1190 * support routines for the 'xtilt' file. Note that this file
1191 * both displays current setting and allows reprogramming.
1192 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001193static ssize_t show_tabletXtilt(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
1195 struct aiptek *aiptek = dev_get_drvdata(dev);
1196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
1198 return snprintf(buf, PAGE_SIZE, "disable\n");
1199 } else {
1200 return snprintf(buf, PAGE_SIZE, "%d\n",
1201 aiptek->curSetting.xTilt);
1202 }
1203}
1204
1205static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001206store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
1208 struct aiptek *aiptek = dev_get_drvdata(dev);
1209 int x;
1210
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 if (strcmp(buf, "disable") == 0) {
1212 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
1213 } else {
1214 x = (int)simple_strtol(buf, NULL, 10);
1215 if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
1216 aiptek->newSetting.xTilt = x;
1217 }
1218 }
1219 return count;
1220}
1221
1222static DEVICE_ATTR(xtilt,
1223 S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt);
1224
1225/***********************************************************************
1226 * support routines for the 'ytilt' file. Note that this file
1227 * both displays current setting and allows reprogramming.
1228 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001229static ssize_t show_tabletYtilt(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
1231 struct aiptek *aiptek = dev_get_drvdata(dev);
1232
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
1234 return snprintf(buf, PAGE_SIZE, "disable\n");
1235 } else {
1236 return snprintf(buf, PAGE_SIZE, "%d\n",
1237 aiptek->curSetting.yTilt);
1238 }
1239}
1240
1241static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001242store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
1244 struct aiptek *aiptek = dev_get_drvdata(dev);
1245 int y;
1246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 if (strcmp(buf, "disable") == 0) {
1248 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
1249 } else {
1250 y = (int)simple_strtol(buf, NULL, 10);
1251 if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
1252 aiptek->newSetting.yTilt = y;
1253 }
1254 }
1255 return count;
1256}
1257
1258static DEVICE_ATTR(ytilt,
1259 S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt);
1260
1261/***********************************************************************
1262 * support routines for the 'jitter' file. Note that this file
1263 * both displays current setting and allows reprogramming.
1264 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001265static ssize_t show_tabletJitterDelay(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266{
1267 struct aiptek *aiptek = dev_get_drvdata(dev);
1268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
1270}
1271
1272static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001273store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274{
1275 struct aiptek *aiptek = dev_get_drvdata(dev);
1276
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10);
1278 return count;
1279}
1280
1281static DEVICE_ATTR(jitter,
1282 S_IRUGO | S_IWUGO,
1283 show_tabletJitterDelay, store_tabletJitterDelay);
1284
1285/***********************************************************************
1286 * support routines for the 'delay' file. Note that this file
1287 * both displays current setting and allows reprogramming.
1288 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001289static ssize_t show_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
1291 struct aiptek *aiptek = dev_get_drvdata(dev);
1292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 return snprintf(buf, PAGE_SIZE, "%d\n",
1294 aiptek->curSetting.programmableDelay);
1295}
1296
1297static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001298store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
1300 struct aiptek *aiptek = dev_get_drvdata(dev);
1301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10);
1303 return count;
1304}
1305
1306static DEVICE_ATTR(delay,
1307 S_IRUGO | S_IWUGO,
1308 show_tabletProgrammableDelay, store_tabletProgrammableDelay);
1309
1310/***********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 * support routines for the 'event_count' file. Note that this file
1312 * only displays current setting.
1313 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001314static ssize_t show_tabletEventsReceived(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
1316 struct aiptek *aiptek = dev_get_drvdata(dev);
1317
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
1319}
1320
1321static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
1322
1323/***********************************************************************
1324 * support routines for the 'diagnostic' file. Note that this file
1325 * only displays current setting.
1326 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001327static ssize_t show_tabletDiagnosticMessage(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
1329 struct aiptek *aiptek = dev_get_drvdata(dev);
1330 char *retMsg;
1331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 switch (aiptek->diagnostic) {
1333 case AIPTEK_DIAGNOSTIC_NA:
1334 retMsg = "no errors\n";
1335 break;
1336
1337 case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
1338 retMsg = "Error: receiving relative reports\n";
1339 break;
1340
1341 case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
1342 retMsg = "Error: receiving absolute reports\n";
1343 break;
1344
1345 case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
1346 if (aiptek->curSetting.pointerMode ==
1347 AIPTEK_POINTER_ONLY_MOUSE_MODE) {
1348 retMsg = "Error: receiving stylus reports\n";
1349 } else {
1350 retMsg = "Error: receiving mouse reports\n";
1351 }
1352 break;
1353
1354 default:
1355 return 0;
1356 }
1357 return snprintf(buf, PAGE_SIZE, retMsg);
1358}
1359
1360static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
1361
1362/***********************************************************************
1363 * support routines for the 'stylus_upper' file. Note that this file
1364 * both displays current setting and allows for setting changing.
1365 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001366
1367static struct aiptek_map stylus_button_map[] = {
1368 { "upper", AIPTEK_STYLUS_UPPER_BUTTON },
1369 { "lower", AIPTEK_STYLUS_LOWER_BUTTON },
1370 { NULL, AIPTEK_INVALID_VALUE }
1371};
1372
Yani Ioannou060b8842005-05-17 06:44:04 -04001373static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
1375 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001377 return snprintf(buf, PAGE_SIZE, "%s\n",
1378 map_val_to_str(stylus_button_map,
1379 aiptek->curSetting.stylusButtonUpper));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380}
1381
1382static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001383store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
1385 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001386 int new_button = map_str_to_val(stylus_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001388 if (new_button == AIPTEK_INVALID_VALUE)
1389 return -EINVAL;
1390
1391 aiptek->newSetting.stylusButtonUpper = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 return count;
1393}
1394
1395static DEVICE_ATTR(stylus_upper,
1396 S_IRUGO | S_IWUGO,
1397 show_tabletStylusUpper, store_tabletStylusUpper);
1398
1399/***********************************************************************
1400 * support routines for the 'stylus_lower' file. Note that this file
1401 * both displays current setting and allows for setting changing.
1402 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001403
Yani Ioannou060b8842005-05-17 06:44:04 -04001404static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405{
1406 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001408 return snprintf(buf, PAGE_SIZE, "%s\n",
1409 map_val_to_str(stylus_button_map,
1410 aiptek->curSetting.stylusButtonLower));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411}
1412
1413static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001414store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
1416 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001417 int new_button = map_str_to_val(stylus_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001419 if (new_button == AIPTEK_INVALID_VALUE)
1420 return -EINVAL;
1421
1422 aiptek->newSetting.stylusButtonLower = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 return count;
1424}
1425
1426static DEVICE_ATTR(stylus_lower,
1427 S_IRUGO | S_IWUGO,
1428 show_tabletStylusLower, store_tabletStylusLower);
1429
1430/***********************************************************************
1431 * support routines for the 'mouse_left' file. Note that this file
1432 * both displays current setting and allows for setting changing.
1433 */
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001434
1435static struct aiptek_map mouse_button_map[] = {
1436 { "left", AIPTEK_MOUSE_LEFT_BUTTON },
1437 { "middle", AIPTEK_MOUSE_MIDDLE_BUTTON },
1438 { "right", AIPTEK_MOUSE_RIGHT_BUTTON },
1439 { NULL, AIPTEK_INVALID_VALUE }
1440};
1441
Yani Ioannou060b8842005-05-17 06:44:04 -04001442static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
1444 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001446 return snprintf(buf, PAGE_SIZE, "%s\n",
1447 map_val_to_str(mouse_button_map,
1448 aiptek->curSetting.mouseButtonLeft));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
1451static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001452store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
1454 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001455 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001457 if (new_button == AIPTEK_INVALID_VALUE)
1458 return -EINVAL;
1459
1460 aiptek->newSetting.mouseButtonLeft = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 return count;
1462}
1463
1464static DEVICE_ATTR(mouse_left,
1465 S_IRUGO | S_IWUGO,
1466 show_tabletMouseLeft, store_tabletMouseLeft);
1467
1468/***********************************************************************
1469 * support routines for the 'mouse_middle' file. Note that this file
1470 * both displays current setting and allows for setting changing.
1471 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001472static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
1474 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001476 return snprintf(buf, PAGE_SIZE, "%s\n",
1477 map_val_to_str(mouse_button_map,
1478 aiptek->curSetting.mouseButtonMiddle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
1481static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001482store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
1484 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001485 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001487 if (new_button == AIPTEK_INVALID_VALUE)
1488 return -EINVAL;
1489
1490 aiptek->newSetting.mouseButtonMiddle = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 return count;
1492}
1493
1494static DEVICE_ATTR(mouse_middle,
1495 S_IRUGO | S_IWUGO,
1496 show_tabletMouseMiddle, store_tabletMouseMiddle);
1497
1498/***********************************************************************
1499 * support routines for the 'mouse_right' file. Note that this file
1500 * both displays current setting and allows for setting changing.
1501 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001502static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
1504 struct aiptek *aiptek = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001506 return snprintf(buf, PAGE_SIZE, "%s\n",
1507 map_val_to_str(mouse_button_map,
1508 aiptek->curSetting.mouseButtonRight));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509}
1510
1511static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001512store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
1514 struct aiptek *aiptek = dev_get_drvdata(dev);
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001515 int new_button = map_str_to_val(mouse_button_map, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Dmitry Torokhovcd438a52007-05-21 00:17:57 -04001517 if (new_button == AIPTEK_INVALID_VALUE)
1518 return -EINVAL;
1519
1520 aiptek->newSetting.mouseButtonRight = new_button;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 return count;
1522}
1523
1524static DEVICE_ATTR(mouse_right,
1525 S_IRUGO | S_IWUGO,
1526 show_tabletMouseRight, store_tabletMouseRight);
1527
1528/***********************************************************************
1529 * support routines for the 'wheel' file. Note that this file
1530 * both displays current setting and allows for setting changing.
1531 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001532static ssize_t show_tabletWheel(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
1534 struct aiptek *aiptek = dev_get_drvdata(dev);
1535
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
1537 return snprintf(buf, PAGE_SIZE, "disable\n");
1538 } else {
1539 return snprintf(buf, PAGE_SIZE, "%d\n",
1540 aiptek->curSetting.wheel);
1541 }
1542}
1543
1544static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001545store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
1547 struct aiptek *aiptek = dev_get_drvdata(dev);
1548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10);
1550 return count;
1551}
1552
1553static DEVICE_ATTR(wheel,
1554 S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel);
1555
1556/***********************************************************************
1557 * support routines for the 'execute' file. Note that this file
1558 * both displays current setting and allows for setting changing.
1559 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001560static ssize_t show_tabletExecute(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 /* There is nothing useful to display, so a one-line manual
1563 * is in order...
1564 */
1565 return snprintf(buf, PAGE_SIZE,
1566 "Write anything to this file to program your tablet.\n");
1567}
1568
1569static ssize_t
Yani Ioannou060b8842005-05-17 06:44:04 -04001570store_tabletExecute(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571{
1572 struct aiptek *aiptek = dev_get_drvdata(dev);
1573
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 /* We do not care what you write to this file. Merely the action
1575 * of writing to this file triggers a tablet reprogramming.
1576 */
1577 memcpy(&aiptek->curSetting, &aiptek->newSetting,
1578 sizeof(struct aiptek_settings));
1579
1580 if (aiptek_program_tablet(aiptek) < 0)
1581 return -EIO;
1582
1583 return count;
1584}
1585
1586static DEVICE_ATTR(execute,
1587 S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute);
1588
1589/***********************************************************************
1590 * support routines for the 'odm_code' file. Note that this file
1591 * only displays current setting.
1592 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001593static ssize_t show_tabletODMCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
1595 struct aiptek *aiptek = dev_get_drvdata(dev);
1596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
1598}
1599
1600static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
1601
1602/***********************************************************************
1603 * support routines for the 'model_code' file. Note that this file
1604 * only displays current setting.
1605 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001606static ssize_t show_tabletModelCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
1608 struct aiptek *aiptek = dev_get_drvdata(dev);
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
1611}
1612
1613static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
1614
1615/***********************************************************************
1616 * support routines for the 'firmware_code' file. Note that this file
1617 * only displays current setting.
1618 */
Yani Ioannou060b8842005-05-17 06:44:04 -04001619static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620{
1621 struct aiptek *aiptek = dev_get_drvdata(dev);
1622
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 return snprintf(buf, PAGE_SIZE, "%04x\n",
1624 aiptek->features.firmwareCode);
1625}
1626
1627static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
1628
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001629static struct attribute *aiptek_attributes[] = {
1630 &dev_attr_size.attr,
1631 &dev_attr_pointer_mode.attr,
1632 &dev_attr_coordinate_mode.attr,
1633 &dev_attr_tool_mode.attr,
1634 &dev_attr_xtilt.attr,
1635 &dev_attr_ytilt.attr,
1636 &dev_attr_jitter.attr,
1637 &dev_attr_delay.attr,
1638 &dev_attr_event_count.attr,
1639 &dev_attr_diagnostic.attr,
1640 &dev_attr_odm_code.attr,
1641 &dev_attr_model_code.attr,
1642 &dev_attr_firmware_code.attr,
1643 &dev_attr_stylus_lower.attr,
1644 &dev_attr_stylus_upper.attr,
1645 &dev_attr_mouse_left.attr,
1646 &dev_attr_mouse_middle.attr,
1647 &dev_attr_mouse_right.attr,
1648 &dev_attr_wheel.attr,
1649 &dev_attr_execute.attr,
1650 NULL
1651};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001653static struct attribute_group aiptek_attribute_group = {
1654 .attrs = aiptek_attributes,
1655};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657/***********************************************************************
1658 * This routine is called when a tablet has been identified. It basically
1659 * sets up the tablet and the driver's internal structures.
1660 */
1661static int
1662aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1663{
1664 struct usb_device *usbdev = interface_to_usbdev(intf);
1665 struct usb_endpoint_descriptor *endpoint;
1666 struct aiptek *aiptek;
1667 struct input_dev *inputdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 int i;
1669 int speeds[] = { 0,
1670 AIPTEK_PROGRAMMABLE_DELAY_50,
1671 AIPTEK_PROGRAMMABLE_DELAY_400,
1672 AIPTEK_PROGRAMMABLE_DELAY_25,
1673 AIPTEK_PROGRAMMABLE_DELAY_100,
1674 AIPTEK_PROGRAMMABLE_DELAY_200,
1675 AIPTEK_PROGRAMMABLE_DELAY_300
1676 };
Dmitry Torokhov50141862007-04-12 01:33:39 -04001677 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 /* programmableDelay is where the command-line specified
1680 * delay is kept. We make it the first element of speeds[],
1681 * so therefore, your override speed is tried first, then the
1682 * remainder. Note that the default value of 400ms will be tried
1683 * if you do not specify any command line parameter.
1684 */
1685 speeds[0] = programmableDelay;
1686
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001687 aiptek = kzalloc(sizeof(struct aiptek), GFP_KERNEL);
1688 inputdev = input_allocate_device();
Rene van Paassen6125a402007-05-21 00:31:59 -04001689 if (!aiptek || !inputdev) {
1690 warn("aiptek: cannot allocate memory or input device");
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001691 goto fail1;
Rene van Paassen6125a402007-05-21 00:31:59 -04001692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
1694 aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
Christoph Lameter54e6ecb2006-12-06 20:33:16 -08001695 GFP_ATOMIC, &aiptek->data_dma);
Rene van Paassen6125a402007-05-21 00:31:59 -04001696 if (!aiptek->data) {
1697 warn("aiptek: cannot allocate usb buffer");
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001698 goto fail1;
Rene van Paassen6125a402007-05-21 00:31:59 -04001699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
1701 aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
Rene van Paassen6125a402007-05-21 00:31:59 -04001702 if (!aiptek->urb) {
1703 warn("aiptek: cannot allocate urb");
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001704 goto fail2;
Rene van Paassen6125a402007-05-21 00:31:59 -04001705 }
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001706
1707 aiptek->inputdev = inputdev;
1708 aiptek->usbdev = usbdev;
1709 aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
1710 aiptek->inDelay = 0;
1711 aiptek->endDelay = 0;
1712 aiptek->previousJitterable = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
1714 /* Set up the curSettings struct. Said struct contains the current
1715 * programmable parameters. The newSetting struct contains changes
1716 * the user makes to the settings via the sysfs interface. Those
1717 * changes are not "committed" to curSettings until the user
1718 * writes to the sysfs/.../execute file.
1719 */
1720 aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
1721 aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
1722 aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
1723 aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
1724 aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
1725 aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
1726 aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
1727 aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
1728 aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
1729 aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
1730 aiptek->curSetting.jitterDelay = jitterDelay;
1731 aiptek->curSetting.programmableDelay = programmableDelay;
1732
1733 /* Both structs should have equivalent settings
1734 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001735 aiptek->newSetting = aiptek->curSetting;
1736
1737 /* Determine the usb devices' physical path.
1738 * Asketh not why we always pretend we're using "../input0",
1739 * but I suspect this will have to be refactored one
1740 * day if a single USB device can be a keyboard & a mouse
1741 * & a tablet, and the inputX number actually will tell
1742 * us something...
1743 */
1744 usb_make_path(usbdev, aiptek->features.usbPath,
1745 sizeof(aiptek->features.usbPath));
1746 strlcat(aiptek->features.usbPath, "/input0",
1747 sizeof(aiptek->features.usbPath));
1748
1749 /* Set up client data, pointers to open and close routines
1750 * for the input device.
1751 */
1752 inputdev->name = "Aiptek";
1753 inputdev->phys = aiptek->features.usbPath;
1754 usb_to_input_id(usbdev, &inputdev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -04001755 inputdev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001756
1757 input_set_drvdata(inputdev, aiptek);
1758
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001759 inputdev->open = aiptek_open;
1760 inputdev->close = aiptek_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
1762 /* Now program the capacities of the tablet, in terms of being
1763 * an input device.
1764 */
Rene van Paassen1a54f492007-05-21 00:31:55 -04001765 for (i = 0; i < ARRAY_SIZE(eventTypes); ++i)
1766 __set_bit(eventTypes[i], inputdev->evbit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
Rene van Paassen1a54f492007-05-21 00:31:55 -04001768 for (i = 0; i < ARRAY_SIZE(absEvents); ++i)
1769 __set_bit(absEvents[i], inputdev->absbit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Rene van Paassen1a54f492007-05-21 00:31:55 -04001771 for (i = 0; i < ARRAY_SIZE(relEvents); ++i)
1772 __set_bit(relEvents[i], inputdev->relbit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Rene van Paassen1a54f492007-05-21 00:31:55 -04001774 __set_bit(MSC_SERIAL, inputdev->mscbit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Dmitry Torokhov33936fa2007-05-21 00:18:15 -04001776 /* Set up key and button codes */
1777 for (i = 0; i < ARRAY_SIZE(buttonEvents); ++i)
1778 __set_bit(buttonEvents[i], inputdev->keybit);
1779
Tobias Klauser52950ed2005-12-11 16:20:08 +01001780 for (i = 0; i < ARRAY_SIZE(macroKeyEvents); ++i)
Dmitry Torokhov33936fa2007-05-21 00:18:15 -04001781 __set_bit(macroKeyEvents[i], inputdev->keybit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001783 /*
1784 * Program the input device coordinate capacities. We do not yet
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 * know what maximum X, Y, and Z values are, so we're putting fake
1786 * values in. Later, we'll ask the tablet to put in the correct
1787 * values.
1788 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001789 input_set_abs_params(inputdev, ABS_X, 0, 2999, 0, 0);
Riccardo Magliocchettif873e3e2005-12-28 20:44:48 -05001790 input_set_abs_params(inputdev, ABS_Y, 0, 2249, 0, 0);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001791 input_set_abs_params(inputdev, ABS_PRESSURE, 0, 511, 0, 0);
1792 input_set_abs_params(inputdev, ABS_TILT_X, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
1793 input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
1794 input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
1796 endpoint = &intf->altsetting[0].endpoint[0].desc;
1797
1798 /* Go set up our URB, which is called when the tablet receives
1799 * input.
1800 */
1801 usb_fill_int_urb(aiptek->urb,
1802 aiptek->usbdev,
1803 usb_rcvintpipe(aiptek->usbdev,
1804 endpoint->bEndpointAddress),
1805 aiptek->data, 8, aiptek_irq, aiptek,
1806 endpoint->bInterval);
1807
1808 aiptek->urb->transfer_dma = aiptek->data_dma;
1809 aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 /* Program the tablet. This sets the tablet up in the mode
1812 * specified in newSetting, and also queries the tablet's
1813 * physical capacities.
1814 *
1815 * Sanity check: if a tablet doesn't like the slow programmatic
1816 * delay, we often get sizes of 0x0. Let's use that as an indicator
1817 * to try faster delays, up to 25 ms. If that logic fails, well, you'll
1818 * have to explain to us how your tablet thinks it's 0x0, and yet that's
1819 * not an error :-)
1820 */
1821
Tobias Klauser52950ed2005-12-11 16:20:08 +01001822 for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 aiptek->curSetting.programmableDelay = speeds[i];
1824 (void)aiptek_program_tablet(aiptek);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001825 if (aiptek->inputdev->absmax[ABS_X] > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 info("input: Aiptek using %d ms programming speed\n",
1827 aiptek->curSetting.programmableDelay);
1828 break;
1829 }
1830 }
1831
Rene van Paassen6125a402007-05-21 00:31:59 -04001832 /* Murphy says that some day someone will have a tablet that fails the
1833 above test. That's you, Frederic Rodrigo */
1834 if (i == ARRAY_SIZE(speeds)) {
1835 info("input: Aiptek tried all speeds, no sane response");
1836 goto fail2;
1837 }
1838
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 /* Associate this driver's struct with the usb interface.
1840 */
1841 usb_set_intfdata(intf, aiptek);
1842
1843 /* Set up the sysfs files
1844 */
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001845 err = sysfs_create_group(&intf->dev.kobj, &aiptek_attribute_group);
Rene van Paassen6125a402007-05-21 00:31:59 -04001846 if (err) {
1847 warn("aiptek: cannot create sysfs group err: %d", err);
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001848 goto fail3;
Rene van Paassen6125a402007-05-21 00:31:59 -04001849 }
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001850
1851 /* Register the tablet as an Input Device
1852 */
1853 err = input_register_device(aiptek->inputdev);
Rene van Paassen6125a402007-05-21 00:31:59 -04001854 if (err) {
1855 warn("aiptek: input_register_device returned err: %d", err);
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001856 goto fail4;
Rene van Paassen6125a402007-05-21 00:31:59 -04001857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 return 0;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001859
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001860 fail4: sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
1861 fail3: usb_free_urb(aiptek->urb);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001862 fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001863 aiptek->data_dma);
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001864 fail1: usb_set_intfdata(intf, NULL);
1865 input_free_device(inputdev);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001866 kfree(aiptek);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001867 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868}
1869
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870/***********************************************************************
1871 * Deal with tablet disconnecting from the system.
1872 */
1873static void aiptek_disconnect(struct usb_interface *intf)
1874{
1875 struct aiptek *aiptek = usb_get_intfdata(intf);
1876
1877 /* Disassociate driver's struct with usb interface
1878 */
1879 usb_set_intfdata(intf, NULL);
1880 if (aiptek != NULL) {
1881 /* Free & unhook everything from the system.
1882 */
1883 usb_kill_urb(aiptek->urb);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -05001884 input_unregister_device(aiptek->inputdev);
Dmitry Torokhovb087e1f2007-05-21 00:17:37 -04001885 sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 usb_free_urb(aiptek->urb);
1887 usb_buffer_free(interface_to_usbdev(intf),
1888 AIPTEK_PACKET_LENGTH,
1889 aiptek->data, aiptek->data_dma);
1890 kfree(aiptek);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 }
1892}
1893
Dmitry Torokhov50141862007-04-12 01:33:39 -04001894static struct usb_driver aiptek_driver = {
1895 .name = "aiptek",
1896 .probe = aiptek_probe,
1897 .disconnect = aiptek_disconnect,
1898 .id_table = aiptek_ids,
1899};
1900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901static int __init aiptek_init(void)
1902{
1903 int result = usb_register(&aiptek_driver);
1904 if (result == 0) {
1905 info(DRIVER_VERSION ": " DRIVER_AUTHOR);
1906 info(DRIVER_DESC);
1907 }
1908 return result;
1909}
1910
1911static void __exit aiptek_exit(void)
1912{
1913 usb_deregister(&aiptek_driver);
1914}
1915
1916MODULE_AUTHOR(DRIVER_AUTHOR);
1917MODULE_DESCRIPTION(DRIVER_DESC);
1918MODULE_LICENSE("GPL");
1919
1920module_param(programmableDelay, int, 0);
1921MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
1922module_param(jitterDelay, int, 0);
1923MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
1924
1925module_init(aiptek_init);
1926module_exit(aiptek_exit);