Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * usbtouchscreen.c |
| 3 | * Driver for USB Touchscreens, supporting those devices: |
| 4 | * - eGalax Touchkit |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 5 | * includes eTurboTouch CT-410/510/700 |
| 6 | * - 3M/Microtouch EX II series |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 7 | * - ITM |
| 8 | * - PanJit TouchSet |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 9 | * - eTurboTouch |
| 10 | * - Gunze AHL61 |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 11 | * - DMC TSC-10/25 |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 12 | * - IRTOUCHSYSTEMS/UNITOP |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 13 | * - IdealTEK URTC1000 |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 14 | * - General Touch |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 15 | * - GoTop Super_Q2/GogoPen/PenPower tablets |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 16 | * - JASTEC USB touch controller/DigiTech DTR-02U |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 17 | * - Zytronic capacitive touchscreen |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 18 | * |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 19 | * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch> |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 20 | * Copyright (C) by Todd E. Johnson (mtouchusb.c) |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or |
| 23 | * modify it under the terms of the GNU General Public License as |
| 24 | * published by the Free Software Foundation; either version 2 of the |
| 25 | * License, or (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, but |
| 28 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 30 | * General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | * |
| 36 | * Driver is based on touchkitusb.c |
| 37 | * - ITM parts are from itmtouch.c |
| 38 | * - 3M parts are from mtouchusb.c |
| 39 | * - PanJit parts are from an unmerged driver by Lanslott Gish |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 40 | * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged |
| 41 | * driver from Marius Vollmer |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 42 | * |
| 43 | *****************************************************************************/ |
| 44 | |
| 45 | //#define DEBUG |
| 46 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 47 | #include <linux/kernel.h> |
| 48 | #include <linux/slab.h> |
| 49 | #include <linux/input.h> |
| 50 | #include <linux/module.h> |
| 51 | #include <linux/init.h> |
| 52 | #include <linux/usb.h> |
David Brownell | ae0dadc | 2006-06-13 10:04:34 -0700 | [diff] [blame] | 53 | #include <linux/usb/input.h> |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 54 | #include <linux/hid.h> |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 55 | |
| 56 | |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 57 | #define DRIVER_VERSION "v0.6" |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 58 | #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>" |
| 59 | #define DRIVER_DESC "USB Touchscreen Driver" |
| 60 | |
| 61 | static int swap_xy; |
| 62 | module_param(swap_xy, bool, 0644); |
| 63 | MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped."); |
| 64 | |
Dan Streetman | c9cbf3d | 2009-01-10 23:44:22 -0800 | [diff] [blame] | 65 | static int hwcalib_xy; |
| 66 | module_param(hwcalib_xy, bool, 0644); |
| 67 | MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available"); |
| 68 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 69 | /* device specifc data/functions */ |
| 70 | struct usbtouch_usb; |
| 71 | struct usbtouch_device_info { |
| 72 | int min_xc, max_xc; |
| 73 | int min_yc, max_yc; |
| 74 | int min_press, max_press; |
| 75 | int rept_size; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 76 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 77 | /* |
| 78 | * Always service the USB devices irq not just when the input device is |
| 79 | * open. This is useful when devices have a watchdog which prevents us |
| 80 | * from periodically polling the device. Leave this unset unless your |
| 81 | * touchscreen device requires it, as it does consume more of the USB |
| 82 | * bandwidth. |
| 83 | */ |
| 84 | bool irq_always; |
| 85 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 86 | void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len); |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * used to get the packet len. possible return values: |
| 90 | * > 0: packet len |
| 91 | * = 0: skip one byte |
| 92 | * < 0: -return value more bytes needed |
| 93 | */ |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 94 | int (*get_pkt_len) (unsigned char *pkt, int len); |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 95 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 96 | int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 97 | int (*init) (struct usbtouch_usb *usbtouch); |
| 98 | }; |
| 99 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 100 | /* a usbtouch device */ |
| 101 | struct usbtouch_usb { |
| 102 | unsigned char *data; |
| 103 | dma_addr_t data_dma; |
| 104 | unsigned char *buffer; |
| 105 | int buf_len; |
| 106 | struct urb *irq; |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 107 | struct usb_interface *interface; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 108 | struct input_dev *input; |
| 109 | struct usbtouch_device_info *type; |
| 110 | char name[128]; |
| 111 | char phys[64]; |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 112 | |
| 113 | int x, y; |
| 114 | int touch, press; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 117 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 118 | /* device types */ |
| 119 | enum { |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 120 | DEVTYPE_IGNORE = -1, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 121 | DEVTYPE_EGALAX, |
| 122 | DEVTYPE_PANJIT, |
| 123 | DEVTYPE_3M, |
| 124 | DEVTYPE_ITM, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 125 | DEVTYPE_ETURBO, |
| 126 | DEVTYPE_GUNZE, |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 127 | DEVTYPE_DMC_TSC10, |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 128 | DEVTYPE_IRTOUCH, |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 129 | DEVTYPE_IDEALTEK, |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 130 | DEVTYPE_GENERAL_TOUCH, |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 131 | DEVTYPE_GOTOP, |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 132 | DEVTYPE_JASTEC, |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 133 | DEVTYPE_E2I, |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 134 | DEVTYPE_ZYTRONIC, |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 135 | DEVTYPE_TC5UH, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 136 | }; |
| 137 | |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 138 | #define USB_DEVICE_HID_CLASS(vend, prod) \ |
| 139 | .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \ |
Daniel Ritz | 139ebe8 | 2009-02-28 12:50:54 -0800 | [diff] [blame] | 140 | | USB_DEVICE_ID_MATCH_INT_PROTOCOL \ |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 141 | | USB_DEVICE_ID_MATCH_DEVICE, \ |
| 142 | .idVendor = (vend), \ |
| 143 | .idProduct = (prod), \ |
| 144 | .bInterfaceClass = USB_INTERFACE_CLASS_HID, \ |
| 145 | .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE |
| 146 | |
Márton Németh | 9cb3ce5 | 2010-01-10 23:59:05 -0800 | [diff] [blame] | 147 | static const struct usb_device_id usbtouch_devices[] = { |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 148 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 149 | /* ignore the HID capable devices, handled by usbhid */ |
| 150 | {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE}, |
| 151 | {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE}, |
| 152 | |
| 153 | /* normal device IDs */ |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 154 | {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 155 | {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX}, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 156 | {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
| 157 | {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
| 158 | {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX}, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 159 | {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
| 160 | {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX}, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 161 | #endif |
| 162 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 163 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 164 | {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT}, |
| 165 | {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT}, |
| 166 | {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT}, |
| 167 | {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT}, |
| 168 | #endif |
| 169 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 170 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 171 | {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M}, |
| 172 | #endif |
| 173 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 174 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 175 | {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM}, |
| 176 | #endif |
| 177 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 178 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 179 | {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO}, |
| 180 | #endif |
| 181 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 182 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 183 | {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE}, |
| 184 | #endif |
| 185 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 186 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 187 | {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10}, |
| 188 | #endif |
| 189 | |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 190 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH |
| 191 | {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, |
| 192 | {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, |
| 193 | #endif |
| 194 | |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 195 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK |
| 196 | {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK}, |
| 197 | #endif |
| 198 | |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 199 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH |
| 200 | {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH}, |
| 201 | #endif |
| 202 | |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 203 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP |
| 204 | {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP}, |
| 205 | {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP}, |
| 206 | {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP}, |
| 207 | #endif |
| 208 | |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 209 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC |
| 210 | {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC}, |
| 211 | #endif |
| 212 | |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 213 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I |
| 214 | {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I}, |
| 215 | #endif |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 216 | |
| 217 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC |
| 218 | {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC}, |
| 219 | #endif |
| 220 | |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 221 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH |
| 222 | {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH}, |
| 223 | #endif |
| 224 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 225 | {} |
| 226 | }; |
| 227 | |
| 228 | |
| 229 | /***************************************************************************** |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 230 | * e2i Part |
| 231 | */ |
| 232 | |
| 233 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I |
| 234 | static int e2i_init(struct usbtouch_usb *usbtouch) |
| 235 | { |
| 236 | int ret; |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 237 | struct usb_device *udev = interface_to_usbdev(usbtouch->interface); |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 238 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 239 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 240 | 0x01, 0x02, 0x0000, 0x0081, |
| 241 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 242 | |
| 243 | dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d", |
| 244 | __func__, ret); |
| 245 | return ret; |
| 246 | } |
| 247 | |
| 248 | static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 249 | { |
| 250 | int tmp = (pkt[0] << 8) | pkt[1]; |
| 251 | dev->x = (pkt[2] << 8) | pkt[3]; |
| 252 | dev->y = (pkt[4] << 8) | pkt[5]; |
| 253 | |
| 254 | tmp = tmp - 0xA000; |
| 255 | dev->touch = (tmp > 0); |
| 256 | dev->press = (tmp > 0 ? tmp : 0); |
| 257 | |
| 258 | return 1; |
| 259 | } |
| 260 | #endif |
| 261 | |
| 262 | |
| 263 | /***************************************************************************** |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 264 | * eGalax part |
| 265 | */ |
| 266 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 267 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 268 | |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 269 | #ifndef MULTI_PACKET |
| 270 | #define MULTI_PACKET |
| 271 | #endif |
| 272 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 273 | #define EGALAX_PKT_TYPE_MASK 0xFE |
| 274 | #define EGALAX_PKT_TYPE_REPT 0x80 |
| 275 | #define EGALAX_PKT_TYPE_DIAG 0x0A |
| 276 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 277 | static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 278 | { |
| 279 | if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT) |
| 280 | return 0; |
| 281 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 282 | dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F); |
| 283 | dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F); |
| 284 | dev->touch = pkt[0] & 0x01; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 285 | |
| 286 | return 1; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 287 | } |
| 288 | |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 289 | static int egalax_get_pkt_len(unsigned char *buf, int len) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 290 | { |
| 291 | switch (buf[0] & EGALAX_PKT_TYPE_MASK) { |
| 292 | case EGALAX_PKT_TYPE_REPT: |
| 293 | return 5; |
| 294 | |
| 295 | case EGALAX_PKT_TYPE_DIAG: |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 296 | if (len < 2) |
| 297 | return -1; |
| 298 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 299 | return buf[1] + 2; |
| 300 | } |
| 301 | |
| 302 | return 0; |
| 303 | } |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 304 | #endif |
| 305 | |
| 306 | |
| 307 | /***************************************************************************** |
| 308 | * PanJit Part |
| 309 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 310 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 311 | static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 312 | { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 313 | dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1]; |
| 314 | dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3]; |
| 315 | dev->touch = pkt[0] & 0x01; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 316 | |
| 317 | return 1; |
| 318 | } |
| 319 | #endif |
| 320 | |
| 321 | |
| 322 | /***************************************************************************** |
| 323 | * 3M/Microtouch Part |
| 324 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 325 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 326 | |
| 327 | #define MTOUCHUSB_ASYNC_REPORT 1 |
| 328 | #define MTOUCHUSB_RESET 7 |
| 329 | #define MTOUCHUSB_REQ_CTRLLR_ID 10 |
| 330 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 331 | static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 332 | { |
Dan Streetman | c9cbf3d | 2009-01-10 23:44:22 -0800 | [diff] [blame] | 333 | if (hwcalib_xy) { |
| 334 | dev->x = (pkt[4] << 8) | pkt[3]; |
| 335 | dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]); |
| 336 | } else { |
| 337 | dev->x = (pkt[8] << 8) | pkt[7]; |
| 338 | dev->y = (pkt[10] << 8) | pkt[9]; |
| 339 | } |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 340 | dev->touch = (pkt[2] & 0x40) ? 1 : 0; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 341 | |
| 342 | return 1; |
| 343 | } |
| 344 | |
| 345 | static int mtouch_init(struct usbtouch_usb *usbtouch) |
| 346 | { |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 347 | int ret, i; |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 348 | struct usb_device *udev = interface_to_usbdev(usbtouch->interface); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 349 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 350 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 351 | MTOUCHUSB_RESET, |
| 352 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 353 | 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 354 | dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 355 | __func__, ret); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 356 | if (ret < 0) |
| 357 | return ret; |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 358 | msleep(150); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 359 | |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 360 | for (i = 0; i < 3; i++) { |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 361 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 362 | MTOUCHUSB_ASYNC_REPORT, |
| 363 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 364 | 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 365 | dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 366 | __func__, ret); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 367 | if (ret >= 0) |
| 368 | break; |
| 369 | if (ret != -EPIPE) |
| 370 | return ret; |
| 371 | } |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 372 | |
Dan Streetman | c9cbf3d | 2009-01-10 23:44:22 -0800 | [diff] [blame] | 373 | /* Default min/max xy are the raw values, override if using hw-calib */ |
| 374 | if (hwcalib_xy) { |
| 375 | input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0); |
| 376 | input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0); |
| 377 | } |
| 378 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 379 | return 0; |
| 380 | } |
| 381 | #endif |
| 382 | |
| 383 | |
| 384 | /***************************************************************************** |
| 385 | * ITM Part |
| 386 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 387 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 388 | static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 389 | { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 390 | int touch; |
| 391 | /* |
| 392 | * ITM devices report invalid x/y data if not touched. |
| 393 | * if the screen was touched before but is not touched any more |
| 394 | * report touch as 0 with the last valid x/y data once. then stop |
| 395 | * reporting data until touched again. |
| 396 | */ |
| 397 | dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 398 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 399 | touch = ~pkt[7] & 0x20; |
| 400 | if (!touch) { |
| 401 | if (dev->touch) { |
| 402 | dev->touch = 0; |
| 403 | return 1; |
| 404 | } |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F); |
| 410 | dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F); |
| 411 | dev->touch = touch; |
| 412 | |
| 413 | return 1; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 414 | } |
| 415 | #endif |
| 416 | |
| 417 | |
| 418 | /***************************************************************************** |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 419 | * eTurboTouch part |
| 420 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 421 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 422 | #ifndef MULTI_PACKET |
| 423 | #define MULTI_PACKET |
| 424 | #endif |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 425 | static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 426 | { |
| 427 | unsigned int shift; |
| 428 | |
| 429 | /* packets should start with sync */ |
| 430 | if (!(pkt[0] & 0x80)) |
| 431 | return 0; |
| 432 | |
| 433 | shift = (6 - (pkt[0] & 0x03)); |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 434 | dev->x = ((pkt[3] << 7) | pkt[4]) >> shift; |
| 435 | dev->y = ((pkt[1] << 7) | pkt[2]) >> shift; |
| 436 | dev->touch = (pkt[0] & 0x10) ? 1 : 0; |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 437 | |
| 438 | return 1; |
| 439 | } |
| 440 | |
| 441 | static int eturbo_get_pkt_len(unsigned char *buf, int len) |
| 442 | { |
| 443 | if (buf[0] & 0x80) |
| 444 | return 5; |
| 445 | if (buf[0] == 0x01) |
| 446 | return 3; |
| 447 | return 0; |
| 448 | } |
| 449 | #endif |
| 450 | |
| 451 | |
| 452 | /***************************************************************************** |
| 453 | * Gunze part |
| 454 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 455 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 456 | static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 457 | { |
| 458 | if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80)) |
| 459 | return 0; |
| 460 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 461 | dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F); |
| 462 | dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F); |
| 463 | dev->touch = pkt[0] & 0x20; |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 464 | |
| 465 | return 1; |
| 466 | } |
| 467 | #endif |
| 468 | |
| 469 | /***************************************************************************** |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 470 | * DMC TSC-10/25 Part |
| 471 | * |
| 472 | * Documentation about the controller and it's protocol can be found at |
| 473 | * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf |
| 474 | * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf |
| 475 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 476 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 477 | |
| 478 | /* supported data rates. currently using 130 */ |
| 479 | #define TSC10_RATE_POINT 0x50 |
| 480 | #define TSC10_RATE_30 0x40 |
| 481 | #define TSC10_RATE_50 0x41 |
| 482 | #define TSC10_RATE_80 0x42 |
| 483 | #define TSC10_RATE_100 0x43 |
| 484 | #define TSC10_RATE_130 0x44 |
| 485 | #define TSC10_RATE_150 0x45 |
| 486 | |
| 487 | /* commands */ |
| 488 | #define TSC10_CMD_RESET 0x55 |
| 489 | #define TSC10_CMD_RATE 0x05 |
| 490 | #define TSC10_CMD_DATA1 0x01 |
| 491 | |
| 492 | static int dmc_tsc10_init(struct usbtouch_usb *usbtouch) |
| 493 | { |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 494 | struct usb_device *dev = interface_to_usbdev(usbtouch->interface); |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 495 | int ret = -ENOMEM; |
| 496 | unsigned char *buf; |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 497 | |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 498 | buf = kmalloc(2, GFP_KERNEL); |
| 499 | if (!buf) |
| 500 | goto err_nobuf; |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 501 | /* reset */ |
| 502 | buf[0] = buf[1] = 0xFF; |
| 503 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), |
| 504 | TSC10_CMD_RESET, |
| 505 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 506 | 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT); |
| 507 | if (ret < 0) |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 508 | goto err_out; |
Nuno Lucas | 2ec6f24 | 2008-11-11 16:48:04 -0500 | [diff] [blame] | 509 | if (buf[0] != 0x06) { |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 510 | ret = -ENODEV; |
| 511 | goto err_out; |
| 512 | } |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 513 | |
| 514 | /* set coordinate output rate */ |
| 515 | buf[0] = buf[1] = 0xFF; |
| 516 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), |
| 517 | TSC10_CMD_RATE, |
| 518 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 519 | TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT); |
| 520 | if (ret < 0) |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 521 | goto err_out; |
Nuno Lucas | 2ec6f24 | 2008-11-11 16:48:04 -0500 | [diff] [blame] | 522 | if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) { |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 523 | ret = -ENODEV; |
| 524 | goto err_out; |
| 525 | } |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 526 | |
| 527 | /* start sending data */ |
| 528 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), |
| 529 | TSC10_CMD_DATA1, |
| 530 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 531 | 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 532 | err_out: |
| 533 | kfree(buf); |
| 534 | err_nobuf: |
| 535 | return ret; |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 539 | static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 540 | { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 541 | dev->x = ((pkt[2] & 0x03) << 8) | pkt[1]; |
| 542 | dev->y = ((pkt[4] & 0x03) << 8) | pkt[3]; |
| 543 | dev->touch = pkt[0] & 0x01; |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 544 | |
| 545 | return 1; |
| 546 | } |
| 547 | #endif |
| 548 | |
| 549 | |
| 550 | /***************************************************************************** |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 551 | * IRTOUCH Part |
| 552 | */ |
| 553 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH |
| 554 | static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 555 | { |
| 556 | dev->x = (pkt[3] << 8) | pkt[2]; |
| 557 | dev->y = (pkt[5] << 8) | pkt[4]; |
| 558 | dev->touch = (pkt[1] & 0x03) ? 1 : 0; |
| 559 | |
| 560 | return 1; |
| 561 | } |
| 562 | #endif |
| 563 | |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 564 | /***************************************************************************** |
| 565 | * ET&T TC5UH part |
| 566 | */ |
| 567 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH |
| 568 | static int tc5uh_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 569 | { |
| 570 | dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1]; |
| 571 | dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3]; |
| 572 | dev->touch = pkt[0] & 0x01; |
| 573 | |
| 574 | return 1; |
| 575 | } |
| 576 | #endif |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 577 | |
| 578 | /***************************************************************************** |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 579 | * IdealTEK URTC1000 Part |
| 580 | */ |
| 581 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 582 | #ifndef MULTI_PACKET |
| 583 | #define MULTI_PACKET |
| 584 | #endif |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 585 | static int idealtek_get_pkt_len(unsigned char *buf, int len) |
| 586 | { |
| 587 | if (buf[0] & 0x80) |
| 588 | return 5; |
| 589 | if (buf[0] == 0x01) |
| 590 | return len; |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 595 | { |
| 596 | switch (pkt[0] & 0x98) { |
| 597 | case 0x88: |
| 598 | /* touch data in IdealTEK mode */ |
| 599 | dev->x = (pkt[1] << 5) | (pkt[2] >> 2); |
| 600 | dev->y = (pkt[3] << 5) | (pkt[4] >> 2); |
| 601 | dev->touch = (pkt[0] & 0x40) ? 1 : 0; |
| 602 | return 1; |
| 603 | |
| 604 | case 0x98: |
| 605 | /* touch data in MT emulation mode */ |
| 606 | dev->x = (pkt[2] << 5) | (pkt[1] >> 2); |
| 607 | dev->y = (pkt[4] << 5) | (pkt[3] >> 2); |
| 608 | dev->touch = (pkt[0] & 0x40) ? 1 : 0; |
| 609 | return 1; |
| 610 | |
| 611 | default: |
| 612 | return 0; |
| 613 | } |
| 614 | } |
| 615 | #endif |
| 616 | |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 617 | /***************************************************************************** |
| 618 | * General Touch Part |
| 619 | */ |
| 620 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH |
| 621 | static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 622 | { |
| 623 | dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ; |
| 624 | dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ; |
| 625 | dev->press = pkt[5] & 0xff; |
| 626 | dev->touch = pkt[0] & 0x01; |
| 627 | |
| 628 | return 1; |
| 629 | } |
| 630 | #endif |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 631 | |
| 632 | /***************************************************************************** |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 633 | * GoTop Part |
| 634 | */ |
| 635 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP |
| 636 | static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 637 | { |
| 638 | dev->x = ((pkt[1] & 0x38) << 4) | pkt[2]; |
| 639 | dev->y = ((pkt[1] & 0x07) << 7) | pkt[3]; |
| 640 | dev->touch = pkt[0] & 0x01; |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 641 | |
| 642 | return 1; |
| 643 | } |
| 644 | #endif |
| 645 | |
| 646 | /***************************************************************************** |
| 647 | * JASTEC Part |
| 648 | */ |
| 649 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC |
| 650 | static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 651 | { |
| 652 | dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f); |
| 653 | dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f); |
| 654 | dev->touch = (pkt[0] & 0x40) >> 6; |
| 655 | |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 656 | return 1; |
| 657 | } |
| 658 | #endif |
| 659 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 660 | /***************************************************************************** |
| 661 | * Zytronic Part |
| 662 | */ |
| 663 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC |
| 664 | static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 665 | { |
| 666 | switch (pkt[0]) { |
| 667 | case 0x3A: /* command response */ |
| 668 | dbg("%s: Command response %d", __func__, pkt[1]); |
| 669 | break; |
| 670 | |
| 671 | case 0xC0: /* down */ |
| 672 | dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7); |
| 673 | dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7); |
| 674 | dev->touch = 1; |
| 675 | dbg("%s: down %d,%d", __func__, dev->x, dev->y); |
| 676 | return 1; |
| 677 | |
| 678 | case 0x80: /* up */ |
| 679 | dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7); |
| 680 | dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7); |
| 681 | dev->touch = 0; |
| 682 | dbg("%s: up %d,%d", __func__, dev->x, dev->y); |
| 683 | return 1; |
| 684 | |
| 685 | default: |
| 686 | dbg("%s: Unknown return %d", __func__, pkt[0]); |
| 687 | break; |
| 688 | } |
| 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | #endif |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 693 | |
| 694 | /***************************************************************************** |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 695 | * the different device descriptors |
| 696 | */ |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 697 | #ifdef MULTI_PACKET |
| 698 | static void usbtouch_process_multi(struct usbtouch_usb *usbtouch, |
| 699 | unsigned char *pkt, int len); |
| 700 | #endif |
| 701 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 702 | static struct usbtouch_device_info usbtouch_dev_info[] = { |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 703 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 704 | [DEVTYPE_EGALAX] = { |
| 705 | .min_xc = 0x0, |
| 706 | .max_xc = 0x07ff, |
| 707 | .min_yc = 0x0, |
| 708 | .max_yc = 0x07ff, |
| 709 | .rept_size = 16, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 710 | .process_pkt = usbtouch_process_multi, |
| 711 | .get_pkt_len = egalax_get_pkt_len, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 712 | .read_data = egalax_read_data, |
| 713 | }, |
| 714 | #endif |
| 715 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 716 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 717 | [DEVTYPE_PANJIT] = { |
| 718 | .min_xc = 0x0, |
| 719 | .max_xc = 0x0fff, |
| 720 | .min_yc = 0x0, |
| 721 | .max_yc = 0x0fff, |
| 722 | .rept_size = 8, |
| 723 | .read_data = panjit_read_data, |
| 724 | }, |
| 725 | #endif |
| 726 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 727 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 728 | [DEVTYPE_3M] = { |
| 729 | .min_xc = 0x0, |
| 730 | .max_xc = 0x4000, |
| 731 | .min_yc = 0x0, |
| 732 | .max_yc = 0x4000, |
| 733 | .rept_size = 11, |
| 734 | .read_data = mtouch_read_data, |
| 735 | .init = mtouch_init, |
| 736 | }, |
| 737 | #endif |
| 738 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 739 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 740 | [DEVTYPE_ITM] = { |
| 741 | .min_xc = 0x0, |
| 742 | .max_xc = 0x0fff, |
| 743 | .min_yc = 0x0, |
| 744 | .max_yc = 0x0fff, |
| 745 | .max_press = 0xff, |
| 746 | .rept_size = 8, |
| 747 | .read_data = itm_read_data, |
| 748 | }, |
| 749 | #endif |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 750 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 751 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 752 | [DEVTYPE_ETURBO] = { |
| 753 | .min_xc = 0x0, |
| 754 | .max_xc = 0x07ff, |
| 755 | .min_yc = 0x0, |
| 756 | .max_yc = 0x07ff, |
| 757 | .rept_size = 8, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 758 | .process_pkt = usbtouch_process_multi, |
| 759 | .get_pkt_len = eturbo_get_pkt_len, |
| 760 | .read_data = eturbo_read_data, |
| 761 | }, |
| 762 | #endif |
| 763 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 764 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 765 | [DEVTYPE_GUNZE] = { |
| 766 | .min_xc = 0x0, |
| 767 | .max_xc = 0x0fff, |
| 768 | .min_yc = 0x0, |
| 769 | .max_yc = 0x0fff, |
| 770 | .rept_size = 4, |
| 771 | .read_data = gunze_read_data, |
| 772 | }, |
| 773 | #endif |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 774 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 775 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 776 | [DEVTYPE_DMC_TSC10] = { |
| 777 | .min_xc = 0x0, |
| 778 | .max_xc = 0x03ff, |
| 779 | .min_yc = 0x0, |
| 780 | .max_yc = 0x03ff, |
| 781 | .rept_size = 5, |
| 782 | .init = dmc_tsc10_init, |
| 783 | .read_data = dmc_tsc10_read_data, |
| 784 | }, |
| 785 | #endif |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 786 | |
| 787 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH |
| 788 | [DEVTYPE_IRTOUCH] = { |
| 789 | .min_xc = 0x0, |
| 790 | .max_xc = 0x0fff, |
| 791 | .min_yc = 0x0, |
| 792 | .max_yc = 0x0fff, |
| 793 | .rept_size = 8, |
| 794 | .read_data = irtouch_read_data, |
| 795 | }, |
| 796 | #endif |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 797 | |
| 798 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK |
| 799 | [DEVTYPE_IDEALTEK] = { |
| 800 | .min_xc = 0x0, |
| 801 | .max_xc = 0x0fff, |
| 802 | .min_yc = 0x0, |
| 803 | .max_yc = 0x0fff, |
| 804 | .rept_size = 8, |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 805 | .process_pkt = usbtouch_process_multi, |
| 806 | .get_pkt_len = idealtek_get_pkt_len, |
| 807 | .read_data = idealtek_read_data, |
| 808 | }, |
| 809 | #endif |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 810 | |
| 811 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH |
| 812 | [DEVTYPE_GENERAL_TOUCH] = { |
| 813 | .min_xc = 0x0, |
| 814 | .max_xc = 0x0500, |
| 815 | .min_yc = 0x0, |
| 816 | .max_yc = 0x0500, |
| 817 | .rept_size = 7, |
| 818 | .read_data = general_touch_read_data, |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 819 | }, |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 820 | #endif |
| 821 | |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 822 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP |
| 823 | [DEVTYPE_GOTOP] = { |
| 824 | .min_xc = 0x0, |
| 825 | .max_xc = 0x03ff, |
| 826 | .min_yc = 0x0, |
| 827 | .max_yc = 0x03ff, |
| 828 | .rept_size = 4, |
| 829 | .read_data = gotop_read_data, |
| 830 | }, |
| 831 | #endif |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 832 | |
| 833 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC |
| 834 | [DEVTYPE_JASTEC] = { |
| 835 | .min_xc = 0x0, |
| 836 | .max_xc = 0x0fff, |
| 837 | .min_yc = 0x0, |
| 838 | .max_yc = 0x0fff, |
| 839 | .rept_size = 4, |
| 840 | .read_data = jastec_read_data, |
| 841 | }, |
| 842 | #endif |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 843 | |
| 844 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I |
| 845 | [DEVTYPE_E2I] = { |
| 846 | .min_xc = 0x0, |
| 847 | .max_xc = 0x7fff, |
| 848 | .min_yc = 0x0, |
| 849 | .max_yc = 0x7fff, |
| 850 | .rept_size = 6, |
| 851 | .init = e2i_init, |
| 852 | .read_data = e2i_read_data, |
| 853 | }, |
| 854 | #endif |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 855 | |
| 856 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC |
| 857 | [DEVTYPE_ZYTRONIC] = { |
| 858 | .min_xc = 0x0, |
| 859 | .max_xc = 0x03ff, |
| 860 | .min_yc = 0x0, |
| 861 | .max_yc = 0x03ff, |
| 862 | .rept_size = 5, |
| 863 | .read_data = zytronic_read_data, |
| 864 | .irq_always = true, |
| 865 | }, |
| 866 | #endif |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 867 | |
| 868 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH |
| 869 | [DEVTYPE_TC5UH] = { |
| 870 | .min_xc = 0x0, |
| 871 | .max_xc = 0x0fff, |
| 872 | .min_yc = 0x0, |
| 873 | .max_yc = 0x0fff, |
| 874 | .rept_size = 5, |
| 875 | .read_data = tc5uh_read_data, |
| 876 | }, |
| 877 | #endif |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 878 | }; |
| 879 | |
| 880 | |
| 881 | /***************************************************************************** |
| 882 | * Generic Part |
| 883 | */ |
| 884 | static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 885 | unsigned char *pkt, int len) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 886 | { |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 887 | struct usbtouch_device_info *type = usbtouch->type; |
| 888 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 889 | if (!type->read_data(usbtouch, pkt)) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 890 | return; |
| 891 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 892 | input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 893 | |
| 894 | if (swap_xy) { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 895 | input_report_abs(usbtouch->input, ABS_X, usbtouch->y); |
| 896 | input_report_abs(usbtouch->input, ABS_Y, usbtouch->x); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 897 | } else { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 898 | input_report_abs(usbtouch->input, ABS_X, usbtouch->x); |
| 899 | input_report_abs(usbtouch->input, ABS_Y, usbtouch->y); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 900 | } |
| 901 | if (type->max_press) |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 902 | input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 903 | input_sync(usbtouch->input); |
| 904 | } |
| 905 | |
| 906 | |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 907 | #ifdef MULTI_PACKET |
| 908 | static void usbtouch_process_multi(struct usbtouch_usb *usbtouch, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 909 | unsigned char *pkt, int len) |
| 910 | { |
| 911 | unsigned char *buffer; |
| 912 | int pkt_len, pos, buf_len, tmp; |
| 913 | |
| 914 | /* process buffer */ |
| 915 | if (unlikely(usbtouch->buf_len)) { |
| 916 | /* try to get size */ |
| 917 | pkt_len = usbtouch->type->get_pkt_len( |
| 918 | usbtouch->buffer, usbtouch->buf_len); |
| 919 | |
| 920 | /* drop? */ |
| 921 | if (unlikely(!pkt_len)) |
| 922 | goto out_flush_buf; |
| 923 | |
| 924 | /* need to append -pkt_len bytes before able to get size */ |
| 925 | if (unlikely(pkt_len < 0)) { |
| 926 | int append = -pkt_len; |
| 927 | if (unlikely(append > len)) |
| 928 | append = len; |
| 929 | if (usbtouch->buf_len + append >= usbtouch->type->rept_size) |
| 930 | goto out_flush_buf; |
| 931 | memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append); |
| 932 | usbtouch->buf_len += append; |
| 933 | |
| 934 | pkt_len = usbtouch->type->get_pkt_len( |
| 935 | usbtouch->buffer, usbtouch->buf_len); |
| 936 | if (pkt_len < 0) |
| 937 | return; |
| 938 | } |
| 939 | |
| 940 | /* append */ |
| 941 | tmp = pkt_len - usbtouch->buf_len; |
| 942 | if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size) |
| 943 | goto out_flush_buf; |
| 944 | memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 945 | usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 946 | |
| 947 | buffer = pkt + tmp; |
| 948 | buf_len = len - tmp; |
| 949 | } else { |
| 950 | buffer = pkt; |
| 951 | buf_len = len; |
| 952 | } |
| 953 | |
| 954 | /* loop over the received packet, process */ |
| 955 | pos = 0; |
| 956 | while (pos < buf_len) { |
| 957 | /* get packet len */ |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 958 | pkt_len = usbtouch->type->get_pkt_len(buffer + pos, |
| 959 | buf_len - pos); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 960 | |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 961 | /* unknown packet: skip one byte */ |
| 962 | if (unlikely(!pkt_len)) { |
| 963 | pos++; |
| 964 | continue; |
| 965 | } |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 966 | |
| 967 | /* full packet: process */ |
| 968 | if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 969 | usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 970 | } else { |
| 971 | /* incomplete packet: save in buffer */ |
| 972 | memcpy(usbtouch->buffer, buffer + pos, buf_len - pos); |
| 973 | usbtouch->buf_len = buf_len - pos; |
| 974 | return; |
| 975 | } |
| 976 | pos += pkt_len; |
| 977 | } |
| 978 | |
| 979 | out_flush_buf: |
| 980 | usbtouch->buf_len = 0; |
| 981 | return; |
| 982 | } |
| 983 | #endif |
| 984 | |
| 985 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 986 | static void usbtouch_irq(struct urb *urb) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 987 | { |
| 988 | struct usbtouch_usb *usbtouch = urb->context; |
| 989 | int retval; |
| 990 | |
| 991 | switch (urb->status) { |
| 992 | case 0: |
| 993 | /* success */ |
| 994 | break; |
Pete Zaitcev | 38e2bfc | 2006-09-18 22:49:02 -0700 | [diff] [blame] | 995 | case -ETIME: |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 996 | /* this urb is timing out */ |
| 997 | dbg("%s - urb timed out - was the device unplugged?", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 998 | __func__); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 999 | return; |
| 1000 | case -ECONNRESET: |
| 1001 | case -ENOENT: |
| 1002 | case -ESHUTDOWN: |
| 1003 | /* this urb is terminated, clean up */ |
| 1004 | dbg("%s - urb shutting down with status: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1005 | __func__, urb->status); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1006 | return; |
| 1007 | default: |
| 1008 | dbg("%s - nonzero urb status received: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1009 | __func__, urb->status); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1010 | goto exit; |
| 1011 | } |
| 1012 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1013 | usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1014 | |
| 1015 | exit: |
| 1016 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
| 1017 | if (retval) |
| 1018 | err("%s - usb_submit_urb failed with result: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1019 | __func__, retval); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | static int usbtouch_open(struct input_dev *input) |
| 1023 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 1024 | struct usbtouch_usb *usbtouch = input_get_drvdata(input); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1025 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 1026 | usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1027 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 1028 | if (!usbtouch->type->irq_always) { |
| 1029 | if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) |
| 1030 | return -EIO; |
| 1031 | } |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1032 | |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
| 1036 | static void usbtouch_close(struct input_dev *input) |
| 1037 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 1038 | struct usbtouch_usb *usbtouch = input_get_drvdata(input); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1039 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 1040 | if (!usbtouch->type->irq_always) |
| 1041 | usb_kill_urb(usbtouch->irq); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | static void usbtouch_free_buffers(struct usb_device *udev, |
| 1046 | struct usbtouch_usb *usbtouch) |
| 1047 | { |
Dmitry Torokhov | e37a97d | 2007-05-03 00:57:29 -0400 | [diff] [blame] | 1048 | usb_buffer_free(udev, usbtouch->type->rept_size, |
| 1049 | usbtouch->data, usbtouch->data_dma); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1050 | kfree(usbtouch->buffer); |
| 1051 | } |
| 1052 | |
| 1053 | |
| 1054 | static int usbtouch_probe(struct usb_interface *intf, |
| 1055 | const struct usb_device_id *id) |
| 1056 | { |
| 1057 | struct usbtouch_usb *usbtouch; |
| 1058 | struct input_dev *input_dev; |
| 1059 | struct usb_host_interface *interface; |
| 1060 | struct usb_endpoint_descriptor *endpoint; |
| 1061 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1062 | struct usbtouch_device_info *type; |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1063 | int err = -ENOMEM; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1064 | |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 1065 | /* some devices are ignored */ |
| 1066 | if (id->driver_info == DEVTYPE_IGNORE) |
| 1067 | return -ENODEV; |
| 1068 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1069 | interface = intf->cur_altsetting; |
| 1070 | endpoint = &interface->endpoint[0].desc; |
| 1071 | |
| 1072 | usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL); |
| 1073 | input_dev = input_allocate_device(); |
| 1074 | if (!usbtouch || !input_dev) |
| 1075 | goto out_free; |
| 1076 | |
| 1077 | type = &usbtouch_dev_info[id->driver_info]; |
| 1078 | usbtouch->type = type; |
| 1079 | if (!type->process_pkt) |
| 1080 | type->process_pkt = usbtouch_process_pkt; |
| 1081 | |
| 1082 | usbtouch->data = usb_buffer_alloc(udev, type->rept_size, |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 1083 | GFP_KERNEL, &usbtouch->data_dma); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1084 | if (!usbtouch->data) |
| 1085 | goto out_free; |
| 1086 | |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 1087 | if (type->get_pkt_len) { |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1088 | usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL); |
| 1089 | if (!usbtouch->buffer) |
| 1090 | goto out_free_buffers; |
| 1091 | } |
| 1092 | |
| 1093 | usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL); |
| 1094 | if (!usbtouch->irq) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1095 | dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1096 | goto out_free_buffers; |
| 1097 | } |
| 1098 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 1099 | usbtouch->interface = intf; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1100 | usbtouch->input = input_dev; |
| 1101 | |
| 1102 | if (udev->manufacturer) |
| 1103 | strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name)); |
| 1104 | |
| 1105 | if (udev->product) { |
| 1106 | if (udev->manufacturer) |
| 1107 | strlcat(usbtouch->name, " ", sizeof(usbtouch->name)); |
| 1108 | strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name)); |
| 1109 | } |
| 1110 | |
| 1111 | if (!strlen(usbtouch->name)) |
| 1112 | snprintf(usbtouch->name, sizeof(usbtouch->name), |
| 1113 | "USB Touchscreen %04x:%04x", |
| 1114 | le16_to_cpu(udev->descriptor.idVendor), |
| 1115 | le16_to_cpu(udev->descriptor.idProduct)); |
| 1116 | |
| 1117 | usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys)); |
Vladimir Shebordaev | 7b6dff9 | 2007-09-06 21:32:16 -0400 | [diff] [blame] | 1118 | strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys)); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1119 | |
| 1120 | input_dev->name = usbtouch->name; |
| 1121 | input_dev->phys = usbtouch->phys; |
| 1122 | usb_to_input_id(udev, &input_dev->id); |
Dmitry Torokhov | c0f82d5 | 2007-04-12 01:35:03 -0400 | [diff] [blame] | 1123 | input_dev->dev.parent = &intf->dev; |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 1124 | |
| 1125 | input_set_drvdata(input_dev, usbtouch); |
| 1126 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1127 | input_dev->open = usbtouch_open; |
| 1128 | input_dev->close = usbtouch_close; |
| 1129 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1130 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 1131 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1132 | input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0); |
| 1133 | input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0); |
| 1134 | if (type->max_press) |
| 1135 | input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press, |
| 1136 | type->max_press, 0, 0); |
| 1137 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 1138 | usb_fill_int_urb(usbtouch->irq, udev, |
| 1139 | usb_rcvintpipe(udev, endpoint->bEndpointAddress), |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1140 | usbtouch->data, type->rept_size, |
| 1141 | usbtouch_irq, usbtouch, endpoint->bInterval); |
| 1142 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame^] | 1143 | usbtouch->irq->dev = udev; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1144 | usbtouch->irq->transfer_dma = usbtouch->data_dma; |
| 1145 | usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 1146 | |
| 1147 | /* device specific init */ |
| 1148 | if (type->init) { |
| 1149 | err = type->init(usbtouch); |
| 1150 | if (err) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1151 | dbg("%s - type->init() failed, err: %d", __func__, err); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1152 | goto out_free_buffers; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | err = input_register_device(usbtouch->input); |
| 1157 | if (err) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1158 | dbg("%s - input_register_device failed, err: %d", __func__, err); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1159 | goto out_free_buffers; |
| 1160 | } |
| 1161 | |
| 1162 | usb_set_intfdata(intf, usbtouch); |
| 1163 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 1164 | if (usbtouch->type->irq_always) |
| 1165 | usb_submit_urb(usbtouch->irq, GFP_KERNEL); |
| 1166 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1167 | return 0; |
| 1168 | |
| 1169 | out_free_buffers: |
| 1170 | usbtouch_free_buffers(udev, usbtouch); |
| 1171 | out_free: |
| 1172 | input_free_device(input_dev); |
| 1173 | kfree(usbtouch); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1174 | return err; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | static void usbtouch_disconnect(struct usb_interface *intf) |
| 1178 | { |
| 1179 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); |
| 1180 | |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1181 | dbg("%s - called", __func__); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1182 | |
| 1183 | if (!usbtouch) |
| 1184 | return; |
| 1185 | |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1186 | dbg("%s - usbtouch is initialized, cleaning up", __func__); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1187 | usb_set_intfdata(intf, NULL); |
Oliver Neukum | 722232bc | 2009-11-23 08:10:50 -0800 | [diff] [blame] | 1188 | /* this will stop IO via close */ |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1189 | input_unregister_device(usbtouch->input); |
| 1190 | usb_free_urb(usbtouch->irq); |
| 1191 | usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch); |
| 1192 | kfree(usbtouch); |
| 1193 | } |
| 1194 | |
| 1195 | MODULE_DEVICE_TABLE(usb, usbtouch_devices); |
| 1196 | |
| 1197 | static struct usb_driver usbtouch_driver = { |
| 1198 | .name = "usbtouchscreen", |
| 1199 | .probe = usbtouch_probe, |
| 1200 | .disconnect = usbtouch_disconnect, |
| 1201 | .id_table = usbtouch_devices, |
| 1202 | }; |
| 1203 | |
| 1204 | static int __init usbtouch_init(void) |
| 1205 | { |
| 1206 | return usb_register(&usbtouch_driver); |
| 1207 | } |
| 1208 | |
| 1209 | static void __exit usbtouch_cleanup(void) |
| 1210 | { |
| 1211 | usb_deregister(&usbtouch_driver); |
| 1212 | } |
| 1213 | |
| 1214 | module_init(usbtouch_init); |
| 1215 | module_exit(usbtouch_cleanup); |
| 1216 | |
| 1217 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1218 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1219 | MODULE_LICENSE("GPL"); |
| 1220 | |
| 1221 | MODULE_ALIAS("touchkitusb"); |
| 1222 | MODULE_ALIAS("itmtouch"); |
| 1223 | MODULE_ALIAS("mtouchusb"); |