Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB Wacom Graphire and Wacom Intuos tablet support |
| 3 | * |
| 4 | * Copyright (c) 2000-2004 Vojtech Pavlik <vojtech@ucw.cz> |
| 5 | * Copyright (c) 2000 Andreas Bach Aaen <abach@stofanet.dk> |
| 6 | * Copyright (c) 2000 Clifford Wolf <clifford@clifford.at> |
| 7 | * Copyright (c) 2000 Sam Mosel <sam.mosel@computer.org> |
| 8 | * Copyright (c) 2000 James E. Blair <corvus@gnu.org> |
| 9 | * Copyright (c) 2000 Daniel Egger <egger@suse.de> |
| 10 | * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com> |
| 11 | * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be> |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 12 | * Copyright (c) 2002-2006 Ping Cheng <pingc@wacom.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
| 14 | * ChangeLog: |
| 15 | * v0.1 (vp) - Initial release |
| 16 | * v0.2 (aba) - Support for all buttons / combinations |
| 17 | * v0.3 (vp) - Support for Intuos added |
| 18 | * v0.4 (sm) - Support for more Intuos models, menustrip |
| 19 | * relative mode, proximity. |
| 20 | * v0.5 (vp) - Big cleanup, nifty features removed, |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 21 | * they belong in userspace |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * v1.8 (vp) - Submit URB only when operating, moved to CVS, |
| 23 | * use input_report_key instead of report_btn and |
| 24 | * other cleanups |
| 25 | * v1.11 (vp) - Add URB ->dev setting for new kernels |
| 26 | * v1.11 (jb) - Add support for the 4D Mouse & Lens |
| 27 | * v1.12 (de) - Add support for two more inking pen IDs |
| 28 | * v1.14 (vp) - Use new USB device id probing scheme. |
| 29 | * Fix Wacom Graphire mouse wheel |
| 30 | * v1.18 (vp) - Fix mouse wheel direction |
| 31 | * Make mouse relative |
| 32 | * v1.20 (fl) - Report tool id for Intuos devices |
| 33 | * - Multi tools support |
| 34 | * - Corrected Intuos protocol decoding (airbrush, 4D mouse, lens cursor...) |
| 35 | * - Add PL models support |
| 36 | * - Fix Wacom Graphire mouse wheel again |
| 37 | * v1.21 (vp) - Removed protocol descriptions |
| 38 | * - Added MISC_SERIAL for tool serial numbers |
| 39 | * (gb) - Identify version on module load. |
| 40 | * v1.21.1 (fl) - added Graphire2 support |
| 41 | * v1.21.2 (fl) - added Intuos2 support |
| 42 | * - added all the PL ids |
| 43 | * v1.21.3 (fl) - added another eraser id from Neil Okamoto |
| 44 | * - added smooth filter for Graphire from Peri Hankey |
| 45 | * - added PenPartner support from Olaf van Es |
| 46 | * - new tool ids from Ole Martin Bjoerndalen |
| 47 | * v1.29 (pc) - Add support for more tablets |
| 48 | * - Fix pressure reporting |
| 49 | * v1.30 (vp) - Merge 2.4 and 2.5 drivers |
| 50 | * - Since 2.5 now has input_sync(), remove MSC_SERIAL abuse |
| 51 | * - Cleanups here and there |
| 52 | * v1.30.1 (pi) - Added Graphire3 support |
| 53 | * v1.40 (pc) - Add support for several new devices, fix eraser reporting, ... |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 54 | * v1.43 (pc) - Added support for Cintiq 21UX |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 55 | * - Fixed a Graphire bug |
| 56 | * - Merged wacom_intuos3_irq into wacom_intuos_irq |
| 57 | * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc. |
| 58 | * - Report Device IDs |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 59 | * v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19 |
| 60 | * - Minor data report fix |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | */ |
| 62 | |
| 63 | /* |
| 64 | * This program is free software; you can redistribute it and/or modify |
| 65 | * it under the terms of the GNU General Public License as published by |
| 66 | * the Free Software Foundation; either version 2 of the License, or |
| 67 | * (at your option) any later version. |
| 68 | */ |
| 69 | |
| 70 | #include <linux/kernel.h> |
| 71 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include <linux/module.h> |
| 73 | #include <linux/init.h> |
David Brownell | ae0dadc | 2006-06-13 10:04:34 -0700 | [diff] [blame] | 74 | #include <linux/usb/input.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Version Information |
| 79 | */ |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 80 | #define DRIVER_VERSION "v1.45" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" |
| 82 | #define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver" |
| 83 | #define DRIVER_LICENSE "GPL" |
| 84 | |
| 85 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 86 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 87 | MODULE_LICENSE(DRIVER_LICENSE); |
| 88 | |
| 89 | #define USB_VENDOR_ID_WACOM 0x056a |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 90 | #define STYLUS_DEVICE_ID 0x02 |
| 91 | #define CURSOR_DEVICE_ID 0x06 |
| 92 | #define ERASER_DEVICE_ID 0x0A |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 94 | enum { |
| 95 | PENPARTNER = 0, |
| 96 | GRAPHIRE, |
Dmitry Torokhov | 1e27ffd | 2006-01-14 00:28:04 -0500 | [diff] [blame] | 97 | WACOM_G4, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 98 | PL, |
| 99 | INTUOS, |
| 100 | INTUOS3, |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 101 | INTUOS312, |
| 102 | INTUOS319, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 103 | CINTIQ, |
| 104 | MAX_TYPE |
| 105 | }; |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | struct wacom_features { |
| 108 | char *name; |
| 109 | int pktlen; |
| 110 | int x_max; |
| 111 | int y_max; |
| 112 | int pressure_max; |
| 113 | int distance_max; |
| 114 | int type; |
| 115 | usb_complete_t irq; |
| 116 | }; |
| 117 | |
| 118 | struct wacom { |
| 119 | signed char *data; |
| 120 | dma_addr_t data_dma; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 121 | struct input_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | struct usb_device *usbdev; |
| 123 | struct urb *irq; |
| 124 | struct wacom_features *features; |
| 125 | int tool[2]; |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 126 | int id[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | __u32 serial[2]; |
| 128 | char phys[32]; |
| 129 | }; |
| 130 | |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 131 | #define USB_REQ_GET_REPORT 0x01 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #define USB_REQ_SET_REPORT 0x09 |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 133 | |
| 134 | static int usb_get_report(struct usb_interface *intf, unsigned char type, |
| 135 | unsigned char id, void *buf, int size) |
| 136 | { |
| 137 | return usb_control_msg(interface_to_usbdev(intf), |
| 138 | usb_rcvctrlpipe(interface_to_usbdev(intf), 0), |
| 139 | USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 140 | (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber, |
| 141 | buf, size, 100); |
| 142 | } |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | static int usb_set_report(struct usb_interface *intf, unsigned char type, |
| 145 | unsigned char id, void *buf, int size) |
| 146 | { |
| 147 | return usb_control_msg(interface_to_usbdev(intf), |
| 148 | usb_sndctrlpipe(interface_to_usbdev(intf), 0), |
| 149 | USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 150 | (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber, |
| 151 | buf, size, 1000); |
| 152 | } |
| 153 | |
| 154 | static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs) |
| 155 | { |
| 156 | struct wacom *wacom = urb->context; |
| 157 | unsigned char *data = wacom->data; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 158 | struct input_dev *dev = wacom->dev; |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 159 | int prox, pressure, id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | int retval; |
| 161 | |
| 162 | switch (urb->status) { |
| 163 | case 0: |
| 164 | /* success */ |
| 165 | break; |
| 166 | case -ECONNRESET: |
| 167 | case -ENOENT: |
| 168 | case -ESHUTDOWN: |
| 169 | /* this urb is terminated, clean up */ |
| 170 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); |
| 171 | return; |
| 172 | default: |
| 173 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); |
| 174 | goto exit; |
| 175 | } |
| 176 | |
| 177 | if (data[0] != 2) { |
| 178 | dbg("wacom_pl_irq: received unknown report #%d", data[0]); |
| 179 | goto exit; |
| 180 | } |
| 181 | |
| 182 | prox = data[1] & 0x40; |
| 183 | |
| 184 | input_regs(dev, regs); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 185 | |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 186 | id = ERASER_DEVICE_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | if (prox) { |
| 188 | |
| 189 | pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); |
| 190 | if (wacom->features->pressure_max > 255) |
| 191 | pressure = (pressure << 1) | ((data[4] >> 6) & 1); |
| 192 | pressure += (wacom->features->pressure_max + 1) / 2; |
| 193 | |
| 194 | /* |
| 195 | * if going from out of proximity into proximity select between the eraser |
| 196 | * and the pen based on the state of the stylus2 button, choose eraser if |
| 197 | * pressed else choose pen. if not a proximity change from out to in, send |
| 198 | * an out of proximity for previous tool then a in for new tool. |
| 199 | */ |
| 200 | if (!wacom->tool[0]) { |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 201 | /* Eraser bit set for DTF */ |
| 202 | if (data[1] & 0x10) |
| 203 | wacom->tool[1] = BTN_TOOL_RUBBER; |
| 204 | else |
| 205 | /* Going into proximity select tool */ |
| 206 | wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 207 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* was entered with stylus2 pressed */ |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 209 | if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /* report out proximity for previous tool */ |
| 211 | input_report_key(dev, wacom->tool[1], 0); |
| 212 | input_sync(dev); |
| 213 | wacom->tool[1] = BTN_TOOL_PEN; |
| 214 | goto exit; |
| 215 | } |
| 216 | } |
| 217 | if (wacom->tool[1] != BTN_TOOL_RUBBER) { |
| 218 | /* Unknown tool selected default to pen tool */ |
| 219 | wacom->tool[1] = BTN_TOOL_PEN; |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 220 | id = STYLUS_DEVICE_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 222 | input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */ |
| 223 | input_report_abs(dev, ABS_MISC, id); /* report tool id */ |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 224 | input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14)); |
| 225 | input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | input_report_abs(dev, ABS_PRESSURE, pressure); |
| 227 | |
| 228 | input_report_key(dev, BTN_TOUCH, data[4] & 0x08); |
| 229 | input_report_key(dev, BTN_STYLUS, data[4] & 0x10); |
| 230 | /* Only allow the stylus2 button to be reported for the pen tool. */ |
| 231 | input_report_key(dev, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20)); |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 232 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* report proximity-out of a (valid) tool */ |
| 234 | if (wacom->tool[1] != BTN_TOOL_RUBBER) { |
| 235 | /* Unknown tool selected default to pen tool */ |
| 236 | wacom->tool[1] = BTN_TOOL_PEN; |
| 237 | } |
| 238 | input_report_key(dev, wacom->tool[1], prox); |
| 239 | } |
| 240 | |
| 241 | wacom->tool[0] = prox; /* Save proximity state */ |
| 242 | input_sync(dev); |
| 243 | |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 244 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | retval = usb_submit_urb (urb, GFP_ATOMIC); |
| 246 | if (retval) |
| 247 | err ("%s - usb_submit_urb failed with result %d", |
| 248 | __FUNCTION__, retval); |
| 249 | } |
| 250 | |
| 251 | static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs) |
| 252 | { |
| 253 | struct wacom *wacom = urb->context; |
| 254 | unsigned char *data = wacom->data; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 255 | struct input_dev *dev = wacom->dev; |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 256 | int retval, id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | switch (urb->status) { |
| 259 | case 0: |
| 260 | /* success */ |
| 261 | break; |
| 262 | case -ECONNRESET: |
| 263 | case -ENOENT: |
| 264 | case -ESHUTDOWN: |
| 265 | /* this urb is terminated, clean up */ |
| 266 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); |
| 267 | return; |
| 268 | default: |
| 269 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); |
| 270 | goto exit; |
| 271 | } |
| 272 | |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 273 | if (data[0] != 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]); |
| 275 | goto exit; |
| 276 | } |
| 277 | |
| 278 | input_regs(dev, regs); |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 279 | if (data[1] & 0x04) { |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 280 | input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | input_report_key(dev, BTN_TOUCH, data[1] & 0x08); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 282 | id = ERASER_DEVICE_ID; |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 283 | } else { |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 284 | input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | input_report_key(dev, BTN_TOUCH, data[1] & 0x01); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 286 | id = STYLUS_DEVICE_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 288 | input_report_abs(dev, ABS_MISC, id); /* report tool id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[2])); |
| 290 | input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[4])); |
| 291 | input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6])); |
| 292 | input_report_key(dev, BTN_STYLUS, data[1] & 0x02); |
| 293 | input_report_key(dev, BTN_STYLUS2, data[1] & 0x10); |
| 294 | |
| 295 | input_sync(dev); |
| 296 | |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 297 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | retval = usb_submit_urb (urb, GFP_ATOMIC); |
| 299 | if (retval) |
| 300 | err ("%s - usb_submit_urb failed with result %d", |
| 301 | __FUNCTION__, retval); |
| 302 | } |
| 303 | |
| 304 | static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs) |
| 305 | { |
| 306 | struct wacom *wacom = urb->context; |
| 307 | unsigned char *data = wacom->data; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 308 | struct input_dev *dev = wacom->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | int retval; |
| 310 | |
| 311 | switch (urb->status) { |
| 312 | case 0: |
| 313 | /* success */ |
| 314 | break; |
| 315 | case -ECONNRESET: |
| 316 | case -ENOENT: |
| 317 | case -ESHUTDOWN: |
| 318 | /* this urb is terminated, clean up */ |
| 319 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); |
| 320 | return; |
| 321 | default: |
| 322 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); |
| 323 | goto exit; |
| 324 | } |
| 325 | |
| 326 | if (data[0] != 2) { |
| 327 | printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]); |
| 328 | goto exit; |
| 329 | } |
| 330 | |
| 331 | input_regs(dev, regs); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 332 | input_report_key(dev, BTN_TOOL_PEN, 1); |
| 333 | input_report_abs(dev, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[1])); |
| 335 | input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[3])); |
| 336 | input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127); |
| 337 | input_report_key(dev, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20)); |
| 338 | input_report_key(dev, BTN_STYLUS, (data[5] & 0x40)); |
| 339 | input_sync(dev); |
| 340 | |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 341 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | retval = usb_submit_urb (urb, GFP_ATOMIC); |
| 343 | if (retval) |
| 344 | err ("%s - usb_submit_urb failed with result %d", |
| 345 | __FUNCTION__, retval); |
| 346 | } |
| 347 | |
| 348 | static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs) |
| 349 | { |
| 350 | struct wacom *wacom = urb->context; |
| 351 | unsigned char *data = wacom->data; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 352 | struct input_dev *dev = wacom->dev; |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 353 | int x, y, id, rw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | int retval; |
| 355 | |
| 356 | switch (urb->status) { |
| 357 | case 0: |
| 358 | /* success */ |
| 359 | break; |
| 360 | case -ECONNRESET: |
| 361 | case -ENOENT: |
| 362 | case -ESHUTDOWN: |
| 363 | /* this urb is terminated, clean up */ |
| 364 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); |
| 365 | return; |
| 366 | default: |
| 367 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); |
| 368 | goto exit; |
| 369 | } |
| 370 | |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 371 | if (data[0] == 99) return; /* for Volito tablets */ |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | if (data[0] != 2) { |
| 374 | dbg("wacom_graphire_irq: received unknown report #%d", data[0]); |
| 375 | goto exit; |
| 376 | } |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | input_regs(dev, regs); |
| 379 | |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 380 | id = STYLUS_DEVICE_ID; |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 381 | if (data[1] & 0x10) { /* in prox */ |
| 382 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 383 | switch ((data[1] >> 5) & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 385 | case 0: /* Pen */ |
| 386 | wacom->tool[0] = BTN_TOOL_PEN; |
| 387 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 389 | case 1: /* Rubber */ |
| 390 | wacom->tool[0] = BTN_TOOL_RUBBER; |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 391 | id = ERASER_DEVICE_ID; |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 392 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 394 | case 2: /* Mouse with wheel */ |
| 395 | input_report_key(dev, BTN_MIDDLE, data[1] & 0x04); |
Dmitry Torokhov | 1e27ffd | 2006-01-14 00:28:04 -0500 | [diff] [blame] | 396 | if (wacom->features->type == WACOM_G4) { |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 397 | rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03); |
| 398 | input_report_rel(dev, REL_WHEEL, -rw); |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 399 | } else |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 400 | input_report_rel(dev, REL_WHEEL, -(signed char) data[6]); |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 401 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 403 | case 3: /* Mouse without wheel */ |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 404 | wacom->tool[0] = BTN_TOOL_MOUSE; |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 405 | id = CURSOR_DEVICE_ID; |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 406 | input_report_key(dev, BTN_LEFT, data[1] & 0x01); |
| 407 | input_report_key(dev, BTN_RIGHT, data[1] & 0x02); |
Dmitry Torokhov | 1e27ffd | 2006-01-14 00:28:04 -0500 | [diff] [blame] | 408 | if (wacom->features->type == WACOM_G4) |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 409 | input_report_abs(dev, ABS_DISTANCE, data[6]); |
| 410 | else |
| 411 | input_report_abs(dev, ABS_DISTANCE, data[7]); |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 412 | break; |
| 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Ping Cheng | dc1d97e | 2005-08-16 15:16:32 -0700 | [diff] [blame] | 416 | if (data[1] & 0x90) { |
| 417 | x = le16_to_cpu(*(__le16 *) &data[2]); |
| 418 | y = le16_to_cpu(*(__le16 *) &data[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | input_report_abs(dev, ABS_X, x); |
| 420 | input_report_abs(dev, ABS_Y, y); |
Ping Cheng | dc1d97e | 2005-08-16 15:16:32 -0700 | [diff] [blame] | 421 | if (wacom->tool[0] != BTN_TOOL_MOUSE) { |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 422 | input_report_abs(dev, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8)); |
Ping Cheng | dc1d97e | 2005-08-16 15:16:32 -0700 | [diff] [blame] | 423 | input_report_key(dev, BTN_TOUCH, data[1] & 0x01); |
| 424 | input_report_key(dev, BTN_STYLUS, data[1] & 0x02); |
| 425 | input_report_key(dev, BTN_STYLUS2, data[1] & 0x04); |
| 426 | } |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 429 | if (data[1] & 0x10) |
| 430 | input_report_abs(dev, ABS_MISC, id); /* report tool id */ |
| 431 | else |
| 432 | input_report_abs(dev, ABS_MISC, 0); /* reset tool id */ |
| 433 | input_report_key(dev, wacom->tool[0], data[1] & 0x10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | input_sync(dev); |
| 435 | |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 436 | /* send pad data */ |
Dmitry Torokhov | 1e27ffd | 2006-01-14 00:28:04 -0500 | [diff] [blame] | 437 | if (wacom->features->type == WACOM_G4) { |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 438 | if ((wacom->serial[1] & 0xc0) != (data[7] & 0xf8)) { |
| 439 | wacom->id[1] = 1; |
| 440 | wacom->serial[1] = (data[7] & 0xf8); |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 441 | input_report_key(dev, BTN_0, (data[7] & 0x40)); |
| 442 | input_report_key(dev, BTN_4, (data[7] & 0x80)); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 443 | rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3); |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 444 | input_report_rel(dev, REL_WHEEL, rw); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 445 | input_report_key(dev, BTN_TOOL_FINGER, 0xf0); |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 446 | input_event(dev, EV_MSC, MSC_SERIAL, 0xf0); |
| 447 | } else if (wacom->id[1]) { |
| 448 | wacom->id[1] = 0; |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 449 | input_report_key(dev, BTN_TOOL_FINGER, 0); |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 450 | input_event(dev, EV_MSC, MSC_SERIAL, 0xf0); |
| 451 | } |
| 452 | input_sync(dev); |
| 453 | } |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 454 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | retval = usb_submit_urb (urb, GFP_ATOMIC); |
| 456 | if (retval) |
| 457 | err ("%s - usb_submit_urb failed with result %d", |
| 458 | __FUNCTION__, retval); |
| 459 | } |
| 460 | |
| 461 | static int wacom_intuos_inout(struct urb *urb) |
| 462 | { |
| 463 | struct wacom *wacom = urb->context; |
| 464 | unsigned char *data = wacom->data; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 465 | struct input_dev *dev = wacom->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | int idx; |
| 467 | |
| 468 | /* tool number */ |
| 469 | idx = data[1] & 0x01; |
| 470 | |
| 471 | /* Enter report */ |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 472 | if ((data[1] & 0xfc) == 0xc0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /* serial number of the tool */ |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 474 | wacom->serial[idx] = ((data[3] & 0x0f) << 28) + |
| 475 | (data[4] << 20) + (data[5] << 12) + |
| 476 | (data[6] << 4) + (data[7] >> 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 478 | wacom->id[idx] = (data[2] << 4) | (data[3] >> 4); |
| 479 | switch (wacom->id[idx]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | case 0x812: /* Inking pen */ |
| 481 | case 0x801: /* Intuos3 Inking pen */ |
| 482 | case 0x012: |
| 483 | wacom->tool[idx] = BTN_TOOL_PENCIL; |
| 484 | break; |
| 485 | case 0x822: /* Pen */ |
| 486 | case 0x842: |
| 487 | case 0x852: |
| 488 | case 0x823: /* Intuos3 Grip Pen */ |
| 489 | case 0x813: /* Intuos3 Classic Pen */ |
| 490 | case 0x885: /* Intuos3 Marker Pen */ |
| 491 | case 0x022: |
| 492 | wacom->tool[idx] = BTN_TOOL_PEN; |
| 493 | break; |
| 494 | case 0x832: /* Stroke pen */ |
| 495 | case 0x032: |
| 496 | wacom->tool[idx] = BTN_TOOL_BRUSH; |
| 497 | break; |
| 498 | case 0x007: /* Mouse 4D and 2D */ |
| 499 | case 0x09c: |
| 500 | case 0x094: |
| 501 | case 0x017: /* Intuos3 2D Mouse */ |
| 502 | wacom->tool[idx] = BTN_TOOL_MOUSE; |
| 503 | break; |
| 504 | case 0x096: /* Lens cursor */ |
| 505 | case 0x097: /* Intuos3 Lens cursor */ |
| 506 | wacom->tool[idx] = BTN_TOOL_LENS; |
| 507 | break; |
| 508 | case 0x82a: /* Eraser */ |
| 509 | case 0x85a: |
| 510 | case 0x91a: |
| 511 | case 0xd1a: |
| 512 | case 0x0fa: |
| 513 | case 0x82b: /* Intuos3 Grip Pen Eraser */ |
| 514 | case 0x81b: /* Intuos3 Classic Pen Eraser */ |
| 515 | case 0x91b: /* Intuos3 Airbrush Eraser */ |
| 516 | wacom->tool[idx] = BTN_TOOL_RUBBER; |
| 517 | break; |
| 518 | case 0xd12: |
| 519 | case 0x912: |
| 520 | case 0x112: |
| 521 | case 0x913: /* Intuos3 Airbrush */ |
| 522 | wacom->tool[idx] = BTN_TOOL_AIRBRUSH; |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 523 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | default: /* Unknown tool */ |
| 525 | wacom->tool[idx] = BTN_TOOL_PEN; |
| 526 | } |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 527 | if(!((wacom->tool[idx] == BTN_TOOL_LENS) && |
| 528 | ((wacom->features->type == INTUOS312) |
| 529 | || (wacom->features->type == INTUOS319)))) { |
| 530 | input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */ |
| 531 | input_report_key(dev, wacom->tool[idx], 1); |
| 532 | input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]); |
| 533 | input_sync(dev); |
| 534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | return 1; |
| 536 | } |
| 537 | |
| 538 | /* Exit report */ |
| 539 | if ((data[1] & 0xfe) == 0x80) { |
| 540 | input_report_key(dev, wacom->tool[idx], 0); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 541 | input_report_abs(dev, ABS_MISC, 0); /* reset tool id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]); |
| 543 | input_sync(dev); |
| 544 | return 1; |
| 545 | } |
| 546 | |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 547 | if((wacom->tool[idx] == BTN_TOOL_LENS) && ((wacom->features->type == INTUOS312) |
| 548 | || (wacom->features->type == INTUOS319))) |
| 549 | return 1; |
| 550 | else |
| 551 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | static void wacom_intuos_general(struct urb *urb) |
| 555 | { |
| 556 | struct wacom *wacom = urb->context; |
| 557 | unsigned char *data = wacom->data; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 558 | struct input_dev *dev = wacom->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | unsigned int t; |
| 560 | |
| 561 | /* general pen packet */ |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 562 | if ((data[1] & 0xb8) == 0xa0) { |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 563 | t = (data[6] << 2) | ((data[7] >> 6) & 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | input_report_abs(dev, ABS_PRESSURE, t); |
| 565 | input_report_abs(dev, ABS_TILT_X, |
| 566 | ((data[7] << 1) & 0x7e) | (data[8] >> 7)); |
| 567 | input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f); |
| 568 | input_report_key(dev, BTN_STYLUS, data[1] & 2); |
| 569 | input_report_key(dev, BTN_STYLUS2, data[1] & 4); |
| 570 | input_report_key(dev, BTN_TOUCH, t > 10); |
| 571 | } |
| 572 | |
| 573 | /* airbrush second packet */ |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 574 | if ((data[1] & 0xbc) == 0xb4) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | input_report_abs(dev, ABS_WHEEL, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 576 | (data[6] << 2) | ((data[7] >> 6) & 3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | input_report_abs(dev, ABS_TILT_X, |
| 578 | ((data[7] << 1) & 0x7e) | (data[8] >> 7)); |
| 579 | input_report_abs(dev, ABS_TILT_Y, data[8] & 0x7f); |
| 580 | } |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs) |
| 585 | { |
| 586 | struct wacom *wacom = urb->context; |
| 587 | unsigned char *data = wacom->data; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 588 | struct input_dev *dev = wacom->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | unsigned int t; |
| 590 | int idx; |
| 591 | int retval; |
| 592 | |
| 593 | switch (urb->status) { |
| 594 | case 0: |
| 595 | /* success */ |
| 596 | break; |
| 597 | case -ECONNRESET: |
| 598 | case -ENOENT: |
| 599 | case -ESHUTDOWN: |
| 600 | /* this urb is terminated, clean up */ |
| 601 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); |
| 602 | return; |
| 603 | default: |
| 604 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); |
| 605 | goto exit; |
| 606 | } |
| 607 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 608 | if (data[0] != 2 && data[0] != 5 && data[0] != 6 && data[0] != 12) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | dbg("wacom_intuos_irq: received unknown report #%d", data[0]); |
| 610 | goto exit; |
| 611 | } |
| 612 | |
| 613 | input_regs(dev, regs); |
| 614 | |
| 615 | /* tool number */ |
| 616 | idx = data[1] & 0x01; |
| 617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | /* pad packets. Works as a second tool and is always in prox */ |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 619 | if (data[0] == 12) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | /* initiate the pad as a device */ |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 621 | if (wacom->tool[1] != BTN_TOOL_FINGER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | wacom->tool[1] = BTN_TOOL_FINGER; |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | input_report_key(dev, BTN_0, (data[5] & 0x01)); |
| 625 | input_report_key(dev, BTN_1, (data[5] & 0x02)); |
| 626 | input_report_key(dev, BTN_2, (data[5] & 0x04)); |
| 627 | input_report_key(dev, BTN_3, (data[5] & 0x08)); |
| 628 | input_report_key(dev, BTN_4, (data[6] & 0x01)); |
| 629 | input_report_key(dev, BTN_5, (data[6] & 0x02)); |
| 630 | input_report_key(dev, BTN_6, (data[6] & 0x04)); |
| 631 | input_report_key(dev, BTN_7, (data[6] & 0x08)); |
| 632 | input_report_abs(dev, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]); |
| 633 | input_report_abs(dev, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 634 | |
| 635 | if((data[5] & 0x0f) | (data[6] & 0x0f) | (data[1] & 0x1f) | data[2]) |
| 636 | input_report_key(dev, wacom->tool[1], 1); |
| 637 | else |
| 638 | input_report_key(dev, wacom->tool[1], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff); |
| 640 | input_sync(dev); |
| 641 | goto exit; |
| 642 | } |
| 643 | |
| 644 | /* process in/out prox events */ |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 645 | if (wacom_intuos_inout(urb)) |
| 646 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 648 | /* Cintiq doesn't send data when RDY bit isn't set */ |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 649 | if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40)) |
Ping Cheng | dc1d97e | 2005-08-16 15:16:32 -0700 | [diff] [blame] | 650 | goto exit; |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 651 | |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 652 | if (wacom->features->type >= INTUOS3) { |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 653 | input_report_abs(dev, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); |
| 654 | input_report_abs(dev, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); |
| 655 | input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 656 | } else { |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 657 | input_report_abs(dev, ABS_X, be16_to_cpu(*(__be16 *) &data[2])); |
| 658 | input_report_abs(dev, ABS_Y, be16_to_cpu(*(__be16 *) &data[4])); |
| 659 | input_report_abs(dev, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); |
| 660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
| 662 | /* process general packets */ |
| 663 | wacom_intuos_general(urb); |
| 664 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 665 | /* 4D mouse, 2D mouse, marker pen rotation, or Lens cursor packets */ |
| 666 | if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0) { |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 667 | |
| 668 | if (data[1] & 0x02) { |
| 669 | /* Rotation packet */ |
| 670 | if (wacom->features->type >= INTUOS3) { |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 671 | /* I3 marker pen rotation reported as wheel |
| 672 | * due to valuator limitation |
| 673 | */ |
| 674 | t = (data[6] << 3) | ((data[7] >> 5) & 7); |
| 675 | t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : |
| 676 | ((t-1) / 2 + 450)) : (450 - t / 2) ; |
| 677 | input_report_abs(dev, ABS_WHEEL, t); |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 678 | } else { |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 679 | /* 4D mouse rotation packet */ |
| 680 | t = (data[6] << 3) | ((data[7] >> 5) & 7); |
| 681 | input_report_abs(dev, ABS_RZ, (data[7] & 0x20) ? |
| 682 | ((t - 1) / 2) : -t / 2); |
| 683 | } |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 684 | |
| 685 | } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3) { |
| 686 | /* 4D mouse packet */ |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 687 | input_report_key(dev, BTN_LEFT, data[8] & 0x01); |
| 688 | input_report_key(dev, BTN_MIDDLE, data[8] & 0x02); |
| 689 | input_report_key(dev, BTN_RIGHT, data[8] & 0x04); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 691 | input_report_key(dev, BTN_SIDE, data[8] & 0x20); |
| 692 | input_report_key(dev, BTN_EXTRA, data[8] & 0x10); |
| 693 | t = (data[6] << 2) | ((data[7] >> 6) & 3); |
| 694 | input_report_abs(dev, ABS_THROTTLE, (data[8] & 0x08) ? -t : t); |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 695 | |
| 696 | } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { |
| 697 | /* 2D mouse packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | input_report_key(dev, BTN_LEFT, data[8] & 0x04); |
| 699 | input_report_key(dev, BTN_MIDDLE, data[8] & 0x08); |
| 700 | input_report_key(dev, BTN_RIGHT, data[8] & 0x10); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 701 | input_report_rel(dev, REL_WHEEL, (data[8] & 0x01) |
| 702 | - ((data[8] & 0x02) >> 1)); |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 703 | |
| 704 | /* I3 2D mouse side buttons */ |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 705 | if (wacom->features->type == INTUOS3) { |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 706 | input_report_key(dev, BTN_SIDE, data[8] & 0x40); |
| 707 | input_report_key(dev, BTN_EXTRA, data[8] & 0x20); |
| 708 | } |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 709 | |
| 710 | } else if (wacom->features->type < INTUOS3) { |
| 711 | /* Lens cursor packets */ |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 712 | input_report_key(dev, BTN_LEFT, data[8] & 0x01); |
| 713 | input_report_key(dev, BTN_MIDDLE, data[8] & 0x02); |
| 714 | input_report_key(dev, BTN_RIGHT, data[8] & 0x04); |
| 715 | input_report_key(dev, BTN_SIDE, data[8] & 0x10); |
| 716 | input_report_key(dev, BTN_EXTRA, data[8] & 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 720 | input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */ |
| 721 | input_report_key(dev, wacom->tool[idx], 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]); |
| 723 | input_sync(dev); |
| 724 | |
| 725 | exit: |
| 726 | retval = usb_submit_urb (urb, GFP_ATOMIC); |
| 727 | if (retval) |
| 728 | err ("%s - usb_submit_urb failed with result %d", |
| 729 | __FUNCTION__, retval); |
| 730 | } |
| 731 | |
| 732 | static struct wacom_features wacom_features[] = { |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 733 | { "Wacom Penpartner", 7, 5040, 3780, 255, 32, PENPARTNER, wacom_penpartner_irq }, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 734 | { "Wacom Graphire", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq }, |
| 735 | { "Wacom Graphire2 4x5", 8, 10206, 7422, 511, 32, GRAPHIRE, wacom_graphire_irq }, |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 736 | { "Wacom Graphire2 5x7", 8, 13918, 10206, 511, 32, GRAPHIRE, wacom_graphire_irq }, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 737 | { "Wacom Graphire3", 8, 10208, 7424, 511, 32, GRAPHIRE, wacom_graphire_irq }, |
| 738 | { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 32, GRAPHIRE, wacom_graphire_irq }, |
Dmitry Torokhov | 1e27ffd | 2006-01-14 00:28:04 -0500 | [diff] [blame] | 739 | { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 32, WACOM_G4, wacom_graphire_irq }, |
| 740 | { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 32, WACOM_G4, wacom_graphire_irq }, |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 741 | { "Wacom Volito", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq }, |
| 742 | { "Wacom PenStation2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq }, |
| 743 | { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 32, GRAPHIRE, wacom_graphire_irq }, |
| 744 | { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 32, GRAPHIRE, wacom_graphire_irq }, |
| 745 | { "Wacom PenPartner2", 8, 3250, 2320, 255, 32, GRAPHIRE, wacom_graphire_irq }, |
Dmitry Torokhov | e511988 | 2005-06-06 02:28:29 -0500 | [diff] [blame] | 746 | { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 747 | { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 748 | { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 749 | { "Wacom Intuos 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 750 | { "Wacom Intuos 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 751 | { "Wacom PL400", 8, 5408, 4056, 255, 32, PL, wacom_pl_irq }, |
| 752 | { "Wacom PL500", 8, 6144, 4608, 255, 32, PL, wacom_pl_irq }, |
| 753 | { "Wacom PL600", 8, 6126, 4604, 255, 32, PL, wacom_pl_irq }, |
| 754 | { "Wacom PL600SX", 8, 6260, 5016, 255, 32, PL, wacom_pl_irq }, |
| 755 | { "Wacom PL550", 8, 6144, 4608, 511, 32, PL, wacom_pl_irq }, |
| 756 | { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq }, |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 757 | { "Wacom PL700", 8, 6758, 5406, 511, 32, PL, wacom_pl_irq }, |
| 758 | { "Wacom PL510", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq }, |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 759 | { "Wacom DTU710", 8, 34080, 27660, 511, 32, PL, wacom_pl_irq }, |
| 760 | { "Wacom DTF521", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq }, |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 761 | { "Wacom DTF720", 8, 6858, 5506, 511, 32, PL, wacom_pl_irq }, |
| 762 | { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq }, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 763 | { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 764 | { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 765 | { "Wacom Intuos2 9x12", 10, 30480, 24060, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 766 | { "Wacom Intuos2 12x12", 10, 30480, 31680, 1023, 15, INTUOS, wacom_intuos_irq }, |
| 767 | { "Wacom Intuos2 12x18", 10, 45720, 31680, 1023, 15, INTUOS, wacom_intuos_irq }, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 768 | { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq }, |
| 769 | { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq }, |
| 770 | { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq }, |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 771 | { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 15, INTUOS312, wacom_intuos_irq }, |
| 772 | { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 15, INTUOS319, wacom_intuos_irq }, |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 773 | { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 15, INTUOS3, wacom_intuos_irq }, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 774 | { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq }, |
| 775 | { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq }, |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 776 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | }; |
| 778 | |
| 779 | static struct usb_device_id wacom_ids[] = { |
| 780 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) }, |
| 781 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) }, |
| 782 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) }, |
| 783 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) }, |
| 784 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) }, |
| 785 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) }, |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 786 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) }, |
| 787 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) }, |
| 788 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) }, |
| 789 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) }, |
| 790 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) }, |
| 791 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) }, |
| 792 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) }, |
| 794 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) }, |
| 795 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) }, |
| 796 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) }, |
| 797 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) }, |
| 798 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) }, |
| 799 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) }, |
| 800 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) }, |
| 801 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) }, |
| 802 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) }, |
| 803 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) }, |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 804 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) }, |
| 805 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) }, |
| 806 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) }, |
| 807 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) }, |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 808 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC3) }, |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 809 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) }, |
| 811 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) }, |
| 812 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) }, |
| 813 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) }, |
| 814 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) }, |
| 816 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) }, |
| 817 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) }, |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 818 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) }, |
| 819 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) }, |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 820 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) }, |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 821 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) }, |
| 823 | { } |
| 824 | }; |
| 825 | |
| 826 | MODULE_DEVICE_TABLE(usb, wacom_ids); |
| 827 | |
| 828 | static int wacom_open(struct input_dev *dev) |
| 829 | { |
| 830 | struct wacom *wacom = dev->private; |
| 831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | wacom->irq->dev = wacom->usbdev; |
Dmitry Torokhov | 65cde54 | 2005-05-29 02:29:38 -0500 | [diff] [blame] | 833 | if (usb_submit_urb(wacom->irq, GFP_KERNEL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | static void wacom_close(struct input_dev *dev) |
| 840 | { |
| 841 | struct wacom *wacom = dev->private; |
| 842 | |
Dmitry Torokhov | 65cde54 | 2005-05-29 02:29:38 -0500 | [diff] [blame] | 843 | usb_kill_urb(wacom->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 847 | { |
| 848 | struct usb_device *dev = interface_to_usbdev(intf); |
| 849 | struct usb_endpoint_descriptor *endpoint; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | struct wacom *wacom; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 851 | struct input_dev *input_dev; |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 852 | char rep_data[2], limit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 854 | wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); |
| 855 | input_dev = input_allocate_device(); |
| 856 | if (!wacom || !input_dev) |
| 857 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
| 859 | wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 860 | if (!wacom->data) |
| 861 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
| 863 | wacom->irq = usb_alloc_urb(0, GFP_KERNEL); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 864 | if (!wacom->irq) |
| 865 | goto fail2; |
| 866 | |
| 867 | wacom->usbdev = dev; |
| 868 | wacom->dev = input_dev; |
| 869 | usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); |
| 870 | strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
| 872 | wacom->features = wacom_features + (id - wacom_ids); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 873 | if (wacom->features->pktlen > 10) |
| 874 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 876 | input_dev->name = wacom->features->name; |
| 877 | usb_to_input_id(dev, &input_dev->id); |
| 878 | |
| 879 | input_dev->cdev.dev = &intf->dev; |
| 880 | input_dev->private = wacom; |
| 881 | input_dev->open = wacom_open; |
| 882 | input_dev->close = wacom_close; |
| 883 | |
| 884 | input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS); |
| 885 | input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS); |
Denny Priebe | 40c37213 | 2005-12-29 22:19:09 -0500 | [diff] [blame] | 886 | input_set_abs_params(input_dev, ABS_X, 0, wacom->features->x_max, 4, 0); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 887 | input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0); |
| 888 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0); |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 889 | input_dev->absbit[LONG(ABS_MISC)] |= BIT(ABS_MISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
| 891 | switch (wacom->features->type) { |
Dmitry Torokhov | 1e27ffd | 2006-01-14 00:28:04 -0500 | [diff] [blame] | 892 | case WACOM_G4: |
Ping Cheng | ebb6f37 | 2005-11-17 09:46:51 -0800 | [diff] [blame] | 893 | input_dev->evbit[0] |= BIT(EV_MSC); |
| 894 | input_dev->mscbit[0] |= BIT(MSC_SERIAL); |
| 895 | input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); |
| 896 | input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); |
| 897 | /* fall through */ |
| 898 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 899 | case GRAPHIRE: |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 900 | input_dev->evbit[0] |= BIT(EV_REL); |
| 901 | input_dev->relbit[0] |= BIT(REL_WHEEL); |
| 902 | input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); |
| 903 | input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2); |
| 904 | input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | break; |
| 906 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 907 | case INTUOS3: |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 908 | case INTUOS312: |
| 909 | case INTUOS319: |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 910 | case CINTIQ: |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 911 | input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); |
| 912 | input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); |
| 913 | input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0); |
| 914 | input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | /* fall through */ |
| 916 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 917 | case INTUOS: |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 918 | input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL); |
| 919 | input_dev->mscbit[0] |= BIT(MSC_SERIAL); |
| 920 | input_dev->relbit[0] |= BIT(REL_WHEEL); |
| 921 | input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA); |
| 922 | input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 924 | input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0); |
| 925 | input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0); |
| 926 | input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0); |
| 927 | input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0); |
| 928 | input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0); |
| 929 | input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | break; |
| 931 | |
Ping Cheng | b2f8636 | 2005-06-06 02:25:50 -0500 | [diff] [blame] | 932 | case PL: |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 933 | input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | break; |
| 935 | } |
| 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | endpoint = &intf->cur_altsetting->endpoint[0].desc; |
| 938 | |
| 939 | if (wacom->features->pktlen > 10) |
| 940 | BUG(); |
| 941 | |
| 942 | usb_fill_int_urb(wacom->irq, dev, |
| 943 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), |
| 944 | wacom->data, wacom->features->pktlen, |
| 945 | wacom->features->irq, wacom, endpoint->bInterval); |
| 946 | wacom->irq->transfer_dma = wacom->data_dma; |
| 947 | wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 948 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 949 | input_register_device(wacom->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
Ping Cheng | 7d3fe085 | 2006-03-29 16:33:49 -0800 | [diff] [blame] | 951 | /* Ask the tablet to report tablet data. Repeat until it succeeds */ |
| 952 | do { |
| 953 | rep_data[0] = 2; |
| 954 | rep_data[1] = 2; |
| 955 | usb_set_report(intf, 3, 2, rep_data, 2); |
| 956 | usb_get_report(intf, 3, 2, rep_data, 2); |
| 957 | } while (rep_data[1] != 2 && limit++ < 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | usb_set_intfdata(intf, wacom); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | return 0; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 961 | |
| 962 | fail2: usb_buffer_free(dev, 10, wacom->data, wacom->data_dma); |
| 963 | fail1: input_free_device(input_dev); |
| 964 | kfree(wacom); |
| 965 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static void wacom_disconnect(struct usb_interface *intf) |
| 969 | { |
| 970 | struct wacom *wacom = usb_get_intfdata (intf); |
| 971 | |
| 972 | usb_set_intfdata(intf, NULL); |
| 973 | if (wacom) { |
| 974 | usb_kill_urb(wacom->irq); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 975 | input_unregister_device(wacom->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | usb_free_urb(wacom->irq); |
| 977 | usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma); |
| 978 | kfree(wacom); |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | static struct usb_driver wacom_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | .name = "wacom", |
| 984 | .probe = wacom_probe, |
| 985 | .disconnect = wacom_disconnect, |
| 986 | .id_table = wacom_ids, |
| 987 | }; |
| 988 | |
| 989 | static int __init wacom_init(void) |
| 990 | { |
| 991 | int result = usb_register(&wacom_driver); |
| 992 | if (result == 0) |
| 993 | info(DRIVER_VERSION ":" DRIVER_DESC); |
| 994 | return result; |
| 995 | } |
| 996 | |
| 997 | static void __exit wacom_exit(void) |
| 998 | { |
| 999 | usb_deregister(&wacom_driver); |
| 1000 | } |
| 1001 | |
| 1002 | module_init(wacom_init); |
| 1003 | module_exit(wacom_exit); |