2 * Native support for the Aiptek 8000U
4 * Copyright (c) 2001 Chris Atenasio <chris@crud.net>
7 * Vojtech Pavlik <vojtech@suse.cz>
8 * Andreas Bach Aaen <abach@stofanet.dk>
9 * Clifford Wolf <clifford@clifford.at>
10 * Sam Mosel <sam.mosel@computer.org>
11 * James E. Blair <corvus@gnu.org>
12 * Daniel Egger <egger@suse.de>
15 * Many thanks to Oliver Kuechemann for his support.
18 * v0.1 - Initial release
19 * v0.2 - Hack to get around fake event 28's.
20 * v0.3 - Make URB dynamic (Bryan W. Headley, Jun-8-2002)
21 * (kernel 2.5.x variant, June-14-2002)
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 #include <linux/kernel.h>
41 #include <linux/slab.h>
42 #include <linux/input.h>
43 #include <linux/module.h>
44 #include <linux/init.h>
45 #include <linux/usb.h>
46 #include <asm/unaligned.h>
47 #include <asm/byteorder.h>
51 #define DRIVER_VERSION "v0.3"
52 #define DRIVER_AUTHOR "Chris Atenasio <chris@crud.net>"
53 #define DRIVER_DESC "USB Aiptek 6000U/8000U tablet driver (Linux 2.5.x)"
55 MODULE_AUTHOR(DRIVER_AUTHOR);
56 MODULE_DESCRIPTION(DRIVER_DESC);
57 MODULE_LICENSE("GPL");
60 * Aiptek status packet:
62 * bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
63 * byte0 0 0 0 0 0 0 1 0
64 * byte1 X7 X6 X5 X4 X3 X2 X1 X0
65 * byte2 X15 X14 X13 X12 X11 X10 X9 X8
66 * byte3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
67 * byte4 Y15 Y14 Y13 Y12 Y11 Y10 Y9 Y8
68 * byte5 * * * BS2 BS1 Tip DV IR
69 * byte6 P7 P6 P5 P4 P3 P2 P1 P0
70 * byte7 P15 P14 P13 P12 P11 P10 P9 P8
72 * IR: In Range = Proximity on
78 * Command/Data Description Return Bytes Return Value
79 * 0x10/0x00 SwitchToMouse 0
80 * 0x10/0x01 SwitchToTablet 0
81 * 0x18/0x04 Resolution500LPI 0
82 * 0x17/0x00 FilterOn 0
83 * 0x12/0xFF AutoGainOn 0
84 * 0x01/0x00 GetXExtension 2 MaxX
85 * 0x01/0x01 GetYExtension 2 MaxY
86 * 0x02/0x00 GetModelCode 2 ModelCode = LOBYTE
87 * 0x03/0x00 GetODMCode 2 ODMCode
88 * 0x08/0x00 GetPressureLevels 2 =512
89 * 0x04/0x00 GetFirmwareVersion 2 Firmware Version
92 * To initialize the tablet:
94 * (1) Send command Resolution500LPI
95 * (2) Option Commands (GetXExtension, GetYExtension)
96 * (3) Send command SwitchToTablet
99 #define USB_VENDOR_ID_AIPTEK 0x08ca
101 struct aiptek_features {
110 unsigned long absbit;
111 unsigned long relbit;
112 unsigned long btnbit;
113 unsigned long digibit;
117 struct input_dev dev;
118 struct usb_device *usbdev;
120 struct aiptek_features *features;
129 aiptek_irq(struct urb *urb, struct pt_regs *regs)
131 struct aiptek *aiptek = urb->context;
132 unsigned char *data = aiptek->data;
133 struct input_dev *dev = &aiptek->dev;
140 switch (urb->status) {
147 /* this urb is terminated, clean up */
148 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
151 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
155 if ((data[0] & 2) == 0) {
156 dbg("received unknown report #%d", data[0]);
159 input_regs(dev, regs);
161 proximity = data[5] & 0x01;
162 input_report_key(dev, BTN_TOOL_PEN, proximity);
164 x = le16_to_cpu(get_unaligned((u16 *) &data[1]));
165 y = le16_to_cpu(get_unaligned((u16 *) &data[3]));
166 pressure = le16_to_cpu(*(u16 *) &data[6]);
167 pressure -= aiptek->features->pressure_min;
174 input_report_abs(dev, ABS_X, x);
175 input_report_abs(dev, ABS_Y, y);
176 input_report_abs(dev, ABS_PRESSURE, pressure);
177 input_report_key(dev, BTN_TOUCH, data[5] & 0x04);
178 input_report_key(dev, BTN_STYLUS, data[5] & 0x08);
179 input_report_key(dev, BTN_STYLUS2, data[5] & 0x10);
185 retval = usb_submit_urb (urb, GFP_ATOMIC);
187 err ("%s - usb_submit_urb failed with result %d",
188 __FUNCTION__, retval);
191 struct aiptek_features aiptek_features[] = {
192 {"Aiptek 6000U/8000U",
193 8, 3000, 2250, 26, 511, aiptek_irq, 0, 0, 0, 0},
197 struct usb_device_id aiptek_ids[] = {
198 {USB_DEVICE(USB_VENDOR_ID_AIPTEK, 0x20), .driver_info = 0},
202 MODULE_DEVICE_TABLE(usb, aiptek_ids);
205 aiptek_open(struct input_dev *dev)
207 struct aiptek *aiptek = dev->private;
212 aiptek->irq->dev = aiptek->usbdev;
213 if (usb_submit_urb(aiptek->irq, GFP_KERNEL)) {
222 aiptek_close(struct input_dev *dev)
224 struct aiptek *aiptek = dev->private;
227 usb_unlink_urb(aiptek->irq);
230 #define USB_REQ_SET_REPORT 0x09
232 usb_set_report(struct usb_device *dev, struct usb_host_interface *inter, unsigned char type,
233 unsigned char id, void *buf, int size)
235 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
236 USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
237 (type << 8) + id, inter->desc.bInterfaceNumber, buf, size, HZ);
241 aiptek_command(struct usb_device *dev, struct usb_host_interface *inter,
242 unsigned char command, unsigned char data)
247 buf = kmalloc(3, GFP_KERNEL);
255 if ((err = usb_set_report(dev, inter, 3, 2, buf, 3)) != 3) {
256 dbg("aiptek_command: 0x%x 0x%x\n", command, data);
260 return err < 0 ? err : 0;
264 aiptek_probe(struct usb_interface *intf,
265 const struct usb_device_id *id)
267 struct usb_device *dev = interface_to_usbdev (intf);
268 struct usb_host_interface *interface = intf->cur_altsetting;
269 struct usb_endpoint_descriptor *endpoint;
270 struct aiptek *aiptek;
273 if (!(aiptek = kmalloc(sizeof (struct aiptek), GFP_KERNEL)))
274 goto error_out_noalloc;
276 memset(aiptek, 0, sizeof (struct aiptek));
278 aiptek->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &aiptek->data_dma);
280 goto error_out_nobuf;
283 aiptek->irq = usb_alloc_urb(0, GFP_KERNEL);
285 goto error_out_nourb;
288 /* Resolution500LPI */
289 err = aiptek_command(dev, interface, 0x18, 0x04);
294 err = aiptek_command(dev, interface, 0x10, 0x01);
298 aiptek->features = aiptek_features + id->driver_info;
300 aiptek->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC) |
301 aiptek->features->evbit;
303 aiptek->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE) |
304 BIT(ABS_MISC) | aiptek->features->absbit;
306 aiptek->dev.relbit[0] |= aiptek->features->relbit;
308 aiptek->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) |
309 BIT(BTN_MIDDLE) | aiptek->features->btnbit;
311 aiptek->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) |
312 BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOUCH) |
313 BIT(BTN_STYLUS) | BIT(BTN_STYLUS2) | aiptek->features->digibit;
315 aiptek->dev.mscbit[0] = BIT(MSC_SERIAL);
317 aiptek->dev.absmax[ABS_X] = aiptek->features->x_max;
318 aiptek->dev.absmax[ABS_Y] = aiptek->features->y_max;
319 aiptek->dev.absmax[ABS_PRESSURE] = aiptek->features->pressure_max -
320 aiptek->features->pressure_min;
322 aiptek->dev.absfuzz[ABS_X] = 0;
323 aiptek->dev.absfuzz[ABS_Y] = 0;
325 aiptek->dev.private = aiptek;
326 aiptek->dev.open = aiptek_open;
327 aiptek->dev.close = aiptek_close;
329 aiptek->dev.name = aiptek->features->name;
330 aiptek->dev.id.bustype = BUS_USB;
331 aiptek->dev.id.vendor = dev->descriptor.idVendor;
332 aiptek->dev.id.product = dev->descriptor.idProduct;
333 aiptek->dev.id.version = dev->descriptor.bcdDevice;
334 aiptek->dev.dev = &intf->dev;
335 aiptek->usbdev = dev;
337 endpoint = &intf->altsetting[0].endpoint[0].desc;
339 if (aiptek->features->pktlen > 10)
342 usb_fill_int_urb(aiptek->irq, dev,
343 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
344 aiptek->data, aiptek->features->pktlen,
345 aiptek->features->irq, aiptek, endpoint->bInterval);
346 aiptek->irq->transfer_dma = aiptek->data_dma;
347 aiptek->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
349 input_register_device(&aiptek->dev);
351 printk(KERN_INFO "input: %s on usb%d:%d\n",
352 aiptek->features->name, dev->bus->busnum, dev->devnum);
354 usb_set_intfdata(intf, aiptek);
358 usb_free_urb(aiptek->irq);
360 usb_buffer_free(dev, 10, aiptek->data, aiptek->data_dma);
369 aiptek_disconnect(struct usb_interface *intf)
371 struct aiptek *aiptek = usb_get_intfdata (intf);
373 usb_set_intfdata(intf, NULL);
375 usb_unlink_urb(aiptek->irq);
376 input_unregister_device(&aiptek->dev);
377 usb_free_urb(aiptek->irq);
378 usb_buffer_free(interface_to_usbdev(intf), 10, aiptek->data, aiptek->data_dma);
383 static struct usb_driver aiptek_driver = {
384 .owner = THIS_MODULE,
386 .probe = aiptek_probe,
387 .disconnect = aiptek_disconnect,
388 .id_table = aiptek_ids,
394 int result = usb_register(&aiptek_driver);
396 info(DRIVER_VERSION " " DRIVER_AUTHOR);
405 usb_deregister(&aiptek_driver);
408 module_init(aiptek_init);
409 module_exit(aiptek_exit);