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