aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/tablet
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/tablet')
-rw-r--r--drivers/input/tablet/Kconfig74
-rw-r--r--drivers/input/tablet/Makefile12
-rw-r--r--drivers/input/tablet/acecad.c289
-rw-r--r--drivers/input/tablet/aiptek.c2236
-rw-r--r--drivers/input/tablet/gtco.c1055
-rw-r--r--drivers/input/tablet/kbtab.c226
-rw-r--r--drivers/input/tablet/wacom.h131
-rw-r--r--drivers/input/tablet/wacom_sys.c318
-rw-r--r--drivers/input/tablet/wacom_wac.c675
-rw-r--r--drivers/input/tablet/wacom_wac.h49
10 files changed, 5065 insertions, 0 deletions
diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
new file mode 100644
index 000000000000..12dfb0eb3262
--- /dev/null
+++ b/drivers/input/tablet/Kconfig
@@ -0,0 +1,74 @@
1#
2# Tablet driver configuration
3#
4menuconfig INPUT_TABLET
5 bool "Tablets"
6 help
7 Say Y here, and a list of supported tablets will be displayed.
8 This option doesn't affect the kernel.
9
10 If unsure, say Y.
11
12if INPUT_TABLET
13
14config TABLET_USB_ACECAD
15 tristate "Acecad Flair tablet support (USB)"
16 select USB
17 help
18 Say Y here if you want to use the USB version of the Acecad Flair
19 tablet. Make sure to say Y to "Mouse support"
20 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support"
21 (CONFIG_INPUT_EVDEV) as well.
22
23 To compile this driver as a module, choose M here: the
24 module will be called acecad.
25
26config TABLET_USB_AIPTEK
27 tristate "Aiptek 6000U/8000U tablet support (USB)"
28 select USB
29 help
30 Say Y here if you want to use the USB version of the Aiptek 6000U
31 or Aiptek 8000U tablet. Make sure to say Y to "Mouse support"
32 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support"
33 (CONFIG_INPUT_EVDEV) as well.
34
35 To compile this driver as a module, choose M here: the
36 module will be called aiptek.
37
38config TABLET_USB_GTCO
39 tristate "GTCO CalComp/InterWrite USB Support"
40 depends on USB && INPUT
41 help
42 Say Y here if you want to use the USB version of the GTCO
43 CalComp/InterWrite Tablet. Make sure to say Y to "Mouse support"
44 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support"
45 (CONFIG_INPUT_EVDEV) as well.
46
47 To compile this driver as a module, choose M here: the
48 module will be called gtco.
49
50config TABLET_USB_KBTAB
51 tristate "KB Gear JamStudio tablet support (USB)"
52 select USB
53 help
54 Say Y here if you want to use the USB version of the KB Gear
55 JamStudio tablet. Make sure to say Y to "Mouse support"
56 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support"
57 (CONFIG_INPUT_EVDEV) as well.
58
59 To compile this driver as a module, choose M here: the
60 module will be called kbtab.
61
62config TABLET_USB_WACOM
63 tristate "Wacom Intuos/Graphire tablet support (USB)"
64 select USB
65 help
66 Say Y here if you want to use the USB version of the Wacom Intuos
67 or Graphire tablet. Make sure to say Y to "Mouse support"
68 (CONFIG_INPUT_MOUSEDEV) and/or "Event interface support"
69 (CONFIG_INPUT_EVDEV) as well.
70
71 To compile this driver as a module, choose M here: the
72 module will be called wacom.
73
74endif
diff --git a/drivers/input/tablet/Makefile b/drivers/input/tablet/Makefile
new file mode 100644
index 000000000000..ce8b9a9cfa40
--- /dev/null
+++ b/drivers/input/tablet/Makefile
@@ -0,0 +1,12 @@
1#
2# Makefile for the tablet drivers
3#
4
5# Multipart objects.
6wacom-objs := wacom_wac.o wacom_sys.o
7
8obj-$(CONFIG_TABLET_USB_ACECAD) += acecad.o
9obj-$(CONFIG_TABLET_USB_AIPTEK) += aiptek.o
10obj-$(CONFIG_TABLET_USB_GTCO) += gtco.o
11obj-$(CONFIG_TABLET_USB_KBTAB) += kbtab.o
12obj-$(CONFIG_TABLET_USB_WACOM) += wacom.o
diff --git a/drivers/input/tablet/acecad.c b/drivers/input/tablet/acecad.c
new file mode 100644
index 000000000000..dd2310458c46
--- /dev/null
+++ b/drivers/input/tablet/acecad.c
@@ -0,0 +1,289 @@
1/*
2 * Copyright (c) 2001-2005 Edouard TISSERANT <edouard.tisserant@wanadoo.fr>
3 * Copyright (c) 2004-2005 Stephane VOLTZ <svoltz@numericable.fr>
4 *
5 * USB Acecad "Acecad Flair" tablet support
6 *
7 * Changelog:
8 * v3.2 - Added sysfs support
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28#include <linux/kernel.h>
29#include <linux/slab.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/usb/input.h>
33
34/*
35 * Version Information
36 */
37#define DRIVER_VERSION "v3.2"
38#define DRIVER_DESC "USB Acecad Flair tablet driver"
39#define DRIVER_LICENSE "GPL"
40#define DRIVER_AUTHOR "Edouard TISSERANT <edouard.tisserant@wanadoo.fr>"
41
42MODULE_AUTHOR(DRIVER_AUTHOR);
43MODULE_DESCRIPTION(DRIVER_DESC);
44MODULE_LICENSE(DRIVER_LICENSE);
45
46#define USB_VENDOR_ID_ACECAD 0x0460
47#define USB_DEVICE_ID_FLAIR 0x0004
48#define USB_DEVICE_ID_302 0x0008
49
50struct usb_acecad {
51 char name[128];
52 char phys[64];
53 struct usb_device *usbdev;
54 struct input_dev *input;
55 struct urb *irq;
56
57 unsigned char *data;
58 dma_addr_t data_dma;
59};
60
61static void usb_acecad_irq(struct urb *urb)
62{
63 struct usb_acecad *acecad = urb->context;
64 unsigned char *data = acecad->data;
65 struct input_dev *dev = acecad->input;
66 int prox, status;
67
68 switch (urb->status) {
69 case 0:
70 /* success */
71 break;
72 case -ECONNRESET:
73 case -ENOENT:
74 case -ESHUTDOWN:
75 /* this urb is terminated, clean up */
76 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
77 return;
78 default:
79 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
80 goto resubmit;
81 }
82
83 prox = (data[0] & 0x04) >> 2;
84 input_report_key(dev, BTN_TOOL_PEN, prox);
85
86 if (prox) {
87 int x = data[1] | (data[2] << 8);
88 int y = data[3] | (data[4] << 8);
89 /* Pressure should compute the same way for flair and 302 */
90 int pressure = data[5] | (data[6] << 8);
91 int touch = data[0] & 0x01;
92 int stylus = (data[0] & 0x10) >> 4;
93 int stylus2 = (data[0] & 0x20) >> 5;
94 input_report_abs(dev, ABS_X, x);
95 input_report_abs(dev, ABS_Y, y);
96 input_report_abs(dev, ABS_PRESSURE, pressure);
97 input_report_key(dev, BTN_TOUCH, touch);
98 input_report_key(dev, BTN_STYLUS, stylus);
99 input_report_key(dev, BTN_STYLUS2, stylus2);
100 }
101
102 /* event termination */
103 input_sync(dev);
104
105resubmit:
106 status = usb_submit_urb(urb, GFP_ATOMIC);
107 if (status)
108 err("can't resubmit intr, %s-%s/input0, status %d",
109 acecad->usbdev->bus->bus_name, acecad->usbdev->devpath, status);
110}
111
112static int usb_acecad_open(struct input_dev *dev)
113{
114 struct usb_acecad *acecad = input_get_drvdata(dev);
115
116 acecad->irq->dev = acecad->usbdev;
117 if (usb_submit_urb(acecad->irq, GFP_KERNEL))
118 return -EIO;
119
120 return 0;
121}
122
123static void usb_acecad_close(struct input_dev *dev)
124{
125 struct usb_acecad *acecad = input_get_drvdata(dev);
126
127 usb_kill_urb(acecad->irq);
128}
129
130static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_id *id)
131{
132 struct usb_device *dev = interface_to_usbdev(intf);
133 struct usb_host_interface *interface = intf->cur_altsetting;
134 struct usb_endpoint_descriptor *endpoint;
135 struct usb_acecad *acecad;
136 struct input_dev *input_dev;
137 int pipe, maxp;
138 int err = -ENOMEM;
139
140 if (interface->desc.bNumEndpoints != 1)
141 return -ENODEV;
142
143 endpoint = &interface->endpoint[0].desc;
144
145 if (!usb_endpoint_is_int_in(endpoint))
146 return -ENODEV;
147
148 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
149 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
150
151 acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL);
152 input_dev = input_allocate_device();
153 if (!acecad || !input_dev) {
154 err = -ENOMEM;
155 goto fail1;
156 }
157
158 acecad->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &acecad->data_dma);
159 if (!acecad->data) {
160 err= -ENOMEM;
161 goto fail1;
162 }
163
164 acecad->irq = usb_alloc_urb(0, GFP_KERNEL);
165 if (!acecad->irq) {
166 err = -ENOMEM;
167 goto fail2;
168 }
169
170 acecad->usbdev = dev;
171 acecad->input = input_dev;
172
173 if (dev->manufacturer)
174 strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
175
176 if (dev->product) {
177 if (dev->manufacturer)
178 strlcat(acecad->name, " ", sizeof(acecad->name));
179 strlcat(acecad->name, dev->product, sizeof(acecad->name));
180 }
181
182 usb_make_path(dev, acecad->phys, sizeof(acecad->phys));
183 strlcat(acecad->phys, "/input0", sizeof(acecad->phys));
184
185 input_dev->name = acecad->name;
186 input_dev->phys = acecad->phys;
187 usb_to_input_id(dev, &input_dev->id);
188 input_dev->dev.parent = &intf->dev;
189
190 input_set_drvdata(input_dev, acecad);
191
192 input_dev->open = usb_acecad_open;
193 input_dev->close = usb_acecad_close;
194
195 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
196 input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
197 input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
198 input_dev->keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2);
199
200 switch (id->driver_info) {
201 case 0:
202 input_dev->absmax[ABS_X] = 5000;
203 input_dev->absmax[ABS_Y] = 3750;
204 input_dev->absmax[ABS_PRESSURE] = 512;
205 if (!strlen(acecad->name))
206 snprintf(acecad->name, sizeof(acecad->name),
207 "USB Acecad Flair Tablet %04x:%04x",
208 le16_to_cpu(dev->descriptor.idVendor),
209 le16_to_cpu(dev->descriptor.idProduct));
210 break;
211 case 1:
212 input_dev->absmax[ABS_X] = 3000;
213 input_dev->absmax[ABS_Y] = 2250;
214 input_dev->absmax[ABS_PRESSURE] = 1024;
215 if (!strlen(acecad->name))
216 snprintf(acecad->name, sizeof(acecad->name),
217 "USB Acecad 302 Tablet %04x:%04x",
218 le16_to_cpu(dev->descriptor.idVendor),
219 le16_to_cpu(dev->descriptor.idProduct));
220 break;
221 }
222
223 input_dev->absfuzz[ABS_X] = 4;
224 input_dev->absfuzz[ABS_Y] = 4;
225
226 usb_fill_int_urb(acecad->irq, dev, pipe,
227 acecad->data, maxp > 8 ? 8 : maxp,
228 usb_acecad_irq, acecad, endpoint->bInterval);
229 acecad->irq->transfer_dma = acecad->data_dma;
230 acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
231
232 err = input_register_device(acecad->input);
233 if (err)
234 goto fail2;
235
236 usb_set_intfdata(intf, acecad);
237
238 return 0;
239
240 fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma);
241 fail1: input_free_device(input_dev);
242 kfree(acecad);
243 return err;
244}
245
246static void usb_acecad_disconnect(struct usb_interface *intf)
247{
248 struct usb_acecad *acecad = usb_get_intfdata(intf);
249
250 usb_set_intfdata(intf, NULL);
251 if (acecad) {
252 usb_kill_urb(acecad->irq);
253 input_unregister_device(acecad->input);
254 usb_free_urb(acecad->irq);
255 usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma);
256 kfree(acecad);
257 }
258}
259
260static struct usb_device_id usb_acecad_id_table [] = {
261 { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_FLAIR), .driver_info = 0 },
262 { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_302), .driver_info = 1 },
263 { }
264};
265
266MODULE_DEVICE_TABLE(usb, usb_acecad_id_table);
267
268static struct usb_driver usb_acecad_driver = {
269 .name = "usb_acecad",
270 .probe = usb_acecad_probe,
271 .disconnect = usb_acecad_disconnect,
272 .id_table = usb_acecad_id_table,
273};
274
275static int __init usb_acecad_init(void)
276{
277 int result = usb_register(&usb_acecad_driver);
278 if (result == 0)
279 info(DRIVER_VERSION ":" DRIVER_DESC);
280 return result;
281}
282
283static void __exit usb_acecad_exit(void)
284{
285 usb_deregister(&usb_acecad_driver);
286}
287
288module_init(usb_acecad_init);
289module_exit(usb_acecad_exit);
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
new file mode 100644
index 000000000000..cc0a498763d8
--- /dev/null
+++ b/drivers/input/tablet/aiptek.c
@@ -0,0 +1,2236 @@
1/*
2 * Native support for the Aiptek HyperPen USB Tablets
3 * (4000U/5000U/6000U/8000U/12000U)
4 *
5 * Copyright (c) 2001 Chris Atenasio <chris@crud.net>
6 * Copyright (c) 2002-2004 Bryan W. Headley <bwheadley@earthlink.net>
7 *
8 * based on wacom.c by
9 * Vojtech Pavlik <vojtech@suse.cz>
10 * Andreas Bach Aaen <abach@stofanet.dk>
11 * Clifford Wolf <clifford@clifford.at>
12 * Sam Mosel <sam.mosel@computer.org>
13 * James E. Blair <corvus@gnu.org>
14 * Daniel Egger <egger@suse.de>
15 *
16 * Many thanks to Oliver Kuechemann for his support.
17 *
18 * ChangeLog:
19 * v0.1 - Initial release
20 * v0.2 - Hack to get around fake event 28's. (Bryan W. Headley)
21 * v0.3 - Make URB dynamic (Bryan W. Headley, Jun-8-2002)
22 * Released to Linux 2.4.19 and 2.5.x
23 * v0.4 - Rewrote substantial portions of the code to deal with
24 * corrected control sequences, timing, dynamic configuration,
25 * support of 6000U - 12000U, procfs, and macro key support
26 * (Jan-1-2003 - Feb-5-2003, Bryan W. Headley)
27 * v1.0 - Added support for diagnostic messages, count of messages
28 * received from URB - Mar-8-2003, Bryan W. Headley
29 * v1.1 - added support for tablet resolution, changed DV and proximity
30 * some corrections - Jun-22-2003, martin schneebacher
31 * - Added support for the sysfs interface, deprecating the
32 * procfs interface for 2.5.x kernel. Also added support for
33 * Wheel command. Bryan W. Headley July-15-2003.
34 * v1.2 - Reworked jitter timer as a kernel thread.
35 * Bryan W. Headley November-28-2003/Jan-10-2004.
36 * v1.3 - Repaired issue of kernel thread going nuts on single-processor
37 * machines, introduced programmableDelay as a command line
38 * parameter. Feb 7 2004, Bryan W. Headley.
39 * v1.4 - Re-wire jitter so it does not require a thread. Courtesy of
40 * Rene van Paassen. Added reporting of physical pointer device
41 * (e.g., stylus, mouse in reports 2, 3, 4, 5. We don't know
42 * for reports 1, 6.)
43 * what physical device reports for reports 1, 6.) Also enabled
44 * MOUSE and LENS tool button modes. Renamed "rubber" to "eraser".
45 * Feb 20, 2004, Bryan W. Headley.
46 * v1.5 - Added previousJitterable, so we don't do jitter delay when the
47 * user is holding a button down for periods of time.
48 *
49 * NOTE:
50 * This kernel driver is augmented by the "Aiptek" XFree86 input
51 * driver for your X server, as well as the Gaiptek GUI Front-end
52 * "Tablet Manager".
53 * These three products are highly interactive with one another,
54 * so therefore it's easier to document them all as one subsystem.
55 * Please visit the project's "home page", located at,
56 * http://aiptektablet.sourceforge.net.
57 *
58 * This program is free software; you can redistribute it and/or modify
59 * it under the terms of the GNU General Public License as published by
60 * the Free Software Foundation; either version 2 of the License, or
61 * (at your option) any later version.
62 *
63 * This program is distributed in the hope that it will be useful,
64 * but WITHOUT ANY WARRANTY; without even the implied warranty of
65 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66 * GNU General Public License for more details.
67 *
68 * You should have received a copy of the GNU General Public License
69 * along with this program; if not, write to the Free Software
70 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
71 */
72
73#include <linux/jiffies.h>
74#include <linux/kernel.h>
75#include <linux/slab.h>
76#include <linux/module.h>
77#include <linux/init.h>
78#include <linux/usb/input.h>
79#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
157 * 0x18/0x04 SetResolution 0
158 * 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
248 /* Time to wait (in ms) to help mask hand jittering
249 * 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 */
297 char inputPath[64 + 1]; /* input device path */
298};
299
300struct aiptek_settings {
301 int pointerMode; /* stylus-, mouse-only or either */
302 int coordinateMode; /* absolute/relative coords */
303 int toolMode; /* pen, pencil, brush, etc. tool */
304 int xTilt; /* synthetic xTilt amount */
305 int yTilt; /* synthetic yTilt amount */
306 int wheel; /* synthetic wheel amount */
307 int stylusButtonUpper; /* stylus upper btn delivers... */
308 int stylusButtonLower; /* stylus lower btn delivers... */
309 int mouseButtonLeft; /* mouse left btn delivers... */
310 int mouseButtonMiddle; /* mouse middle btn delivers... */
311 int mouseButtonRight; /* mouse right btn delivers... */
312 int programmableDelay; /* delay for tablet programming */
313 int jitterDelay; /* delay for hand jittering */
314};
315
316struct aiptek {
317 struct input_dev *inputdev; /* input device struct */
318 struct usb_device *usbdev; /* usb device struct */
319 struct urb *urb; /* urb for incoming reports */
320 dma_addr_t data_dma; /* our dma stuffage */
321 struct aiptek_features features; /* tablet's array of features */
322 struct aiptek_settings curSetting; /* tablet's current programmable */
323 struct aiptek_settings newSetting; /* ... and new param settings */
324 unsigned int ifnum; /* interface number for IO */
325 int diagnostic; /* tablet diagnostic codes */
326 unsigned long eventCount; /* event count */
327 int inDelay; /* jitter: in jitter delay? */
328 unsigned long endDelay; /* jitter: time when delay ends */
329 int previousJitterable; /* jitterable prev value */
330 unsigned char *data; /* incoming packet data */
331};
332
333/*
334 * Permit easy lookup of keyboard events to send, versus
335 * the bitmap which comes from the tablet. This hides the
336 * issue that the F_keys are not sequentially numbered.
337 */
338static const int macroKeyEvents[] = {
339 KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
340 KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
341 KEY_F12, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17,
342 KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23,
343 KEY_F24, KEY_STOP, KEY_AGAIN, KEY_PROPS, KEY_UNDO,
344 KEY_FRONT, KEY_COPY, KEY_OPEN, KEY_PASTE, 0
345};
346
347/***********************************************************************
348 * Relative reports deliver values in 2's complement format to
349 * deal with negative offsets.
350 */
351static int aiptek_convert_from_2s_complement(unsigned char c)
352{
353 int ret;
354 unsigned char b = c;
355 int negate = 0;
356
357 if ((b & 0x80) != 0) {
358 b = ~b;
359 b--;
360 negate = 1;
361 }
362 ret = b;
363 ret = (negate == 1) ? -ret : ret;
364 return ret;
365}
366
367/***********************************************************************
368 * aiptek_irq can receive one of six potential reports.
369 * The documentation for each is in the body of the function.
370 *
371 * The tablet reports on several attributes per invocation of
372 * aiptek_irq. Because the Linux Input Event system allows the
373 * transmission of ONE attribute per input_report_xxx() call,
374 * collation has to be done on the other end to reconstitute
375 * a complete tablet report. Further, the number of Input Event reports
376 * submitted varies, depending on what USB report type, and circumstance.
377 * To deal with this, EV_MSC is used to indicate an 'end-of-report'
378 * message. This has been an undocumented convention understood by the kernel
379 * tablet driver and clients such as gpm and XFree86's tablet drivers.
380 *
381 * Of the information received from the tablet, the one piece I
382 * cannot transmit is the proximity bit (without resorting to an EV_MSC
383 * convention above.) I therefore have taken over REL_MISC and ABS_MISC
384 * (for relative and absolute reports, respectively) for communicating
385 * Proximity. Why two events? I thought it interesting to know if the
386 * Proximity event occurred while the tablet was in absolute or relative
387 * mode.
388 *
389 * Other tablets use the notion of a certain minimum stylus pressure
390 * to infer proximity. While that could have been done, that is yet
391 * another 'by convention' behavior, the documentation for which
392 * would be spread between two (or more) pieces of software.
393 *
394 * EV_MSC usage was terminated for this purpose in Linux 2.5.x, and
395 * replaced with the input_sync() method (which emits EV_SYN.)
396 */
397
398static void aiptek_irq(struct urb *urb)
399{
400 struct aiptek *aiptek = urb->context;
401 unsigned char *data = aiptek->data;
402 struct input_dev *inputdev = aiptek->inputdev;
403 int jitterable = 0;
404 int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
405
406 switch (urb->status) {
407 case 0:
408 /* Success */
409 break;
410
411 case -ECONNRESET:
412 case -ENOENT:
413 case -ESHUTDOWN:
414 /* This urb is terminated, clean up */
415 dbg("%s - urb shutting down with status: %d",
416 __FUNCTION__, urb->status);
417 return;
418
419 default:
420 dbg("%s - nonzero urb status received: %d",
421 __FUNCTION__, urb->status);
422 goto exit;
423 }
424
425 /* See if we are in a delay loop -- throw out report if true.
426 */
427 if (aiptek->inDelay == 1 && time_after(aiptek->endDelay, jiffies)) {
428 goto exit;
429 }
430
431 aiptek->inDelay = 0;
432 aiptek->eventCount++;
433
434 /* Report 1 delivers relative coordinates with either a stylus
435 * or the mouse. You do not know, however, which input
436 * tool generated the event.
437 */
438 if (data[0] == 1) {
439 if (aiptek->curSetting.coordinateMode ==
440 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
441 aiptek->diagnostic =
442 AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE;
443 } else {
444 x = aiptek_convert_from_2s_complement(data[2]);
445 y = aiptek_convert_from_2s_complement(data[3]);
446
447 /* jitterable keeps track of whether any button has been pressed.
448 * We're also using it to remap the physical mouse button mask
449 * to pseudo-settings. (We don't specifically care about it's
450 * value after moving/transposing mouse button bitmasks, except
451 * that a non-zero value indicates that one or more
452 * mouse button was pressed.)
453 */
454 jitterable = data[5] & 0x07;
455
456 left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
457 right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
458 middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
459
460 input_report_key(inputdev, BTN_LEFT, left);
461 input_report_key(inputdev, BTN_MIDDLE, middle);
462 input_report_key(inputdev, BTN_RIGHT, right);
463 input_report_rel(inputdev, REL_X, x);
464 input_report_rel(inputdev, REL_Y, y);
465 input_report_rel(inputdev, REL_MISC, 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
466
467 /* Wheel support is in the form of a single-event
468 * firing.
469 */
470 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
471 input_report_rel(inputdev, REL_WHEEL,
472 aiptek->curSetting.wheel);
473 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
474 }
475 input_sync(inputdev);
476 }
477 }
478 /* Report 2 is delivered only by the stylus, and delivers
479 * absolute coordinates.
480 */
481 else if (data[0] == 2) {
482 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
483 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
484 } else if (!AIPTEK_POINTER_ALLOW_STYLUS_MODE
485 (aiptek->curSetting.pointerMode)) {
486 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
487 } else {
488 x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
489 y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
490 z = le16_to_cpu(get_unaligned((__le16 *) (data + 6)));
491
492 p = (data[5] & 0x01) != 0 ? 1 : 0;
493 dv = (data[5] & 0x02) != 0 ? 1 : 0;
494 tip = (data[5] & 0x04) != 0 ? 1 : 0;
495
496 /* Use jitterable to re-arrange button masks
497 */
498 jitterable = data[5] & 0x18;
499
500 bs = (data[5] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
501 pck = (data[5] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
502
503 /* dv indicates 'data valid' (e.g., the tablet is in sync
504 * and has delivered a "correct" report) We will ignore
505 * all 'bad' reports...
506 */
507 if (dv != 0) {
508 /* If we've not already sent a tool_button_?? code, do
509 * so now. Then set FIRED_BIT so it won't be resent unless
510 * the user forces FIRED_BIT off.
511 */
512 if (TOOL_BUTTON_FIRED
513 (aiptek->curSetting.toolMode) == 0) {
514 input_report_key(inputdev,
515 TOOL_BUTTON(aiptek->curSetting.toolMode),
516 1);
517 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
518 }
519
520 if (p != 0) {
521 input_report_abs(inputdev, ABS_X, x);
522 input_report_abs(inputdev, ABS_Y, y);
523 input_report_abs(inputdev, ABS_PRESSURE, z);
524
525 input_report_key(inputdev, BTN_TOUCH, tip);
526 input_report_key(inputdev, BTN_STYLUS, bs);
527 input_report_key(inputdev, BTN_STYLUS2, pck);
528
529 if (aiptek->curSetting.xTilt !=
530 AIPTEK_TILT_DISABLE) {
531 input_report_abs(inputdev,
532 ABS_TILT_X,
533 aiptek->curSetting.xTilt);
534 }
535 if (aiptek->curSetting.yTilt != AIPTEK_TILT_DISABLE) {
536 input_report_abs(inputdev,
537 ABS_TILT_Y,
538 aiptek->curSetting.yTilt);
539 }
540
541 /* Wheel support is in the form of a single-event
542 * firing.
543 */
544 if (aiptek->curSetting.wheel !=
545 AIPTEK_WHEEL_DISABLE) {
546 input_report_abs(inputdev,
547 ABS_WHEEL,
548 aiptek->curSetting.wheel);
549 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
550 }
551 }
552 input_report_abs(inputdev, ABS_MISC, p | AIPTEK_REPORT_TOOL_STYLUS);
553 input_sync(inputdev);
554 }
555 }
556 }
557 /* Report 3's come from the mouse in absolute mode.
558 */
559 else if (data[0] == 3) {
560 if (aiptek->curSetting.coordinateMode == AIPTEK_COORDINATE_RELATIVE_MODE) {
561 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE;
562 } else if (!AIPTEK_POINTER_ALLOW_MOUSE_MODE
563 (aiptek->curSetting.pointerMode)) {
564 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED;
565 } else {
566 x = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
567 y = le16_to_cpu(get_unaligned((__le16 *) (data + 3)));
568
569 jitterable = data[5] & 0x1c;
570
571 p = (data[5] & 0x01) != 0 ? 1 : 0;
572 dv = (data[5] & 0x02) != 0 ? 1 : 0;
573 left = (data[5] & aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
574 right = (data[5] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
575 middle = (data[5] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
576
577 if (dv != 0) {
578 /* If we've not already sent a tool_button_?? code, do
579 * so now. Then set FIRED_BIT so it won't be resent unless
580 * the user forces FIRED_BIT off.
581 */
582 if (TOOL_BUTTON_FIRED
583 (aiptek->curSetting.toolMode) == 0) {
584 input_report_key(inputdev,
585 TOOL_BUTTON(aiptek->curSetting.toolMode),
586 1);
587 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
588 }
589
590 if (p != 0) {
591 input_report_abs(inputdev, ABS_X, x);
592 input_report_abs(inputdev, ABS_Y, y);
593
594 input_report_key(inputdev, BTN_LEFT, left);
595 input_report_key(inputdev, BTN_MIDDLE, middle);
596 input_report_key(inputdev, BTN_RIGHT, right);
597
598 /* Wheel support is in the form of a single-event
599 * firing.
600 */
601 if (aiptek->curSetting.wheel != AIPTEK_WHEEL_DISABLE) {
602 input_report_abs(inputdev,
603 ABS_WHEEL,
604 aiptek->curSetting.wheel);
605 aiptek->curSetting.wheel = AIPTEK_WHEEL_DISABLE;
606 }
607 }
608 input_report_rel(inputdev, REL_MISC, p | AIPTEK_REPORT_TOOL_MOUSE);
609 input_sync(inputdev);
610 }
611 }
612 }
613 /* Report 4s come from the macro keys when pressed by stylus
614 */
615 else if (data[0] == 4) {
616 jitterable = data[1] & 0x18;
617
618 p = (data[1] & 0x01) != 0 ? 1 : 0;
619 dv = (data[1] & 0x02) != 0 ? 1 : 0;
620 tip = (data[1] & 0x04) != 0 ? 1 : 0;
621 bs = (data[1] & aiptek->curSetting.stylusButtonLower) != 0 ? 1 : 0;
622 pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
623
624 macro = data[3];
625 z = le16_to_cpu(get_unaligned((__le16 *) (data + 4)));
626
627 if (dv != 0) {
628 /* If we've not already sent a tool_button_?? code, do
629 * so now. Then set FIRED_BIT so it won't be resent unless
630 * the user forces FIRED_BIT off.
631 */
632 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
633 input_report_key(inputdev,
634 TOOL_BUTTON(aiptek->curSetting.toolMode),
635 1);
636 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
637 }
638
639 if (p != 0) {
640 input_report_key(inputdev, BTN_TOUCH, tip);
641 input_report_key(inputdev, BTN_STYLUS, bs);
642 input_report_key(inputdev, BTN_STYLUS2, pck);
643 input_report_abs(inputdev, ABS_PRESSURE, z);
644 }
645
646 /* For safety, we're sending key 'break' codes for the
647 * neighboring macro keys.
648 */
649 if (macro > 0) {
650 input_report_key(inputdev,
651 macroKeyEvents[macro - 1], 0);
652 }
653 if (macro < 25) {
654 input_report_key(inputdev,
655 macroKeyEvents[macro + 1], 0);
656 }
657 input_report_key(inputdev, macroKeyEvents[macro], p);
658 input_report_abs(inputdev, ABS_MISC,
659 p | AIPTEK_REPORT_TOOL_STYLUS);
660 input_sync(inputdev);
661 }
662 }
663 /* Report 5s come from the macro keys when pressed by mouse
664 */
665 else if (data[0] == 5) {
666 jitterable = data[1] & 0x1c;
667
668 p = (data[1] & 0x01) != 0 ? 1 : 0;
669 dv = (data[1] & 0x02) != 0 ? 1 : 0;
670 left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
671 right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
672 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
673 macro = data[3];
674
675 if (dv != 0) {
676 /* If we've not already sent a tool_button_?? code, do
677 * so now. Then set FIRED_BIT so it won't be resent unless
678 * the user forces FIRED_BIT off.
679 */
680 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
681 input_report_key(inputdev,
682 TOOL_BUTTON(aiptek->curSetting.toolMode),
683 1);
684 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
685 }
686
687 if (p != 0) {
688 input_report_key(inputdev, BTN_LEFT, left);
689 input_report_key(inputdev, BTN_MIDDLE, middle);
690 input_report_key(inputdev, BTN_RIGHT, right);
691 }
692
693 /* For safety, we're sending key 'break' codes for the
694 * neighboring macro keys.
695 */
696 if (macro > 0) {
697 input_report_key(inputdev,
698 macroKeyEvents[macro - 1], 0);
699 }
700 if (macro < 25) {
701 input_report_key(inputdev,
702 macroKeyEvents[macro + 1], 0);
703 }
704
705 input_report_key(inputdev, macroKeyEvents[macro], 1);
706 input_report_rel(inputdev, ABS_MISC,
707 p | AIPTEK_REPORT_TOOL_MOUSE);
708 input_sync(inputdev);
709 }
710 }
711 /* We have no idea which tool can generate a report 6. Theoretically,
712 * neither need to, having been given reports 4 & 5 for such use.
713 * However, report 6 is the 'official-looking' report for macroKeys;
714 * reports 4 & 5 supposively are used to support unnamed, unknown
715 * hat switches (which just so happen to be the macroKeys.)
716 */
717 else if (data[0] == 6) {
718 macro = le16_to_cpu(get_unaligned((__le16 *) (data + 1)));
719 if (macro > 0) {
720 input_report_key(inputdev, macroKeyEvents[macro - 1],
721 0);
722 }
723 if (macro < 25) {
724 input_report_key(inputdev, macroKeyEvents[macro + 1],
725 0);
726 }
727
728 /* If we've not already sent a tool_button_?? code, do
729 * so now. Then set FIRED_BIT so it won't be resent unless
730 * the user forces FIRED_BIT off.
731 */
732 if (TOOL_BUTTON_FIRED(aiptek->curSetting.toolMode) == 0) {
733 input_report_key(inputdev,
734 TOOL_BUTTON(aiptek->curSetting.
735 toolMode), 1);
736 aiptek->curSetting.toolMode |= TOOL_BUTTON_FIRED_BIT;
737 }
738
739 input_report_key(inputdev, macroKeyEvents[macro], 1);
740 input_report_abs(inputdev, ABS_MISC,
741 1 | AIPTEK_REPORT_TOOL_UNKNOWN);
742 input_sync(inputdev);
743 } else {
744 dbg("Unknown report %d", data[0]);
745 }
746
747 /* Jitter may occur when the user presses a button on the stlyus
748 * or the mouse. What we do to prevent that is wait 'x' milliseconds
749 * following a 'jitterable' event, which should give the hand some time
750 * stabilize itself.
751 *
752 * We just introduced aiptek->previousJitterable to carry forth the
753 * notion that jitter occurs when the button state changes from on to off:
754 * a person drawing, holding a button down is not subject to jittering.
755 * With that in mind, changing from upper button depressed to lower button
756 * WILL transition through a jitter delay.
757 */
758
759 if (aiptek->previousJitterable != jitterable &&
760 aiptek->curSetting.jitterDelay != 0 && aiptek->inDelay != 1) {
761 aiptek->endDelay = jiffies +
762 ((aiptek->curSetting.jitterDelay * HZ) / 1000);
763 aiptek->inDelay = 1;
764 }
765 aiptek->previousJitterable = jitterable;
766
767exit:
768 retval = usb_submit_urb(urb, GFP_ATOMIC);
769 if (retval != 0) {
770 err("%s - usb_submit_urb failed with result %d",
771 __FUNCTION__, retval);
772 }
773}
774
775/***********************************************************************
776 * These are the USB id's known so far. We do not identify them to
777 * specific Aiptek model numbers, because there has been overlaps,
778 * use, and reuse of id's in existing models. Certain models have
779 * been known to use more than one ID, indicative perhaps of
780 * manufacturing revisions. In any event, we consider these
781 * IDs to not be model-specific nor unique.
782 */
783static const struct usb_device_id aiptek_ids[] = {
784 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x01)},
785 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x10)},
786 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20)},
787 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x21)},
788 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x22)},
789 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x23)},
790 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x24)},
791 {}
792};
793
794MODULE_DEVICE_TABLE(usb, aiptek_ids);
795
796/***********************************************************************
797 * Open an instance of the tablet driver.
798 */
799static int aiptek_open(struct input_dev *inputdev)
800{
801 struct aiptek *aiptek = input_get_drvdata(inputdev);
802
803 aiptek->urb->dev = aiptek->usbdev;
804 if (usb_submit_urb(aiptek->urb, GFP_KERNEL) != 0)
805 return -EIO;
806
807 return 0;
808}
809
810/***********************************************************************
811 * Close an instance of the tablet driver.
812 */
813static void aiptek_close(struct input_dev *inputdev)
814{
815 struct aiptek *aiptek = input_get_drvdata(inputdev);
816
817 usb_kill_urb(aiptek->urb);
818}
819
820/***********************************************************************
821 * aiptek_set_report and aiptek_get_report() are borrowed from Linux 2.4.x,
822 * where they were known as usb_set_report and usb_get_report.
823 */
824static int
825aiptek_set_report(struct aiptek *aiptek,
826 unsigned char report_type,
827 unsigned char report_id, void *buffer, int size)
828{
829 return usb_control_msg(aiptek->usbdev,
830 usb_sndctrlpipe(aiptek->usbdev, 0),
831 USB_REQ_SET_REPORT,
832 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
833 USB_DIR_OUT, (report_type << 8) + report_id,
834 aiptek->ifnum, buffer, size, 5000);
835}
836
837static int
838aiptek_get_report(struct aiptek *aiptek,
839 unsigned char report_type,
840 unsigned char report_id, void *buffer, int size)
841{
842 return usb_control_msg(aiptek->usbdev,
843 usb_rcvctrlpipe(aiptek->usbdev, 0),
844 USB_REQ_GET_REPORT,
845 USB_TYPE_CLASS | USB_RECIP_INTERFACE |
846 USB_DIR_IN, (report_type << 8) + report_id,
847 aiptek->ifnum, buffer, size, 5000);
848}
849
850/***********************************************************************
851 * Send a command to the tablet.
852 */
853static int
854aiptek_command(struct aiptek *aiptek, unsigned char command, unsigned char data)
855{
856 const int sizeof_buf = 3 * sizeof(u8);
857 int ret;
858 u8 *buf;
859
860 buf = kmalloc(sizeof_buf, GFP_KERNEL);
861 if (!buf)
862 return -ENOMEM;
863
864 buf[0] = 2;
865 buf[1] = command;
866 buf[2] = data;
867
868 if ((ret =
869 aiptek_set_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
870 dbg("aiptek_program: failed, tried to send: 0x%02x 0x%02x",
871 command, data);
872 }
873 kfree(buf);
874 return ret < 0 ? ret : 0;
875}
876
877/***********************************************************************
878 * Retrieve information from the tablet. Querying info is defined as first
879 * sending the {command,data} sequence as a command, followed by a wait
880 * (aka, "programmaticDelay") and then a "read" request.
881 */
882static int
883aiptek_query(struct aiptek *aiptek, unsigned char command, unsigned char data)
884{
885 const int sizeof_buf = 3 * sizeof(u8);
886 int ret;
887 u8 *buf;
888
889 buf = kmalloc(sizeof_buf, GFP_KERNEL);
890 if (!buf)
891 return -ENOMEM;
892
893 buf[0] = 2;
894 buf[1] = command;
895 buf[2] = data;
896
897 if (aiptek_command(aiptek, command, data) != 0) {
898 kfree(buf);
899 return -EIO;
900 }
901 msleep(aiptek->curSetting.programmableDelay);
902
903 if ((ret =
904 aiptek_get_report(aiptek, 3, 2, buf, sizeof_buf)) != sizeof_buf) {
905 dbg("aiptek_query failed: returned 0x%02x 0x%02x 0x%02x",
906 buf[0], buf[1], buf[2]);
907 ret = -EIO;
908 } else {
909 ret = le16_to_cpu(get_unaligned((__le16 *) (buf + 1)));
910 }
911 kfree(buf);
912 return ret;
913}
914
915/***********************************************************************
916 * Program the tablet into either absolute or relative mode.
917 * We also get information about the tablet's size.
918 */
919static int aiptek_program_tablet(struct aiptek *aiptek)
920{
921 int ret;
922 /* Execute Resolution500LPI */
923 if ((ret = aiptek_command(aiptek, 0x18, 0x04)) < 0)
924 return ret;
925
926 /* Query getModelCode */
927 if ((ret = aiptek_query(aiptek, 0x02, 0x00)) < 0)
928 return ret;
929 aiptek->features.modelCode = ret & 0xff;
930
931 /* Query getODMCode */
932 if ((ret = aiptek_query(aiptek, 0x03, 0x00)) < 0)
933 return ret;
934 aiptek->features.odmCode = ret;
935
936 /* Query getFirmwareCode */
937 if ((ret = aiptek_query(aiptek, 0x04, 0x00)) < 0)
938 return ret;
939 aiptek->features.firmwareCode = ret;
940
941 /* Query getXextension */
942 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
943 return ret;
944 aiptek->inputdev->absmin[ABS_X] = 0;
945 aiptek->inputdev->absmax[ABS_X] = ret - 1;
946
947 /* Query getYextension */
948 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
949 return ret;
950 aiptek->inputdev->absmin[ABS_Y] = 0;
951 aiptek->inputdev->absmax[ABS_Y] = ret - 1;
952
953 /* Query getPressureLevels */
954 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
955 return ret;
956 aiptek->inputdev->absmin[ABS_PRESSURE] = 0;
957 aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
958
959 /* Depending on whether we are in absolute or relative mode, we will
960 * do a switchToTablet(absolute) or switchToMouse(relative) command.
961 */
962 if (aiptek->curSetting.coordinateMode ==
963 AIPTEK_COORDINATE_ABSOLUTE_MODE) {
964 /* Execute switchToTablet */
965 if ((ret = aiptek_command(aiptek, 0x10, 0x01)) < 0) {
966 return ret;
967 }
968 } else {
969 /* Execute switchToMouse */
970 if ((ret = aiptek_command(aiptek, 0x10, 0x00)) < 0) {
971 return ret;
972 }
973 }
974
975 /* Enable the macro keys */
976 if ((ret = aiptek_command(aiptek, 0x11, 0x02)) < 0)
977 return ret;
978#if 0
979 /* Execute FilterOn */
980 if ((ret = aiptek_command(aiptek, 0x17, 0x00)) < 0)
981 return ret;
982#endif
983
984 /* Execute AutoGainOn */
985 if ((ret = aiptek_command(aiptek, 0x12, 0xff)) < 0)
986 return ret;
987
988 /* Reset the eventCount, so we track events from last (re)programming
989 */
990 aiptek->diagnostic = AIPTEK_DIAGNOSTIC_NA;
991 aiptek->eventCount = 0;
992
993 return 0;
994}
995
996/***********************************************************************
997 * Sysfs functions. Sysfs prefers that individually-tunable parameters
998 * exist in their separate pseudo-files. Summary data that is immutable
999 * may exist in a singular file so long as you don't define a writeable
1000 * interface.
1001 */
1002
1003/***********************************************************************
1004 * support the 'size' file -- display support
1005 */
1006static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr, char *buf)
1007{
1008 struct aiptek *aiptek = dev_get_drvdata(dev);
1009
1010 if (aiptek == NULL)
1011 return 0;
1012
1013 return snprintf(buf, PAGE_SIZE, "%dx%d\n",
1014 aiptek->inputdev->absmax[ABS_X] + 1,
1015 aiptek->inputdev->absmax[ABS_Y] + 1);
1016}
1017
1018/* These structs define the sysfs files, param #1 is the name of the
1019 * file, param 2 is the file permissions, param 3 & 4 are to the
1020 * output generator and input parser routines. Absence of a routine is
1021 * permitted -- it only means can't either 'cat' the file, or send data
1022 * to it.
1023 */
1024static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
1025
1026/***********************************************************************
1027 * support routines for the 'product_id' file
1028 */
1029static ssize_t show_tabletProductId(struct device *dev, struct device_attribute *attr, char *buf)
1030{
1031 struct aiptek *aiptek = dev_get_drvdata(dev);
1032
1033 if (aiptek == NULL)
1034 return 0;
1035
1036 return snprintf(buf, PAGE_SIZE, "0x%04x\n",
1037 aiptek->inputdev->id.product);
1038}
1039
1040static DEVICE_ATTR(product_id, S_IRUGO, show_tabletProductId, NULL);
1041
1042/***********************************************************************
1043 * support routines for the 'vendor_id' file
1044 */
1045static ssize_t show_tabletVendorId(struct device *dev, struct device_attribute *attr, char *buf)
1046{
1047 struct aiptek *aiptek = dev_get_drvdata(dev);
1048
1049 if (aiptek == NULL)
1050 return 0;
1051
1052 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->inputdev->id.vendor);
1053}
1054
1055static DEVICE_ATTR(vendor_id, S_IRUGO, show_tabletVendorId, NULL);
1056
1057/***********************************************************************
1058 * support routines for the 'vendor' file
1059 */
1060static ssize_t show_tabletManufacturer(struct device *dev, struct device_attribute *attr, char *buf)
1061{
1062 struct aiptek *aiptek = dev_get_drvdata(dev);
1063 int retval;
1064
1065 if (aiptek == NULL)
1066 return 0;
1067
1068 retval = snprintf(buf, PAGE_SIZE, "%s\n", aiptek->usbdev->manufacturer);
1069 return retval;
1070}
1071
1072static DEVICE_ATTR(vendor, S_IRUGO, show_tabletManufacturer, NULL);
1073
1074/***********************************************************************
1075 * support routines for the 'product' file
1076 */
1077static ssize_t show_tabletProduct(struct device *dev, struct device_attribute *attr, char *buf)
1078{
1079 struct aiptek *aiptek = dev_get_drvdata(dev);
1080 int retval;
1081
1082 if (aiptek == NULL)
1083 return 0;
1084
1085 retval = snprintf(buf, PAGE_SIZE, "%s\n", aiptek->usbdev->product);
1086 return retval;
1087}
1088
1089static DEVICE_ATTR(product, S_IRUGO, show_tabletProduct, NULL);
1090
1091/***********************************************************************
1092 * support routines for the 'pointer_mode' file. Note that this file
1093 * both displays current setting and allows reprogramming.
1094 */
1095static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
1096{
1097 struct aiptek *aiptek = dev_get_drvdata(dev);
1098 char *s;
1099
1100 if (aiptek == NULL)
1101 return 0;
1102
1103 switch (aiptek->curSetting.pointerMode) {
1104 case AIPTEK_POINTER_ONLY_STYLUS_MODE:
1105 s = "stylus";
1106 break;
1107
1108 case AIPTEK_POINTER_ONLY_MOUSE_MODE:
1109 s = "mouse";
1110 break;
1111
1112 case AIPTEK_POINTER_EITHER_MODE:
1113 s = "either";
1114 break;
1115
1116 default:
1117 s = "unknown";
1118 break;
1119 }
1120 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1121}
1122
1123static ssize_t
1124store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1125{
1126 struct aiptek *aiptek = dev_get_drvdata(dev);
1127 if (aiptek == NULL)
1128 return 0;
1129
1130 if (strcmp(buf, "stylus") == 0) {
1131 aiptek->newSetting.pointerMode =
1132 AIPTEK_POINTER_ONLY_STYLUS_MODE;
1133 } else if (strcmp(buf, "mouse") == 0) {
1134 aiptek->newSetting.pointerMode = AIPTEK_POINTER_ONLY_MOUSE_MODE;
1135 } else if (strcmp(buf, "either") == 0) {
1136 aiptek->newSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
1137 }
1138 return count;
1139}
1140
1141static DEVICE_ATTR(pointer_mode,
1142 S_IRUGO | S_IWUGO,
1143 show_tabletPointerMode, store_tabletPointerMode);
1144
1145/***********************************************************************
1146 * support routines for the 'coordinate_mode' file. Note that this file
1147 * both displays current setting and allows reprogramming.
1148 */
1149static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
1150{
1151 struct aiptek *aiptek = dev_get_drvdata(dev);
1152 char *s;
1153
1154 if (aiptek == NULL)
1155 return 0;
1156
1157 switch (aiptek->curSetting.coordinateMode) {
1158 case AIPTEK_COORDINATE_ABSOLUTE_MODE:
1159 s = "absolute";
1160 break;
1161
1162 case AIPTEK_COORDINATE_RELATIVE_MODE:
1163 s = "relative";
1164 break;
1165
1166 default:
1167 s = "unknown";
1168 break;
1169 }
1170 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1171}
1172
1173static ssize_t
1174store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1175{
1176 struct aiptek *aiptek = dev_get_drvdata(dev);
1177 if (aiptek == NULL)
1178 return 0;
1179
1180 if (strcmp(buf, "absolute") == 0) {
1181 aiptek->newSetting.pointerMode =
1182 AIPTEK_COORDINATE_ABSOLUTE_MODE;
1183 } else if (strcmp(buf, "relative") == 0) {
1184 aiptek->newSetting.pointerMode =
1185 AIPTEK_COORDINATE_RELATIVE_MODE;
1186 }
1187 return count;
1188}
1189
1190static DEVICE_ATTR(coordinate_mode,
1191 S_IRUGO | S_IWUGO,
1192 show_tabletCoordinateMode, store_tabletCoordinateMode);
1193
1194/***********************************************************************
1195 * support routines for the 'tool_mode' file. Note that this file
1196 * both displays current setting and allows reprogramming.
1197 */
1198static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
1199{
1200 struct aiptek *aiptek = dev_get_drvdata(dev);
1201 char *s;
1202
1203 if (aiptek == NULL)
1204 return 0;
1205
1206 switch (TOOL_BUTTON(aiptek->curSetting.toolMode)) {
1207 case AIPTEK_TOOL_BUTTON_MOUSE_MODE:
1208 s = "mouse";
1209 break;
1210
1211 case AIPTEK_TOOL_BUTTON_ERASER_MODE:
1212 s = "eraser";
1213 break;
1214
1215 case AIPTEK_TOOL_BUTTON_PENCIL_MODE:
1216 s = "pencil";
1217 break;
1218
1219 case AIPTEK_TOOL_BUTTON_PEN_MODE:
1220 s = "pen";
1221 break;
1222
1223 case AIPTEK_TOOL_BUTTON_BRUSH_MODE:
1224 s = "brush";
1225 break;
1226
1227 case AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE:
1228 s = "airbrush";
1229 break;
1230
1231 case AIPTEK_TOOL_BUTTON_LENS_MODE:
1232 s = "lens";
1233 break;
1234
1235 default:
1236 s = "unknown";
1237 break;
1238 }
1239 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1240}
1241
1242static ssize_t
1243store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1244{
1245 struct aiptek *aiptek = dev_get_drvdata(dev);
1246 if (aiptek == NULL)
1247 return 0;
1248
1249 if (strcmp(buf, "mouse") == 0) {
1250 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_MOUSE_MODE;
1251 } else if (strcmp(buf, "eraser") == 0) {
1252 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_ERASER_MODE;
1253 } else if (strcmp(buf, "pencil") == 0) {
1254 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PENCIL_MODE;
1255 } else if (strcmp(buf, "pen") == 0) {
1256 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
1257 } else if (strcmp(buf, "brush") == 0) {
1258 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_BRUSH_MODE;
1259 } else if (strcmp(buf, "airbrush") == 0) {
1260 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE;
1261 } else if (strcmp(buf, "lens") == 0) {
1262 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_LENS_MODE;
1263 }
1264
1265 return count;
1266}
1267
1268static DEVICE_ATTR(tool_mode,
1269 S_IRUGO | S_IWUGO,
1270 show_tabletToolMode, store_tabletToolMode);
1271
1272/***********************************************************************
1273 * support routines for the 'xtilt' file. Note that this file
1274 * both displays current setting and allows reprogramming.
1275 */
1276static ssize_t show_tabletXtilt(struct device *dev, struct device_attribute *attr, char *buf)
1277{
1278 struct aiptek *aiptek = dev_get_drvdata(dev);
1279
1280 if (aiptek == NULL)
1281 return 0;
1282
1283 if (aiptek->curSetting.xTilt == AIPTEK_TILT_DISABLE) {
1284 return snprintf(buf, PAGE_SIZE, "disable\n");
1285 } else {
1286 return snprintf(buf, PAGE_SIZE, "%d\n",
1287 aiptek->curSetting.xTilt);
1288 }
1289}
1290
1291static ssize_t
1292store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1293{
1294 struct aiptek *aiptek = dev_get_drvdata(dev);
1295 int x;
1296
1297 if (aiptek == NULL)
1298 return 0;
1299
1300 if (strcmp(buf, "disable") == 0) {
1301 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
1302 } else {
1303 x = (int)simple_strtol(buf, NULL, 10);
1304 if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) {
1305 aiptek->newSetting.xTilt = x;
1306 }
1307 }
1308 return count;
1309}
1310
1311static DEVICE_ATTR(xtilt,
1312 S_IRUGO | S_IWUGO, show_tabletXtilt, store_tabletXtilt);
1313
1314/***********************************************************************
1315 * support routines for the 'ytilt' file. Note that this file
1316 * both displays current setting and allows reprogramming.
1317 */
1318static ssize_t show_tabletYtilt(struct device *dev, struct device_attribute *attr, char *buf)
1319{
1320 struct aiptek *aiptek = dev_get_drvdata(dev);
1321
1322 if (aiptek == NULL)
1323 return 0;
1324
1325 if (aiptek->curSetting.yTilt == AIPTEK_TILT_DISABLE) {
1326 return snprintf(buf, PAGE_SIZE, "disable\n");
1327 } else {
1328 return snprintf(buf, PAGE_SIZE, "%d\n",
1329 aiptek->curSetting.yTilt);
1330 }
1331}
1332
1333static ssize_t
1334store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1335{
1336 struct aiptek *aiptek = dev_get_drvdata(dev);
1337 int y;
1338
1339 if (aiptek == NULL)
1340 return 0;
1341
1342 if (strcmp(buf, "disable") == 0) {
1343 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
1344 } else {
1345 y = (int)simple_strtol(buf, NULL, 10);
1346 if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) {
1347 aiptek->newSetting.yTilt = y;
1348 }
1349 }
1350 return count;
1351}
1352
1353static DEVICE_ATTR(ytilt,
1354 S_IRUGO | S_IWUGO, show_tabletYtilt, store_tabletYtilt);
1355
1356/***********************************************************************
1357 * support routines for the 'jitter' file. Note that this file
1358 * both displays current setting and allows reprogramming.
1359 */
1360static ssize_t show_tabletJitterDelay(struct device *dev, struct device_attribute *attr, char *buf)
1361{
1362 struct aiptek *aiptek = dev_get_drvdata(dev);
1363
1364 if (aiptek == NULL)
1365 return 0;
1366
1367 return snprintf(buf, PAGE_SIZE, "%d\n", aiptek->curSetting.jitterDelay);
1368}
1369
1370static ssize_t
1371store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1372{
1373 struct aiptek *aiptek = dev_get_drvdata(dev);
1374
1375 if (aiptek == NULL)
1376 return 0;
1377
1378 aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10);
1379 return count;
1380}
1381
1382static DEVICE_ATTR(jitter,
1383 S_IRUGO | S_IWUGO,
1384 show_tabletJitterDelay, store_tabletJitterDelay);
1385
1386/***********************************************************************
1387 * support routines for the 'delay' file. Note that this file
1388 * both displays current setting and allows reprogramming.
1389 */
1390static ssize_t show_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, char *buf)
1391{
1392 struct aiptek *aiptek = dev_get_drvdata(dev);
1393
1394 if (aiptek == NULL)
1395 return 0;
1396
1397 return snprintf(buf, PAGE_SIZE, "%d\n",
1398 aiptek->curSetting.programmableDelay);
1399}
1400
1401static ssize_t
1402store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1403{
1404 struct aiptek *aiptek = dev_get_drvdata(dev);
1405
1406 if (aiptek == NULL)
1407 return 0;
1408
1409 aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10);
1410 return count;
1411}
1412
1413static DEVICE_ATTR(delay,
1414 S_IRUGO | S_IWUGO,
1415 show_tabletProgrammableDelay, store_tabletProgrammableDelay);
1416
1417/***********************************************************************
1418 * support routines for the 'input_path' file. Note that this file
1419 * only displays current setting.
1420 */
1421static ssize_t show_tabletInputDevice(struct device *dev, struct device_attribute *attr, char *buf)
1422{
1423 struct aiptek *aiptek = dev_get_drvdata(dev);
1424
1425 if (aiptek == NULL)
1426 return 0;
1427
1428 return snprintf(buf, PAGE_SIZE, "/dev/input/%s\n",
1429 aiptek->features.inputPath);
1430}
1431
1432static DEVICE_ATTR(input_path, S_IRUGO, show_tabletInputDevice, NULL);
1433
1434/***********************************************************************
1435 * support routines for the 'event_count' file. Note that this file
1436 * only displays current setting.
1437 */
1438static ssize_t show_tabletEventsReceived(struct device *dev, struct device_attribute *attr, char *buf)
1439{
1440 struct aiptek *aiptek = dev_get_drvdata(dev);
1441
1442 if (aiptek == NULL)
1443 return 0;
1444
1445 return snprintf(buf, PAGE_SIZE, "%ld\n", aiptek->eventCount);
1446}
1447
1448static DEVICE_ATTR(event_count, S_IRUGO, show_tabletEventsReceived, NULL);
1449
1450/***********************************************************************
1451 * support routines for the 'diagnostic' file. Note that this file
1452 * only displays current setting.
1453 */
1454static ssize_t show_tabletDiagnosticMessage(struct device *dev, struct device_attribute *attr, char *buf)
1455{
1456 struct aiptek *aiptek = dev_get_drvdata(dev);
1457 char *retMsg;
1458
1459 if (aiptek == NULL)
1460 return 0;
1461
1462 switch (aiptek->diagnostic) {
1463 case AIPTEK_DIAGNOSTIC_NA:
1464 retMsg = "no errors\n";
1465 break;
1466
1467 case AIPTEK_DIAGNOSTIC_SENDING_RELATIVE_IN_ABSOLUTE:
1468 retMsg = "Error: receiving relative reports\n";
1469 break;
1470
1471 case AIPTEK_DIAGNOSTIC_SENDING_ABSOLUTE_IN_RELATIVE:
1472 retMsg = "Error: receiving absolute reports\n";
1473 break;
1474
1475 case AIPTEK_DIAGNOSTIC_TOOL_DISALLOWED:
1476 if (aiptek->curSetting.pointerMode ==
1477 AIPTEK_POINTER_ONLY_MOUSE_MODE) {
1478 retMsg = "Error: receiving stylus reports\n";
1479 } else {
1480 retMsg = "Error: receiving mouse reports\n";
1481 }
1482 break;
1483
1484 default:
1485 return 0;
1486 }
1487 return snprintf(buf, PAGE_SIZE, retMsg);
1488}
1489
1490static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
1491
1492/***********************************************************************
1493 * support routines for the 'stylus_upper' file. Note that this file
1494 * both displays current setting and allows for setting changing.
1495 */
1496static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
1497{
1498 struct aiptek *aiptek = dev_get_drvdata(dev);
1499 char *s;
1500
1501 if (aiptek == NULL)
1502 return 0;
1503
1504 switch (aiptek->curSetting.stylusButtonUpper) {
1505 case AIPTEK_STYLUS_UPPER_BUTTON:
1506 s = "upper";
1507 break;
1508
1509 case AIPTEK_STYLUS_LOWER_BUTTON:
1510 s = "lower";
1511 break;
1512
1513 default:
1514 s = "unknown";
1515 break;
1516 }
1517 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1518}
1519
1520static ssize_t
1521store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1522{
1523 struct aiptek *aiptek = dev_get_drvdata(dev);
1524
1525 if (aiptek == NULL)
1526 return 0;
1527
1528 if (strcmp(buf, "upper") == 0) {
1529 aiptek->newSetting.stylusButtonUpper =
1530 AIPTEK_STYLUS_UPPER_BUTTON;
1531 } else if (strcmp(buf, "lower") == 0) {
1532 aiptek->newSetting.stylusButtonUpper =
1533 AIPTEK_STYLUS_LOWER_BUTTON;
1534 }
1535 return count;
1536}
1537
1538static DEVICE_ATTR(stylus_upper,
1539 S_IRUGO | S_IWUGO,
1540 show_tabletStylusUpper, store_tabletStylusUpper);
1541
1542/***********************************************************************
1543 * support routines for the 'stylus_lower' file. Note that this file
1544 * both displays current setting and allows for setting changing.
1545 */
1546static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
1547{
1548 struct aiptek *aiptek = dev_get_drvdata(dev);
1549 char *s;
1550
1551 if (aiptek == NULL)
1552 return 0;
1553
1554 switch (aiptek->curSetting.stylusButtonLower) {
1555 case AIPTEK_STYLUS_UPPER_BUTTON:
1556 s = "upper";
1557 break;
1558
1559 case AIPTEK_STYLUS_LOWER_BUTTON:
1560 s = "lower";
1561 break;
1562
1563 default:
1564 s = "unknown";
1565 break;
1566 }
1567 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1568}
1569
1570static ssize_t
1571store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1572{
1573 struct aiptek *aiptek = dev_get_drvdata(dev);
1574
1575 if (aiptek == NULL)
1576 return 0;
1577
1578 if (strcmp(buf, "upper") == 0) {
1579 aiptek->newSetting.stylusButtonLower =
1580 AIPTEK_STYLUS_UPPER_BUTTON;
1581 } else if (strcmp(buf, "lower") == 0) {
1582 aiptek->newSetting.stylusButtonLower =
1583 AIPTEK_STYLUS_LOWER_BUTTON;
1584 }
1585 return count;
1586}
1587
1588static DEVICE_ATTR(stylus_lower,
1589 S_IRUGO | S_IWUGO,
1590 show_tabletStylusLower, store_tabletStylusLower);
1591
1592/***********************************************************************
1593 * support routines for the 'mouse_left' file. Note that this file
1594 * both displays current setting and allows for setting changing.
1595 */
1596static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
1597{
1598 struct aiptek *aiptek = dev_get_drvdata(dev);
1599 char *s;
1600
1601 if (aiptek == NULL)
1602 return 0;
1603
1604 switch (aiptek->curSetting.mouseButtonLeft) {
1605 case AIPTEK_MOUSE_LEFT_BUTTON:
1606 s = "left";
1607 break;
1608
1609 case AIPTEK_MOUSE_MIDDLE_BUTTON:
1610 s = "middle";
1611 break;
1612
1613 case AIPTEK_MOUSE_RIGHT_BUTTON:
1614 s = "right";
1615 break;
1616
1617 default:
1618 s = "unknown";
1619 break;
1620 }
1621 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1622}
1623
1624static ssize_t
1625store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1626{
1627 struct aiptek *aiptek = dev_get_drvdata(dev);
1628
1629 if (aiptek == NULL)
1630 return 0;
1631
1632 if (strcmp(buf, "left") == 0) {
1633 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
1634 } else if (strcmp(buf, "middle") == 0) {
1635 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_MIDDLE_BUTTON;
1636 } else if (strcmp(buf, "right") == 0) {
1637 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_RIGHT_BUTTON;
1638 }
1639 return count;
1640}
1641
1642static DEVICE_ATTR(mouse_left,
1643 S_IRUGO | S_IWUGO,
1644 show_tabletMouseLeft, store_tabletMouseLeft);
1645
1646/***********************************************************************
1647 * support routines for the 'mouse_middle' file. Note that this file
1648 * both displays current setting and allows for setting changing.
1649 */
1650static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
1651{
1652 struct aiptek *aiptek = dev_get_drvdata(dev);
1653 char *s;
1654
1655 if (aiptek == NULL)
1656 return 0;
1657
1658 switch (aiptek->curSetting.mouseButtonMiddle) {
1659 case AIPTEK_MOUSE_LEFT_BUTTON:
1660 s = "left";
1661 break;
1662
1663 case AIPTEK_MOUSE_MIDDLE_BUTTON:
1664 s = "middle";
1665 break;
1666
1667 case AIPTEK_MOUSE_RIGHT_BUTTON:
1668 s = "right";
1669 break;
1670
1671 default:
1672 s = "unknown";
1673 break;
1674 }
1675 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1676}
1677
1678static ssize_t
1679store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1680{
1681 struct aiptek *aiptek = dev_get_drvdata(dev);
1682
1683 if (aiptek == NULL)
1684 return 0;
1685
1686 if (strcmp(buf, "left") == 0) {
1687 aiptek->newSetting.mouseButtonMiddle = AIPTEK_MOUSE_LEFT_BUTTON;
1688 } else if (strcmp(buf, "middle") == 0) {
1689 aiptek->newSetting.mouseButtonMiddle =
1690 AIPTEK_MOUSE_MIDDLE_BUTTON;
1691 } else if (strcmp(buf, "right") == 0) {
1692 aiptek->newSetting.mouseButtonMiddle =
1693 AIPTEK_MOUSE_RIGHT_BUTTON;
1694 }
1695 return count;
1696}
1697
1698static DEVICE_ATTR(mouse_middle,
1699 S_IRUGO | S_IWUGO,
1700 show_tabletMouseMiddle, store_tabletMouseMiddle);
1701
1702/***********************************************************************
1703 * support routines for the 'mouse_right' file. Note that this file
1704 * both displays current setting and allows for setting changing.
1705 */
1706static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
1707{
1708 struct aiptek *aiptek = dev_get_drvdata(dev);
1709 char *s;
1710
1711 if (aiptek == NULL)
1712 return 0;
1713
1714 switch (aiptek->curSetting.mouseButtonRight) {
1715 case AIPTEK_MOUSE_LEFT_BUTTON:
1716 s = "left";
1717 break;
1718
1719 case AIPTEK_MOUSE_MIDDLE_BUTTON:
1720 s = "middle";
1721 break;
1722
1723 case AIPTEK_MOUSE_RIGHT_BUTTON:
1724 s = "right";
1725 break;
1726
1727 default:
1728 s = "unknown";
1729 break;
1730 }
1731 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1732}
1733
1734static ssize_t
1735store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1736{
1737 struct aiptek *aiptek = dev_get_drvdata(dev);
1738
1739 if (aiptek == NULL)
1740 return 0;
1741
1742 if (strcmp(buf, "left") == 0) {
1743 aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_LEFT_BUTTON;
1744 } else if (strcmp(buf, "middle") == 0) {
1745 aiptek->newSetting.mouseButtonRight =
1746 AIPTEK_MOUSE_MIDDLE_BUTTON;
1747 } else if (strcmp(buf, "right") == 0) {
1748 aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
1749 }
1750 return count;
1751}
1752
1753static DEVICE_ATTR(mouse_right,
1754 S_IRUGO | S_IWUGO,
1755 show_tabletMouseRight, store_tabletMouseRight);
1756
1757/***********************************************************************
1758 * support routines for the 'wheel' file. Note that this file
1759 * both displays current setting and allows for setting changing.
1760 */
1761static ssize_t show_tabletWheel(struct device *dev, struct device_attribute *attr, char *buf)
1762{
1763 struct aiptek *aiptek = dev_get_drvdata(dev);
1764
1765 if (aiptek == NULL)
1766 return 0;
1767
1768 if (aiptek->curSetting.wheel == AIPTEK_WHEEL_DISABLE) {
1769 return snprintf(buf, PAGE_SIZE, "disable\n");
1770 } else {
1771 return snprintf(buf, PAGE_SIZE, "%d\n",
1772 aiptek->curSetting.wheel);
1773 }
1774}
1775
1776static ssize_t
1777store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1778{
1779 struct aiptek *aiptek = dev_get_drvdata(dev);
1780
1781 if (aiptek == NULL)
1782 return 0;
1783
1784 aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10);
1785 return count;
1786}
1787
1788static DEVICE_ATTR(wheel,
1789 S_IRUGO | S_IWUGO, show_tabletWheel, store_tabletWheel);
1790
1791/***********************************************************************
1792 * support routines for the 'execute' file. Note that this file
1793 * both displays current setting and allows for setting changing.
1794 */
1795static ssize_t show_tabletExecute(struct device *dev, struct device_attribute *attr, char *buf)
1796{
1797 struct aiptek *aiptek = dev_get_drvdata(dev);
1798
1799 if (aiptek == NULL)
1800 return 0;
1801
1802 /* There is nothing useful to display, so a one-line manual
1803 * is in order...
1804 */
1805 return snprintf(buf, PAGE_SIZE,
1806 "Write anything to this file to program your tablet.\n");
1807}
1808
1809static ssize_t
1810store_tabletExecute(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1811{
1812 struct aiptek *aiptek = dev_get_drvdata(dev);
1813
1814 if (aiptek == NULL)
1815 return 0;
1816
1817 /* We do not care what you write to this file. Merely the action
1818 * of writing to this file triggers a tablet reprogramming.
1819 */
1820 memcpy(&aiptek->curSetting, &aiptek->newSetting,
1821 sizeof(struct aiptek_settings));
1822
1823 if (aiptek_program_tablet(aiptek) < 0)
1824 return -EIO;
1825
1826 return count;
1827}
1828
1829static DEVICE_ATTR(execute,
1830 S_IRUGO | S_IWUGO, show_tabletExecute, store_tabletExecute);
1831
1832/***********************************************************************
1833 * support routines for the 'odm_code' file. Note that this file
1834 * only displays current setting.
1835 */
1836static ssize_t show_tabletODMCode(struct device *dev, struct device_attribute *attr, char *buf)
1837{
1838 struct aiptek *aiptek = dev_get_drvdata(dev);
1839
1840 if (aiptek == NULL)
1841 return 0;
1842
1843 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.odmCode);
1844}
1845
1846static DEVICE_ATTR(odm_code, S_IRUGO, show_tabletODMCode, NULL);
1847
1848/***********************************************************************
1849 * support routines for the 'model_code' file. Note that this file
1850 * only displays current setting.
1851 */
1852static ssize_t show_tabletModelCode(struct device *dev, struct device_attribute *attr, char *buf)
1853{
1854 struct aiptek *aiptek = dev_get_drvdata(dev);
1855
1856 if (aiptek == NULL)
1857 return 0;
1858
1859 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->features.modelCode);
1860}
1861
1862static DEVICE_ATTR(model_code, S_IRUGO, show_tabletModelCode, NULL);
1863
1864/***********************************************************************
1865 * support routines for the 'firmware_code' file. Note that this file
1866 * only displays current setting.
1867 */
1868static ssize_t show_firmwareCode(struct device *dev, struct device_attribute *attr, char *buf)
1869{
1870 struct aiptek *aiptek = dev_get_drvdata(dev);
1871
1872 if (aiptek == NULL)
1873 return 0;
1874
1875 return snprintf(buf, PAGE_SIZE, "%04x\n",
1876 aiptek->features.firmwareCode);
1877}
1878
1879static DEVICE_ATTR(firmware_code, S_IRUGO, show_firmwareCode, NULL);
1880
1881/***********************************************************************
1882 * This routine removes all existing sysfs files managed by this device
1883 * driver.
1884 */
1885static void aiptek_delete_files(struct device *dev)
1886{
1887 device_remove_file(dev, &dev_attr_size);
1888 device_remove_file(dev, &dev_attr_product_id);
1889 device_remove_file(dev, &dev_attr_vendor_id);
1890 device_remove_file(dev, &dev_attr_vendor);
1891 device_remove_file(dev, &dev_attr_product);
1892 device_remove_file(dev, &dev_attr_pointer_mode);
1893 device_remove_file(dev, &dev_attr_coordinate_mode);
1894 device_remove_file(dev, &dev_attr_tool_mode);
1895 device_remove_file(dev, &dev_attr_xtilt);
1896 device_remove_file(dev, &dev_attr_ytilt);
1897 device_remove_file(dev, &dev_attr_jitter);
1898 device_remove_file(dev, &dev_attr_delay);
1899 device_remove_file(dev, &dev_attr_input_path);
1900 device_remove_file(dev, &dev_attr_event_count);
1901 device_remove_file(dev, &dev_attr_diagnostic);
1902 device_remove_file(dev, &dev_attr_odm_code);
1903 device_remove_file(dev, &dev_attr_model_code);
1904 device_remove_file(dev, &dev_attr_firmware_code);
1905 device_remove_file(dev, &dev_attr_stylus_lower);
1906 device_remove_file(dev, &dev_attr_stylus_upper);
1907 device_remove_file(dev, &dev_attr_mouse_left);
1908 device_remove_file(dev, &dev_attr_mouse_middle);
1909 device_remove_file(dev, &dev_attr_mouse_right);
1910 device_remove_file(dev, &dev_attr_wheel);
1911 device_remove_file(dev, &dev_attr_execute);
1912}
1913
1914/***********************************************************************
1915 * This routine creates the sysfs files managed by this device
1916 * driver.
1917 */
1918static int aiptek_add_files(struct device *dev)
1919{
1920 int ret;
1921
1922 if ((ret = device_create_file(dev, &dev_attr_size)) ||
1923 (ret = device_create_file(dev, &dev_attr_product_id)) ||
1924 (ret = device_create_file(dev, &dev_attr_vendor_id)) ||
1925 (ret = device_create_file(dev, &dev_attr_vendor)) ||
1926 (ret = device_create_file(dev, &dev_attr_product)) ||
1927 (ret = device_create_file(dev, &dev_attr_pointer_mode)) ||
1928 (ret = device_create_file(dev, &dev_attr_coordinate_mode)) ||
1929 (ret = device_create_file(dev, &dev_attr_tool_mode)) ||
1930 (ret = device_create_file(dev, &dev_attr_xtilt)) ||
1931 (ret = device_create_file(dev, &dev_attr_ytilt)) ||
1932 (ret = device_create_file(dev, &dev_attr_jitter)) ||
1933 (ret = device_create_file(dev, &dev_attr_delay)) ||
1934 (ret = device_create_file(dev, &dev_attr_input_path)) ||
1935 (ret = device_create_file(dev, &dev_attr_event_count)) ||
1936 (ret = device_create_file(dev, &dev_attr_diagnostic)) ||
1937 (ret = device_create_file(dev, &dev_attr_odm_code)) ||
1938 (ret = device_create_file(dev, &dev_attr_model_code)) ||
1939 (ret = device_create_file(dev, &dev_attr_firmware_code)) ||
1940 (ret = device_create_file(dev, &dev_attr_stylus_lower)) ||
1941 (ret = device_create_file(dev, &dev_attr_stylus_upper)) ||
1942 (ret = device_create_file(dev, &dev_attr_mouse_left)) ||
1943 (ret = device_create_file(dev, &dev_attr_mouse_middle)) ||
1944 (ret = device_create_file(dev, &dev_attr_mouse_right)) ||
1945 (ret = device_create_file(dev, &dev_attr_wheel)) ||
1946 (ret = device_create_file(dev, &dev_attr_execute))) {
1947 err("aiptek: killing own sysfs device files\n");
1948 aiptek_delete_files(dev);
1949 }
1950 return ret;
1951}
1952
1953/***********************************************************************
1954 * This routine is called when a tablet has been identified. It basically
1955 * sets up the tablet and the driver's internal structures.
1956 */
1957static int
1958aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1959{
1960 struct usb_device *usbdev = interface_to_usbdev(intf);
1961 struct usb_endpoint_descriptor *endpoint;
1962 struct aiptek *aiptek;
1963 struct input_dev *inputdev;
1964 struct input_handle *inputhandle;
1965 struct list_head *node, *next;
1966 int i;
1967 int speeds[] = { 0,
1968 AIPTEK_PROGRAMMABLE_DELAY_50,
1969 AIPTEK_PROGRAMMABLE_DELAY_400,
1970 AIPTEK_PROGRAMMABLE_DELAY_25,
1971 AIPTEK_PROGRAMMABLE_DELAY_100,
1972 AIPTEK_PROGRAMMABLE_DELAY_200,
1973 AIPTEK_PROGRAMMABLE_DELAY_300
1974 };
1975 int err = -ENOMEM;
1976
1977 /* programmableDelay is where the command-line specified
1978 * delay is kept. We make it the first element of speeds[],
1979 * so therefore, your override speed is tried first, then the
1980 * remainder. Note that the default value of 400ms will be tried
1981 * if you do not specify any command line parameter.
1982 */
1983 speeds[0] = programmableDelay;
1984
1985 aiptek = kzalloc(sizeof(struct aiptek), GFP_KERNEL);
1986 inputdev = input_allocate_device();
1987 if (!aiptek || !inputdev)
1988 goto fail1;
1989
1990 aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
1991 GFP_ATOMIC, &aiptek->data_dma);
1992 if (!aiptek->data)
1993 goto fail1;
1994
1995 aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
1996 if (!aiptek->urb)
1997 goto fail2;
1998
1999 aiptek->inputdev = inputdev;
2000 aiptek->usbdev = usbdev;
2001 aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
2002 aiptek->inDelay = 0;
2003 aiptek->endDelay = 0;
2004 aiptek->previousJitterable = 0;
2005
2006 /* Set up the curSettings struct. Said struct contains the current
2007 * programmable parameters. The newSetting struct contains changes
2008 * the user makes to the settings via the sysfs interface. Those
2009 * changes are not "committed" to curSettings until the user
2010 * writes to the sysfs/.../execute file.
2011 */
2012 aiptek->curSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
2013 aiptek->curSetting.coordinateMode = AIPTEK_COORDINATE_ABSOLUTE_MODE;
2014 aiptek->curSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
2015 aiptek->curSetting.xTilt = AIPTEK_TILT_DISABLE;
2016 aiptek->curSetting.yTilt = AIPTEK_TILT_DISABLE;
2017 aiptek->curSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON;
2018 aiptek->curSetting.mouseButtonMiddle = AIPTEK_MOUSE_MIDDLE_BUTTON;
2019 aiptek->curSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
2020 aiptek->curSetting.stylusButtonUpper = AIPTEK_STYLUS_UPPER_BUTTON;
2021 aiptek->curSetting.stylusButtonLower = AIPTEK_STYLUS_LOWER_BUTTON;
2022 aiptek->curSetting.jitterDelay = jitterDelay;
2023 aiptek->curSetting.programmableDelay = programmableDelay;
2024
2025 /* Both structs should have equivalent settings
2026 */
2027 aiptek->newSetting = aiptek->curSetting;
2028
2029 /* Determine the usb devices' physical path.
2030 * Asketh not why we always pretend we're using "../input0",
2031 * but I suspect this will have to be refactored one
2032 * day if a single USB device can be a keyboard & a mouse
2033 * & a tablet, and the inputX number actually will tell
2034 * us something...
2035 */
2036 usb_make_path(usbdev, aiptek->features.usbPath,
2037 sizeof(aiptek->features.usbPath));
2038 strlcat(aiptek->features.usbPath, "/input0",
2039 sizeof(aiptek->features.usbPath));
2040
2041 /* Set up client data, pointers to open and close routines
2042 * for the input device.
2043 */
2044 inputdev->name = "Aiptek";
2045 inputdev->phys = aiptek->features.usbPath;
2046 usb_to_input_id(usbdev, &inputdev->id);
2047 inputdev->dev.parent = &intf->dev;
2048
2049 input_set_drvdata(inputdev, aiptek);
2050
2051 inputdev->open = aiptek_open;
2052 inputdev->close = aiptek_close;
2053
2054 /* Now program the capacities of the tablet, in terms of being
2055 * an input device.
2056 */
2057 inputdev->evbit[0] |= BIT(EV_KEY)
2058 | BIT(EV_ABS)
2059 | BIT(EV_REL)
2060 | BIT(EV_MSC);
2061
2062 inputdev->absbit[0] |= BIT(ABS_MISC);
2063
2064 inputdev->relbit[0] |=
2065 (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC));
2066
2067 inputdev->keybit[LONG(BTN_LEFT)] |=
2068 (BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE));
2069
2070 inputdev->keybit[LONG(BTN_DIGI)] |=
2071 (BIT(BTN_TOOL_PEN) |
2072 BIT(BTN_TOOL_RUBBER) |
2073 BIT(BTN_TOOL_PENCIL) |
2074 BIT(BTN_TOOL_AIRBRUSH) |
2075 BIT(BTN_TOOL_BRUSH) |
2076 BIT(BTN_TOOL_MOUSE) |
2077 BIT(BTN_TOOL_LENS) |
2078 BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2));
2079
2080 inputdev->mscbit[0] = BIT(MSC_SERIAL);
2081
2082 /* Programming the tablet macro keys needs to be done with a for loop
2083 * as the keycodes are discontiguous.
2084 */
2085 for (i = 0; i < ARRAY_SIZE(macroKeyEvents); ++i)
2086 set_bit(macroKeyEvents[i], inputdev->keybit);
2087
2088 /*
2089 * Program the input device coordinate capacities. We do not yet
2090 * know what maximum X, Y, and Z values are, so we're putting fake
2091 * values in. Later, we'll ask the tablet to put in the correct
2092 * values.
2093 */
2094 input_set_abs_params(inputdev, ABS_X, 0, 2999, 0, 0);
2095 input_set_abs_params(inputdev, ABS_Y, 0, 2249, 0, 0);
2096 input_set_abs_params(inputdev, ABS_PRESSURE, 0, 511, 0, 0);
2097 input_set_abs_params(inputdev, ABS_TILT_X, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
2098 input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
2099 input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0);
2100
2101 endpoint = &intf->altsetting[0].endpoint[0].desc;
2102
2103 /* Go set up our URB, which is called when the tablet receives
2104 * input.
2105 */
2106 usb_fill_int_urb(aiptek->urb,
2107 aiptek->usbdev,
2108 usb_rcvintpipe(aiptek->usbdev,
2109 endpoint->bEndpointAddress),
2110 aiptek->data, 8, aiptek_irq, aiptek,
2111 endpoint->bInterval);
2112
2113 aiptek->urb->transfer_dma = aiptek->data_dma;
2114 aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2115
2116 /* Program the tablet. This sets the tablet up in the mode
2117 * specified in newSetting, and also queries the tablet's
2118 * physical capacities.
2119 *
2120 * Sanity check: if a tablet doesn't like the slow programmatic
2121 * delay, we often get sizes of 0x0. Let's use that as an indicator
2122 * to try faster delays, up to 25 ms. If that logic fails, well, you'll
2123 * have to explain to us how your tablet thinks it's 0x0, and yet that's
2124 * not an error :-)
2125 */
2126
2127 for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
2128 aiptek->curSetting.programmableDelay = speeds[i];
2129 (void)aiptek_program_tablet(aiptek);
2130 if (aiptek->inputdev->absmax[ABS_X] > 0) {
2131 info("input: Aiptek using %d ms programming speed\n",
2132 aiptek->curSetting.programmableDelay);
2133 break;
2134 }
2135 }
2136
2137 /* Register the tablet as an Input Device
2138 */
2139 err = input_register_device(aiptek->inputdev);
2140 if (err)
2141 goto fail2;
2142
2143 /* We now will look for the evdev device which is mapped to
2144 * the tablet. The partial name is kept in the link list of
2145 * input_handles associated with this input device.
2146 * What identifies an evdev input_handler is that it begins
2147 * with 'event', continues with a digit, and that in turn
2148 * is mapped to input/eventN.
2149 */
2150 list_for_each_safe(node, next, &inputdev->h_list) {
2151 inputhandle = to_handle(node);
2152 if (strncmp(inputhandle->name, "event", 5) == 0) {
2153 strcpy(aiptek->features.inputPath, inputhandle->name);
2154 break;
2155 }
2156 }
2157
2158 /* Associate this driver's struct with the usb interface.
2159 */
2160 usb_set_intfdata(intf, aiptek);
2161
2162 /* Set up the sysfs files
2163 */
2164 aiptek_add_files(&intf->dev);
2165
2166 /* Make sure the evdev module is loaded. Assuming evdev IS a module :-)
2167 */
2168 if (request_module("evdev") != 0)
2169 info("aiptek: error loading 'evdev' module");
2170
2171 return 0;
2172
2173 fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
2174 aiptek->data_dma);
2175 fail1: input_free_device(inputdev);
2176 kfree(aiptek);
2177 return err;
2178}
2179
2180/***********************************************************************
2181 * Deal with tablet disconnecting from the system.
2182 */
2183static void aiptek_disconnect(struct usb_interface *intf)
2184{
2185 struct aiptek *aiptek = usb_get_intfdata(intf);
2186
2187 /* Disassociate driver's struct with usb interface
2188 */
2189 usb_set_intfdata(intf, NULL);
2190 if (aiptek != NULL) {
2191 /* Free & unhook everything from the system.
2192 */
2193 usb_kill_urb(aiptek->urb);
2194 input_unregister_device(aiptek->inputdev);
2195 aiptek_delete_files(&intf->dev);
2196 usb_free_urb(aiptek->urb);
2197 usb_buffer_free(interface_to_usbdev(intf),
2198 AIPTEK_PACKET_LENGTH,
2199 aiptek->data, aiptek->data_dma);
2200 kfree(aiptek);
2201 }
2202}
2203
2204static struct usb_driver aiptek_driver = {
2205 .name = "aiptek",
2206 .probe = aiptek_probe,
2207 .disconnect = aiptek_disconnect,
2208 .id_table = aiptek_ids,
2209};
2210
2211static int __init aiptek_init(void)
2212{
2213 int result = usb_register(&aiptek_driver);
2214 if (result == 0) {
2215 info(DRIVER_VERSION ": " DRIVER_AUTHOR);
2216 info(DRIVER_DESC);
2217 }
2218 return result;
2219}
2220
2221static void __exit aiptek_exit(void)
2222{
2223 usb_deregister(&aiptek_driver);
2224}
2225
2226MODULE_AUTHOR(DRIVER_AUTHOR);
2227MODULE_DESCRIPTION(DRIVER_DESC);
2228MODULE_LICENSE("GPL");
2229
2230module_param(programmableDelay, int, 0);
2231MODULE_PARM_DESC(programmableDelay, "delay used during tablet programming");
2232module_param(jitterDelay, int, 0);
2233MODULE_PARM_DESC(jitterDelay, "stylus/mouse settlement delay");
2234
2235module_init(aiptek_init);
2236module_exit(aiptek_exit);
diff --git a/drivers/input/tablet/gtco.c b/drivers/input/tablet/gtco.c
new file mode 100644
index 000000000000..b2ca10f2fe0e
--- /dev/null
+++ b/drivers/input/tablet/gtco.c
@@ -0,0 +1,1055 @@
1/* -*- linux-c -*-
2
3GTCO digitizer USB driver
4
5Use the err(), dbg() and info() macros from usb.h for system logging
6
7TO CHECK: Is pressure done right on report 5?
8
9Copyright (C) 2006 GTCO CalComp
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; version 2
14of the License.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
25Permission to use, copy, modify, distribute, and sell this software and its
26documentation for any purpose is hereby granted without fee, provided that
27the above copyright notice appear in all copies and that both that
28copyright notice and this permission notice appear in supporting
29documentation, and that the name of GTCO-CalComp not be used in advertising
30or publicity pertaining to distribution of the software without specific,
31written prior permission. GTCO-CalComp makes no representations about the
32suitability of this software for any purpose. It is provided "as is"
33without express or implied warranty.
34
35GTCO-CALCOMP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
36INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
37EVENT SHALL GTCO-CALCOMP BE LIABLE FOR ANY SPECIAL, INDIRECT OR
38CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
39DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
40TORTIOUS ACTIONS, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41PERFORMANCE OF THIS SOFTWARE.
42
43GTCO CalComp, Inc.
447125 Riverwood Drive
45Columbia, MD 21046
46
47Jeremy Roberson jroberson@gtcocalcomp.com
48Scott Hill shill@gtcocalcomp.com
49*/
50
51
52
53/*#define DEBUG*/
54
55#include <linux/kernel.h>
56#include <linux/module.h>
57#include <linux/errno.h>
58#include <linux/init.h>
59#include <linux/slab.h>
60#include <linux/input.h>
61#include <linux/usb.h>
62#include <asm/uaccess.h>
63#include <asm/unaligned.h>
64#include <asm/byteorder.h>
65
66
67#include <linux/version.h>
68#include <linux/usb/input.h>
69
70/* Version with a Major number of 2 is for kernel inclusion only. */
71#define GTCO_VERSION "2.00.0006"
72
73
74/* MACROS */
75
76#define VENDOR_ID_GTCO 0x078C
77#define PID_400 0x400
78#define PID_401 0x401
79#define PID_1000 0x1000
80#define PID_1001 0x1001
81#define PID_1002 0x1002
82
83/* Max size of a single report */
84#define REPORT_MAX_SIZE 10
85
86
87/* Bitmask whether pen is in range */
88#define MASK_INRANGE 0x20
89#define MASK_BUTTON 0x01F
90
91#define PATHLENGTH 64
92
93/* DATA STRUCTURES */
94
95/* Device table */
96static struct usb_device_id gtco_usbid_table [] = {
97 { USB_DEVICE(VENDOR_ID_GTCO, PID_400) },
98 { USB_DEVICE(VENDOR_ID_GTCO, PID_401) },
99 { USB_DEVICE(VENDOR_ID_GTCO, PID_1000) },
100 { USB_DEVICE(VENDOR_ID_GTCO, PID_1001) },
101 { USB_DEVICE(VENDOR_ID_GTCO, PID_1002) },
102 { }
103};
104MODULE_DEVICE_TABLE (usb, gtco_usbid_table);
105
106
107/* Structure to hold all of our device specific stuff */
108struct gtco {
109
110 struct input_dev *inputdevice; /* input device struct pointer */
111 struct usb_device *usbdev; /* the usb device for this device */
112 struct urb *urbinfo; /* urb for incoming reports */
113 dma_addr_t buf_dma; /* dma addr of the data buffer*/
114 unsigned char * buffer; /* databuffer for reports */
115
116 char usbpath[PATHLENGTH];
117 int openCount;
118
119 /* Information pulled from Report Descriptor */
120 u32 usage;
121 u32 min_X;
122 u32 max_X;
123 u32 min_Y;
124 u32 max_Y;
125 s8 mintilt_X;
126 s8 maxtilt_X;
127 s8 mintilt_Y;
128 s8 maxtilt_Y;
129 u32 maxpressure;
130 u32 minpressure;
131};
132
133
134
135/* Code for parsing the HID REPORT DESCRIPTOR */
136
137/* From HID1.11 spec */
138struct hid_descriptor
139{
140 struct usb_descriptor_header header;
141 __le16 bcdHID;
142 u8 bCountryCode;
143 u8 bNumDescriptors;
144 u8 bDescriptorType;
145 __le16 wDescriptorLength;
146} __attribute__ ((packed));
147
148
149#define HID_DESCRIPTOR_SIZE 9
150#define HID_DEVICE_TYPE 33
151#define REPORT_DEVICE_TYPE 34
152
153
154#define PREF_TAG(x) ((x)>>4)
155#define PREF_TYPE(x) ((x>>2)&0x03)
156#define PREF_SIZE(x) ((x)&0x03)
157
158#define TYPE_MAIN 0
159#define TYPE_GLOBAL 1
160#define TYPE_LOCAL 2
161#define TYPE_RESERVED 3
162
163#define TAG_MAIN_INPUT 0x8
164#define TAG_MAIN_OUTPUT 0x9
165#define TAG_MAIN_FEATURE 0xB
166#define TAG_MAIN_COL_START 0xA
167#define TAG_MAIN_COL_END 0xC
168
169#define TAG_GLOB_USAGE 0
170#define TAG_GLOB_LOG_MIN 1
171#define TAG_GLOB_LOG_MAX 2
172#define TAG_GLOB_PHYS_MIN 3
173#define TAG_GLOB_PHYS_MAX 4
174#define TAG_GLOB_UNIT_EXP 5
175#define TAG_GLOB_UNIT 6
176#define TAG_GLOB_REPORT_SZ 7
177#define TAG_GLOB_REPORT_ID 8
178#define TAG_GLOB_REPORT_CNT 9
179#define TAG_GLOB_PUSH 10
180#define TAG_GLOB_POP 11
181
182#define TAG_GLOB_MAX 12
183
184#define DIGITIZER_USAGE_TIP_PRESSURE 0x30
185#define DIGITIZER_USAGE_TILT_X 0x3D
186#define DIGITIZER_USAGE_TILT_Y 0x3E
187
188
189/*
190 * This is an abbreviated parser for the HID Report Descriptor. We
191 * know what devices we are talking to, so this is by no means meant
192 * to be generic. We can make some safe assumptions:
193 *
194 * - We know there are no LONG tags, all short
195 * - We know that we have no MAIN Feature and MAIN Output items
196 * - We know what the IRQ reports are supposed to look like.
197 *
198 * The main purpose of this is to use the HID report desc to figure
199 * out the mins and maxs of the fields in the IRQ reports. The IRQ
200 * reports for 400/401 change slightly if the max X is bigger than 64K.
201 *
202 */
203static void parse_hid_report_descriptor(struct gtco *device, char * report,
204 int length)
205{
206 int x, i = 0;
207
208 /* Tag primitive vars */
209 __u8 prefix;
210 __u8 size;
211 __u8 tag;
212 __u8 type;
213 __u8 data = 0;
214 __u16 data16 = 0;
215 __u32 data32 = 0;
216
217 /* For parsing logic */
218 int inputnum = 0;
219 __u32 usage = 0;
220
221 /* Global Values, indexed by TAG */
222 __u32 globalval[TAG_GLOB_MAX];
223 __u32 oldval[TAG_GLOB_MAX];
224
225 /* Debug stuff */
226 char maintype = 'x';
227 char globtype[12];
228 int indent = 0;
229 char indentstr[10] = "";
230
231
232 dbg("======>>>>>>PARSE<<<<<<======");
233
234 /* Walk this report and pull out the info we need */
235 while (i < length) {
236 prefix = report[i];
237
238 /* Skip over prefix */
239 i++;
240
241 /* Determine data size and save the data in the proper variable */
242 size = PREF_SIZE(prefix);
243 switch (size) {
244 case 1:
245 data = report[i];
246 break;
247 case 2:
248 data16 = le16_to_cpu(get_unaligned((__le16 *)&report[i]));
249 break;
250 case 3:
251 size = 4;
252 data32 = le32_to_cpu(get_unaligned((__le32 *)&report[i]));
253 break;
254 }
255
256 /* Skip size of data */
257 i += size;
258
259 /* What we do depends on the tag type */
260 tag = PREF_TAG(prefix);
261 type = PREF_TYPE(prefix);
262 switch (type) {
263 case TYPE_MAIN:
264 strcpy(globtype, "");
265 switch (tag) {
266
267 case TAG_MAIN_INPUT:
268 /*
269 * The INPUT MAIN tag signifies this is
270 * information from a report. We need to
271 * figure out what it is and store the
272 * min/max values
273 */
274
275 maintype = 'I';
276 if (data == 2)
277 strcpy(globtype, "Variable");
278 else if (data == 3)
279 strcpy(globtype, "Var|Const");
280
281 dbg("::::: Saving Report: %d input #%d Max: 0x%X(%d) Min:0x%X(%d) of %d bits",
282 globalval[TAG_GLOB_REPORT_ID], inputnum,
283 globalval[TAG_GLOB_LOG_MAX], globalval[TAG_GLOB_LOG_MAX],
284 globalval[TAG_GLOB_LOG_MIN], globalval[TAG_GLOB_LOG_MIN],
285 globalval[TAG_GLOB_REPORT_SZ] * globalval[TAG_GLOB_REPORT_CNT]);
286
287
288 /*
289 We can assume that the first two input items
290 are always the X and Y coordinates. After
291 that, we look for everything else by
292 local usage value
293 */
294 switch (inputnum) {
295 case 0: /* X coord */
296 dbg("GER: X Usage: 0x%x", usage);
297 if (device->max_X == 0) {
298 device->max_X = globalval[TAG_GLOB_LOG_MAX];
299 device->min_X = globalval[TAG_GLOB_LOG_MIN];
300 }
301 break;
302
303 case 1: /* Y coord */
304 dbg("GER: Y Usage: 0x%x", usage);
305 if (device->max_Y == 0) {
306 device->max_Y = globalval[TAG_GLOB_LOG_MAX];
307 device->min_Y = globalval[TAG_GLOB_LOG_MIN];
308 }
309 break;
310
311 default:
312 /* Tilt X */
313 if (usage == DIGITIZER_USAGE_TILT_X) {
314 if (device->maxtilt_X == 0) {
315 device->maxtilt_X = globalval[TAG_GLOB_LOG_MAX];
316 device->mintilt_X = globalval[TAG_GLOB_LOG_MIN];
317 }
318 }
319
320 /* Tilt Y */
321 if (usage == DIGITIZER_USAGE_TILT_Y) {
322 if (device->maxtilt_Y == 0) {
323 device->maxtilt_Y = globalval[TAG_GLOB_LOG_MAX];
324 device->mintilt_Y = globalval[TAG_GLOB_LOG_MIN];
325 }
326 }
327
328 /* Pressure */
329 if (usage == DIGITIZER_USAGE_TIP_PRESSURE) {
330 if (device->maxpressure == 0) {
331 device->maxpressure = globalval[TAG_GLOB_LOG_MAX];
332 device->minpressure = globalval[TAG_GLOB_LOG_MIN];
333 }
334 }
335
336 break;
337 }
338
339 inputnum++;
340 break;
341
342 case TAG_MAIN_OUTPUT:
343 maintype = 'O';
344 break;
345
346 case TAG_MAIN_FEATURE:
347 maintype = 'F';
348 break;
349
350 case TAG_MAIN_COL_START:
351 maintype = 'S';
352
353 if (data == 0) {
354 dbg("======>>>>>> Physical");
355 strcpy(globtype, "Physical");
356 } else
357 dbg("======>>>>>>");
358
359 /* Indent the debug output */
360 indent++;
361 for (x = 0; x < indent; x++)
362 indentstr[x] = '-';
363 indentstr[x] = 0;
364
365 /* Save global tags */
366 for (x = 0; x < TAG_GLOB_MAX; x++)
367 oldval[x] = globalval[x];
368
369 break;
370
371 case TAG_MAIN_COL_END:
372 dbg("<<<<<<======");
373 maintype = 'E';
374 indent--;
375 for (x = 0; x < indent; x++)
376 indentstr[x] = '-';
377 indentstr[x] = 0;
378
379 /* Copy global tags back */
380 for (x = 0; x < TAG_GLOB_MAX; x++)
381 globalval[x] = oldval[x];
382
383 break;
384 }
385
386 switch (size) {
387 case 1:
388 dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x",
389 indentstr, tag, maintype, size, globtype, data);
390 break;
391
392 case 2:
393 dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x",
394 indentstr, tag, maintype, size, globtype, data16);
395 break;
396
397 case 4:
398 dbg("%sMAINTAG:(%d) %c SIZE: %d Data: %s 0x%x",
399 indentstr, tag, maintype, size, globtype, data32);
400 break;
401 }
402 break;
403
404 case TYPE_GLOBAL:
405 switch (tag) {
406 case TAG_GLOB_USAGE:
407 /*
408 * First time we hit the global usage tag,
409 * it should tell us the type of device
410 */
411 if (device->usage == 0)
412 device->usage = data;
413
414 strcpy(globtype, "USAGE");
415 break;
416
417 case TAG_GLOB_LOG_MIN:
418 strcpy(globtype, "LOG_MIN");
419 break;
420
421 case TAG_GLOB_LOG_MAX:
422 strcpy(globtype, "LOG_MAX");
423 break;
424
425 case TAG_GLOB_PHYS_MIN:
426 strcpy(globtype, "PHYS_MIN");
427 break;
428
429 case TAG_GLOB_PHYS_MAX:
430 strcpy(globtype, "PHYS_MAX");
431 break;
432
433 case TAG_GLOB_UNIT_EXP:
434 strcpy(globtype, "EXP");
435 break;
436
437 case TAG_GLOB_UNIT:
438 strcpy(globtype, "UNIT");
439 break;
440
441 case TAG_GLOB_REPORT_SZ:
442 strcpy(globtype, "REPORT_SZ");
443 break;
444
445 case TAG_GLOB_REPORT_ID:
446 strcpy(globtype, "REPORT_ID");
447 /* New report, restart numbering */
448 inputnum = 0;
449 break;
450
451 case TAG_GLOB_REPORT_CNT:
452 strcpy(globtype, "REPORT_CNT");
453 break;
454
455 case TAG_GLOB_PUSH:
456 strcpy(globtype, "PUSH");
457 break;
458
459 case TAG_GLOB_POP:
460 strcpy(globtype, "POP");
461 break;
462 }
463
464 /* Check to make sure we have a good tag number
465 so we don't overflow array */
466 if (tag < TAG_GLOB_MAX) {
467 switch (size) {
468 case 1:
469 dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",
470 indentstr, globtype, tag, size, data);
471 globalval[tag] = data;
472 break;
473
474 case 2:
475 dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",
476 indentstr, globtype, tag, size, data16);
477 globalval[tag] = data16;
478 break;
479
480 case 4:
481 dbg("%sGLOBALTAG:%s(%d) SIZE: %d Data: 0x%x",
482 indentstr, globtype, tag, size, data32);
483 globalval[tag] = data32;
484 break;
485 }
486 } else {
487 dbg("%sGLOBALTAG: ILLEGAL TAG:%d SIZE: %d ",
488 indentstr, tag, size);
489 }
490 break;
491
492 case TYPE_LOCAL:
493 switch (tag) {
494 case TAG_GLOB_USAGE:
495 strcpy(globtype, "USAGE");
496 /* Always 1 byte */
497 usage = data;
498 break;
499
500 case TAG_GLOB_LOG_MIN:
501 strcpy(globtype, "MIN");
502 break;
503
504 case TAG_GLOB_LOG_MAX:
505 strcpy(globtype, "MAX");
506 break;
507
508 default:
509 strcpy(globtype, "UNKNOWN");
510 break;
511 }
512
513 switch (size) {
514 case 1:
515 dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x",
516 indentstr, tag, globtype, size, data);
517 break;
518
519 case 2:
520 dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x",
521 indentstr, tag, globtype, size, data16);
522 break;
523
524 case 4:
525 dbg("%sLOCALTAG:(%d) %s SIZE: %d Data: 0x%x",
526 indentstr, tag, globtype, size, data32);
527 break;
528 }
529
530 break;
531 }
532 }
533}
534
535/* INPUT DRIVER Routines */
536
537/*
538 * Called when opening the input device. This will submit the URB to
539 * the usb system so we start getting reports
540 */
541static int gtco_input_open(struct input_dev *inputdev)
542{
543 struct gtco *device = input_get_drvdata(inputdev);
544
545 device->urbinfo->dev = device->usbdev;
546 if (usb_submit_urb(device->urbinfo, GFP_KERNEL))
547 return -EIO;
548
549 return 0;
550}
551
552/*
553 * Called when closing the input device. This will unlink the URB
554 */
555static void gtco_input_close(struct input_dev *inputdev)
556{
557 struct gtco *device = input_get_drvdata(inputdev);
558
559 usb_kill_urb(device->urbinfo);
560}
561
562
563/*
564 * Setup input device capabilities. Tell the input system what this
565 * device is capable of generating.
566 *
567 * This information is based on what is read from the HID report and
568 * placed in the struct gtco structure
569 *
570 */
571static void gtco_setup_caps(struct input_dev *inputdev)
572{
573 struct gtco *device = input_get_drvdata(inputdev);
574
575 /* Which events */
576 inputdev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC);
577
578 /* Misc event menu block */
579 inputdev->mscbit[0] = BIT(MSC_SCAN)|BIT(MSC_SERIAL)|BIT(MSC_RAW) ;
580
581 /* Absolute values based on HID report info */
582 input_set_abs_params(inputdev, ABS_X, device->min_X, device->max_X,
583 0, 0);
584 input_set_abs_params(inputdev, ABS_Y, device->min_Y, device->max_Y,
585 0, 0);
586
587 /* Proximity */
588 input_set_abs_params(inputdev, ABS_DISTANCE, 0, 1, 0, 0);
589
590 /* Tilt & pressure */
591 input_set_abs_params(inputdev, ABS_TILT_X, device->mintilt_X,
592 device->maxtilt_X, 0, 0);
593 input_set_abs_params(inputdev, ABS_TILT_Y, device->mintilt_Y,
594 device->maxtilt_Y, 0, 0);
595 input_set_abs_params(inputdev, ABS_PRESSURE, device->minpressure,
596 device->maxpressure, 0, 0);
597
598 /* Transducer */
599 input_set_abs_params(inputdev, ABS_MISC, 0, 0xFF, 0, 0);
600}
601
602/* USB Routines */
603
604/*
605 * URB callback routine. Called when we get IRQ reports from the
606 * digitizer.
607 *
608 * This bridges the USB and input device worlds. It generates events
609 * on the input device based on the USB reports.
610 */
611static void gtco_urb_callback(struct urb *urbinfo)
612{
613 struct gtco *device = urbinfo->context;
614 struct input_dev *inputdev;
615 int rc;
616 u32 val = 0;
617 s8 valsigned = 0;
618 char le_buffer[2];
619
620 inputdev = device->inputdevice;
621
622 /* Was callback OK? */
623 if (urbinfo->status == -ECONNRESET ||
624 urbinfo->status == -ENOENT ||
625 urbinfo->status == -ESHUTDOWN) {
626
627 /* Shutdown is occurring. Return and don't queue up any more */
628 return;
629 }
630
631 if (urbinfo->status != 0) {
632 /*
633 * Some unknown error. Hopefully temporary. Just go and
634 * requeue an URB
635 */
636 goto resubmit;
637 }
638
639 /*
640 * Good URB, now process
641 */
642
643 /* PID dependent when we interpret the report */
644 if (inputdev->id.product == PID_1000 ||
645 inputdev->id.product == PID_1001 ||
646 inputdev->id.product == PID_1002) {
647
648 /*
649 * Switch on the report ID
650 * Conveniently, the reports have more information, the higher
651 * the report number. We can just fall through the case
652 * statements if we start with the highest number report
653 */
654 switch (device->buffer[0]) {
655 case 5:
656 /* Pressure is 9 bits */
657 val = ((u16)(device->buffer[8]) << 1);
658 val |= (u16)(device->buffer[7] >> 7);
659 input_report_abs(inputdev, ABS_PRESSURE,
660 device->buffer[8]);
661
662 /* Mask out the Y tilt value used for pressure */
663 device->buffer[7] = (u8)((device->buffer[7]) & 0x7F);
664
665 /* Fall thru */
666 case 4:
667 /* Tilt */
668
669 /* Sign extend these 7 bit numbers. */
670 if (device->buffer[6] & 0x40)
671 device->buffer[6] |= 0x80;
672
673 if (device->buffer[7] & 0x40)
674 device->buffer[7] |= 0x80;
675
676
677 valsigned = (device->buffer[6]);
678 input_report_abs(inputdev, ABS_TILT_X, (s32)valsigned);
679
680 valsigned = (device->buffer[7]);
681 input_report_abs(inputdev, ABS_TILT_Y, (s32)valsigned);
682
683 /* Fall thru */
684 case 2:
685 case 3:
686 /* Convert buttons, only 5 bits possible */
687 val = (device->buffer[5]) & MASK_BUTTON;
688
689 /* We don't apply any meaning to the bitmask,
690 just report */
691 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
692
693 /* Fall thru */
694 case 1:
695 /* All reports have X and Y coords in the same place */
696 val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[1]));
697 input_report_abs(inputdev, ABS_X, val);
698
699 val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[3]));
700 input_report_abs(inputdev, ABS_Y, val);
701
702 /* Ditto for proximity bit */
703 val = device->buffer[5] & MASK_INRANGE ? 1 : 0;
704 input_report_abs(inputdev, ABS_DISTANCE, val);
705
706 /* Report 1 is an exception to how we handle buttons */
707 /* Buttons are an index, not a bitmask */
708 if (device->buffer[0] == 1) {
709
710 /*
711 * Convert buttons, 5 bit index
712 * Report value of index set as one,
713 * the rest as 0
714 */
715 val = device->buffer[5] & MASK_BUTTON;
716 dbg("======>>>>>>REPORT 1: val 0x%X(%d)",
717 val, val);
718
719 /*
720 * We don't apply any meaning to the button
721 * index, just report it
722 */
723 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
724 }
725 break;
726
727 case 7:
728 /* Menu blocks */
729 input_event(inputdev, EV_MSC, MSC_SCAN,
730 device->buffer[1]);
731 break;
732 }
733 }
734
735 /* Other pid class */
736 if (inputdev->id.product == PID_400 ||
737 inputdev->id.product == PID_401) {
738
739 /* Report 2 */
740 if (device->buffer[0] == 2) {
741 /* Menu blocks */
742 input_event(inputdev, EV_MSC, MSC_SCAN, device->buffer[1]);
743 }
744
745 /* Report 1 */
746 if (device->buffer[0] == 1) {
747 char buttonbyte;
748
749 /* IF X max > 64K, we still a bit from the y report */
750 if (device->max_X > 0x10000) {
751
752 val = (u16)(((u16)(device->buffer[2] << 8)) | (u8)device->buffer[1]);
753 val |= (u32)(((u8)device->buffer[3] & 0x1) << 16);
754
755 input_report_abs(inputdev, ABS_X, val);
756
757 le_buffer[0] = (u8)((u8)(device->buffer[3]) >> 1);
758 le_buffer[0] |= (u8)((device->buffer[3] & 0x1) << 7);
759
760 le_buffer[1] = (u8)(device->buffer[4] >> 1);
761 le_buffer[1] |= (u8)((device->buffer[5] & 0x1) << 7);
762
763 val = le16_to_cpu(get_unaligned((__le16 *)le_buffer));
764 input_report_abs(inputdev, ABS_Y, val);
765
766 /*
767 * Shift the button byte right by one to
768 * make it look like the standard report
769 */
770 buttonbyte = device->buffer[5] >> 1;
771 } else {
772
773 val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[1]));
774 input_report_abs(inputdev, ABS_X, val);
775
776 val = le16_to_cpu(get_unaligned((__le16 *)&device->buffer[3]));
777 input_report_abs(inputdev, ABS_Y, val);
778
779 buttonbyte = device->buffer[5];
780 }
781
782 /* BUTTONS and PROXIMITY */
783 val = buttonbyte & MASK_INRANGE ? 1 : 0;
784 input_report_abs(inputdev, ABS_DISTANCE, val);
785
786 /* Convert buttons, only 4 bits possible */
787 val = buttonbyte & 0x0F;
788#ifdef USE_BUTTONS
789 for (i = 0; i < 5; i++)
790 input_report_key(inputdev, BTN_DIGI + i, val & (1 << i));
791#else
792 /* We don't apply any meaning to the bitmask, just report */
793 input_event(inputdev, EV_MSC, MSC_SERIAL, val);
794#endif
795
796 /* TRANSDUCER */
797 input_report_abs(inputdev, ABS_MISC, device->buffer[6]);
798 }
799 }
800
801 /* Everybody gets report ID's */
802 input_event(inputdev, EV_MSC, MSC_RAW, device->buffer[0]);
803
804 /* Sync it up */
805 input_sync(inputdev);
806
807 resubmit:
808 rc = usb_submit_urb(urbinfo, GFP_ATOMIC);
809 if (rc != 0)
810 err("usb_submit_urb failed rc=0x%x", rc);
811}
812
813/*
814 * The probe routine. This is called when the kernel find the matching USB
815 * vendor/product. We do the following:
816 *
817 * - Allocate mem for a local structure to manage the device
818 * - Request a HID Report Descriptor from the device and parse it to
819 * find out the device parameters
820 * - Create an input device and assign it attributes
821 * - Allocate an URB so the device can talk to us when the input
822 * queue is open
823 */
824static int gtco_probe(struct usb_interface *usbinterface,
825 const struct usb_device_id *id)
826{
827
828 struct gtco *gtco;
829 struct input_dev *input_dev;
830 struct hid_descriptor *hid_desc;
831 char *report = NULL;
832 int result = 0, retry;
833 int error;
834 struct usb_endpoint_descriptor *endpoint;
835
836 /* Allocate memory for device structure */
837 gtco = kzalloc(sizeof(struct gtco), GFP_KERNEL);
838 input_dev = input_allocate_device();
839 if (!gtco || !input_dev) {
840 err("No more memory");
841 error = -ENOMEM;
842 goto err_free_devs;
843 }
844
845 /* Set pointer to the input device */
846 gtco->inputdevice = input_dev;
847
848 /* Save interface information */
849 gtco->usbdev = usb_get_dev(interface_to_usbdev(usbinterface));
850
851 /* Allocate some data for incoming reports */
852 gtco->buffer = usb_buffer_alloc(gtco->usbdev, REPORT_MAX_SIZE,
853 GFP_KERNEL, &gtco->buf_dma);
854 if (!gtco->buffer) {
855 err("No more memory for us buffers");
856 error = -ENOMEM;
857 goto err_free_devs;
858 }
859
860 /* Allocate URB for reports */
861 gtco->urbinfo = usb_alloc_urb(0, GFP_KERNEL);
862 if (!gtco->urbinfo) {
863 err("Failed to allocate URB");
864 return -ENOMEM;
865 goto err_free_buf;
866 }
867
868 /*
869 * The endpoint is always altsetting 0, we know this since we know
870 * this device only has one interrupt endpoint
871 */
872 endpoint = &usbinterface->altsetting[0].endpoint[0].desc;
873
874 /* Some debug */
875 dbg("gtco # interfaces: %d", usbinterface->num_altsetting);
876 dbg("num endpoints: %d", usbinterface->cur_altsetting->desc.bNumEndpoints);
877 dbg("interface class: %d", usbinterface->cur_altsetting->desc.bInterfaceClass);
878 dbg("endpoint: attribute:0x%x type:0x%x", endpoint->bmAttributes, endpoint->bDescriptorType);
879 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
880 dbg("endpoint: we have interrupt endpoint\n");
881
882 dbg("endpoint extra len:%d ", usbinterface->altsetting[0].extralen);
883
884 /*
885 * Find the HID descriptor so we can find out the size of the
886 * HID report descriptor
887 */
888 if (usb_get_extra_descriptor(usbinterface->cur_altsetting,
889 HID_DEVICE_TYPE, &hid_desc) != 0){
890 err("Can't retrieve exta USB descriptor to get hid report descriptor length");
891 error = -EIO;
892 goto err_free_urb;
893 }
894
895 dbg("Extra descriptor success: type:%d len:%d",
896 hid_desc->bDescriptorType, hid_desc->wDescriptorLength);
897
898 report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
899 if (!report) {
900 err("No more memory for report");
901 error = -ENOMEM;
902 goto err_free_urb;
903 }
904
905 /* Couple of tries to get reply */
906 for (retry = 0; retry < 3; retry++) {
907 result = usb_control_msg(gtco->usbdev,
908 usb_rcvctrlpipe(gtco->usbdev, 0),
909 USB_REQ_GET_DESCRIPTOR,
910 USB_RECIP_INTERFACE | USB_DIR_IN,
911 REPORT_DEVICE_TYPE << 8,
912 0, /* interface */
913 report,
914 hid_desc->wDescriptorLength,
915 5000); /* 5 secs */
916
917 if (result == hid_desc->wDescriptorLength)
918 break;
919 }
920
921 /* If we didn't get the report, fail */
922 dbg("usb_control_msg result: :%d", result);
923 if (result != hid_desc->wDescriptorLength) {
924 err("Failed to get HID Report Descriptor of size: %d",
925 hid_desc->wDescriptorLength);
926 error = -EIO;
927 goto err_free_urb;
928 }
929
930 /* Now we parse the report */
931 parse_hid_report_descriptor(gtco, report, result);
932
933 /* Now we delete it */
934 kfree(report);
935
936 /* Create a device file node */
937 usb_make_path(gtco->usbdev, gtco->usbpath, sizeof(gtco->usbpath));
938 strlcat(gtco->usbpath, "/input0", sizeof(gtco->usbpath));
939
940 /* Set Input device functions */
941 input_dev->open = gtco_input_open;
942 input_dev->close = gtco_input_close;
943
944 /* Set input device information */
945 input_dev->name = "GTCO_CalComp";
946 input_dev->phys = gtco->usbpath;
947
948 input_set_drvdata(input_dev, gtco);
949
950 /* Now set up all the input device capabilities */
951 gtco_setup_caps(input_dev);
952
953 /* Set input device required ID information */
954 usb_to_input_id(gtco->usbdev, &input_dev->id);
955 input_dev->dev.parent = &usbinterface->dev;
956
957 /* Setup the URB, it will be posted later on open of input device */
958 endpoint = &usbinterface->altsetting[0].endpoint[0].desc;
959
960 usb_fill_int_urb(gtco->urbinfo,
961 gtco->usbdev,
962 usb_rcvintpipe(gtco->usbdev,
963 endpoint->bEndpointAddress),
964 gtco->buffer,
965 REPORT_MAX_SIZE,
966 gtco_urb_callback,
967 gtco,
968 endpoint->bInterval);
969
970 gtco->urbinfo->transfer_dma = gtco->buf_dma;
971 gtco->urbinfo->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
972
973 /* Save gtco pointer in USB interface gtco */
974 usb_set_intfdata(usbinterface, gtco);
975
976 /* All done, now register the input device */
977 error = input_register_device(input_dev);
978 if (error)
979 goto err_free_urb;
980
981 return 0;
982
983 err_free_urb:
984 usb_free_urb(gtco->urbinfo);
985 err_free_buf:
986 usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE,
987 gtco->buffer, gtco->buf_dma);
988 err_free_devs:
989 kfree(report);
990 input_free_device(input_dev);
991 kfree(gtco);
992 return error;
993}
994
995/*
996 * This function is a standard USB function called when the USB device
997 * is disconnected. We will get rid of the URV, de-register the input
998 * device, and free up allocated memory
999 */
1000static void gtco_disconnect(struct usb_interface *interface)
1001{
1002 /* Grab private device ptr */
1003 struct gtco *gtco = usb_get_intfdata(interface);
1004
1005 /* Now reverse all the registration stuff */
1006 if (gtco) {
1007 input_unregister_device(gtco->inputdevice);
1008 usb_kill_urb(gtco->urbinfo);
1009 usb_free_urb(gtco->urbinfo);
1010 usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE,
1011 gtco->buffer, gtco->buf_dma);
1012 kfree(gtco);
1013 }
1014
1015 info("gtco driver disconnected");
1016}
1017
1018/* STANDARD MODULE LOAD ROUTINES */
1019
1020static struct usb_driver gtco_driverinfo_table = {
1021 .name = "gtco",
1022 .id_table = gtco_usbid_table,
1023 .probe = gtco_probe,
1024 .disconnect = gtco_disconnect,
1025};
1026
1027/*
1028 * Register this module with the USB subsystem
1029 */
1030static int __init gtco_init(void)
1031{
1032 int error;
1033
1034 error = usb_register(&gtco_driverinfo_table);
1035 if (error) {
1036 err("usb_register() failed rc=0x%x", error);
1037 return error;
1038 }
1039
1040 printk("GTCO usb driver version: %s", GTCO_VERSION);
1041 return 0;
1042}
1043
1044/*
1045 * Deregister this module with the USB subsystem
1046 */
1047static void __exit gtco_exit(void)
1048{
1049 usb_deregister(&gtco_driverinfo_table);
1050}
1051
1052module_init(gtco_init);
1053module_exit(gtco_exit);
1054
1055MODULE_LICENSE("GPL");
diff --git a/drivers/input/tablet/kbtab.c b/drivers/input/tablet/kbtab.c
new file mode 100644
index 000000000000..91e6d00d4a43
--- /dev/null
+++ b/drivers/input/tablet/kbtab.c
@@ -0,0 +1,226 @@
1#include <linux/kernel.h>
2#include <linux/slab.h>
3#include <linux/module.h>
4#include <linux/init.h>
5#include <linux/usb/input.h>
6#include <asm/unaligned.h>
7
8/*
9 * Version Information
10 * v0.0.1 - Original, extremely basic version, 2.4.xx only
11 * v0.0.2 - Updated, works with 2.5.62 and 2.4.20;
12 * - added pressure-threshold modules param code from
13 * Alex Perry <alex.perry@ieee.org>
14 */
15
16#define DRIVER_VERSION "v0.0.2"
17#define DRIVER_AUTHOR "Josh Myer <josh@joshisanerd.com>"
18#define DRIVER_DESC "USB KB Gear JamStudio Tablet driver"
19#define DRIVER_LICENSE "GPL"
20
21MODULE_AUTHOR(DRIVER_AUTHOR);
22MODULE_DESCRIPTION(DRIVER_DESC);
23MODULE_LICENSE(DRIVER_LICENSE);
24
25#define USB_VENDOR_ID_KBGEAR 0x084e
26
27static int kb_pressure_click = 0x10;
28module_param(kb_pressure_click, int, 0);
29MODULE_PARM_DESC(kb_pressure_click, "pressure threshold for clicks");
30
31struct kbtab {
32 unsigned char *data;
33 dma_addr_t data_dma;
34 struct input_dev *dev;
35 struct usb_device *usbdev;
36 struct urb *irq;
37 int x, y;
38 int button;
39 int pressure;
40 __u32 serial[2];
41 char phys[32];
42};
43
44static void kbtab_irq(struct urb *urb)
45{
46 struct kbtab *kbtab = urb->context;
47 unsigned char *data = kbtab->data;
48 struct input_dev *dev = kbtab->dev;
49 int retval;
50
51 switch (urb->status) {
52 case 0:
53 /* success */
54 break;
55 case -ECONNRESET:
56 case -ENOENT:
57 case -ESHUTDOWN:
58 /* this urb is terminated, clean up */
59 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
60 return;
61 default:
62 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
63 goto exit;
64 }
65
66 kbtab->x = le16_to_cpu(get_unaligned((__le16 *) &data[1]));
67 kbtab->y = le16_to_cpu(get_unaligned((__le16 *) &data[3]));
68
69 kbtab->pressure = (data[5]);
70
71 input_report_key(dev, BTN_TOOL_PEN, 1);
72
73 input_report_abs(dev, ABS_X, kbtab->x);
74 input_report_abs(dev, ABS_Y, kbtab->y);
75
76 /*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/
77 input_report_key(dev, BTN_RIGHT, data[0] & 0x02);
78
79 if (-1 == kb_pressure_click) {
80 input_report_abs(dev, ABS_PRESSURE, kbtab->pressure);
81 } else {
82 input_report_key(dev, BTN_LEFT, (kbtab->pressure > kb_pressure_click) ? 1 : 0);
83 };
84
85 input_sync(dev);
86
87 exit:
88 retval = usb_submit_urb (urb, GFP_ATOMIC);
89 if (retval)
90 err ("%s - usb_submit_urb failed with result %d",
91 __FUNCTION__, retval);
92}
93
94static struct usb_device_id kbtab_ids[] = {
95 { USB_DEVICE(USB_VENDOR_ID_KBGEAR, 0x1001), .driver_info = 0 },
96 { }
97};
98
99MODULE_DEVICE_TABLE(usb, kbtab_ids);
100
101static int kbtab_open(struct input_dev *dev)
102{
103 struct kbtab *kbtab = input_get_drvdata(dev);
104
105 kbtab->irq->dev = kbtab->usbdev;
106 if (usb_submit_urb(kbtab->irq, GFP_KERNEL))
107 return -EIO;
108
109 return 0;
110}
111
112static void kbtab_close(struct input_dev *dev)
113{
114 struct kbtab *kbtab = input_get_drvdata(dev);
115
116 usb_kill_urb(kbtab->irq);
117}
118
119static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id)
120{
121 struct usb_device *dev = interface_to_usbdev(intf);
122 struct usb_endpoint_descriptor *endpoint;
123 struct kbtab *kbtab;
124 struct input_dev *input_dev;
125 int error = -ENOMEM;
126
127 kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL);
128 input_dev = input_allocate_device();
129 if (!kbtab || !input_dev)
130 goto fail1;
131
132 kbtab->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &kbtab->data_dma);
133 if (!kbtab->data)
134 goto fail1;
135
136 kbtab->irq = usb_alloc_urb(0, GFP_KERNEL);
137 if (!kbtab->irq)
138 goto fail2;
139
140 kbtab->usbdev = dev;
141 kbtab->dev = input_dev;
142
143 usb_make_path(dev, kbtab->phys, sizeof(kbtab->phys));
144 strlcat(kbtab->phys, "/input0", sizeof(kbtab->phys));
145
146 input_dev->name = "KB Gear Tablet";
147 input_dev->phys = kbtab->phys;
148 usb_to_input_id(dev, &input_dev->id);
149 input_dev->dev.parent = &intf->dev;
150
151 input_set_drvdata(input_dev, kbtab);
152
153 input_dev->open = kbtab_open;
154 input_dev->close = kbtab_close;
155
156 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC);
157 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
158 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH);
159 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
160 input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0);
161 input_set_abs_params(input_dev, ABS_Y, 0, 0x1750, 4, 0);
162 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0);
163
164 endpoint = &intf->cur_altsetting->endpoint[0].desc;
165
166 usb_fill_int_urb(kbtab->irq, dev,
167 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
168 kbtab->data, 8,
169 kbtab_irq, kbtab, endpoint->bInterval);
170 kbtab->irq->transfer_dma = kbtab->data_dma;
171 kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
172
173 error = input_register_device(kbtab->dev);
174 if (error)
175 goto fail3;
176
177 usb_set_intfdata(intf, kbtab);
178
179 return 0;
180
181 fail3: usb_free_urb(kbtab->irq);
182 fail2: usb_buffer_free(dev, 10, kbtab->data, kbtab->data_dma);
183 fail1: input_free_device(input_dev);
184 kfree(kbtab);
185 return error;
186}
187
188static void kbtab_disconnect(struct usb_interface *intf)
189{
190 struct kbtab *kbtab = usb_get_intfdata(intf);
191
192 usb_set_intfdata(intf, NULL);
193 if (kbtab) {
194 usb_kill_urb(kbtab->irq);
195 input_unregister_device(kbtab->dev);
196 usb_free_urb(kbtab->irq);
197 usb_buffer_free(interface_to_usbdev(intf), 10, kbtab->data, kbtab->data_dma);
198 kfree(kbtab);
199 }
200}
201
202static struct usb_driver kbtab_driver = {
203 .name = "kbtab",
204 .probe = kbtab_probe,
205 .disconnect = kbtab_disconnect,
206 .id_table = kbtab_ids,
207};
208
209static int __init kbtab_init(void)
210{
211 int retval;
212 retval = usb_register(&kbtab_driver);
213 if (retval)
214 goto out;
215 info(DRIVER_VERSION ":" DRIVER_DESC);
216out:
217 return retval;
218}
219
220static void __exit kbtab_exit(void)
221{
222 usb_deregister(&kbtab_driver);
223}
224
225module_init(kbtab_init);
226module_exit(kbtab_exit);
diff --git a/drivers/input/tablet/wacom.h b/drivers/input/tablet/wacom.h
new file mode 100644
index 000000000000..ef01a807ec0f
--- /dev/null
+++ b/drivers/input/tablet/wacom.h
@@ -0,0 +1,131 @@
1/*
2 * drivers/input/tablet/wacom.h
3 *
4 * USB Wacom Graphire and Wacom Intuos tablet support
5 *
6 * Copyright (c) 2000-2004 Vojtech Pavlik <vojtech@ucw.cz>
7 * Copyright (c) 2000 Andreas Bach Aaen <abach@stofanet.dk>
8 * Copyright (c) 2000 Clifford Wolf <clifford@clifford.at>
9 * Copyright (c) 2000 Sam Mosel <sam.mosel@computer.org>
10 * Copyright (c) 2000 James E. Blair <corvus@gnu.org>
11 * Copyright (c) 2000 Daniel Egger <egger@suse.de>
12 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com>
13 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be>
14 * Copyright (c) 2002-2006 Ping Cheng <pingc@wacom.com>
15 *
16 * ChangeLog:
17 * v0.1 (vp) - Initial release
18 * v0.2 (aba) - Support for all buttons / combinations
19 * v0.3 (vp) - Support for Intuos added
20 * v0.4 (sm) - Support for more Intuos models, menustrip
21 * relative mode, proximity.
22 * v0.5 (vp) - Big cleanup, nifty features removed,
23 * they belong in userspace
24 * v1.8 (vp) - Submit URB only when operating, moved to CVS,
25 * use input_report_key instead of report_btn and
26 * other cleanups
27 * v1.11 (vp) - Add URB ->dev setting for new kernels
28 * v1.11 (jb) - Add support for the 4D Mouse & Lens
29 * v1.12 (de) - Add support for two more inking pen IDs
30 * v1.14 (vp) - Use new USB device id probing scheme.
31 * Fix Wacom Graphire mouse wheel
32 * v1.18 (vp) - Fix mouse wheel direction
33 * Make mouse relative
34 * v1.20 (fl) - Report tool id for Intuos devices
35 * - Multi tools support
36 * - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...)
37 * - Add PL models support
38 * - Fix Wacom Graphire mouse wheel again
39 * v1.21 (vp) - Removed protocol descriptions
40 * - Added MISC_SERIAL for tool serial numbers
41 * (gb) - Identify version on module load.
42 * v1.21.1 (fl) - added Graphire2 support
43 * v1.21.2 (fl) - added Intuos2 support
44 * - added all the PL ids
45 * v1.21.3 (fl) - added another eraser id from Neil Okamoto
46 * - added smooth filter for Graphire from Peri Hankey
47 * - added PenPartner support from Olaf van Es
48 * - new tool ids from Ole Martin Bjoerndalen
49 * v1.29 (pc) - Add support for more tablets
50 * - Fix pressure reporting
51 * v1.30 (vp) - Merge 2.4 and 2.5 drivers
52 * - Since 2.5 now has input_sync(), remove MSC_SERIAL abuse
53 * - Cleanups here and there
54 * v1.30.1 (pi) - Added Graphire3 support
55 * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ...
56 * v1.43 (pc) - Added support for Cintiq 21UX
57 * - Fixed a Graphire bug
58 * - Merged wacom_intuos3_irq into wacom_intuos_irq
59 * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc.
60 * - Report Device IDs
61 * v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19
62 * - Minor data report fix
63 * v1.46 (pc) - Split wacom.c into wacom_sys.c and wacom_wac.c,
64 * - where wacom_sys.c deals with system specific code,
65 * - and wacom_wac.c deals with Wacom specific code
66 * - Support Intuos3 4x6
67 */
68
69/*
70 * This program is free software; you can redistribute it and/or modify
71 * it under the terms of the GNU General Public License as published by
72 * the Free Software Foundation; either version 2 of the License, or
73 * (at your option) any later version.
74 */
75#ifndef WACOM_H
76#define WACOM_H
77#include <linux/kernel.h>
78#include <linux/slab.h>
79#include <linux/module.h>
80#include <linux/init.h>
81#include <linux/usb/input.h>
82#include <asm/unaligned.h>
83
84/*
85 * Version Information
86 */
87#define DRIVER_VERSION "v1.46"
88#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
89#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
90#define DRIVER_LICENSE "GPL"
91
92MODULE_AUTHOR(DRIVER_AUTHOR);
93MODULE_DESCRIPTION(DRIVER_DESC);
94MODULE_LICENSE(DRIVER_LICENSE);
95
96#define USB_VENDOR_ID_WACOM 0x056a
97
98struct wacom {
99 dma_addr_t data_dma;
100 struct input_dev *dev;
101 struct usb_device *usbdev;
102 struct urb *irq;
103 struct wacom_wac * wacom_wac;
104 char phys[32];
105};
106
107struct wacom_combo {
108 struct wacom * wacom;
109 struct urb * urb;
110};
111
112extern int wacom_wac_irq(struct wacom_wac * wacom_wac, void * wcombo);
113extern void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data);
114extern void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data);
115extern void wacom_report_key(void *wcombo, unsigned int key_type, int key_data);
116extern void wacom_input_event(void *wcombo, unsigned int type, unsigned int code, int value);
117extern void wacom_input_sync(void *wcombo);
118extern void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
119extern void input_dev_g4(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
120extern void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
121extern void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
122extern void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
123extern void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
124extern void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
125extern void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
126extern __u16 wacom_le16_to_cpu(unsigned char *data);
127extern __u16 wacom_be16_to_cpu(unsigned char *data);
128extern struct wacom_features * get_wacom_feature(const struct usb_device_id *id);
129extern const struct usb_device_id * get_device_table(void);
130
131#endif
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
new file mode 100644
index 000000000000..83bddef66067
--- /dev/null
+++ b/drivers/input/tablet/wacom_sys.c
@@ -0,0 +1,318 @@
1/*
2 * drivers/input/tablet/wacom_sys.c
3 *
4 * USB Wacom Graphire and Wacom Intuos tablet support - system specific code
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include "wacom.h"
15#include "wacom_wac.h"
16
17#define USB_REQ_GET_REPORT 0x01
18#define USB_REQ_SET_REPORT 0x09
19
20static int usb_get_report(struct usb_interface *intf, unsigned char type,
21 unsigned char id, void *buf, int size)
22{
23 return usb_control_msg(interface_to_usbdev(intf),
24 usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
25 USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
26 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
27 buf, size, 100);
28}
29
30static int usb_set_report(struct usb_interface *intf, unsigned char type,
31 unsigned char id, void *buf, int size)
32{
33 return usb_control_msg(interface_to_usbdev(intf),
34 usb_sndctrlpipe(interface_to_usbdev(intf), 0),
35 USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
36 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
37 buf, size, 1000);
38}
39
40static struct input_dev * get_input_dev(struct wacom_combo *wcombo)
41{
42 return wcombo->wacom->dev;
43}
44
45static void wacom_sys_irq(struct urb *urb)
46{
47 struct wacom *wacom = urb->context;
48 struct wacom_combo wcombo;
49 int retval;
50
51 switch (urb->status) {
52 case 0:
53 /* success */
54 break;
55 case -ECONNRESET:
56 case -ENOENT:
57 case -ESHUTDOWN:
58 /* this urb is terminated, clean up */
59 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
60 return;
61 default:
62 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
63 goto exit;
64 }
65
66 wcombo.wacom = wacom;
67 wcombo.urb = urb;
68
69 if (wacom_wac_irq(wacom->wacom_wac, (void *)&wcombo))
70 input_sync(get_input_dev(&wcombo));
71
72 exit:
73 retval = usb_submit_urb (urb, GFP_ATOMIC);
74 if (retval)
75 err ("%s - usb_submit_urb failed with result %d",
76 __FUNCTION__, retval);
77}
78
79void wacom_report_key(void *wcombo, unsigned int key_type, int key_data)
80{
81 input_report_key(get_input_dev((struct wacom_combo *)wcombo), key_type, key_data);
82 return;
83}
84
85void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data)
86{
87 input_report_abs(get_input_dev((struct wacom_combo *)wcombo), abs_type, abs_data);
88 return;
89}
90
91void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data)
92{
93 input_report_rel(get_input_dev((struct wacom_combo *)wcombo), rel_type, rel_data);
94 return;
95}
96
97void wacom_input_event(void *wcombo, unsigned int type, unsigned int code, int value)
98{
99 input_event(get_input_dev((struct wacom_combo *)wcombo), type, code, value);
100 return;
101}
102
103__u16 wacom_be16_to_cpu(unsigned char *data)
104{
105 __u16 value;
106 value = be16_to_cpu(*(__be16 *) data);
107 return value;
108}
109
110__u16 wacom_le16_to_cpu(unsigned char *data)
111{
112 __u16 value;
113 value = le16_to_cpu(*(__le16 *) data);
114 return value;
115}
116
117void wacom_input_sync(void *wcombo)
118{
119 input_sync(get_input_dev((struct wacom_combo *)wcombo));
120 return;
121}
122
123static int wacom_open(struct input_dev *dev)
124{
125 struct wacom *wacom = input_get_drvdata(dev);
126
127 wacom->irq->dev = wacom->usbdev;
128 if (usb_submit_urb(wacom->irq, GFP_KERNEL))
129 return -EIO;
130
131 return 0;
132}
133
134static void wacom_close(struct input_dev *dev)
135{
136 struct wacom *wacom = input_get_drvdata(dev);
137
138 usb_kill_urb(wacom->irq);
139}
140
141void input_dev_g4(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
142{
143 input_dev->evbit[0] |= BIT(EV_MSC);
144 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
145 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
146 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_4);
147}
148
149void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
150{
151 input_dev->evbit[0] |= BIT(EV_REL);
152 input_dev->relbit[0] |= BIT(REL_WHEEL);
153 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
154 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
155 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
156}
157
158void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
159{
160 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
161 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3);
162 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
163}
164
165void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
166{
167 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
168 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
169}
170
171void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
172{
173 input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
174 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
175 input_dev->relbit[0] |= BIT(REL_WHEEL);
176 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
177 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
178 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
179 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
180 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
181 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
182 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
183 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
184 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
185}
186
187void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
188{
189 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
190}
191
192void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
193{
194 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER);
195}
196
197static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
198{
199 struct usb_device *dev = interface_to_usbdev(intf);
200 struct usb_endpoint_descriptor *endpoint;
201 struct wacom *wacom;
202 struct wacom_wac *wacom_wac;
203 struct input_dev *input_dev;
204 int error = -ENOMEM;
205 char rep_data[2], limit = 0;
206
207 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
208 wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL);
209 input_dev = input_allocate_device();
210 if (!wacom || !input_dev || !wacom_wac)
211 goto fail1;
212
213 wacom_wac->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
214 if (!wacom_wac->data)
215 goto fail1;
216
217 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
218 if (!wacom->irq)
219 goto fail2;
220
221 wacom->usbdev = dev;
222 wacom->dev = input_dev;
223 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
224 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
225
226 wacom_wac->features = get_wacom_feature(id);
227 BUG_ON(wacom_wac->features->pktlen > 10);
228
229 input_dev->name = wacom_wac->features->name;
230 wacom->wacom_wac = wacom_wac;
231 usb_to_input_id(dev, &input_dev->id);
232
233 input_dev->dev.parent = &intf->dev;
234
235 input_set_drvdata(input_dev, wacom);
236
237 input_dev->open = wacom_open;
238 input_dev->close = wacom_close;
239
240 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
241 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
242 input_set_abs_params(input_dev, ABS_X, 0, wacom_wac->features->x_max, 4, 0);
243 input_set_abs_params(input_dev, ABS_Y, 0, wacom_wac->features->y_max, 4, 0);
244 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom_wac->features->pressure_max, 0, 0);
245 input_dev->absbit[LONG(ABS_MISC)] |= BIT(ABS_MISC);
246
247 wacom_init_input_dev(input_dev, wacom_wac);
248
249 endpoint = &intf->cur_altsetting->endpoint[0].desc;
250
251 usb_fill_int_urb(wacom->irq, dev,
252 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
253 wacom_wac->data, wacom_wac->features->pktlen,
254 wacom_sys_irq, wacom, endpoint->bInterval);
255 wacom->irq->transfer_dma = wacom->data_dma;
256 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
257
258 error = input_register_device(wacom->dev);
259 if (error)
260 goto fail3;
261
262 /* Ask the tablet to report tablet data. Repeat until it succeeds */
263 do {
264 rep_data[0] = 2;
265 rep_data[1] = 2;
266 usb_set_report(intf, 3, 2, rep_data, 2);
267 usb_get_report(intf, 3, 2, rep_data, 2);
268 } while (rep_data[1] != 2 && limit++ < 5);
269
270 usb_set_intfdata(intf, wacom);
271 return 0;
272
273 fail3: usb_free_urb(wacom->irq);
274 fail2: usb_buffer_free(dev, 10, wacom_wac->data, wacom->data_dma);
275 fail1: input_free_device(input_dev);
276 kfree(wacom);
277 kfree(wacom_wac);
278 return error;
279}
280
281static void wacom_disconnect(struct usb_interface *intf)
282{
283 struct wacom *wacom = usb_get_intfdata (intf);
284
285 usb_set_intfdata(intf, NULL);
286 if (wacom) {
287 usb_kill_urb(wacom->irq);
288 input_unregister_device(wacom->dev);
289 usb_free_urb(wacom->irq);
290 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->wacom_wac->data, wacom->data_dma);
291 kfree(wacom->wacom_wac);
292 kfree(wacom);
293 }
294}
295
296static struct usb_driver wacom_driver = {
297 .name = "wacom",
298 .probe = wacom_probe,
299 .disconnect = wacom_disconnect,
300};
301
302static int __init wacom_init(void)
303{
304 int result;
305 wacom_driver.id_table = get_device_table();
306 result = usb_register(&wacom_driver);
307 if (result == 0)
308 info(DRIVER_VERSION ":" DRIVER_DESC);
309 return result;
310}
311
312static void __exit wacom_exit(void)
313{
314 usb_deregister(&wacom_driver);
315}
316
317module_init(wacom_init);
318module_exit(wacom_exit);
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
new file mode 100644
index 000000000000..7661f03a2db2
--- /dev/null
+++ b/drivers/input/tablet/wacom_wac.c
@@ -0,0 +1,675 @@
1/*
2 * drivers/input/tablet/wacom_wac.c
3 *
4 * USB Wacom Graphire and Wacom Intuos tablet support - Wacom specific code
5 *
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14#include "wacom.h"
15#include "wacom_wac.h"
16
17static int wacom_penpartner_irq(struct wacom_wac *wacom, void *wcombo)
18{
19 unsigned char *data = wacom->data;
20
21 switch (data[0]) {
22 case 1:
23 if (data[5] & 0x80) {
24 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
25 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
26 wacom_report_key(wcombo, wacom->tool[0], 1);
27 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
28 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1]));
29 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3]));
30 wacom_report_abs(wcombo, ABS_PRESSURE, (signed char)data[6] + 127);
31 wacom_report_key(wcombo, BTN_TOUCH, ((signed char)data[6] > -127));
32 wacom_report_key(wcombo, BTN_STYLUS, (data[5] & 0x40));
33 } else {
34 wacom_report_key(wcombo, wacom->tool[0], 0);
35 wacom_report_abs(wcombo, ABS_MISC, 0); /* report tool id */
36 wacom_report_abs(wcombo, ABS_PRESSURE, -1);
37 wacom_report_key(wcombo, BTN_TOUCH, 0);
38 }
39 break;
40 case 2:
41 wacom_report_key(wcombo, BTN_TOOL_PEN, 1);
42 wacom_report_abs(wcombo, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
43 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1]));
44 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3]));
45 wacom_report_abs(wcombo, ABS_PRESSURE, (signed char)data[6] + 127);
46 wacom_report_key(wcombo, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
47 wacom_report_key(wcombo, BTN_STYLUS, (data[5] & 0x40));
48 break;
49 default:
50 printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
51 return 0;
52 }
53 return 1;
54}
55
56static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
57{
58 unsigned char *data = wacom->data;
59 int prox, id, pressure;
60
61 if (data[0] != 2) {
62 dbg("wacom_pl_irq: received unknown report #%d", data[0]);
63 return 0;
64 }
65
66 prox = data[1] & 0x40;
67
68 id = ERASER_DEVICE_ID;
69 if (prox) {
70
71 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
72 if (wacom->features->pressure_max > 255)
73 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
74 pressure += (wacom->features->pressure_max + 1) / 2;
75
76 /*
77 * if going from out of proximity into proximity select between the eraser
78 * and the pen based on the state of the stylus2 button, choose eraser if
79 * pressed else choose pen. if not a proximity change from out to in, send
80 * an out of proximity for previous tool then a in for new tool.
81 */
82 if (!wacom->tool[0]) {
83 /* Eraser bit set for DTF */
84 if (data[1] & 0x10)
85 wacom->tool[1] = BTN_TOOL_RUBBER;
86 else
87 /* Going into proximity select tool */
88 wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
89 } else {
90 /* was entered with stylus2 pressed */
91 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
92 /* report out proximity for previous tool */
93 wacom_report_key(wcombo, wacom->tool[1], 0);
94 wacom_input_sync(wcombo);
95 wacom->tool[1] = BTN_TOOL_PEN;
96 return 0;
97 }
98 }
99 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
100 /* Unknown tool selected default to pen tool */
101 wacom->tool[1] = BTN_TOOL_PEN;
102 id = STYLUS_DEVICE_ID;
103 }
104 wacom_report_key(wcombo, wacom->tool[1], prox); /* report in proximity for tool */
105 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
106 wacom_report_abs(wcombo, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
107 wacom_report_abs(wcombo, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
108 wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
109
110 wacom_report_key(wcombo, BTN_TOUCH, data[4] & 0x08);
111 wacom_report_key(wcombo, BTN_STYLUS, data[4] & 0x10);
112 /* Only allow the stylus2 button to be reported for the pen tool. */
113 wacom_report_key(wcombo, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
114 } else {
115 /* report proximity-out of a (valid) tool */
116 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
117 /* Unknown tool selected default to pen tool */
118 wacom->tool[1] = BTN_TOOL_PEN;
119 }
120 wacom_report_key(wcombo, wacom->tool[1], prox);
121 }
122
123 wacom->tool[0] = prox; /* Save proximity state */
124 return 1;
125}
126
127static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
128{
129 unsigned char *data = wacom->data;
130 int id;
131
132 if (data[0] != 2) {
133 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
134 return 0;
135 }
136
137 if (data[1] & 0x04) {
138 wacom_report_key(wcombo, BTN_TOOL_RUBBER, data[1] & 0x20);
139 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x08);
140 id = ERASER_DEVICE_ID;
141 } else {
142 wacom_report_key(wcombo, BTN_TOOL_PEN, data[1] & 0x20);
143 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
144 id = STYLUS_DEVICE_ID;
145 }
146 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
147 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
148 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
149 wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6]));
150 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
151 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10);
152 return 1;
153}
154
155static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
156{
157 unsigned char *data = wacom->data;
158 int x, y, id, rw;
159
160 if (data[0] != 2) {
161 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
162 return 0;
163 }
164
165 id = STYLUS_DEVICE_ID;
166 if (data[1] & 0x80) { /* in prox */
167
168 switch ((data[1] >> 5) & 3) {
169
170 case 0: /* Pen */
171 wacom->tool[0] = BTN_TOOL_PEN;
172 break;
173
174 case 1: /* Rubber */
175 wacom->tool[0] = BTN_TOOL_RUBBER;
176 id = ERASER_DEVICE_ID;
177 break;
178
179 case 2: /* Mouse with wheel */
180 wacom_report_key(wcombo, BTN_MIDDLE, data[1] & 0x04);
181 if (wacom->features->type == WACOM_G4) {
182 rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
183 wacom_report_rel(wcombo, REL_WHEEL, -rw);
184 } else
185 wacom_report_rel(wcombo, REL_WHEEL, -(signed char) data[6]);
186 /* fall through */
187
188 case 3: /* Mouse without wheel */
189 wacom->tool[0] = BTN_TOOL_MOUSE;
190 id = CURSOR_DEVICE_ID;
191 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01);
192 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02);
193 if (wacom->features->type == WACOM_G4)
194 wacom_report_abs(wcombo, ABS_DISTANCE, data[6] & 0x3f);
195 else
196 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f);
197 break;
198 }
199 x = wacom_le16_to_cpu(&data[2]);
200 y = wacom_le16_to_cpu(&data[4]);
201 wacom_report_abs(wcombo, ABS_X, x);
202 wacom_report_abs(wcombo, ABS_Y, y);
203 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
204 wacom_report_abs(wcombo, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8));
205 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
206 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
207 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04);
208 }
209 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
210 wacom_report_key(wcombo, wacom->tool[0], 1);
211 } else if (!(data[1] & 0x90)) {
212 wacom_report_abs(wcombo, ABS_X, 0);
213 wacom_report_abs(wcombo, ABS_Y, 0);
214 if (wacom->tool[0] == BTN_TOOL_MOUSE) {
215 wacom_report_key(wcombo, BTN_LEFT, 0);
216 wacom_report_key(wcombo, BTN_RIGHT, 0);
217 wacom_report_abs(wcombo, ABS_DISTANCE, 0);
218 } else {
219 wacom_report_abs(wcombo, ABS_PRESSURE, 0);
220 wacom_report_key(wcombo, BTN_TOUCH, 0);
221 wacom_report_key(wcombo, BTN_STYLUS, 0);
222 wacom_report_key(wcombo, BTN_STYLUS2, 0);
223 }
224 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
225 wacom_report_key(wcombo, wacom->tool[0], 0);
226 }
227
228 /* send pad data */
229 if (wacom->features->type == WACOM_G4) {
230 if (data[7] & 0xf8) {
231 wacom_input_sync(wcombo); /* sync last event */
232 wacom->id[1] = 1;
233 wacom->serial[1] = (data[7] & 0xf8);
234 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
235 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
236 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
237 wacom_report_rel(wcombo, REL_WHEEL, rw);
238 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
239 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID);
240 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
241 } else if (wacom->id[1]) {
242 wacom_input_sync(wcombo); /* sync last event */
243 wacom->id[1] = 0;
244 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
245 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
246 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
247 wacom_report_abs(wcombo, ABS_MISC, 0);
248 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
249 }
250 }
251 return 1;
252}
253
254static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
255{
256 unsigned char *data = wacom->data;
257 int idx;
258
259 /* tool number */
260 idx = data[1] & 0x01;
261
262 /* Enter report */
263 if ((data[1] & 0xfc) == 0xc0) {
264 /* serial number of the tool */
265 wacom->serial[idx] = ((data[3] & 0x0f) << 28) +
266 (data[4] << 20) + (data[5] << 12) +
267 (data[6] << 4) + (data[7] >> 4);
268
269 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
270 switch (wacom->id[idx]) {
271 case 0x812: /* Inking pen */
272 case 0x801: /* Intuos3 Inking pen */
273 case 0x012:
274 wacom->tool[idx] = BTN_TOOL_PENCIL;
275 break;
276 case 0x822: /* Pen */
277 case 0x842:
278 case 0x852:
279 case 0x823: /* Intuos3 Grip Pen */
280 case 0x813: /* Intuos3 Classic Pen */
281 case 0x885: /* Intuos3 Marker Pen */
282 case 0x022:
283 wacom->tool[idx] = BTN_TOOL_PEN;
284 break;
285 case 0x832: /* Stroke pen */
286 case 0x032:
287 wacom->tool[idx] = BTN_TOOL_BRUSH;
288 break;
289 case 0x007: /* Mouse 4D and 2D */
290 case 0x09c:
291 case 0x094:
292 case 0x017: /* Intuos3 2D Mouse */
293 wacom->tool[idx] = BTN_TOOL_MOUSE;
294 break;
295 case 0x096: /* Lens cursor */
296 case 0x097: /* Intuos3 Lens cursor */
297 wacom->tool[idx] = BTN_TOOL_LENS;
298 break;
299 case 0x82a: /* Eraser */
300 case 0x85a:
301 case 0x91a:
302 case 0xd1a:
303 case 0x0fa:
304 case 0x82b: /* Intuos3 Grip Pen Eraser */
305 case 0x81b: /* Intuos3 Classic Pen Eraser */
306 case 0x91b: /* Intuos3 Airbrush Eraser */
307 wacom->tool[idx] = BTN_TOOL_RUBBER;
308 break;
309 case 0xd12:
310 case 0x912:
311 case 0x112:
312 case 0x913: /* Intuos3 Airbrush */
313 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
314 break;
315 default: /* Unknown tool */
316 wacom->tool[idx] = BTN_TOOL_PEN;
317 }
318 return 1;
319 }
320
321 /* Exit report */
322 if ((data[1] & 0xfe) == 0x80) {
323 wacom_report_abs(wcombo, ABS_X, 0);
324 wacom_report_abs(wcombo, ABS_Y, 0);
325 wacom_report_abs(wcombo, ABS_DISTANCE, 0);
326 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
327 wacom_report_key(wcombo, BTN_LEFT, 0);
328 wacom_report_key(wcombo, BTN_MIDDLE, 0);
329 wacom_report_key(wcombo, BTN_RIGHT, 0);
330 wacom_report_key(wcombo, BTN_SIDE, 0);
331 wacom_report_key(wcombo, BTN_EXTRA, 0);
332 wacom_report_abs(wcombo, ABS_THROTTLE, 0);
333 wacom_report_abs(wcombo, ABS_RZ, 0);
334 } else {
335 wacom_report_abs(wcombo, ABS_PRESSURE, 0);
336 wacom_report_abs(wcombo, ABS_TILT_X, 0);
337 wacom_report_abs(wcombo, ABS_TILT_Y, 0);
338 wacom_report_key(wcombo, BTN_STYLUS, 0);
339 wacom_report_key(wcombo, BTN_STYLUS2, 0);
340 wacom_report_key(wcombo, BTN_TOUCH, 0);
341 wacom_report_abs(wcombo, ABS_WHEEL, 0);
342 }
343 wacom_report_key(wcombo, wacom->tool[idx], 0);
344 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
345 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
346 return 2;
347 }
348 return 0;
349}
350
351static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo)
352{
353 unsigned char *data = wacom->data;
354 unsigned int t;
355
356 /* general pen packet */
357 if ((data[1] & 0xb8) == 0xa0) {
358 t = (data[6] << 2) | ((data[7] >> 6) & 3);
359 wacom_report_abs(wcombo, ABS_PRESSURE, t);
360 wacom_report_abs(wcombo, ABS_TILT_X,
361 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
362 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
363 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 2);
364 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 4);
365 wacom_report_key(wcombo, BTN_TOUCH, t > 10);
366 }
367
368 /* airbrush second packet */
369 if ((data[1] & 0xbc) == 0xb4) {
370 wacom_report_abs(wcombo, ABS_WHEEL,
371 (data[6] << 2) | ((data[7] >> 6) & 3));
372 wacom_report_abs(wcombo, ABS_TILT_X,
373 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
374 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f);
375 }
376 return;
377}
378
379static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
380{
381 unsigned char *data = wacom->data;
382 unsigned int t;
383 int idx, result;
384
385 if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) {
386 dbg("wacom_intuos_irq: received unknown report #%d", data[0]);
387 return 0;
388 }
389
390 /* tool number */
391 idx = data[1] & 0x01;
392
393 /* pad packets. Works as a second tool and is always in prox */
394 if (data[0] == 12) {
395 /* initiate the pad as a device */
396 if (wacom->tool[1] != BTN_TOOL_FINGER)
397 wacom->tool[1] = BTN_TOOL_FINGER;
398
399 wacom_report_key(wcombo, BTN_0, (data[5] & 0x01));
400 wacom_report_key(wcombo, BTN_1, (data[5] & 0x02));
401 wacom_report_key(wcombo, BTN_2, (data[5] & 0x04));
402 wacom_report_key(wcombo, BTN_3, (data[5] & 0x08));
403 wacom_report_key(wcombo, BTN_4, (data[6] & 0x01));
404 wacom_report_key(wcombo, BTN_5, (data[6] & 0x02));
405 wacom_report_key(wcombo, BTN_6, (data[6] & 0x04));
406 wacom_report_key(wcombo, BTN_7, (data[6] & 0x08));
407 wacom_report_abs(wcombo, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
408 wacom_report_abs(wcombo, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
409
410 if((data[5] & 0x0f) | (data[6] & 0x0f) | (data[1] & 0x1f) |
411 data[2] | (data[3] & 0x1f) | data[4])
412 wacom_report_key(wcombo, wacom->tool[1], 1);
413 else
414 wacom_report_key(wcombo, wacom->tool[1], 0);
415 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID);
416 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff);
417 return 1;
418 }
419
420 /* process in/out prox events */
421 result = wacom_intuos_inout(wacom, wcombo);
422 if (result)
423 return result-1;
424
425 /* Only large I3 and I1 & I2 support Lense Cursor */
426 if((wacom->tool[idx] == BTN_TOOL_LENS)
427 && ((wacom->features->type == INTUOS3)
428 || (wacom->features->type == INTUOS3S)))
429 return 0;
430
431 /* Cintiq doesn't send data when RDY bit isn't set */
432 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
433 return 0;
434
435 if (wacom->features->type >= INTUOS3S) {
436 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
437 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
438 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
439 } else {
440 wacom_report_abs(wcombo, ABS_X, wacom_be16_to_cpu(&data[2]));
441 wacom_report_abs(wcombo, ABS_Y, wacom_be16_to_cpu(&data[4]));
442 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
443 }
444
445 /* process general packets */
446 wacom_intuos_general(wacom, wcombo);
447
448 /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */
449 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) {
450
451 if (data[1] & 0x02) {
452 /* Rotation packet */
453 if (wacom->features->type >= INTUOS3S) {
454 /* I3 marker pen rotation reported as wheel
455 * due to valuator limitation
456 */
457 t = (data[6] << 3) | ((data[7] >> 5) & 7);
458 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
459 ((t-1) / 2 + 450)) : (450 - t / 2) ;
460 wacom_report_abs(wcombo, ABS_WHEEL, t);
461 } else {
462 /* 4D mouse rotation packet */
463 t = (data[6] << 3) | ((data[7] >> 5) & 7);
464 wacom_report_abs(wcombo, ABS_RZ, (data[7] & 0x20) ?
465 ((t - 1) / 2) : -t / 2);
466 }
467
468 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3S) {
469 /* 4D mouse packet */
470 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01);
471 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
472 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x04);
473
474 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x20);
475 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x10);
476 t = (data[6] << 2) | ((data[7] >> 6) & 3);
477 wacom_report_abs(wcombo, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
478
479 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
480 /* 2D mouse packet */
481 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x04);
482 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x08);
483 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x10);
484 wacom_report_rel(wcombo, REL_WHEEL, (data[8] & 0x01)
485 - ((data[8] & 0x02) >> 1));
486
487 /* I3 2D mouse side buttons */
488 if (wacom->features->type >= INTUOS3S && wacom->features->type <= INTUOS3L) {
489 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x40);
490 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x20);
491 }
492
493 } else if (wacom->features->type < INTUOS3S || wacom->features->type == INTUOS3L) {
494 /* Lens cursor packets */
495 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01);
496 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
497 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x04);
498 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x10);
499 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x08);
500 }
501 }
502
503 wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */
504 wacom_report_key(wcombo, wacom->tool[idx], 1);
505 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
506 return 1;
507}
508
509int wacom_wac_irq(struct wacom_wac *wacom_wac, void *wcombo)
510{
511 switch (wacom_wac->features->type) {
512 case PENPARTNER:
513 return (wacom_penpartner_irq(wacom_wac, wcombo));
514 break;
515 case PL:
516 return (wacom_pl_irq(wacom_wac, wcombo));
517 break;
518 case WACOM_G4:
519 case GRAPHIRE:
520 return (wacom_graphire_irq(wacom_wac, wcombo));
521 break;
522 case PTU:
523 return (wacom_ptu_irq(wacom_wac, wcombo));
524 break;
525 case INTUOS:
526 case INTUOS3S:
527 case INTUOS3:
528 case INTUOS3L:
529 case CINTIQ:
530 return (wacom_intuos_irq(wacom_wac, wcombo));
531 break;
532 default:
533 return 0;
534 }
535 return 0;
536}
537
538void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
539{
540 switch (wacom_wac->features->type) {
541 case WACOM_G4:
542 input_dev_g4(input_dev, wacom_wac);
543 /* fall through */
544 case GRAPHIRE:
545 input_dev_g(input_dev, wacom_wac);
546 break;
547 case INTUOS3:
548 case INTUOS3L:
549 case CINTIQ:
550 input_dev_i3(input_dev, wacom_wac);
551 /* fall through */
552 case INTUOS3S:
553 input_dev_i3s(input_dev, wacom_wac);
554 case INTUOS:
555 input_dev_i(input_dev, wacom_wac);
556 break;
557 case PL:
558 case PTU:
559 input_dev_pl(input_dev, wacom_wac);
560 break;
561 case PENPARTNER:
562 input_dev_pt(input_dev, wacom_wac);
563 break;
564 }
565 return;
566}
567
568static struct wacom_features wacom_features[] = {
569 { "Wacom Penpartner", 7, 5040, 3780, 255, 0, PENPARTNER },
570 { "Wacom Graphire", 8, 10206, 7422, 511, 63, GRAPHIRE },
571 { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 63, GRAPHIRE },
572 { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 63, GRAPHIRE },
573 { "Wacom Graphire3", 8, 10208, 7424, 511, 63, GRAPHIRE },
574 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 63, GRAPHIRE },
575 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 63, WACOM_G4 },
576 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 63, WACOM_G4 },
577 { "Wacom Volito", 8, 5104, 3712, 511, 63, GRAPHIRE },
578 { "Wacom PenStation2", 8, 3250, 2320, 255, 63, GRAPHIRE },
579 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE },
580 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE },
581 { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE },
582 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 31, INTUOS },
583 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
584 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 31, INTUOS },
585 { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 31, INTUOS },
586 { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 31, INTUOS },
587 { "Wacom PL400", 8, 5408, 4056, 255, 0, PL },
588 { "Wacom PL500", 8, 6144, 4608, 255, 0, PL },
589 { "Wacom PL600", 8, 6126, 4604, 255, 0, PL },
590 { "Wacom PL600SX", 8, 6260, 5016, 255, 0, PL },
591 { "Wacom PL550", 8, 6144, 4608, 511, 0, PL },
592 { "Wacom PL800", 8, 7220, 5780, 511, 0, PL },
593 { "Wacom PL700", 8, 6758, 5406, 511, 0, PL },
594 { "Wacom PL510", 8, 6282, 4762, 511, 0, PL },
595 { "Wacom DTU710", 8, 34080, 27660, 511, 0, PL },
596 { "Wacom DTF521", 8, 6282, 4762, 511, 0, PL },
597 { "Wacom DTF720", 8, 6858, 5506, 511, 0, PL },
598 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 0, PTU },
599 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 31, INTUOS },
600 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
601 { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 31, INTUOS },
602 { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 31, INTUOS },
603 { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 31, INTUOS },
604 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 63, INTUOS3S },
605 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 63, INTUOS3 },
606 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 63, INTUOS3 },
607 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 63, INTUOS3L },
608 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 63, INTUOS3L },
609 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 },
610 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S },
611 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ },
612 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 31, INTUOS },
613 { }
614};
615
616static struct usb_device_id wacom_ids[] = {
617 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
618 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
619 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
620 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
621 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
622 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
623 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
624 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
625 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
626 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
627 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
628 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
629 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
630 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
631 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
632 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
633 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
634 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
635 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
636 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
637 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
638 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
639 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
640 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
641 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
642 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
643 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
644 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
645 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC4) },
646 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
647 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
648 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
649 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
650 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
651 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
652 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
653 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
654 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
655 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
656 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
657 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
658 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7) },
659 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
660 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
661 { }
662};
663
664const struct usb_device_id * get_device_table(void) {
665 const struct usb_device_id * id_table = wacom_ids;
666 return id_table;
667}
668
669struct wacom_features * get_wacom_feature(const struct usb_device_id * id) {
670 int index = id - wacom_ids;
671 struct wacom_features *wf = &wacom_features[index];
672 return wf;
673}
674
675MODULE_DEVICE_TABLE(usb, wacom_ids);
diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h
new file mode 100644
index 000000000000..a5e12e8756de
--- /dev/null
+++ b/drivers/input/tablet/wacom_wac.h
@@ -0,0 +1,49 @@
1/*
2 * drivers/input/tablet/wacom_wac.h
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9#ifndef WACOM_WAC_H
10#define WACOM_WAC_H
11
12#define STYLUS_DEVICE_ID 0x02
13#define CURSOR_DEVICE_ID 0x06
14#define ERASER_DEVICE_ID 0x0A
15#define PAD_DEVICE_ID 0x0F
16
17enum {
18 PENPARTNER = 0,
19 GRAPHIRE,
20 WACOM_G4,
21 PTU,
22 PL,
23 INTUOS,
24 INTUOS3S,
25 INTUOS3,
26 INTUOS3L,
27 CINTIQ,
28 MAX_TYPE
29};
30
31struct wacom_features {
32 char *name;
33 int pktlen;
34 int x_max;
35 int y_max;
36 int pressure_max;
37 int distance_max;
38 int type;
39};
40
41struct wacom_wac {
42 unsigned char *data;
43 int tool[2];
44 int id[2];
45 __u32 serial[2];
46 struct wacom_features *features;
47};
48
49#endif