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 |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 18 | * - NEXIO/iNexio |
Michael Gebetsroither | d2cc817a | 2011-11-04 23:56:05 -0700 | [diff] [blame] | 19 | * - Elo TouchSystems 2700 IntelliTouch |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 20 | * |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 21 | * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch> |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 22 | * Copyright (C) by Todd E. Johnson (mtouchusb.c) |
| 23 | * |
| 24 | * This program is free software; you can redistribute it and/or |
| 25 | * modify it under the terms of the GNU General Public License as |
| 26 | * published by the Free Software Foundation; either version 2 of the |
| 27 | * License, or (at your option) any later version. |
| 28 | * |
| 29 | * This program is distributed in the hope that it will be useful, but |
| 30 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 32 | * General Public License for more details. |
| 33 | * |
| 34 | * You should have received a copy of the GNU General Public License |
| 35 | * along with this program; if not, write to the Free Software |
| 36 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 37 | * |
| 38 | * Driver is based on touchkitusb.c |
| 39 | * - ITM parts are from itmtouch.c |
| 40 | * - 3M parts are from mtouchusb.c |
| 41 | * - PanJit parts are from an unmerged driver by Lanslott Gish |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 42 | * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged |
| 43 | * driver from Marius Vollmer |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 44 | * |
| 45 | *****************************************************************************/ |
| 46 | |
| 47 | //#define DEBUG |
| 48 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 49 | #include <linux/kernel.h> |
| 50 | #include <linux/slab.h> |
| 51 | #include <linux/input.h> |
| 52 | #include <linux/module.h> |
| 53 | #include <linux/init.h> |
| 54 | #include <linux/usb.h> |
David Brownell | ae0dadc | 2006-06-13 10:04:34 -0700 | [diff] [blame] | 55 | #include <linux/usb/input.h> |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 56 | #include <linux/hid.h> |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 57 | |
| 58 | |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 59 | #define DRIVER_VERSION "v0.6" |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 60 | #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>" |
| 61 | #define DRIVER_DESC "USB Touchscreen Driver" |
| 62 | |
| 63 | static int swap_xy; |
| 64 | module_param(swap_xy, bool, 0644); |
| 65 | MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped."); |
| 66 | |
Dan Streetman | c9cbf3d | 2009-01-10 23:44:22 -0800 | [diff] [blame] | 67 | static int hwcalib_xy; |
| 68 | module_param(hwcalib_xy, bool, 0644); |
| 69 | MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available"); |
| 70 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 71 | /* device specifc data/functions */ |
| 72 | struct usbtouch_usb; |
| 73 | struct usbtouch_device_info { |
| 74 | int min_xc, max_xc; |
| 75 | int min_yc, max_yc; |
| 76 | int min_press, max_press; |
| 77 | int rept_size; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 78 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 79 | /* |
| 80 | * Always service the USB devices irq not just when the input device is |
| 81 | * open. This is useful when devices have a watchdog which prevents us |
| 82 | * from periodically polling the device. Leave this unset unless your |
| 83 | * touchscreen device requires it, as it does consume more of the USB |
| 84 | * bandwidth. |
| 85 | */ |
| 86 | bool irq_always; |
| 87 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 88 | void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len); |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * used to get the packet len. possible return values: |
| 92 | * > 0: packet len |
| 93 | * = 0: skip one byte |
| 94 | * < 0: -return value more bytes needed |
| 95 | */ |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 96 | int (*get_pkt_len) (unsigned char *pkt, int len); |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 97 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 98 | int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt); |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 99 | int (*alloc) (struct usbtouch_usb *usbtouch); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 100 | int (*init) (struct usbtouch_usb *usbtouch); |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 101 | void (*exit) (struct usbtouch_usb *usbtouch); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 102 | }; |
| 103 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 104 | /* a usbtouch device */ |
| 105 | struct usbtouch_usb { |
| 106 | unsigned char *data; |
| 107 | dma_addr_t data_dma; |
| 108 | unsigned char *buffer; |
| 109 | int buf_len; |
| 110 | struct urb *irq; |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 111 | struct usb_interface *interface; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 112 | struct input_dev *input; |
| 113 | struct usbtouch_device_info *type; |
| 114 | char name[128]; |
| 115 | char phys[64]; |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 116 | void *priv; |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 117 | |
| 118 | int x, y; |
| 119 | int touch, press; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 122 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 123 | /* device types */ |
| 124 | enum { |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 125 | DEVTYPE_IGNORE = -1, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 126 | DEVTYPE_EGALAX, |
| 127 | DEVTYPE_PANJIT, |
| 128 | DEVTYPE_3M, |
| 129 | DEVTYPE_ITM, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 130 | DEVTYPE_ETURBO, |
| 131 | DEVTYPE_GUNZE, |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 132 | DEVTYPE_DMC_TSC10, |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 133 | DEVTYPE_IRTOUCH, |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 134 | DEVTYPE_IDEALTEK, |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 135 | DEVTYPE_GENERAL_TOUCH, |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 136 | DEVTYPE_GOTOP, |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 137 | DEVTYPE_JASTEC, |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 138 | DEVTYPE_E2I, |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 139 | DEVTYPE_ZYTRONIC, |
Petr Å tetiar | 38771bb | 2010-06-28 09:38:48 -0700 | [diff] [blame] | 140 | DEVTYPE_TC45USB, |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 141 | DEVTYPE_NEXIO, |
Michael Gebetsroither | d2cc817a | 2011-11-04 23:56:05 -0700 | [diff] [blame] | 142 | DEVTYPE_ELO, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 143 | }; |
| 144 | |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 145 | #define USB_DEVICE_HID_CLASS(vend, prod) \ |
| 146 | .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \ |
Daniel Ritz | 139ebe8 | 2009-02-28 12:50:54 -0800 | [diff] [blame] | 147 | | USB_DEVICE_ID_MATCH_INT_PROTOCOL \ |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 148 | | USB_DEVICE_ID_MATCH_DEVICE, \ |
| 149 | .idVendor = (vend), \ |
| 150 | .idProduct = (prod), \ |
| 151 | .bInterfaceClass = USB_INTERFACE_CLASS_HID, \ |
| 152 | .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE |
| 153 | |
Márton Németh | 9cb3ce5 | 2010-01-10 23:59:05 -0800 | [diff] [blame] | 154 | static const struct usb_device_id usbtouch_devices[] = { |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 155 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 156 | /* ignore the HID capable devices, handled by usbhid */ |
| 157 | {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE}, |
| 158 | {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE}, |
| 159 | |
| 160 | /* normal device IDs */ |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 161 | {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 162 | {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX}, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 163 | {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
| 164 | {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
| 165 | {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX}, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 166 | {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX}, |
| 167 | {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX}, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 168 | #endif |
| 169 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 170 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 171 | {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT}, |
| 172 | {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT}, |
| 173 | {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT}, |
| 174 | {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT}, |
| 175 | #endif |
| 176 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 177 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 178 | {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M}, |
| 179 | #endif |
| 180 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 181 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 182 | {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM}, |
Glenn Sommer | 0991050 | 2010-11-22 12:00:05 -0800 | [diff] [blame] | 183 | {USB_DEVICE(0x16e3, 0xf9e9), .driver_info = DEVTYPE_ITM}, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 184 | #endif |
| 185 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 186 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 187 | {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO}, |
| 188 | #endif |
| 189 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 190 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 191 | {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE}, |
| 192 | #endif |
| 193 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 194 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 195 | {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10}, |
| 196 | #endif |
| 197 | |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 198 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH |
| 199 | {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, |
| 200 | {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, |
| 201 | #endif |
| 202 | |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 203 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK |
| 204 | {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK}, |
| 205 | #endif |
| 206 | |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 207 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH |
| 208 | {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH}, |
| 209 | #endif |
| 210 | |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 211 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP |
| 212 | {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP}, |
| 213 | {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP}, |
| 214 | {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP}, |
| 215 | #endif |
| 216 | |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 217 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC |
| 218 | {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC}, |
| 219 | #endif |
| 220 | |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 221 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I |
| 222 | {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I}, |
| 223 | #endif |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 224 | |
| 225 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC |
| 226 | {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC}, |
| 227 | #endif |
| 228 | |
Petr Å tetiar | 38771bb | 2010-06-28 09:38:48 -0700 | [diff] [blame] | 229 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB |
| 230 | /* TC5UH */ |
| 231 | {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC45USB}, |
| 232 | /* TC4UM */ |
| 233 | {USB_DEVICE(0x0664, 0x0306), .driver_info = DEVTYPE_TC45USB}, |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 234 | #endif |
| 235 | |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 236 | #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO |
| 237 | /* data interface only */ |
| 238 | {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00), |
| 239 | .driver_info = DEVTYPE_NEXIO}, |
| 240 | {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00), |
| 241 | .driver_info = DEVTYPE_NEXIO}, |
| 242 | #endif |
| 243 | |
Michael Gebetsroither | d2cc817a | 2011-11-04 23:56:05 -0700 | [diff] [blame] | 244 | #ifdef CONFIG_TOUCHSCREEN_USB_ELO |
| 245 | {USB_DEVICE(0x04e7, 0x0020), .driver_info = DEVTYPE_ELO}, |
| 246 | #endif |
| 247 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 248 | {} |
| 249 | }; |
| 250 | |
| 251 | |
| 252 | /***************************************************************************** |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 253 | * e2i Part |
| 254 | */ |
| 255 | |
| 256 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I |
| 257 | static int e2i_init(struct usbtouch_usb *usbtouch) |
| 258 | { |
| 259 | int ret; |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 260 | struct usb_device *udev = interface_to_usbdev(usbtouch->interface); |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 261 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 262 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 263 | 0x01, 0x02, 0x0000, 0x0081, |
| 264 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 265 | |
| 266 | dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d", |
| 267 | __func__, ret); |
| 268 | return ret; |
| 269 | } |
| 270 | |
| 271 | static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 272 | { |
| 273 | int tmp = (pkt[0] << 8) | pkt[1]; |
| 274 | dev->x = (pkt[2] << 8) | pkt[3]; |
| 275 | dev->y = (pkt[4] << 8) | pkt[5]; |
| 276 | |
| 277 | tmp = tmp - 0xA000; |
| 278 | dev->touch = (tmp > 0); |
| 279 | dev->press = (tmp > 0 ? tmp : 0); |
| 280 | |
| 281 | return 1; |
| 282 | } |
| 283 | #endif |
| 284 | |
| 285 | |
| 286 | /***************************************************************************** |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 287 | * eGalax part |
| 288 | */ |
| 289 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 290 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 291 | |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 292 | #ifndef MULTI_PACKET |
| 293 | #define MULTI_PACKET |
| 294 | #endif |
| 295 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 296 | #define EGALAX_PKT_TYPE_MASK 0xFE |
| 297 | #define EGALAX_PKT_TYPE_REPT 0x80 |
| 298 | #define EGALAX_PKT_TYPE_DIAG 0x0A |
| 299 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 300 | static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 301 | { |
| 302 | if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT) |
| 303 | return 0; |
| 304 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 305 | dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F); |
| 306 | dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F); |
| 307 | dev->touch = pkt[0] & 0x01; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 308 | |
| 309 | return 1; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 312 | static int egalax_get_pkt_len(unsigned char *buf, int len) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 313 | { |
| 314 | switch (buf[0] & EGALAX_PKT_TYPE_MASK) { |
| 315 | case EGALAX_PKT_TYPE_REPT: |
| 316 | return 5; |
| 317 | |
| 318 | case EGALAX_PKT_TYPE_DIAG: |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 319 | if (len < 2) |
| 320 | return -1; |
| 321 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 322 | return buf[1] + 2; |
| 323 | } |
| 324 | |
| 325 | return 0; |
| 326 | } |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 327 | #endif |
| 328 | |
| 329 | |
| 330 | /***************************************************************************** |
| 331 | * PanJit Part |
| 332 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 333 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 334 | static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 335 | { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 336 | dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1]; |
| 337 | dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3]; |
| 338 | dev->touch = pkt[0] & 0x01; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 339 | |
| 340 | return 1; |
| 341 | } |
| 342 | #endif |
| 343 | |
| 344 | |
| 345 | /***************************************************************************** |
| 346 | * 3M/Microtouch Part |
| 347 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 348 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 349 | |
| 350 | #define MTOUCHUSB_ASYNC_REPORT 1 |
| 351 | #define MTOUCHUSB_RESET 7 |
| 352 | #define MTOUCHUSB_REQ_CTRLLR_ID 10 |
| 353 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 354 | static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 355 | { |
Dan Streetman | c9cbf3d | 2009-01-10 23:44:22 -0800 | [diff] [blame] | 356 | if (hwcalib_xy) { |
| 357 | dev->x = (pkt[4] << 8) | pkt[3]; |
| 358 | dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]); |
| 359 | } else { |
| 360 | dev->x = (pkt[8] << 8) | pkt[7]; |
| 361 | dev->y = (pkt[10] << 8) | pkt[9]; |
| 362 | } |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 363 | dev->touch = (pkt[2] & 0x40) ? 1 : 0; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 364 | |
| 365 | return 1; |
| 366 | } |
| 367 | |
| 368 | static int mtouch_init(struct usbtouch_usb *usbtouch) |
| 369 | { |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 370 | int ret, i; |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 371 | struct usb_device *udev = interface_to_usbdev(usbtouch->interface); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 372 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 373 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 374 | MTOUCHUSB_RESET, |
| 375 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 376 | 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 377 | dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 378 | __func__, ret); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 379 | if (ret < 0) |
| 380 | return ret; |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 381 | msleep(150); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 382 | |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 383 | for (i = 0; i < 3; i++) { |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 384 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 385 | MTOUCHUSB_ASYNC_REPORT, |
| 386 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 387 | 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 388 | dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 389 | __func__, ret); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 390 | if (ret >= 0) |
| 391 | break; |
| 392 | if (ret != -EPIPE) |
| 393 | return ret; |
| 394 | } |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 395 | |
Dan Streetman | c9cbf3d | 2009-01-10 23:44:22 -0800 | [diff] [blame] | 396 | /* Default min/max xy are the raw values, override if using hw-calib */ |
| 397 | if (hwcalib_xy) { |
| 398 | input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0); |
| 399 | input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0); |
| 400 | } |
| 401 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | #endif |
| 405 | |
| 406 | |
| 407 | /***************************************************************************** |
| 408 | * ITM Part |
| 409 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 410 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 411 | static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 412 | { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 413 | int touch; |
| 414 | /* |
| 415 | * ITM devices report invalid x/y data if not touched. |
| 416 | * if the screen was touched before but is not touched any more |
| 417 | * report touch as 0 with the last valid x/y data once. then stop |
| 418 | * reporting data until touched again. |
| 419 | */ |
| 420 | dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 421 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 422 | touch = ~pkt[7] & 0x20; |
| 423 | if (!touch) { |
| 424 | if (dev->touch) { |
| 425 | dev->touch = 0; |
| 426 | return 1; |
| 427 | } |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F); |
| 433 | dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F); |
| 434 | dev->touch = touch; |
| 435 | |
| 436 | return 1; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 437 | } |
| 438 | #endif |
| 439 | |
| 440 | |
| 441 | /***************************************************************************** |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 442 | * eTurboTouch part |
| 443 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 444 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 445 | #ifndef MULTI_PACKET |
| 446 | #define MULTI_PACKET |
| 447 | #endif |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 448 | static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 449 | { |
| 450 | unsigned int shift; |
| 451 | |
| 452 | /* packets should start with sync */ |
| 453 | if (!(pkt[0] & 0x80)) |
| 454 | return 0; |
| 455 | |
| 456 | shift = (6 - (pkt[0] & 0x03)); |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 457 | dev->x = ((pkt[3] << 7) | pkt[4]) >> shift; |
| 458 | dev->y = ((pkt[1] << 7) | pkt[2]) >> shift; |
| 459 | dev->touch = (pkt[0] & 0x10) ? 1 : 0; |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 460 | |
| 461 | return 1; |
| 462 | } |
| 463 | |
| 464 | static int eturbo_get_pkt_len(unsigned char *buf, int len) |
| 465 | { |
| 466 | if (buf[0] & 0x80) |
| 467 | return 5; |
| 468 | if (buf[0] == 0x01) |
| 469 | return 3; |
| 470 | return 0; |
| 471 | } |
| 472 | #endif |
| 473 | |
| 474 | |
| 475 | /***************************************************************************** |
| 476 | * Gunze part |
| 477 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 478 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 479 | static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 480 | { |
| 481 | if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80)) |
| 482 | return 0; |
| 483 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 484 | dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F); |
| 485 | dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F); |
| 486 | dev->touch = pkt[0] & 0x20; |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 487 | |
| 488 | return 1; |
| 489 | } |
| 490 | #endif |
| 491 | |
| 492 | /***************************************************************************** |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 493 | * DMC TSC-10/25 Part |
| 494 | * |
| 495 | * Documentation about the controller and it's protocol can be found at |
| 496 | * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf |
| 497 | * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf |
| 498 | */ |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 499 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 500 | |
| 501 | /* supported data rates. currently using 130 */ |
| 502 | #define TSC10_RATE_POINT 0x50 |
| 503 | #define TSC10_RATE_30 0x40 |
| 504 | #define TSC10_RATE_50 0x41 |
| 505 | #define TSC10_RATE_80 0x42 |
| 506 | #define TSC10_RATE_100 0x43 |
| 507 | #define TSC10_RATE_130 0x44 |
| 508 | #define TSC10_RATE_150 0x45 |
| 509 | |
| 510 | /* commands */ |
| 511 | #define TSC10_CMD_RESET 0x55 |
| 512 | #define TSC10_CMD_RATE 0x05 |
| 513 | #define TSC10_CMD_DATA1 0x01 |
| 514 | |
| 515 | static int dmc_tsc10_init(struct usbtouch_usb *usbtouch) |
| 516 | { |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 517 | struct usb_device *dev = interface_to_usbdev(usbtouch->interface); |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 518 | int ret = -ENOMEM; |
| 519 | unsigned char *buf; |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 520 | |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 521 | buf = kmalloc(2, GFP_NOIO); |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 522 | if (!buf) |
| 523 | goto err_nobuf; |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 524 | /* reset */ |
| 525 | buf[0] = buf[1] = 0xFF; |
| 526 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), |
| 527 | TSC10_CMD_RESET, |
| 528 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 529 | 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT); |
| 530 | if (ret < 0) |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 531 | goto err_out; |
Nuno Lucas | 2ec6f24 | 2008-11-11 16:48:04 -0500 | [diff] [blame] | 532 | if (buf[0] != 0x06) { |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 533 | ret = -ENODEV; |
| 534 | goto err_out; |
| 535 | } |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 536 | |
| 537 | /* set coordinate output rate */ |
| 538 | buf[0] = buf[1] = 0xFF; |
| 539 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), |
| 540 | TSC10_CMD_RATE, |
| 541 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 542 | TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT); |
| 543 | if (ret < 0) |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 544 | goto err_out; |
Nuno Lucas | 2ec6f24 | 2008-11-11 16:48:04 -0500 | [diff] [blame] | 545 | if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) { |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 546 | ret = -ENODEV; |
| 547 | goto err_out; |
| 548 | } |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 549 | |
| 550 | /* start sending data */ |
| 551 | ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), |
| 552 | TSC10_CMD_DATA1, |
| 553 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 554 | 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); |
Oliver Neukum | 76d057c | 2008-04-04 15:31:47 -0400 | [diff] [blame] | 555 | err_out: |
| 556 | kfree(buf); |
| 557 | err_nobuf: |
| 558 | return ret; |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 562 | 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] | 563 | { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 564 | dev->x = ((pkt[2] & 0x03) << 8) | pkt[1]; |
| 565 | dev->y = ((pkt[4] & 0x03) << 8) | pkt[3]; |
| 566 | dev->touch = pkt[0] & 0x01; |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 567 | |
| 568 | return 1; |
| 569 | } |
| 570 | #endif |
| 571 | |
| 572 | |
| 573 | /***************************************************************************** |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 574 | * IRTOUCH Part |
| 575 | */ |
| 576 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH |
| 577 | static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 578 | { |
| 579 | dev->x = (pkt[3] << 8) | pkt[2]; |
| 580 | dev->y = (pkt[5] << 8) | pkt[4]; |
| 581 | dev->touch = (pkt[1] & 0x03) ? 1 : 0; |
| 582 | |
| 583 | return 1; |
| 584 | } |
| 585 | #endif |
| 586 | |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 587 | /***************************************************************************** |
Petr Å tetiar | 38771bb | 2010-06-28 09:38:48 -0700 | [diff] [blame] | 588 | * ET&T TC5UH/TC4UM part |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 589 | */ |
Petr Å tetiar | 38771bb | 2010-06-28 09:38:48 -0700 | [diff] [blame] | 590 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB |
| 591 | static int tc45usb_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 592 | { |
| 593 | dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1]; |
| 594 | dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3]; |
| 595 | dev->touch = pkt[0] & 0x01; |
| 596 | |
| 597 | return 1; |
| 598 | } |
| 599 | #endif |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 600 | |
| 601 | /***************************************************************************** |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 602 | * IdealTEK URTC1000 Part |
| 603 | */ |
| 604 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 605 | #ifndef MULTI_PACKET |
| 606 | #define MULTI_PACKET |
| 607 | #endif |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 608 | static int idealtek_get_pkt_len(unsigned char *buf, int len) |
| 609 | { |
| 610 | if (buf[0] & 0x80) |
| 611 | return 5; |
| 612 | if (buf[0] == 0x01) |
| 613 | return len; |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 618 | { |
| 619 | switch (pkt[0] & 0x98) { |
| 620 | case 0x88: |
| 621 | /* touch data in IdealTEK mode */ |
| 622 | dev->x = (pkt[1] << 5) | (pkt[2] >> 2); |
| 623 | dev->y = (pkt[3] << 5) | (pkt[4] >> 2); |
| 624 | dev->touch = (pkt[0] & 0x40) ? 1 : 0; |
| 625 | return 1; |
| 626 | |
| 627 | case 0x98: |
| 628 | /* touch data in MT emulation mode */ |
| 629 | dev->x = (pkt[2] << 5) | (pkt[1] >> 2); |
| 630 | dev->y = (pkt[4] << 5) | (pkt[3] >> 2); |
| 631 | dev->touch = (pkt[0] & 0x40) ? 1 : 0; |
| 632 | return 1; |
| 633 | |
| 634 | default: |
| 635 | return 0; |
| 636 | } |
| 637 | } |
| 638 | #endif |
| 639 | |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 640 | /***************************************************************************** |
| 641 | * General Touch Part |
| 642 | */ |
| 643 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH |
| 644 | static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 645 | { |
Roy Yin | eb083ba | 2010-02-21 22:52:49 -0800 | [diff] [blame] | 646 | dev->x = (pkt[2] << 8) | pkt[1]; |
| 647 | dev->y = (pkt[4] << 8) | pkt[3]; |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 648 | dev->press = pkt[5] & 0xff; |
| 649 | dev->touch = pkt[0] & 0x01; |
| 650 | |
| 651 | return 1; |
| 652 | } |
| 653 | #endif |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 654 | |
| 655 | /***************************************************************************** |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 656 | * GoTop Part |
| 657 | */ |
| 658 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP |
| 659 | static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 660 | { |
| 661 | dev->x = ((pkt[1] & 0x38) << 4) | pkt[2]; |
| 662 | dev->y = ((pkt[1] & 0x07) << 7) | pkt[3]; |
| 663 | dev->touch = pkt[0] & 0x01; |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 664 | |
| 665 | return 1; |
| 666 | } |
| 667 | #endif |
| 668 | |
| 669 | /***************************************************************************** |
| 670 | * JASTEC Part |
| 671 | */ |
| 672 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC |
| 673 | static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 674 | { |
| 675 | dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f); |
| 676 | dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f); |
| 677 | dev->touch = (pkt[0] & 0x40) >> 6; |
| 678 | |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 679 | return 1; |
| 680 | } |
| 681 | #endif |
| 682 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 683 | /***************************************************************************** |
| 684 | * Zytronic Part |
| 685 | */ |
| 686 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC |
| 687 | static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 688 | { |
| 689 | switch (pkt[0]) { |
| 690 | case 0x3A: /* command response */ |
| 691 | dbg("%s: Command response %d", __func__, pkt[1]); |
| 692 | break; |
| 693 | |
| 694 | case 0xC0: /* down */ |
| 695 | dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7); |
| 696 | dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7); |
| 697 | dev->touch = 1; |
| 698 | dbg("%s: down %d,%d", __func__, dev->x, dev->y); |
| 699 | return 1; |
| 700 | |
| 701 | case 0x80: /* up */ |
| 702 | dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7); |
| 703 | dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7); |
| 704 | dev->touch = 0; |
| 705 | dbg("%s: up %d,%d", __func__, dev->x, dev->y); |
| 706 | return 1; |
| 707 | |
| 708 | default: |
| 709 | dbg("%s: Unknown return %d", __func__, pkt[0]); |
| 710 | break; |
| 711 | } |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | #endif |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 716 | |
| 717 | /***************************************************************************** |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 718 | * NEXIO Part |
| 719 | */ |
| 720 | #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO |
| 721 | |
| 722 | #define NEXIO_TIMEOUT 5000 |
| 723 | #define NEXIO_BUFSIZE 1024 |
| 724 | #define NEXIO_THRESHOLD 50 |
| 725 | |
| 726 | struct nexio_priv { |
| 727 | struct urb *ack; |
| 728 | unsigned char *ack_buf; |
| 729 | }; |
| 730 | |
| 731 | struct nexio_touch_packet { |
| 732 | u8 flags; /* 0xe1 = touch, 0xe1 = release */ |
| 733 | __be16 data_len; /* total bytes of touch data */ |
| 734 | __be16 x_len; /* bytes for X axis */ |
| 735 | __be16 y_len; /* bytes for Y axis */ |
| 736 | u8 data[]; |
| 737 | } __attribute__ ((packed)); |
| 738 | |
| 739 | static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 }; |
| 740 | static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f }; |
| 741 | |
| 742 | static void nexio_ack_complete(struct urb *urb) |
| 743 | { |
| 744 | } |
| 745 | |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 746 | static int nexio_alloc(struct usbtouch_usb *usbtouch) |
| 747 | { |
| 748 | struct nexio_priv *priv; |
| 749 | int ret = -ENOMEM; |
| 750 | |
| 751 | usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL); |
| 752 | if (!usbtouch->priv) |
| 753 | goto out_buf; |
| 754 | |
| 755 | priv = usbtouch->priv; |
| 756 | |
| 757 | priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt), |
| 758 | GFP_KERNEL); |
| 759 | if (!priv->ack_buf) |
| 760 | goto err_priv; |
| 761 | |
| 762 | priv->ack = usb_alloc_urb(0, GFP_KERNEL); |
| 763 | if (!priv->ack) { |
| 764 | dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__); |
| 765 | goto err_ack_buf; |
| 766 | } |
| 767 | |
| 768 | return 0; |
| 769 | |
| 770 | err_ack_buf: |
| 771 | kfree(priv->ack_buf); |
| 772 | err_priv: |
| 773 | kfree(priv); |
| 774 | out_buf: |
| 775 | return ret; |
| 776 | } |
| 777 | |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 778 | static int nexio_init(struct usbtouch_usb *usbtouch) |
| 779 | { |
| 780 | struct usb_device *dev = interface_to_usbdev(usbtouch->interface); |
| 781 | struct usb_host_interface *interface = usbtouch->interface->cur_altsetting; |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 782 | struct nexio_priv *priv = usbtouch->priv; |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 783 | int ret = -ENOMEM; |
| 784 | int actual_len, i; |
| 785 | unsigned char *buf; |
| 786 | char *firmware_ver = NULL, *device_name = NULL; |
| 787 | int input_ep = 0, output_ep = 0; |
| 788 | |
| 789 | /* find first input and output endpoint */ |
| 790 | for (i = 0; i < interface->desc.bNumEndpoints; i++) { |
| 791 | if (!input_ep && |
| 792 | usb_endpoint_dir_in(&interface->endpoint[i].desc)) |
| 793 | input_ep = interface->endpoint[i].desc.bEndpointAddress; |
| 794 | if (!output_ep && |
| 795 | usb_endpoint_dir_out(&interface->endpoint[i].desc)) |
| 796 | output_ep = interface->endpoint[i].desc.bEndpointAddress; |
| 797 | } |
| 798 | if (!input_ep || !output_ep) |
| 799 | return -ENXIO; |
| 800 | |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 801 | buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO); |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 802 | if (!buf) |
| 803 | goto out_buf; |
| 804 | |
| 805 | /* two empty reads */ |
| 806 | for (i = 0; i < 2; i++) { |
| 807 | ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep), |
| 808 | buf, NEXIO_BUFSIZE, &actual_len, |
| 809 | NEXIO_TIMEOUT); |
| 810 | if (ret < 0) |
| 811 | goto out_buf; |
| 812 | } |
| 813 | |
| 814 | /* send init command */ |
| 815 | memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt)); |
| 816 | ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep), |
| 817 | buf, sizeof(nexio_init_pkt), &actual_len, |
| 818 | NEXIO_TIMEOUT); |
| 819 | if (ret < 0) |
| 820 | goto out_buf; |
| 821 | |
| 822 | /* read replies */ |
| 823 | for (i = 0; i < 3; i++) { |
| 824 | memset(buf, 0, NEXIO_BUFSIZE); |
| 825 | ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep), |
| 826 | buf, NEXIO_BUFSIZE, &actual_len, |
| 827 | NEXIO_TIMEOUT); |
| 828 | if (ret < 0 || actual_len < 1 || buf[1] != actual_len) |
| 829 | continue; |
| 830 | switch (buf[0]) { |
| 831 | case 0x83: /* firmware version */ |
| 832 | if (!firmware_ver) |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 833 | firmware_ver = kstrdup(&buf[2], GFP_NOIO); |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 834 | break; |
| 835 | case 0x84: /* device name */ |
| 836 | if (!device_name) |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 837 | device_name = kstrdup(&buf[2], GFP_NOIO); |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 838 | break; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | printk(KERN_INFO "Nexio device: %s, firmware version: %s\n", |
| 843 | device_name, firmware_ver); |
| 844 | |
| 845 | kfree(firmware_ver); |
| 846 | kfree(device_name); |
| 847 | |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 848 | usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep), |
| 849 | priv->ack_buf, sizeof(nexio_ack_pkt), |
| 850 | nexio_ack_complete, usbtouch); |
| 851 | ret = 0; |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 852 | |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 853 | out_buf: |
| 854 | kfree(buf); |
| 855 | return ret; |
| 856 | } |
| 857 | |
| 858 | static void nexio_exit(struct usbtouch_usb *usbtouch) |
| 859 | { |
| 860 | struct nexio_priv *priv = usbtouch->priv; |
| 861 | |
| 862 | usb_kill_urb(priv->ack); |
| 863 | usb_free_urb(priv->ack); |
| 864 | kfree(priv->ack_buf); |
| 865 | kfree(priv); |
| 866 | } |
| 867 | |
| 868 | static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt) |
| 869 | { |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 870 | struct nexio_touch_packet *packet = (void *) pkt; |
| 871 | struct nexio_priv *priv = usbtouch->priv; |
Dmitry Torokhov | 4aa5bbe | 2010-06-08 01:01:46 -0700 | [diff] [blame] | 872 | unsigned int data_len = be16_to_cpu(packet->data_len); |
| 873 | unsigned int x_len = be16_to_cpu(packet->x_len); |
| 874 | unsigned int y_len = be16_to_cpu(packet->y_len); |
| 875 | int x, y, begin_x, begin_y, end_x, end_y, w, h, ret; |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 876 | |
| 877 | /* got touch data? */ |
| 878 | if ((pkt[0] & 0xe0) != 0xe0) |
| 879 | return 0; |
| 880 | |
Dmitry Torokhov | 4aa5bbe | 2010-06-08 01:01:46 -0700 | [diff] [blame] | 881 | if (data_len > 0xff) |
| 882 | data_len -= 0x100; |
| 883 | if (x_len > 0xff) |
| 884 | x_len -= 0x80; |
Ondrej Zary | 388bbca | 2010-05-26 23:30:54 -0700 | [diff] [blame] | 885 | |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 886 | /* send ACK */ |
| 887 | ret = usb_submit_urb(priv->ack, GFP_ATOMIC); |
| 888 | |
| 889 | if (!usbtouch->type->max_xc) { |
Dmitry Torokhov | 4aa5bbe | 2010-06-08 01:01:46 -0700 | [diff] [blame] | 890 | usbtouch->type->max_xc = 2 * x_len; |
| 891 | input_set_abs_params(usbtouch->input, ABS_X, |
| 892 | 0, usbtouch->type->max_xc, 0, 0); |
| 893 | usbtouch->type->max_yc = 2 * y_len; |
| 894 | input_set_abs_params(usbtouch->input, ABS_Y, |
| 895 | 0, usbtouch->type->max_yc, 0, 0); |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 896 | } |
| 897 | /* |
| 898 | * The device reports state of IR sensors on X and Y axes. |
| 899 | * Each byte represents "darkness" percentage (0-100) of one element. |
| 900 | * 17" touchscreen reports only 64 x 52 bytes so the resolution is low. |
| 901 | * This also means that there's a limited multi-touch capability but |
| 902 | * it's disabled (and untested) here as there's no X driver for that. |
| 903 | */ |
| 904 | begin_x = end_x = begin_y = end_y = -1; |
Dmitry Torokhov | 4aa5bbe | 2010-06-08 01:01:46 -0700 | [diff] [blame] | 905 | for (x = 0; x < x_len; x++) { |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 906 | if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) { |
| 907 | begin_x = x; |
| 908 | continue; |
| 909 | } |
| 910 | if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) { |
| 911 | end_x = x - 1; |
Dmitry Torokhov | 4aa5bbe | 2010-06-08 01:01:46 -0700 | [diff] [blame] | 912 | for (y = x_len; y < data_len; y++) { |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 913 | if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) { |
Dmitry Torokhov | 4aa5bbe | 2010-06-08 01:01:46 -0700 | [diff] [blame] | 914 | begin_y = y - x_len; |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 915 | continue; |
| 916 | } |
| 917 | if (end_y == -1 && |
| 918 | begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) { |
Dmitry Torokhov | 4aa5bbe | 2010-06-08 01:01:46 -0700 | [diff] [blame] | 919 | end_y = y - 1 - x_len; |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 920 | w = end_x - begin_x; |
| 921 | h = end_y - begin_y; |
| 922 | #if 0 |
| 923 | /* multi-touch */ |
| 924 | input_report_abs(usbtouch->input, |
| 925 | ABS_MT_TOUCH_MAJOR, max(w,h)); |
| 926 | input_report_abs(usbtouch->input, |
| 927 | ABS_MT_TOUCH_MINOR, min(x,h)); |
| 928 | input_report_abs(usbtouch->input, |
| 929 | ABS_MT_POSITION_X, 2*begin_x+w); |
| 930 | input_report_abs(usbtouch->input, |
| 931 | ABS_MT_POSITION_Y, 2*begin_y+h); |
| 932 | input_report_abs(usbtouch->input, |
| 933 | ABS_MT_ORIENTATION, w > h); |
| 934 | input_mt_sync(usbtouch->input); |
| 935 | #endif |
| 936 | /* single touch */ |
| 937 | usbtouch->x = 2 * begin_x + w; |
| 938 | usbtouch->y = 2 * begin_y + h; |
| 939 | usbtouch->touch = packet->flags & 0x01; |
| 940 | begin_y = end_y = -1; |
| 941 | return 1; |
| 942 | } |
| 943 | } |
| 944 | begin_x = end_x = -1; |
| 945 | } |
| 946 | |
| 947 | } |
| 948 | return 0; |
| 949 | } |
| 950 | #endif |
| 951 | |
| 952 | |
| 953 | /***************************************************************************** |
Michael Gebetsroither | d2cc817a | 2011-11-04 23:56:05 -0700 | [diff] [blame] | 954 | * ELO part |
| 955 | */ |
| 956 | |
| 957 | #ifdef CONFIG_TOUCHSCREEN_USB_ELO |
| 958 | |
| 959 | static int elo_read_data(struct usbtouch_usb *dev, unsigned char *pkt) |
| 960 | { |
| 961 | dev->x = (pkt[3] << 8) | pkt[2]; |
| 962 | dev->y = (pkt[5] << 8) | pkt[4]; |
| 963 | dev->touch = pkt[6] > 0; |
| 964 | dev->press = pkt[6]; |
| 965 | |
| 966 | return 1; |
| 967 | } |
| 968 | #endif |
| 969 | |
| 970 | |
| 971 | /***************************************************************************** |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 972 | * the different device descriptors |
| 973 | */ |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 974 | #ifdef MULTI_PACKET |
| 975 | static void usbtouch_process_multi(struct usbtouch_usb *usbtouch, |
| 976 | unsigned char *pkt, int len); |
| 977 | #endif |
| 978 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 979 | static struct usbtouch_device_info usbtouch_dev_info[] = { |
Michael Gebetsroither | d2cc817a | 2011-11-04 23:56:05 -0700 | [diff] [blame] | 980 | #ifdef CONFIG_TOUCHSCREEN_USB_ELO |
| 981 | [DEVTYPE_ELO] = { |
| 982 | .min_xc = 0x0, |
| 983 | .max_xc = 0x0fff, |
| 984 | .min_yc = 0x0, |
| 985 | .max_yc = 0x0fff, |
| 986 | .max_press = 0xff, |
| 987 | .rept_size = 8, |
| 988 | .read_data = elo_read_data, |
| 989 | }, |
| 990 | #endif |
| 991 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 992 | #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 993 | [DEVTYPE_EGALAX] = { |
| 994 | .min_xc = 0x0, |
| 995 | .max_xc = 0x07ff, |
| 996 | .min_yc = 0x0, |
| 997 | .max_yc = 0x07ff, |
| 998 | .rept_size = 16, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 999 | .process_pkt = usbtouch_process_multi, |
| 1000 | .get_pkt_len = egalax_get_pkt_len, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1001 | .read_data = egalax_read_data, |
| 1002 | }, |
| 1003 | #endif |
| 1004 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 1005 | #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1006 | [DEVTYPE_PANJIT] = { |
| 1007 | .min_xc = 0x0, |
| 1008 | .max_xc = 0x0fff, |
| 1009 | .min_yc = 0x0, |
| 1010 | .max_yc = 0x0fff, |
| 1011 | .rept_size = 8, |
| 1012 | .read_data = panjit_read_data, |
| 1013 | }, |
| 1014 | #endif |
| 1015 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 1016 | #ifdef CONFIG_TOUCHSCREEN_USB_3M |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1017 | [DEVTYPE_3M] = { |
| 1018 | .min_xc = 0x0, |
| 1019 | .max_xc = 0x4000, |
| 1020 | .min_yc = 0x0, |
| 1021 | .max_yc = 0x4000, |
| 1022 | .rept_size = 11, |
| 1023 | .read_data = mtouch_read_data, |
| 1024 | .init = mtouch_init, |
| 1025 | }, |
| 1026 | #endif |
| 1027 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 1028 | #ifdef CONFIG_TOUCHSCREEN_USB_ITM |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1029 | [DEVTYPE_ITM] = { |
| 1030 | .min_xc = 0x0, |
| 1031 | .max_xc = 0x0fff, |
| 1032 | .min_yc = 0x0, |
| 1033 | .max_yc = 0x0fff, |
| 1034 | .max_press = 0xff, |
| 1035 | .rept_size = 8, |
| 1036 | .read_data = itm_read_data, |
| 1037 | }, |
| 1038 | #endif |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1039 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 1040 | #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1041 | [DEVTYPE_ETURBO] = { |
| 1042 | .min_xc = 0x0, |
| 1043 | .max_xc = 0x07ff, |
| 1044 | .min_yc = 0x0, |
| 1045 | .max_yc = 0x07ff, |
| 1046 | .rept_size = 8, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1047 | .process_pkt = usbtouch_process_multi, |
| 1048 | .get_pkt_len = eturbo_get_pkt_len, |
| 1049 | .read_data = eturbo_read_data, |
| 1050 | }, |
| 1051 | #endif |
| 1052 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 1053 | #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1054 | [DEVTYPE_GUNZE] = { |
| 1055 | .min_xc = 0x0, |
| 1056 | .max_xc = 0x0fff, |
| 1057 | .min_yc = 0x0, |
| 1058 | .max_yc = 0x0fff, |
| 1059 | .rept_size = 4, |
| 1060 | .read_data = gunze_read_data, |
| 1061 | }, |
| 1062 | #endif |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 1063 | |
Ondrej Zary | c6f8d70 | 2007-06-12 00:33:13 -0400 | [diff] [blame] | 1064 | #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 |
Holger Schurig | 24ced06 | 2006-11-17 22:50:15 +0100 | [diff] [blame] | 1065 | [DEVTYPE_DMC_TSC10] = { |
| 1066 | .min_xc = 0x0, |
| 1067 | .max_xc = 0x03ff, |
| 1068 | .min_yc = 0x0, |
| 1069 | .max_yc = 0x03ff, |
| 1070 | .rept_size = 5, |
| 1071 | .init = dmc_tsc10_init, |
| 1072 | .read_data = dmc_tsc10_read_data, |
| 1073 | }, |
| 1074 | #endif |
Ondrej Zary | df561fc | 2007-07-03 01:55:03 -0400 | [diff] [blame] | 1075 | |
| 1076 | #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH |
| 1077 | [DEVTYPE_IRTOUCH] = { |
| 1078 | .min_xc = 0x0, |
| 1079 | .max_xc = 0x0fff, |
| 1080 | .min_yc = 0x0, |
| 1081 | .max_yc = 0x0fff, |
| 1082 | .rept_size = 8, |
| 1083 | .read_data = irtouch_read_data, |
| 1084 | }, |
| 1085 | #endif |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 1086 | |
| 1087 | #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK |
| 1088 | [DEVTYPE_IDEALTEK] = { |
| 1089 | .min_xc = 0x0, |
| 1090 | .max_xc = 0x0fff, |
| 1091 | .min_yc = 0x0, |
| 1092 | .max_yc = 0x0fff, |
| 1093 | .rept_size = 8, |
Ondrej Zary | a14a840 | 2007-09-04 23:45:01 -0400 | [diff] [blame] | 1094 | .process_pkt = usbtouch_process_multi, |
| 1095 | .get_pkt_len = idealtek_get_pkt_len, |
| 1096 | .read_data = idealtek_read_data, |
| 1097 | }, |
| 1098 | #endif |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 1099 | |
| 1100 | #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH |
| 1101 | [DEVTYPE_GENERAL_TOUCH] = { |
| 1102 | .min_xc = 0x0, |
Roy Yin | eb083ba | 2010-02-21 22:52:49 -0800 | [diff] [blame] | 1103 | .max_xc = 0x7fff, |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 1104 | .min_yc = 0x0, |
Roy Yin | eb083ba | 2010-02-21 22:52:49 -0800 | [diff] [blame] | 1105 | .max_yc = 0x7fff, |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 1106 | .rept_size = 7, |
| 1107 | .read_data = general_touch_read_data, |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 1108 | }, |
Ilya Frolov | 9d5657d | 2007-10-12 14:19:40 -0400 | [diff] [blame] | 1109 | #endif |
| 1110 | |
Jerrold Jones | 14e4020 | 2007-10-22 00:59:47 -0400 | [diff] [blame] | 1111 | #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP |
| 1112 | [DEVTYPE_GOTOP] = { |
| 1113 | .min_xc = 0x0, |
| 1114 | .max_xc = 0x03ff, |
| 1115 | .min_yc = 0x0, |
| 1116 | .max_yc = 0x03ff, |
| 1117 | .rept_size = 4, |
| 1118 | .read_data = gotop_read_data, |
| 1119 | }, |
| 1120 | #endif |
Jim Persson | f737069 | 2009-07-07 22:07:59 -0700 | [diff] [blame] | 1121 | |
| 1122 | #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC |
| 1123 | [DEVTYPE_JASTEC] = { |
| 1124 | .min_xc = 0x0, |
| 1125 | .max_xc = 0x0fff, |
| 1126 | .min_yc = 0x0, |
| 1127 | .max_yc = 0x0fff, |
| 1128 | .rept_size = 4, |
| 1129 | .read_data = jastec_read_data, |
| 1130 | }, |
| 1131 | #endif |
Florian Echtler | 9e3b258 | 2009-07-27 17:35:39 -0700 | [diff] [blame] | 1132 | |
| 1133 | #ifdef CONFIG_TOUCHSCREEN_USB_E2I |
| 1134 | [DEVTYPE_E2I] = { |
| 1135 | .min_xc = 0x0, |
| 1136 | .max_xc = 0x7fff, |
| 1137 | .min_yc = 0x0, |
| 1138 | .max_yc = 0x7fff, |
| 1139 | .rept_size = 6, |
| 1140 | .init = e2i_init, |
| 1141 | .read_data = e2i_read_data, |
| 1142 | }, |
| 1143 | #endif |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 1144 | |
| 1145 | #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC |
| 1146 | [DEVTYPE_ZYTRONIC] = { |
| 1147 | .min_xc = 0x0, |
| 1148 | .max_xc = 0x03ff, |
| 1149 | .min_yc = 0x0, |
| 1150 | .max_yc = 0x03ff, |
| 1151 | .rept_size = 5, |
| 1152 | .read_data = zytronic_read_data, |
| 1153 | .irq_always = true, |
| 1154 | }, |
| 1155 | #endif |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 1156 | |
Petr Å tetiar | 38771bb | 2010-06-28 09:38:48 -0700 | [diff] [blame] | 1157 | #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB |
| 1158 | [DEVTYPE_TC45USB] = { |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 1159 | .min_xc = 0x0, |
| 1160 | .max_xc = 0x0fff, |
| 1161 | .min_yc = 0x0, |
| 1162 | .max_yc = 0x0fff, |
| 1163 | .rept_size = 5, |
Petr Å tetiar | 38771bb | 2010-06-28 09:38:48 -0700 | [diff] [blame] | 1164 | .read_data = tc45usb_read_data, |
Petr Å tetiar | dbe1420 | 2009-11-29 23:37:07 -0800 | [diff] [blame] | 1165 | }, |
| 1166 | #endif |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1167 | |
| 1168 | #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO |
| 1169 | [DEVTYPE_NEXIO] = { |
Ondrej Zary | 388bbca | 2010-05-26 23:30:54 -0700 | [diff] [blame] | 1170 | .rept_size = 1024, |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1171 | .irq_always = true, |
| 1172 | .read_data = nexio_read_data, |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 1173 | .alloc = nexio_alloc, |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1174 | .init = nexio_init, |
| 1175 | .exit = nexio_exit, |
| 1176 | }, |
| 1177 | #endif |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1178 | }; |
| 1179 | |
| 1180 | |
| 1181 | /***************************************************************************** |
| 1182 | * Generic Part |
| 1183 | */ |
| 1184 | static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch, |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1185 | unsigned char *pkt, int len) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1186 | { |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1187 | struct usbtouch_device_info *type = usbtouch->type; |
| 1188 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 1189 | if (!type->read_data(usbtouch, pkt)) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1190 | return; |
| 1191 | |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 1192 | input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1193 | |
| 1194 | if (swap_xy) { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 1195 | input_report_abs(usbtouch->input, ABS_X, usbtouch->y); |
| 1196 | input_report_abs(usbtouch->input, ABS_Y, usbtouch->x); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1197 | } else { |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 1198 | input_report_abs(usbtouch->input, ABS_X, usbtouch->x); |
| 1199 | input_report_abs(usbtouch->input, ABS_Y, usbtouch->y); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1200 | } |
| 1201 | if (type->max_press) |
Daniel Ritz | c9d8c2b | 2006-12-11 18:17:45 +0100 | [diff] [blame] | 1202 | input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1203 | input_sync(usbtouch->input); |
| 1204 | } |
| 1205 | |
| 1206 | |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1207 | #ifdef MULTI_PACKET |
| 1208 | static void usbtouch_process_multi(struct usbtouch_usb *usbtouch, |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1209 | unsigned char *pkt, int len) |
| 1210 | { |
| 1211 | unsigned char *buffer; |
| 1212 | int pkt_len, pos, buf_len, tmp; |
| 1213 | |
| 1214 | /* process buffer */ |
| 1215 | if (unlikely(usbtouch->buf_len)) { |
| 1216 | /* try to get size */ |
| 1217 | pkt_len = usbtouch->type->get_pkt_len( |
| 1218 | usbtouch->buffer, usbtouch->buf_len); |
| 1219 | |
| 1220 | /* drop? */ |
| 1221 | if (unlikely(!pkt_len)) |
| 1222 | goto out_flush_buf; |
| 1223 | |
| 1224 | /* need to append -pkt_len bytes before able to get size */ |
| 1225 | if (unlikely(pkt_len < 0)) { |
| 1226 | int append = -pkt_len; |
| 1227 | if (unlikely(append > len)) |
| 1228 | append = len; |
| 1229 | if (usbtouch->buf_len + append >= usbtouch->type->rept_size) |
| 1230 | goto out_flush_buf; |
| 1231 | memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append); |
| 1232 | usbtouch->buf_len += append; |
| 1233 | |
| 1234 | pkt_len = usbtouch->type->get_pkt_len( |
| 1235 | usbtouch->buffer, usbtouch->buf_len); |
| 1236 | if (pkt_len < 0) |
| 1237 | return; |
| 1238 | } |
| 1239 | |
| 1240 | /* append */ |
| 1241 | tmp = pkt_len - usbtouch->buf_len; |
| 1242 | if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size) |
| 1243 | goto out_flush_buf; |
| 1244 | memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1245 | usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1246 | |
| 1247 | buffer = pkt + tmp; |
| 1248 | buf_len = len - tmp; |
| 1249 | } else { |
| 1250 | buffer = pkt; |
| 1251 | buf_len = len; |
| 1252 | } |
| 1253 | |
| 1254 | /* loop over the received packet, process */ |
| 1255 | pos = 0; |
| 1256 | while (pos < buf_len) { |
| 1257 | /* get packet len */ |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 1258 | pkt_len = usbtouch->type->get_pkt_len(buffer + pos, |
| 1259 | buf_len - pos); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1260 | |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 1261 | /* unknown packet: skip one byte */ |
| 1262 | if (unlikely(!pkt_len)) { |
| 1263 | pos++; |
| 1264 | continue; |
| 1265 | } |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1266 | |
| 1267 | /* full packet: process */ |
| 1268 | if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1269 | usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1270 | } else { |
| 1271 | /* incomplete packet: save in buffer */ |
| 1272 | memcpy(usbtouch->buffer, buffer + pos, buf_len - pos); |
| 1273 | usbtouch->buf_len = buf_len - pos; |
| 1274 | return; |
| 1275 | } |
| 1276 | pos += pkt_len; |
| 1277 | } |
| 1278 | |
| 1279 | out_flush_buf: |
| 1280 | usbtouch->buf_len = 0; |
| 1281 | return; |
| 1282 | } |
| 1283 | #endif |
| 1284 | |
| 1285 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1286 | static void usbtouch_irq(struct urb *urb) |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1287 | { |
| 1288 | struct usbtouch_usb *usbtouch = urb->context; |
| 1289 | int retval; |
| 1290 | |
| 1291 | switch (urb->status) { |
| 1292 | case 0: |
| 1293 | /* success */ |
| 1294 | break; |
Pete Zaitcev | 38e2bfc | 2006-09-18 22:49:02 -0700 | [diff] [blame] | 1295 | case -ETIME: |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1296 | /* this urb is timing out */ |
| 1297 | dbg("%s - urb timed out - was the device unplugged?", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1298 | __func__); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1299 | return; |
| 1300 | case -ECONNRESET: |
| 1301 | case -ENOENT: |
| 1302 | case -ESHUTDOWN: |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1303 | case -EPIPE: |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1304 | /* this urb is terminated, clean up */ |
| 1305 | dbg("%s - urb shutting down with status: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1306 | __func__, urb->status); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1307 | return; |
| 1308 | default: |
| 1309 | dbg("%s - nonzero urb status received: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1310 | __func__, urb->status); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1311 | goto exit; |
| 1312 | } |
| 1313 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1314 | usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1315 | |
| 1316 | exit: |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1317 | usb_mark_last_busy(interface_to_usbdev(usbtouch->interface)); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1318 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
| 1319 | if (retval) |
| 1320 | err("%s - usb_submit_urb failed with result: %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1321 | __func__, retval); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | static int usbtouch_open(struct input_dev *input) |
| 1325 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 1326 | struct usbtouch_usb *usbtouch = input_get_drvdata(input); |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1327 | int r; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1328 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 1329 | usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1330 | |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1331 | r = usb_autopm_get_interface(usbtouch->interface) ? -EIO : 0; |
| 1332 | if (r < 0) |
| 1333 | goto out; |
| 1334 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 1335 | if (!usbtouch->type->irq_always) { |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1336 | if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) { |
| 1337 | r = -EIO; |
| 1338 | goto out_put; |
| 1339 | } |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 1340 | } |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1341 | |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1342 | usbtouch->interface->needs_remote_wakeup = 1; |
| 1343 | out_put: |
| 1344 | usb_autopm_put_interface(usbtouch->interface); |
| 1345 | out: |
| 1346 | return r; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | static void usbtouch_close(struct input_dev *input) |
| 1350 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 1351 | struct usbtouch_usb *usbtouch = input_get_drvdata(input); |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1352 | int r; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1353 | |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 1354 | if (!usbtouch->type->irq_always) |
| 1355 | usb_kill_urb(usbtouch->irq); |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1356 | r = usb_autopm_get_interface(usbtouch->interface); |
| 1357 | usbtouch->interface->needs_remote_wakeup = 0; |
| 1358 | if (!r) |
| 1359 | usb_autopm_put_interface(usbtouch->interface); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1360 | } |
| 1361 | |
Oliver Neukum | ed4299e | 2010-07-15 09:16:39 -0700 | [diff] [blame] | 1362 | static int usbtouch_suspend |
| 1363 | (struct usb_interface *intf, pm_message_t message) |
| 1364 | { |
| 1365 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); |
| 1366 | |
| 1367 | usb_kill_urb(usbtouch->irq); |
| 1368 | |
| 1369 | return 0; |
| 1370 | } |
| 1371 | |
| 1372 | static int usbtouch_resume(struct usb_interface *intf) |
| 1373 | { |
| 1374 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); |
| 1375 | struct input_dev *input = usbtouch->input; |
| 1376 | int result = 0; |
| 1377 | |
| 1378 | mutex_lock(&input->mutex); |
| 1379 | if (input->users || usbtouch->type->irq_always) |
| 1380 | result = usb_submit_urb(usbtouch->irq, GFP_NOIO); |
| 1381 | mutex_unlock(&input->mutex); |
| 1382 | |
| 1383 | return result; |
| 1384 | } |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1385 | |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 1386 | static int usbtouch_reset_resume(struct usb_interface *intf) |
| 1387 | { |
| 1388 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); |
| 1389 | struct input_dev *input = usbtouch->input; |
| 1390 | int err = 0; |
| 1391 | |
| 1392 | /* reinit the device */ |
| 1393 | if (usbtouch->type->init) { |
| 1394 | err = usbtouch->type->init(usbtouch); |
| 1395 | if (err) { |
| 1396 | dbg("%s - type->init() failed, err: %d", |
| 1397 | __func__, err); |
| 1398 | return err; |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | /* restart IO if needed */ |
| 1403 | mutex_lock(&input->mutex); |
| 1404 | if (input->users) |
| 1405 | err = usb_submit_urb(usbtouch->irq, GFP_NOIO); |
| 1406 | mutex_unlock(&input->mutex); |
| 1407 | |
| 1408 | return err; |
| 1409 | } |
| 1410 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1411 | static void usbtouch_free_buffers(struct usb_device *udev, |
| 1412 | struct usbtouch_usb *usbtouch) |
| 1413 | { |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1414 | usb_free_coherent(udev, usbtouch->type->rept_size, |
| 1415 | usbtouch->data, usbtouch->data_dma); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1416 | kfree(usbtouch->buffer); |
| 1417 | } |
| 1418 | |
Ondrej Zary | f4a5e35 | 2010-02-03 23:54:59 -0800 | [diff] [blame] | 1419 | static struct usb_endpoint_descriptor * |
| 1420 | usbtouch_get_input_endpoint(struct usb_host_interface *interface) |
| 1421 | { |
| 1422 | int i; |
| 1423 | |
| 1424 | for (i = 0; i < interface->desc.bNumEndpoints; i++) |
| 1425 | if (usb_endpoint_dir_in(&interface->endpoint[i].desc)) |
| 1426 | return &interface->endpoint[i].desc; |
| 1427 | |
| 1428 | return NULL; |
| 1429 | } |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1430 | |
| 1431 | static int usbtouch_probe(struct usb_interface *intf, |
| 1432 | const struct usb_device_id *id) |
| 1433 | { |
| 1434 | struct usbtouch_usb *usbtouch; |
| 1435 | struct input_dev *input_dev; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1436 | struct usb_endpoint_descriptor *endpoint; |
| 1437 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1438 | struct usbtouch_device_info *type; |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1439 | int err = -ENOMEM; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1440 | |
Daniel Ritz | ec42d44 | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 1441 | /* some devices are ignored */ |
| 1442 | if (id->driver_info == DEVTYPE_IGNORE) |
| 1443 | return -ENODEV; |
| 1444 | |
Ondrej Zary | f4a5e35 | 2010-02-03 23:54:59 -0800 | [diff] [blame] | 1445 | endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting); |
| 1446 | if (!endpoint) |
| 1447 | return -ENXIO; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1448 | |
| 1449 | usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL); |
| 1450 | input_dev = input_allocate_device(); |
| 1451 | if (!usbtouch || !input_dev) |
| 1452 | goto out_free; |
| 1453 | |
| 1454 | type = &usbtouch_dev_info[id->driver_info]; |
| 1455 | usbtouch->type = type; |
| 1456 | if (!type->process_pkt) |
| 1457 | type->process_pkt = usbtouch_process_pkt; |
| 1458 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 1459 | usbtouch->data = usb_alloc_coherent(udev, type->rept_size, |
| 1460 | GFP_KERNEL, &usbtouch->data_dma); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1461 | if (!usbtouch->data) |
| 1462 | goto out_free; |
| 1463 | |
Daniel Ritz | 62aa366 | 2008-01-17 12:01:18 -0500 | [diff] [blame] | 1464 | if (type->get_pkt_len) { |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1465 | usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL); |
| 1466 | if (!usbtouch->buffer) |
| 1467 | goto out_free_buffers; |
| 1468 | } |
| 1469 | |
| 1470 | usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL); |
| 1471 | if (!usbtouch->irq) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1472 | dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1473 | goto out_free_buffers; |
| 1474 | } |
| 1475 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 1476 | usbtouch->interface = intf; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1477 | usbtouch->input = input_dev; |
| 1478 | |
| 1479 | if (udev->manufacturer) |
| 1480 | strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name)); |
| 1481 | |
| 1482 | if (udev->product) { |
| 1483 | if (udev->manufacturer) |
| 1484 | strlcat(usbtouch->name, " ", sizeof(usbtouch->name)); |
| 1485 | strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name)); |
| 1486 | } |
| 1487 | |
| 1488 | if (!strlen(usbtouch->name)) |
| 1489 | snprintf(usbtouch->name, sizeof(usbtouch->name), |
| 1490 | "USB Touchscreen %04x:%04x", |
| 1491 | le16_to_cpu(udev->descriptor.idVendor), |
| 1492 | le16_to_cpu(udev->descriptor.idProduct)); |
| 1493 | |
| 1494 | usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys)); |
Vladimir Shebordaev | 7b6dff9 | 2007-09-06 21:32:16 -0400 | [diff] [blame] | 1495 | strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys)); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1496 | |
| 1497 | input_dev->name = usbtouch->name; |
| 1498 | input_dev->phys = usbtouch->phys; |
| 1499 | usb_to_input_id(udev, &input_dev->id); |
Dmitry Torokhov | c0f82d5 | 2007-04-12 01:35:03 -0400 | [diff] [blame] | 1500 | input_dev->dev.parent = &intf->dev; |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 1501 | |
| 1502 | input_set_drvdata(input_dev, usbtouch); |
| 1503 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1504 | input_dev->open = usbtouch_open; |
| 1505 | input_dev->close = usbtouch_close; |
| 1506 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 1507 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 1508 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1509 | input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0); |
| 1510 | input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0); |
| 1511 | if (type->max_press) |
| 1512 | input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press, |
| 1513 | type->max_press, 0, 0); |
| 1514 | |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1515 | if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT) |
| 1516 | usb_fill_int_urb(usbtouch->irq, udev, |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 1517 | usb_rcvintpipe(udev, endpoint->bEndpointAddress), |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1518 | usbtouch->data, type->rept_size, |
| 1519 | usbtouch_irq, usbtouch, endpoint->bInterval); |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1520 | else |
| 1521 | usb_fill_bulk_urb(usbtouch->irq, udev, |
| 1522 | usb_rcvbulkpipe(udev, endpoint->bEndpointAddress), |
| 1523 | usbtouch->data, type->rept_size, |
| 1524 | usbtouch_irq, usbtouch); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1525 | |
Ondrej Zary | fea4d14 | 2010-02-03 23:46:48 -0800 | [diff] [blame] | 1526 | usbtouch->irq->dev = udev; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1527 | usbtouch->irq->transfer_dma = usbtouch->data_dma; |
| 1528 | usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 1529 | |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 1530 | /* device specific allocations */ |
| 1531 | if (type->alloc) { |
| 1532 | err = type->alloc(usbtouch); |
| 1533 | if (err) { |
| 1534 | dbg("%s - type->alloc() failed, err: %d", __func__, err); |
| 1535 | goto out_free_urb; |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | /* device specific initialisation*/ |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1540 | if (type->init) { |
| 1541 | err = type->init(usbtouch); |
| 1542 | if (err) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1543 | dbg("%s - type->init() failed, err: %d", __func__, err); |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 1544 | goto out_do_exit; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | err = input_register_device(usbtouch->input); |
| 1549 | if (err) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1550 | dbg("%s - input_register_device failed, err: %d", __func__, err); |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1551 | goto out_do_exit; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | usb_set_intfdata(intf, usbtouch); |
| 1555 | |
Ondrej Zary | 1e87a43 | 2010-02-04 00:20:35 -0800 | [diff] [blame] | 1556 | if (usbtouch->type->irq_always) { |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1557 | /* this can't fail */ |
| 1558 | usb_autopm_get_interface(intf); |
Ondrej Zary | 1e87a43 | 2010-02-04 00:20:35 -0800 | [diff] [blame] | 1559 | err = usb_submit_urb(usbtouch->irq, GFP_KERNEL); |
| 1560 | if (err) { |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1561 | usb_autopm_put_interface(intf); |
Ondrej Zary | 1e87a43 | 2010-02-04 00:20:35 -0800 | [diff] [blame] | 1562 | err("%s - usb_submit_urb failed with result: %d", |
| 1563 | __func__, err); |
| 1564 | goto out_unregister_input; |
| 1565 | } |
| 1566 | } |
Daniel Silverstone | 2330ed1 | 2009-11-23 08:38:16 -0800 | [diff] [blame] | 1567 | |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1568 | return 0; |
| 1569 | |
Ondrej Zary | 1e87a43 | 2010-02-04 00:20:35 -0800 | [diff] [blame] | 1570 | out_unregister_input: |
| 1571 | input_unregister_device(input_dev); |
| 1572 | input_dev = NULL; |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1573 | out_do_exit: |
| 1574 | if (type->exit) |
| 1575 | type->exit(usbtouch); |
Ondrej Zary | 1e87a43 | 2010-02-04 00:20:35 -0800 | [diff] [blame] | 1576 | out_free_urb: |
| 1577 | usb_free_urb(usbtouch->irq); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1578 | out_free_buffers: |
| 1579 | usbtouch_free_buffers(udev, usbtouch); |
| 1580 | out_free: |
| 1581 | input_free_device(input_dev); |
| 1582 | kfree(usbtouch); |
Daniel Ritz | 5d89266 | 2006-07-31 21:43:24 +0200 | [diff] [blame] | 1583 | return err; |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | static void usbtouch_disconnect(struct usb_interface *intf) |
| 1587 | { |
| 1588 | struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); |
| 1589 | |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1590 | dbg("%s - called", __func__); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1591 | |
| 1592 | if (!usbtouch) |
| 1593 | return; |
| 1594 | |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 1595 | dbg("%s - usbtouch is initialized, cleaning up", __func__); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1596 | usb_set_intfdata(intf, NULL); |
Oliver Neukum | 722232b | 2009-11-23 08:10:50 -0800 | [diff] [blame] | 1597 | /* this will stop IO via close */ |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1598 | input_unregister_device(usbtouch->input); |
| 1599 | usb_free_urb(usbtouch->irq); |
Ondrej Zary | 5197424 | 2010-02-04 00:17:18 -0800 | [diff] [blame] | 1600 | if (usbtouch->type->exit) |
| 1601 | usbtouch->type->exit(usbtouch); |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1602 | usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch); |
| 1603 | kfree(usbtouch); |
| 1604 | } |
| 1605 | |
| 1606 | MODULE_DEVICE_TABLE(usb, usbtouch_devices); |
| 1607 | |
| 1608 | static struct usb_driver usbtouch_driver = { |
| 1609 | .name = "usbtouchscreen", |
| 1610 | .probe = usbtouch_probe, |
| 1611 | .disconnect = usbtouch_disconnect, |
Oliver Neukum | ed4299e | 2010-07-15 09:16:39 -0700 | [diff] [blame] | 1612 | .suspend = usbtouch_suspend, |
| 1613 | .resume = usbtouch_resume, |
Oliver Neukum | a8aef62 | 2010-07-15 09:21:40 -0700 | [diff] [blame] | 1614 | .reset_resume = usbtouch_reset_resume, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1615 | .id_table = usbtouch_devices, |
Oliver Neukum | 5d9efc5 | 2010-07-15 09:19:51 -0700 | [diff] [blame] | 1616 | .supports_autosuspend = 1, |
Daniel Ritz | 1d3e202 | 2006-03-29 22:41:07 +0200 | [diff] [blame] | 1617 | }; |
| 1618 | |
| 1619 | static int __init usbtouch_init(void) |
| 1620 | { |
| 1621 | return usb_register(&usbtouch_driver); |
| 1622 | } |
| 1623 | |
| 1624 | static void __exit usbtouch_cleanup(void) |
| 1625 | { |
| 1626 | usb_deregister(&usbtouch_driver); |
| 1627 | } |
| 1628 | |
| 1629 | module_init(usbtouch_init); |
| 1630 | module_exit(usbtouch_cleanup); |
| 1631 | |
| 1632 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1633 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1634 | MODULE_LICENSE("GPL"); |
| 1635 | |
| 1636 | MODULE_ALIAS("touchkitusb"); |
| 1637 | MODULE_ALIAS("itmtouch"); |
| 1638 | MODULE_ALIAS("mtouchusb"); |