blob: 5f87bed054674b487e724d3588806235b5b5f738 [file] [log] [blame]
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001/******************************************************************************
2 * usbtouchscreen.c
3 * Driver for USB Touchscreens, supporting those devices:
4 * - eGalax Touchkit
Daniel Ritz5d892662006-07-31 21:43:24 +02005 * includes eTurboTouch CT-410/510/700
6 * - 3M/Microtouch EX II series
Daniel Ritz1d3e2022006-03-29 22:41:07 +02007 * - ITM
8 * - PanJit TouchSet
Daniel Ritz5d892662006-07-31 21:43:24 +02009 * - eTurboTouch
10 * - Gunze AHL61
Holger Schurig24ced062006-11-17 22:50:15 +010011 * - DMC TSC-10/25
Ondrej Zarydf561fc2007-07-03 01:55:03 -040012 * - IRTOUCHSYSTEMS/UNITOP
Ondrej Zarya14a8402007-09-04 23:45:01 -040013 * - IdealTEK URTC1000
Daniel Ritz62aa3662008-01-17 12:01:18 -050014 * - General Touch
Jerrold Jones14e40202007-10-22 00:59:47 -040015 * - GoTop Super_Q2/GogoPen/PenPower tablets
Jim Perssonf7370692009-07-07 22:07:59 -070016 * - JASTEC USB touch controller/DigiTech DTR-02U
Daniel Silverstone2330ed12009-11-23 08:38:16 -080017 * - Zytronic capacitive touchscreen
Ondrej Zary51974242010-02-04 00:17:18 -080018 * - NEXIO/iNexio
Michael Gebetsroitherd2cc817a2011-11-04 23:56:05 -070019 * - Elo TouchSystems 2700 IntelliTouch
Armando Viscontiaa875122012-03-04 10:41:36 -080020 * - EasyTouch USB Dual/Multi touch controller from Data Modul
Daniel Ritz1d3e2022006-03-29 22:41:07 +020021 *
Jerrold Jones14e40202007-10-22 00:59:47 -040022 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
Daniel Ritz1d3e2022006-03-29 22:41:07 +020023 * 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 Schurig24ced062006-11-17 22:50:15 +010043 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
44 * driver from Marius Vollmer
Daniel Ritz1d3e2022006-03-29 22:41:07 +020045 *
46 *****************************************************************************/
47
48//#define DEBUG
49
Daniel Ritz1d3e2022006-03-29 22:41:07 +020050#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 Brownellae0dadc2006-06-13 10:04:34 -070056#include <linux/usb/input.h>
Daniel Ritzec42d442008-07-03 10:45:37 -040057#include <linux/hid.h>
Daniel Ritz1d3e2022006-03-29 22:41:07 +020058
59
Daniel Ritz62aa3662008-01-17 12:01:18 -050060#define DRIVER_VERSION "v0.6"
Daniel Ritz1d3e2022006-03-29 22:41:07 +020061#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
62#define DRIVER_DESC "USB Touchscreen Driver"
63
Rusty Russell90ab5ee2012-01-13 09:32:20 +103064static bool swap_xy;
Daniel Ritz1d3e2022006-03-29 22:41:07 +020065module_param(swap_xy, bool, 0644);
66MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
67
Rusty Russell90ab5ee2012-01-13 09:32:20 +103068static bool hwcalib_xy;
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -080069module_param(hwcalib_xy, bool, 0644);
70MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
71
Daniel Ritz1d3e2022006-03-29 22:41:07 +020072/* device specifc data/functions */
73struct usbtouch_usb;
74struct 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 Ritz1d3e2022006-03-29 22:41:07 +020079
Daniel Silverstone2330ed12009-11-23 08:38:16 -080080 /*
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 Howells7d12e782006-10-05 14:55:46 +010089 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
Daniel Ritz62aa3662008-01-17 12:01:18 -050090
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 Ritz5d892662006-07-31 21:43:24 +020097 int (*get_pkt_len) (unsigned char *pkt, int len);
Daniel Ritz62aa3662008-01-17 12:01:18 -050098
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +010099 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
Oliver Neukuma8aef622010-07-15 09:21:40 -0700100 int (*alloc) (struct usbtouch_usb *usbtouch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200101 int (*init) (struct usbtouch_usb *usbtouch);
Ondrej Zary51974242010-02-04 00:17:18 -0800102 void (*exit) (struct usbtouch_usb *usbtouch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200103};
104
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200105/* a usbtouch device */
106struct usbtouch_usb {
107 unsigned char *data;
108 dma_addr_t data_dma;
Christian Engelmayer4ef38352013-11-26 18:16:17 -0800109 int data_size;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200110 unsigned char *buffer;
111 int buf_len;
112 struct urb *irq;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800113 struct usb_interface *interface;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200114 struct input_dev *input;
115 struct usbtouch_device_info *type;
116 char name[128];
117 char phys[64];
Ondrej Zary51974242010-02-04 00:17:18 -0800118 void *priv;
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100119
120 int x, y;
121 int touch, press;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200122};
123
Daniel Ritz5d892662006-07-31 21:43:24 +0200124
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200125/* device types */
126enum {
Daniel Ritzec42d442008-07-03 10:45:37 -0400127 DEVTYPE_IGNORE = -1,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200128 DEVTYPE_EGALAX,
129 DEVTYPE_PANJIT,
130 DEVTYPE_3M,
131 DEVTYPE_ITM,
Daniel Ritz5d892662006-07-31 21:43:24 +0200132 DEVTYPE_ETURBO,
133 DEVTYPE_GUNZE,
Holger Schurig24ced062006-11-17 22:50:15 +0100134 DEVTYPE_DMC_TSC10,
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400135 DEVTYPE_IRTOUCH,
Ondrej Zarya14a8402007-09-04 23:45:01 -0400136 DEVTYPE_IDEALTEK,
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400137 DEVTYPE_GENERAL_TOUCH,
Jerrold Jones14e40202007-10-22 00:59:47 -0400138 DEVTYPE_GOTOP,
Jim Perssonf7370692009-07-07 22:07:59 -0700139 DEVTYPE_JASTEC,
Florian Echtler9e3b2582009-07-27 17:35:39 -0700140 DEVTYPE_E2I,
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800141 DEVTYPE_ZYTRONIC,
Petr Å tetiar38771bb2010-06-28 09:38:48 -0700142 DEVTYPE_TC45USB,
Ondrej Zary51974242010-02-04 00:17:18 -0800143 DEVTYPE_NEXIO,
Michael Gebetsroitherd2cc817a2011-11-04 23:56:05 -0700144 DEVTYPE_ELO,
Armando Viscontiaa875122012-03-04 10:41:36 -0800145 DEVTYPE_ETOUCH,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200146};
147
Daniel Ritzec42d442008-07-03 10:45:37 -0400148#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 Bondae2aa3a2013-10-21 12:38:18 -0400153 .bInterfaceClass = USB_INTERFACE_CLASS_HID
Daniel Ritzec42d442008-07-03 10:45:37 -0400154
Márton Németh9cb3ce52010-01-10 23:59:05 -0800155static const struct usb_device_id usbtouch_devices[] = {
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400156#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritzec42d442008-07-03 10:45:37 -0400157 /* 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 Ritz1d3e2022006-03-29 22:41:07 +0200162 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz5d892662006-07-31 21:43:24 +0200163 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200164 {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 Ritz5d892662006-07-31 21:43:24 +0200167 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
168 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200169#endif
170
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400171#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200172 {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 Zaryc6f8d702007-06-12 00:33:13 -0400178#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200179 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
180#endif
181
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400182#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200183 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
Glenn Sommer09910502010-11-22 12:00:05 -0800184 {USB_DEVICE(0x16e3, 0xf9e9), .driver_info = DEVTYPE_ITM},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200185#endif
186
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400187#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz5d892662006-07-31 21:43:24 +0200188 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
189#endif
190
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400191#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritz5d892662006-07-31 21:43:24 +0200192 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
193#endif
194
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400195#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100196 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
197#endif
198
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400199#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 Zarya14a8402007-09-04 23:45:01 -0400204#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
205 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
206#endif
207
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400208#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
209 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
210#endif
211
Jerrold Jones14e40202007-10-22 00:59:47 -0400212#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 Perssonf7370692009-07-07 22:07:59 -0700218#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
219 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
220#endif
221
Florian Echtler9e3b2582009-07-27 17:35:39 -0700222#ifdef CONFIG_TOUCHSCREEN_USB_E2I
223 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
224#endif
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800225
226#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
227 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
228#endif
229
Petr Å tetiar38771bb2010-06-28 09:38:48 -0700230#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 Å tetiardbe14202009-11-29 23:37:07 -0800235#endif
236
Ondrej Zary51974242010-02-04 00:17:18 -0800237#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 Gebetsroitherd2cc817a2011-11-04 23:56:05 -0700245#ifdef CONFIG_TOUCHSCREEN_USB_ELO
246 {USB_DEVICE(0x04e7, 0x0020), .driver_info = DEVTYPE_ELO},
247#endif
248
Armando Viscontiaa875122012-03-04 10:41:36 -0800249#ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
250 {USB_DEVICE(0x7374, 0x0001), .driver_info = DEVTYPE_ETOUCH},
251#endif
252
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200253 {}
254};
255
256
257/*****************************************************************************
Florian Echtler9e3b2582009-07-27 17:35:39 -0700258 * e2i Part
259 */
260
261#ifdef CONFIG_TOUCHSCREEN_USB_E2I
262static int e2i_init(struct usbtouch_usb *usbtouch)
263{
264 int ret;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800265 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
Florian Echtler9e3b2582009-07-27 17:35:39 -0700266
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800267 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Florian Echtler9e3b2582009-07-27 17:35:39 -0700268 0x01, 0x02, 0x0000, 0x0081,
269 NULL, 0, USB_CTRL_SET_TIMEOUT);
270
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -0700271 dev_dbg(&usbtouch->interface->dev,
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -0700272 "%s - usb_control_msg - E2I_RESET - bytes|err: %d\n",
273 __func__, ret);
Florian Echtler9e3b2582009-07-27 17:35:39 -0700274 return ret;
275}
276
277static 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 Ritz1d3e2022006-03-29 22:41:07 +0200293 * eGalax part
294 */
295
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400296#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200297
Daniel Ritz62aa3662008-01-17 12:01:18 -0500298#ifndef MULTI_PACKET
299#define MULTI_PACKET
300#endif
301
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200302#define EGALAX_PKT_TYPE_MASK 0xFE
303#define EGALAX_PKT_TYPE_REPT 0x80
304#define EGALAX_PKT_TYPE_DIAG 0x0A
305
Forest Bond037a8332012-09-04 20:27:37 -0700306static 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 Ritzc9d8c2b2006-12-11 18:17:45 +0100345static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200346{
347 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
348 return 0;
349
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100350 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 Ritz1d3e2022006-03-29 22:41:07 +0200353
354 return 1;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200355}
356
Daniel Ritz5d892662006-07-31 21:43:24 +0200357static int egalax_get_pkt_len(unsigned char *buf, int len)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200358{
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 Ritz5d892662006-07-31 21:43:24 +0200364 if (len < 2)
365 return -1;
366
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200367 return buf[1] + 2;
368 }
369
370 return 0;
371}
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200372#endif
373
Armando Viscontiaa875122012-03-04 10:41:36 -0800374/*****************************************************************************
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
389static 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
402static 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 Ritz1d3e2022006-03-29 22:41:07 +0200419
420/*****************************************************************************
421 * PanJit Part
422 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400423#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100424static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200425{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100426 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
427 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
428 dev->touch = pkt[0] & 0x01;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200429
430 return 1;
431}
432#endif
433
434
435/*****************************************************************************
436 * 3M/Microtouch Part
437 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400438#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200439
440#define MTOUCHUSB_ASYNC_REPORT 1
441#define MTOUCHUSB_RESET 7
442#define MTOUCHUSB_REQ_CTRLLR_ID 10
443
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100444static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200445{
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -0800446 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 Ritzc9d8c2b2006-12-11 18:17:45 +0100453 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200454
455 return 1;
456}
457
458static int mtouch_init(struct usbtouch_usb *usbtouch)
459{
Daniel Ritz5d892662006-07-31 21:43:24 +0200460 int ret, i;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800461 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200462
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800463 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200464 MTOUCHUSB_RESET,
465 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
466 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -0700467 dev_dbg(&usbtouch->interface->dev,
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -0700468 "%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d\n",
469 __func__, ret);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200470 if (ret < 0)
471 return ret;
Daniel Ritz5d892662006-07-31 21:43:24 +0200472 msleep(150);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200473
Daniel Ritz5d892662006-07-31 21:43:24 +0200474 for (i = 0; i < 3; i++) {
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800475 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Daniel Ritz5d892662006-07-31 21:43:24 +0200476 MTOUCHUSB_ASYNC_REPORT,
477 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
478 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -0700479 dev_dbg(&usbtouch->interface->dev,
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -0700480 "%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d\n",
481 __func__, ret);
Daniel Ritz5d892662006-07-31 21:43:24 +0200482 if (ret >= 0)
483 break;
484 if (ret != -EPIPE)
485 return ret;
486 }
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200487
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -0800488 /* 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 Ritz1d3e2022006-03-29 22:41:07 +0200494 return 0;
495}
496#endif
497
498
499/*****************************************************************************
500 * ITM Part
501 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400502#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100503static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200504{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100505 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 Ritz1d3e2022006-03-29 22:41:07 +0200513
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100514 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 Ritz1d3e2022006-03-29 22:41:07 +0200529}
530#endif
531
532
533/*****************************************************************************
Daniel Ritz5d892662006-07-31 21:43:24 +0200534 * eTurboTouch part
535 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400536#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz62aa3662008-01-17 12:01:18 -0500537#ifndef MULTI_PACKET
538#define MULTI_PACKET
539#endif
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100540static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz5d892662006-07-31 21:43:24 +0200541{
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 Ritzc9d8c2b2006-12-11 18:17:45 +0100549 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 Ritz5d892662006-07-31 21:43:24 +0200552
553 return 1;
554}
555
556static 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 Zaryc6f8d702007-06-12 00:33:13 -0400570#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100571static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz5d892662006-07-31 21:43:24 +0200572{
573 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
574 return 0;
575
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100576 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 Ritz5d892662006-07-31 21:43:24 +0200579
580 return 1;
581}
582#endif
583
584/*****************************************************************************
Holger Schurig24ced062006-11-17 22:50:15 +0100585 * 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 Zaryc6f8d702007-06-12 00:33:13 -0400591#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100592
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
607static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
608{
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800609 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
Oliver Neukum76d057c2008-04-04 15:31:47 -0400610 int ret = -ENOMEM;
611 unsigned char *buf;
Holger Schurig24ced062006-11-17 22:50:15 +0100612
Oliver Neukuma8aef622010-07-15 09:21:40 -0700613 buf = kmalloc(2, GFP_NOIO);
Oliver Neukum76d057c2008-04-04 15:31:47 -0400614 if (!buf)
615 goto err_nobuf;
Holger Schurig24ced062006-11-17 22:50:15 +0100616 /* 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 Neukum76d057c2008-04-04 15:31:47 -0400623 goto err_out;
Nuno Lucas2ec6f242008-11-11 16:48:04 -0500624 if (buf[0] != 0x06) {
Oliver Neukum76d057c2008-04-04 15:31:47 -0400625 ret = -ENODEV;
626 goto err_out;
627 }
Holger Schurig24ced062006-11-17 22:50:15 +0100628
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 Neukum76d057c2008-04-04 15:31:47 -0400636 goto err_out;
Nuno Lucas2ec6f242008-11-11 16:48:04 -0500637 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
Oliver Neukum76d057c2008-04-04 15:31:47 -0400638 ret = -ENODEV;
639 goto err_out;
640 }
Holger Schurig24ced062006-11-17 22:50:15 +0100641
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 Neukum76d057c2008-04-04 15:31:47 -0400647err_out:
648 kfree(buf);
649err_nobuf:
650 return ret;
Holger Schurig24ced062006-11-17 22:50:15 +0100651}
652
653
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100654static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Holger Schurig24ced062006-11-17 22:50:15 +0100655{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100656 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
657 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
658 dev->touch = pkt[0] & 0x01;
Holger Schurig24ced062006-11-17 22:50:15 +0100659
660 return 1;
661}
662#endif
663
664
665/*****************************************************************************
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400666 * IRTOUCH Part
667 */
668#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
669static 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 Å tetiardbe14202009-11-29 23:37:07 -0800679/*****************************************************************************
Petr Å tetiar38771bb2010-06-28 09:38:48 -0700680 * ET&T TC5UH/TC4UM part
Petr Å tetiardbe14202009-11-29 23:37:07 -0800681 */
Petr Å tetiar38771bb2010-06-28 09:38:48 -0700682#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
683static int tc45usb_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Petr Å tetiardbe14202009-11-29 23:37:07 -0800684{
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 Zarydf561fc2007-07-03 01:55:03 -0400692
693/*****************************************************************************
Ondrej Zarya14a8402007-09-04 23:45:01 -0400694 * IdealTEK URTC1000 Part
695 */
696#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
Daniel Ritz62aa3662008-01-17 12:01:18 -0500697#ifndef MULTI_PACKET
698#define MULTI_PACKET
699#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400700static 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
709static 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 Frolov9d5657d2007-10-12 14:19:40 -0400732/*****************************************************************************
733 * General Touch Part
734 */
735#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
736static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
737{
Roy Yineb083ba2010-02-21 22:52:49 -0800738 dev->x = (pkt[2] << 8) | pkt[1];
739 dev->y = (pkt[4] << 8) | pkt[3];
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400740 dev->press = pkt[5] & 0xff;
741 dev->touch = pkt[0] & 0x01;
742
743 return 1;
744}
745#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400746
747/*****************************************************************************
Jerrold Jones14e40202007-10-22 00:59:47 -0400748 * GoTop Part
749 */
750#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
751static 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 Perssonf7370692009-07-07 22:07:59 -0700756
757 return 1;
758}
759#endif
760
761/*****************************************************************************
762 * JASTEC Part
763 */
764#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
765static 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 Jones14e40202007-10-22 00:59:47 -0400771 return 1;
772}
773#endif
774
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800775/*****************************************************************************
776 * Zytronic Part
777 */
778#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
779static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
780{
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -0700781 struct usb_interface *intf = dev->interface;
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -0700782
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800783 switch (pkt[0]) {
784 case 0x3A: /* command response */
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -0700785 dev_dbg(&intf->dev, "%s: Command response %d\n", __func__, pkt[1]);
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800786 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-Hartman0a5ebc82012-05-04 15:33:16 -0700792 dev_dbg(&intf->dev, "%s: down %d,%d\n", __func__, dev->x, dev->y);
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800793 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-Hartman0a5ebc82012-05-04 15:33:16 -0700799 dev_dbg(&intf->dev, "%s: up %d,%d\n", __func__, dev->x, dev->y);
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800800 return 1;
801
802 default:
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -0700803 dev_dbg(&intf->dev, "%s: Unknown return %d\n", __func__, pkt[0]);
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800804 break;
805 }
806
807 return 0;
808}
809#endif
Jerrold Jones14e40202007-10-22 00:59:47 -0400810
811/*****************************************************************************
Ondrej Zary51974242010-02-04 00:17:18 -0800812 * 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
820struct nexio_priv {
821 struct urb *ack;
822 unsigned char *ack_buf;
823};
824
825struct 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
833static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 };
834static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f };
835
836static void nexio_ack_complete(struct urb *urb)
837{
838}
839
Oliver Neukuma8aef622010-07-15 09:21:40 -0700840static 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-Hartman0a5ebc82012-05-04 15:33:16 -0700858 dev_dbg(&usbtouch->interface->dev,
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -0700859 "%s - usb_alloc_urb failed: usbtouch->ack\n", __func__);
Oliver Neukuma8aef622010-07-15 09:21:40 -0700860 goto err_ack_buf;
861 }
862
863 return 0;
864
865err_ack_buf:
866 kfree(priv->ack_buf);
867err_priv:
868 kfree(priv);
869out_buf:
870 return ret;
871}
872
Ondrej Zary51974242010-02-04 00:17:18 -0800873static 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 Neukuma8aef622010-07-15 09:21:40 -0700877 struct nexio_priv *priv = usbtouch->priv;
Ondrej Zary51974242010-02-04 00:17:18 -0800878 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 Neukuma8aef622010-07-15 09:21:40 -0700896 buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
Ondrej Zary51974242010-02-04 00:17:18 -0800897 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 Neukuma8aef622010-07-15 09:21:40 -0700928 firmware_ver = kstrdup(&buf[2], GFP_NOIO);
Ondrej Zary51974242010-02-04 00:17:18 -0800929 break;
930 case 0x84: /* device name */
931 if (!device_name)
Oliver Neukuma8aef622010-07-15 09:21:40 -0700932 device_name = kstrdup(&buf[2], GFP_NOIO);
Ondrej Zary51974242010-02-04 00:17:18 -0800933 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 Zary51974242010-02-04 00:17:18 -0800943 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 Zary51974242010-02-04 00:17:18 -0800947
Ondrej Zary51974242010-02-04 00:17:18 -0800948out_buf:
949 kfree(buf);
950 return ret;
951}
952
953static 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
963static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
964{
Ondrej Zary51974242010-02-04 00:17:18 -0800965 struct nexio_touch_packet *packet = (void *) pkt;
966 struct nexio_priv *priv = usbtouch->priv;
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700967 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 Zary51974242010-02-04 00:17:18 -0800971
972 /* got touch data? */
973 if ((pkt[0] & 0xe0) != 0xe0)
974 return 0;
975
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700976 if (data_len > 0xff)
977 data_len -= 0x100;
978 if (x_len > 0xff)
979 x_len -= 0x80;
Ondrej Zary388bbca2010-05-26 23:30:54 -0700980
Ondrej Zary51974242010-02-04 00:17:18 -0800981 /* send ACK */
982 ret = usb_submit_urb(priv->ack, GFP_ATOMIC);
983
984 if (!usbtouch->type->max_xc) {
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700985 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 Zary51974242010-02-04 00:17:18 -0800991 }
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 Torokhov4aa5bbe2010-06-08 01:01:46 -07001000 for (x = 0; x < x_len; x++) {
Ondrej Zary51974242010-02-04 00:17:18 -08001001 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 Torokhov4aa5bbe2010-06-08 01:01:46 -07001007 for (y = x_len; y < data_len; y++) {
Ondrej Zary51974242010-02-04 00:17:18 -08001008 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -07001009 begin_y = y - x_len;
Ondrej Zary51974242010-02-04 00:17:18 -08001010 continue;
1011 }
1012 if (end_y == -1 &&
1013 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -07001014 end_y = y - 1 - x_len;
Ondrej Zary51974242010-02-04 00:17:18 -08001015 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 Gebetsroitherd2cc817a2011-11-04 23:56:05 -07001049 * ELO part
1050 */
1051
1052#ifdef CONFIG_TOUCHSCREEN_USB_ELO
1053
1054static 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 Ritz1d3e2022006-03-29 22:41:07 +02001067 * the different device descriptors
1068 */
Daniel Ritz62aa3662008-01-17 12:01:18 -05001069#ifdef MULTI_PACKET
1070static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
1071 unsigned char *pkt, int len);
1072#endif
1073
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001074static struct usbtouch_device_info usbtouch_dev_info[] = {
Michael Gebetsroitherd2cc817a2011-11-04 23:56:05 -07001075#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 Zaryc6f8d702007-06-12 00:33:13 -04001087#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001088 [DEVTYPE_EGALAX] = {
1089 .min_xc = 0x0,
1090 .max_xc = 0x07ff,
1091 .min_yc = 0x0,
1092 .max_yc = 0x07ff,
1093 .rept_size = 16,
Daniel Ritz5d892662006-07-31 21:43:24 +02001094 .process_pkt = usbtouch_process_multi,
1095 .get_pkt_len = egalax_get_pkt_len,
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001096 .read_data = egalax_read_data,
Forest Bond037a8332012-09-04 20:27:37 -07001097 .init = egalax_init,
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001098 },
1099#endif
1100
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001101#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001102 [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 Zaryc6f8d702007-06-12 00:33:13 -04001112#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001113 [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 Zaryc6f8d702007-06-12 00:33:13 -04001124#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001125 [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 Ritz5d892662006-07-31 21:43:24 +02001135
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001136#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz5d892662006-07-31 21:43:24 +02001137 [DEVTYPE_ETURBO] = {
1138 .min_xc = 0x0,
1139 .max_xc = 0x07ff,
1140 .min_yc = 0x0,
1141 .max_yc = 0x07ff,
1142 .rept_size = 8,
Daniel Ritz5d892662006-07-31 21:43:24 +02001143 .process_pkt = usbtouch_process_multi,
1144 .get_pkt_len = eturbo_get_pkt_len,
1145 .read_data = eturbo_read_data,
1146 },
1147#endif
1148
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001149#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritz5d892662006-07-31 21:43:24 +02001150 [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 Schurig24ced062006-11-17 22:50:15 +01001159
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001160#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +01001161 [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 Zarydf561fc2007-07-03 01:55:03 -04001171
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 Zarya14a8402007-09-04 23:45:01 -04001182
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 Zarya14a8402007-09-04 23:45:01 -04001190 .process_pkt = usbtouch_process_multi,
1191 .get_pkt_len = idealtek_get_pkt_len,
1192 .read_data = idealtek_read_data,
1193 },
1194#endif
Ilya Frolov9d5657d2007-10-12 14:19:40 -04001195
1196#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1197 [DEVTYPE_GENERAL_TOUCH] = {
1198 .min_xc = 0x0,
Roy Yineb083ba2010-02-21 22:52:49 -08001199 .max_xc = 0x7fff,
Ilya Frolov9d5657d2007-10-12 14:19:40 -04001200 .min_yc = 0x0,
Roy Yineb083ba2010-02-21 22:52:49 -08001201 .max_yc = 0x7fff,
Ilya Frolov9d5657d2007-10-12 14:19:40 -04001202 .rept_size = 7,
1203 .read_data = general_touch_read_data,
Jerrold Jones14e40202007-10-22 00:59:47 -04001204 },
Ilya Frolov9d5657d2007-10-12 14:19:40 -04001205#endif
1206
Jerrold Jones14e40202007-10-22 00:59:47 -04001207#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 Perssonf7370692009-07-07 22:07:59 -07001217
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 Echtler9e3b2582009-07-27 17:35:39 -07001228
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 Silverstone2330ed12009-11-23 08:38:16 -08001240
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 Å tetiardbe14202009-11-29 23:37:07 -08001252
Petr Å tetiar38771bb2010-06-28 09:38:48 -07001253#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1254 [DEVTYPE_TC45USB] = {
Petr Å tetiardbe14202009-11-29 23:37:07 -08001255 .min_xc = 0x0,
1256 .max_xc = 0x0fff,
1257 .min_yc = 0x0,
1258 .max_yc = 0x0fff,
1259 .rept_size = 5,
Petr Å tetiar38771bb2010-06-28 09:38:48 -07001260 .read_data = tc45usb_read_data,
Petr Å tetiardbe14202009-11-29 23:37:07 -08001261 },
1262#endif
Ondrej Zary51974242010-02-04 00:17:18 -08001263
1264#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1265 [DEVTYPE_NEXIO] = {
Ondrej Zary388bbca2010-05-26 23:30:54 -07001266 .rept_size = 1024,
Ondrej Zary51974242010-02-04 00:17:18 -08001267 .irq_always = true,
1268 .read_data = nexio_read_data,
Oliver Neukuma8aef622010-07-15 09:21:40 -07001269 .alloc = nexio_alloc,
Ondrej Zary51974242010-02-04 00:17:18 -08001270 .init = nexio_init,
1271 .exit = nexio_exit,
1272 },
1273#endif
Armando Viscontiaa875122012-03-04 10:41:36 -08001274#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 Ritz1d3e2022006-03-29 22:41:07 +02001286};
1287
1288
1289/*****************************************************************************
1290 * Generic Part
1291 */
1292static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
David Howells7d12e782006-10-05 14:55:46 +01001293 unsigned char *pkt, int len)
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001294{
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001295 struct usbtouch_device_info *type = usbtouch->type;
1296
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001297 if (!type->read_data(usbtouch, pkt))
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001298 return;
1299
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001300 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001301
1302 if (swap_xy) {
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001303 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
1304 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001305 } else {
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001306 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
1307 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001308 }
1309 if (type->max_press)
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001310 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001311 input_sync(usbtouch->input);
1312}
1313
1314
Daniel Ritz5d892662006-07-31 21:43:24 +02001315#ifdef MULTI_PACKET
1316static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
Daniel Ritz5d892662006-07-31 21:43:24 +02001317 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 Howells7d12e782006-10-05 14:55:46 +01001353 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
Daniel Ritz5d892662006-07-31 21:43:24 +02001354
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 Ritz62aa3662008-01-17 12:01:18 -05001366 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
1367 buf_len - pos);
Daniel Ritz5d892662006-07-31 21:43:24 +02001368
Daniel Ritz62aa3662008-01-17 12:01:18 -05001369 /* unknown packet: skip one byte */
1370 if (unlikely(!pkt_len)) {
1371 pos++;
1372 continue;
1373 }
Daniel Ritz5d892662006-07-31 21:43:24 +02001374
1375 /* full packet: process */
1376 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
David Howells7d12e782006-10-05 14:55:46 +01001377 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
Daniel Ritz5d892662006-07-31 21:43:24 +02001378 } 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
1387out_flush_buf:
1388 usbtouch->buf_len = 0;
1389 return;
1390}
1391#endif
1392
1393
David Howells7d12e782006-10-05 14:55:46 +01001394static void usbtouch_irq(struct urb *urb)
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001395{
1396 struct usbtouch_usb *usbtouch = urb->context;
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -07001397 struct device *dev = &usbtouch->interface->dev;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001398 int retval;
1399
1400 switch (urb->status) {
1401 case 0:
1402 /* success */
1403 break;
Pete Zaitcev38e2bfc2006-09-18 22:49:02 -07001404 case -ETIME:
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001405 /* this urb is timing out */
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -07001406 dev_dbg(dev,
1407 "%s - urb timed out - was the device unplugged?\n",
1408 __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001409 return;
1410 case -ECONNRESET:
1411 case -ENOENT:
1412 case -ESHUTDOWN:
Ondrej Zary51974242010-02-04 00:17:18 -08001413 case -EPIPE:
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001414 /* this urb is terminated, clean up */
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -07001415 dev_dbg(dev, "%s - urb shutting down with status: %d\n",
1416 __func__, urb->status);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001417 return;
1418 default:
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -07001419 dev_dbg(dev, "%s - nonzero urb status received: %d\n",
1420 __func__, urb->status);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001421 goto exit;
1422 }
1423
David Howells7d12e782006-10-05 14:55:46 +01001424 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001425
1426exit:
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001427 usb_mark_last_busy(interface_to_usbdev(usbtouch->interface));
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001428 retval = usb_submit_urb(urb, GFP_ATOMIC);
1429 if (retval)
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -07001430 dev_err(dev, "%s - usb_submit_urb failed with result: %d\n",
Greg Kroah-Hartmane27ad0f2012-04-25 14:48:46 -07001431 __func__, retval);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001432}
1433
1434static int usbtouch_open(struct input_dev *input)
1435{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001436 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001437 int r;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001438
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001439 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001440
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001441 r = usb_autopm_get_interface(usbtouch->interface) ? -EIO : 0;
1442 if (r < 0)
1443 goto out;
1444
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001445 if (!usbtouch->type->irq_always) {
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001446 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) {
1447 r = -EIO;
1448 goto out_put;
1449 }
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001450 }
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001451
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001452 usbtouch->interface->needs_remote_wakeup = 1;
1453out_put:
1454 usb_autopm_put_interface(usbtouch->interface);
1455out:
1456 return r;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001457}
1458
1459static void usbtouch_close(struct input_dev *input)
1460{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001461 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001462 int r;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001463
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001464 if (!usbtouch->type->irq_always)
1465 usb_kill_urb(usbtouch->irq);
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001466 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 Ritz1d3e2022006-03-29 22:41:07 +02001470}
1471
Oliver Neukumed4299e2010-07-15 09:16:39 -07001472static 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
1482static 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 Ritz1d3e2022006-03-29 22:41:07 +02001495
Oliver Neukuma8aef622010-07-15 09:21:40 -07001496static 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-Hartman0a5ebc82012-05-04 15:33:16 -07001506 dev_dbg(&intf->dev,
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -07001507 "%s - type->init() failed, err: %d\n",
1508 __func__, err);
Oliver Neukuma8aef622010-07-15 09:21:40 -07001509 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 Ritz1d3e2022006-03-29 22:41:07 +02001522static void usbtouch_free_buffers(struct usb_device *udev,
1523 struct usbtouch_usb *usbtouch)
1524{
Christian Engelmayer4ef38352013-11-26 18:16:17 -08001525 usb_free_coherent(udev, usbtouch->data_size,
Daniel Mack997ea582010-04-12 13:17:25 +02001526 usbtouch->data, usbtouch->data_dma);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001527 kfree(usbtouch->buffer);
1528}
1529
Ondrej Zaryf4a5e352010-02-03 23:54:59 -08001530static struct usb_endpoint_descriptor *
1531usbtouch_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 Ritz1d3e2022006-03-29 22:41:07 +02001541
1542static 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 Ritz1d3e2022006-03-29 22:41:07 +02001547 struct usb_endpoint_descriptor *endpoint;
1548 struct usb_device *udev = interface_to_usbdev(intf);
1549 struct usbtouch_device_info *type;
Daniel Ritz5d892662006-07-31 21:43:24 +02001550 int err = -ENOMEM;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001551
Daniel Ritzec42d442008-07-03 10:45:37 -04001552 /* some devices are ignored */
1553 if (id->driver_info == DEVTYPE_IGNORE)
1554 return -ENODEV;
1555
Ondrej Zaryf4a5e352010-02-03 23:54:59 -08001556 endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
1557 if (!endpoint)
1558 return -ENXIO;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001559
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 Engelmayer4ef38352013-11-26 18:16:17 -08001570 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 Mack997ea582010-04-12 13:17:25 +02001584 GFP_KERNEL, &usbtouch->data_dma);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001585 if (!usbtouch->data)
1586 goto out_free;
1587
Daniel Ritz62aa3662008-01-17 12:01:18 -05001588 if (type->get_pkt_len) {
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001589 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-Hartmanb741ab92012-05-01 21:33:23 -07001596 dev_dbg(&intf->dev,
1597 "%s - usb_alloc_urb failed: usbtouch->irq\n", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001598 goto out_free_buffers;
1599 }
1600
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001601 usbtouch->interface = intf;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001602 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 Shebordaev7b6dff92007-09-06 21:32:16 -04001620 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001621
1622 input_dev->name = usbtouch->name;
1623 input_dev->phys = usbtouch->phys;
1624 usb_to_input_id(udev, &input_dev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -04001625 input_dev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001626
1627 input_set_drvdata(input_dev, usbtouch);
1628
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001629 input_dev->open = usbtouch_open;
1630 input_dev->close = usbtouch_close;
1631
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001632 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 Ritz1d3e2022006-03-29 22:41:07 +02001634 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 Zary51974242010-02-04 00:17:18 -08001640 if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT)
1641 usb_fill_int_urb(usbtouch->irq, udev,
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001642 usb_rcvintpipe(udev, endpoint->bEndpointAddress),
Christian Engelmayer4ef38352013-11-26 18:16:17 -08001643 usbtouch->data, usbtouch->data_size,
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001644 usbtouch_irq, usbtouch, endpoint->bInterval);
Ondrej Zary51974242010-02-04 00:17:18 -08001645 else
1646 usb_fill_bulk_urb(usbtouch->irq, udev,
1647 usb_rcvbulkpipe(udev, endpoint->bEndpointAddress),
Christian Engelmayer4ef38352013-11-26 18:16:17 -08001648 usbtouch->data, usbtouch->data_size,
Ondrej Zary51974242010-02-04 00:17:18 -08001649 usbtouch_irq, usbtouch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001650
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001651 usbtouch->irq->dev = udev;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001652 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1653 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1654
Oliver Neukuma8aef622010-07-15 09:21:40 -07001655 /* device specific allocations */
1656 if (type->alloc) {
1657 err = type->alloc(usbtouch);
1658 if (err) {
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -07001659 dev_dbg(&intf->dev,
1660 "%s - type->alloc() failed, err: %d\n",
1661 __func__, err);
Oliver Neukuma8aef622010-07-15 09:21:40 -07001662 goto out_free_urb;
1663 }
1664 }
1665
1666 /* device specific initialisation*/
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001667 if (type->init) {
1668 err = type->init(usbtouch);
1669 if (err) {
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -07001670 dev_dbg(&intf->dev,
1671 "%s - type->init() failed, err: %d\n",
1672 __func__, err);
Oliver Neukuma8aef622010-07-15 09:21:40 -07001673 goto out_do_exit;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001674 }
1675 }
1676
1677 err = input_register_device(usbtouch->input);
1678 if (err) {
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -07001679 dev_dbg(&intf->dev,
1680 "%s - input_register_device failed, err: %d\n",
1681 __func__, err);
Ondrej Zary51974242010-02-04 00:17:18 -08001682 goto out_do_exit;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001683 }
1684
1685 usb_set_intfdata(intf, usbtouch);
1686
Ondrej Zary1e87a432010-02-04 00:20:35 -08001687 if (usbtouch->type->irq_always) {
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001688 /* this can't fail */
1689 usb_autopm_get_interface(intf);
Ondrej Zary1e87a432010-02-04 00:20:35 -08001690 err = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1691 if (err) {
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001692 usb_autopm_put_interface(intf);
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -07001693 dev_err(&intf->dev,
Greg Kroah-Hartmane27ad0f2012-04-25 14:48:46 -07001694 "%s - usb_submit_urb failed with result: %d\n",
1695 __func__, err);
Ondrej Zary1e87a432010-02-04 00:20:35 -08001696 goto out_unregister_input;
1697 }
1698 }
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001699
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001700 return 0;
1701
Ondrej Zary1e87a432010-02-04 00:20:35 -08001702out_unregister_input:
1703 input_unregister_device(input_dev);
1704 input_dev = NULL;
Ondrej Zary51974242010-02-04 00:17:18 -08001705out_do_exit:
1706 if (type->exit)
1707 type->exit(usbtouch);
Ondrej Zary1e87a432010-02-04 00:20:35 -08001708out_free_urb:
1709 usb_free_urb(usbtouch->irq);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001710out_free_buffers:
1711 usbtouch_free_buffers(udev, usbtouch);
1712out_free:
1713 input_free_device(input_dev);
1714 kfree(usbtouch);
Daniel Ritz5d892662006-07-31 21:43:24 +02001715 return err;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001716}
1717
1718static void usbtouch_disconnect(struct usb_interface *intf)
1719{
1720 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1721
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001722 if (!usbtouch)
1723 return;
1724
Greg Kroah-Hartman0a5ebc82012-05-04 15:33:16 -07001725 dev_dbg(&intf->dev,
Greg Kroah-Hartmanb741ab92012-05-01 21:33:23 -07001726 "%s - usbtouch is initialized, cleaning up\n", __func__);
1727
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001728 usb_set_intfdata(intf, NULL);
Oliver Neukum722232bc2009-11-23 08:10:50 -08001729 /* this will stop IO via close */
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001730 input_unregister_device(usbtouch->input);
1731 usb_free_urb(usbtouch->irq);
Ondrej Zary51974242010-02-04 00:17:18 -08001732 if (usbtouch->type->exit)
1733 usbtouch->type->exit(usbtouch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001734 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1735 kfree(usbtouch);
1736}
1737
1738MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1739
1740static struct usb_driver usbtouch_driver = {
1741 .name = "usbtouchscreen",
1742 .probe = usbtouch_probe,
1743 .disconnect = usbtouch_disconnect,
Oliver Neukumed4299e2010-07-15 09:16:39 -07001744 .suspend = usbtouch_suspend,
1745 .resume = usbtouch_resume,
Oliver Neukuma8aef622010-07-15 09:21:40 -07001746 .reset_resume = usbtouch_reset_resume,
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001747 .id_table = usbtouch_devices,
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001748 .supports_autosuspend = 1,
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001749};
1750
Greg Kroah-Hartman08642e72011-11-18 09:48:31 -08001751module_usb_driver(usbtouch_driver);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001752
1753MODULE_AUTHOR(DRIVER_AUTHOR);
1754MODULE_DESCRIPTION(DRIVER_DESC);
1755MODULE_LICENSE("GPL");
1756
1757MODULE_ALIAS("touchkitusb");
1758MODULE_ALIAS("itmtouch");
1759MODULE_ALIAS("mtouchusb");