blob: 22cd96f58c99b33451f2cc99757fb561ab738232 [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;
109 unsigned char *buffer;
110 int buf_len;
111 struct urb *irq;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800112 struct usb_interface *interface;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200113 struct input_dev *input;
114 struct usbtouch_device_info *type;
115 char name[128];
116 char phys[64];
Ondrej Zary51974242010-02-04 00:17:18 -0800117 void *priv;
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100118
119 int x, y;
120 int touch, press;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200121};
122
Daniel Ritz5d892662006-07-31 21:43:24 +0200123
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200124/* device types */
125enum {
Daniel Ritzec42d442008-07-03 10:45:37 -0400126 DEVTYPE_IGNORE = -1,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200127 DEVTYPE_EGALAX,
128 DEVTYPE_PANJIT,
129 DEVTYPE_3M,
130 DEVTYPE_ITM,
Daniel Ritz5d892662006-07-31 21:43:24 +0200131 DEVTYPE_ETURBO,
132 DEVTYPE_GUNZE,
Holger Schurig24ced062006-11-17 22:50:15 +0100133 DEVTYPE_DMC_TSC10,
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400134 DEVTYPE_IRTOUCH,
Ondrej Zarya14a8402007-09-04 23:45:01 -0400135 DEVTYPE_IDEALTEK,
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400136 DEVTYPE_GENERAL_TOUCH,
Jerrold Jones14e40202007-10-22 00:59:47 -0400137 DEVTYPE_GOTOP,
Jim Perssonf7370692009-07-07 22:07:59 -0700138 DEVTYPE_JASTEC,
Florian Echtler9e3b2582009-07-27 17:35:39 -0700139 DEVTYPE_E2I,
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800140 DEVTYPE_ZYTRONIC,
Petr Å tetiar38771bb2010-06-28 09:38:48 -0700141 DEVTYPE_TC45USB,
Ondrej Zary51974242010-02-04 00:17:18 -0800142 DEVTYPE_NEXIO,
Michael Gebetsroitherd2cc817a2011-11-04 23:56:05 -0700143 DEVTYPE_ELO,
Armando Viscontiaa875122012-03-04 10:41:36 -0800144 DEVTYPE_ETOUCH,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200145};
146
Daniel Ritzec42d442008-07-03 10:45:37 -0400147#define USB_DEVICE_HID_CLASS(vend, prod) \
148 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
Daniel Ritz139ebe82009-02-28 12:50:54 -0800149 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
Daniel Ritzec42d442008-07-03 10:45:37 -0400150 | USB_DEVICE_ID_MATCH_DEVICE, \
151 .idVendor = (vend), \
152 .idProduct = (prod), \
153 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
154 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
155
Márton Németh9cb3ce52010-01-10 23:59:05 -0800156static const struct usb_device_id usbtouch_devices[] = {
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400157#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritzec42d442008-07-03 10:45:37 -0400158 /* ignore the HID capable devices, handled by usbhid */
159 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
160 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
161
162 /* normal device IDs */
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200163 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz5d892662006-07-31 21:43:24 +0200164 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200165 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
166 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
167 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz5d892662006-07-31 21:43:24 +0200168 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
169 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200170#endif
171
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400172#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200173 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
174 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
175 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
176 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
177#endif
178
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400179#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200180 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
181#endif
182
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400183#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200184 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
Glenn Sommer09910502010-11-22 12:00:05 -0800185 {USB_DEVICE(0x16e3, 0xf9e9), .driver_info = DEVTYPE_ITM},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200186#endif
187
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400188#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz5d892662006-07-31 21:43:24 +0200189 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
190#endif
191
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400192#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritz5d892662006-07-31 21:43:24 +0200193 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
194#endif
195
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400196#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100197 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
198#endif
199
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400200#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
201 {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
202 {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
203#endif
204
Ondrej Zarya14a8402007-09-04 23:45:01 -0400205#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
206 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
207#endif
208
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400209#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
210 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
211#endif
212
Jerrold Jones14e40202007-10-22 00:59:47 -0400213#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
214 {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP},
215 {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP},
216 {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP},
217#endif
218
Jim Perssonf7370692009-07-07 22:07:59 -0700219#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
220 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
221#endif
222
Florian Echtler9e3b2582009-07-27 17:35:39 -0700223#ifdef CONFIG_TOUCHSCREEN_USB_E2I
224 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
225#endif
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800226
227#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
228 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
229#endif
230
Petr Å tetiar38771bb2010-06-28 09:38:48 -0700231#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
232 /* TC5UH */
233 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC45USB},
234 /* TC4UM */
235 {USB_DEVICE(0x0664, 0x0306), .driver_info = DEVTYPE_TC45USB},
Petr Å tetiardbe14202009-11-29 23:37:07 -0800236#endif
237
Ondrej Zary51974242010-02-04 00:17:18 -0800238#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
239 /* data interface only */
240 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
241 .driver_info = DEVTYPE_NEXIO},
242 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
243 .driver_info = DEVTYPE_NEXIO},
244#endif
245
Michael Gebetsroitherd2cc817a2011-11-04 23:56:05 -0700246#ifdef CONFIG_TOUCHSCREEN_USB_ELO
247 {USB_DEVICE(0x04e7, 0x0020), .driver_info = DEVTYPE_ELO},
248#endif
249
Armando Viscontiaa875122012-03-04 10:41:36 -0800250#ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
251 {USB_DEVICE(0x7374, 0x0001), .driver_info = DEVTYPE_ETOUCH},
252#endif
253
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200254 {}
255};
256
257
258/*****************************************************************************
Florian Echtler9e3b2582009-07-27 17:35:39 -0700259 * e2i Part
260 */
261
262#ifdef CONFIG_TOUCHSCREEN_USB_E2I
263static int e2i_init(struct usbtouch_usb *usbtouch)
264{
265 int ret;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800266 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
Florian Echtler9e3b2582009-07-27 17:35:39 -0700267
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800268 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Florian Echtler9e3b2582009-07-27 17:35:39 -0700269 0x01, 0x02, 0x0000, 0x0081,
270 NULL, 0, USB_CTRL_SET_TIMEOUT);
271
272 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
273 __func__, ret);
274 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
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100306static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200307{
308 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
309 return 0;
310
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100311 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
312 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
313 dev->touch = pkt[0] & 0x01;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200314
315 return 1;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200316}
317
Daniel Ritz5d892662006-07-31 21:43:24 +0200318static int egalax_get_pkt_len(unsigned char *buf, int len)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200319{
320 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
321 case EGALAX_PKT_TYPE_REPT:
322 return 5;
323
324 case EGALAX_PKT_TYPE_DIAG:
Daniel Ritz5d892662006-07-31 21:43:24 +0200325 if (len < 2)
326 return -1;
327
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200328 return buf[1] + 2;
329 }
330
331 return 0;
332}
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200333#endif
334
Armando Viscontiaa875122012-03-04 10:41:36 -0800335/*****************************************************************************
336 * EasyTouch part
337 */
338
339#ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
340
341#ifndef MULTI_PACKET
342#define MULTI_PACKET
343#endif
344
345#define ETOUCH_PKT_TYPE_MASK 0xFE
346#define ETOUCH_PKT_TYPE_REPT 0x80
347#define ETOUCH_PKT_TYPE_REPT2 0xB0
348#define ETOUCH_PKT_TYPE_DIAG 0x0A
349
350static int etouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
351{
352 if ((pkt[0] & ETOUCH_PKT_TYPE_MASK) != ETOUCH_PKT_TYPE_REPT &&
353 (pkt[0] & ETOUCH_PKT_TYPE_MASK) != ETOUCH_PKT_TYPE_REPT2)
354 return 0;
355
356 dev->x = ((pkt[1] & 0x1F) << 7) | (pkt[2] & 0x7F);
357 dev->y = ((pkt[3] & 0x1F) << 7) | (pkt[4] & 0x7F);
358 dev->touch = pkt[0] & 0x01;
359
360 return 1;
361}
362
363static int etouch_get_pkt_len(unsigned char *buf, int len)
364{
365 switch (buf[0] & ETOUCH_PKT_TYPE_MASK) {
366 case ETOUCH_PKT_TYPE_REPT:
367 case ETOUCH_PKT_TYPE_REPT2:
368 return 5;
369
370 case ETOUCH_PKT_TYPE_DIAG:
371 if (len < 2)
372 return -1;
373
374 return buf[1] + 2;
375 }
376
377 return 0;
378}
379#endif
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200380
381/*****************************************************************************
382 * PanJit Part
383 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400384#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100385static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200386{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100387 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
388 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
389 dev->touch = pkt[0] & 0x01;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200390
391 return 1;
392}
393#endif
394
395
396/*****************************************************************************
397 * 3M/Microtouch Part
398 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400399#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200400
401#define MTOUCHUSB_ASYNC_REPORT 1
402#define MTOUCHUSB_RESET 7
403#define MTOUCHUSB_REQ_CTRLLR_ID 10
404
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100405static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200406{
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -0800407 if (hwcalib_xy) {
408 dev->x = (pkt[4] << 8) | pkt[3];
409 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
410 } else {
411 dev->x = (pkt[8] << 8) | pkt[7];
412 dev->y = (pkt[10] << 8) | pkt[9];
413 }
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100414 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200415
416 return 1;
417}
418
419static int mtouch_init(struct usbtouch_usb *usbtouch)
420{
Daniel Ritz5d892662006-07-31 21:43:24 +0200421 int ret, i;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800422 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200423
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800424 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200425 MTOUCHUSB_RESET,
426 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
427 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
428 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400429 __func__, ret);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200430 if (ret < 0)
431 return ret;
Daniel Ritz5d892662006-07-31 21:43:24 +0200432 msleep(150);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200433
Daniel Ritz5d892662006-07-31 21:43:24 +0200434 for (i = 0; i < 3; i++) {
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800435 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Daniel Ritz5d892662006-07-31 21:43:24 +0200436 MTOUCHUSB_ASYNC_REPORT,
437 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
438 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
439 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400440 __func__, ret);
Daniel Ritz5d892662006-07-31 21:43:24 +0200441 if (ret >= 0)
442 break;
443 if (ret != -EPIPE)
444 return ret;
445 }
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200446
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -0800447 /* Default min/max xy are the raw values, override if using hw-calib */
448 if (hwcalib_xy) {
449 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
450 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
451 }
452
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200453 return 0;
454}
455#endif
456
457
458/*****************************************************************************
459 * ITM Part
460 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400461#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100462static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200463{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100464 int touch;
465 /*
466 * ITM devices report invalid x/y data if not touched.
467 * if the screen was touched before but is not touched any more
468 * report touch as 0 with the last valid x/y data once. then stop
469 * reporting data until touched again.
470 */
471 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200472
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100473 touch = ~pkt[7] & 0x20;
474 if (!touch) {
475 if (dev->touch) {
476 dev->touch = 0;
477 return 1;
478 }
479
480 return 0;
481 }
482
483 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
484 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
485 dev->touch = touch;
486
487 return 1;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200488}
489#endif
490
491
492/*****************************************************************************
Daniel Ritz5d892662006-07-31 21:43:24 +0200493 * eTurboTouch part
494 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400495#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz62aa3662008-01-17 12:01:18 -0500496#ifndef MULTI_PACKET
497#define MULTI_PACKET
498#endif
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100499static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz5d892662006-07-31 21:43:24 +0200500{
501 unsigned int shift;
502
503 /* packets should start with sync */
504 if (!(pkt[0] & 0x80))
505 return 0;
506
507 shift = (6 - (pkt[0] & 0x03));
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100508 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
509 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
510 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
Daniel Ritz5d892662006-07-31 21:43:24 +0200511
512 return 1;
513}
514
515static int eturbo_get_pkt_len(unsigned char *buf, int len)
516{
517 if (buf[0] & 0x80)
518 return 5;
519 if (buf[0] == 0x01)
520 return 3;
521 return 0;
522}
523#endif
524
525
526/*****************************************************************************
527 * Gunze part
528 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400529#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100530static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz5d892662006-07-31 21:43:24 +0200531{
532 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
533 return 0;
534
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100535 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
536 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
537 dev->touch = pkt[0] & 0x20;
Daniel Ritz5d892662006-07-31 21:43:24 +0200538
539 return 1;
540}
541#endif
542
543/*****************************************************************************
Holger Schurig24ced062006-11-17 22:50:15 +0100544 * DMC TSC-10/25 Part
545 *
546 * Documentation about the controller and it's protocol can be found at
547 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
548 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
549 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400550#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100551
552/* supported data rates. currently using 130 */
553#define TSC10_RATE_POINT 0x50
554#define TSC10_RATE_30 0x40
555#define TSC10_RATE_50 0x41
556#define TSC10_RATE_80 0x42
557#define TSC10_RATE_100 0x43
558#define TSC10_RATE_130 0x44
559#define TSC10_RATE_150 0x45
560
561/* commands */
562#define TSC10_CMD_RESET 0x55
563#define TSC10_CMD_RATE 0x05
564#define TSC10_CMD_DATA1 0x01
565
566static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
567{
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800568 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
Oliver Neukum76d057c2008-04-04 15:31:47 -0400569 int ret = -ENOMEM;
570 unsigned char *buf;
Holger Schurig24ced062006-11-17 22:50:15 +0100571
Oliver Neukuma8aef622010-07-15 09:21:40 -0700572 buf = kmalloc(2, GFP_NOIO);
Oliver Neukum76d057c2008-04-04 15:31:47 -0400573 if (!buf)
574 goto err_nobuf;
Holger Schurig24ced062006-11-17 22:50:15 +0100575 /* reset */
576 buf[0] = buf[1] = 0xFF;
577 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
578 TSC10_CMD_RESET,
579 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
580 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
581 if (ret < 0)
Oliver Neukum76d057c2008-04-04 15:31:47 -0400582 goto err_out;
Nuno Lucas2ec6f242008-11-11 16:48:04 -0500583 if (buf[0] != 0x06) {
Oliver Neukum76d057c2008-04-04 15:31:47 -0400584 ret = -ENODEV;
585 goto err_out;
586 }
Holger Schurig24ced062006-11-17 22:50:15 +0100587
588 /* set coordinate output rate */
589 buf[0] = buf[1] = 0xFF;
590 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
591 TSC10_CMD_RATE,
592 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
593 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
594 if (ret < 0)
Oliver Neukum76d057c2008-04-04 15:31:47 -0400595 goto err_out;
Nuno Lucas2ec6f242008-11-11 16:48:04 -0500596 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
Oliver Neukum76d057c2008-04-04 15:31:47 -0400597 ret = -ENODEV;
598 goto err_out;
599 }
Holger Schurig24ced062006-11-17 22:50:15 +0100600
601 /* start sending data */
602 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
603 TSC10_CMD_DATA1,
604 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
605 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
Oliver Neukum76d057c2008-04-04 15:31:47 -0400606err_out:
607 kfree(buf);
608err_nobuf:
609 return ret;
Holger Schurig24ced062006-11-17 22:50:15 +0100610}
611
612
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100613static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Holger Schurig24ced062006-11-17 22:50:15 +0100614{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100615 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
616 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
617 dev->touch = pkt[0] & 0x01;
Holger Schurig24ced062006-11-17 22:50:15 +0100618
619 return 1;
620}
621#endif
622
623
624/*****************************************************************************
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400625 * IRTOUCH Part
626 */
627#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
628static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
629{
630 dev->x = (pkt[3] << 8) | pkt[2];
631 dev->y = (pkt[5] << 8) | pkt[4];
632 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
633
634 return 1;
635}
636#endif
637
Petr Å tetiardbe14202009-11-29 23:37:07 -0800638/*****************************************************************************
Petr Å tetiar38771bb2010-06-28 09:38:48 -0700639 * ET&T TC5UH/TC4UM part
Petr Å tetiardbe14202009-11-29 23:37:07 -0800640 */
Petr Å tetiar38771bb2010-06-28 09:38:48 -0700641#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
642static int tc45usb_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Petr Å tetiardbe14202009-11-29 23:37:07 -0800643{
644 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
645 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
646 dev->touch = pkt[0] & 0x01;
647
648 return 1;
649}
650#endif
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400651
652/*****************************************************************************
Ondrej Zarya14a8402007-09-04 23:45:01 -0400653 * IdealTEK URTC1000 Part
654 */
655#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
Daniel Ritz62aa3662008-01-17 12:01:18 -0500656#ifndef MULTI_PACKET
657#define MULTI_PACKET
658#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400659static int idealtek_get_pkt_len(unsigned char *buf, int len)
660{
661 if (buf[0] & 0x80)
662 return 5;
663 if (buf[0] == 0x01)
664 return len;
665 return 0;
666}
667
668static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
669{
670 switch (pkt[0] & 0x98) {
671 case 0x88:
672 /* touch data in IdealTEK mode */
673 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
674 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
675 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
676 return 1;
677
678 case 0x98:
679 /* touch data in MT emulation mode */
680 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
681 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
682 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
683 return 1;
684
685 default:
686 return 0;
687 }
688}
689#endif
690
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400691/*****************************************************************************
692 * General Touch Part
693 */
694#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
695static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
696{
Roy Yineb083ba2010-02-21 22:52:49 -0800697 dev->x = (pkt[2] << 8) | pkt[1];
698 dev->y = (pkt[4] << 8) | pkt[3];
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400699 dev->press = pkt[5] & 0xff;
700 dev->touch = pkt[0] & 0x01;
701
702 return 1;
703}
704#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400705
706/*****************************************************************************
Jerrold Jones14e40202007-10-22 00:59:47 -0400707 * GoTop Part
708 */
709#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
710static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
711{
712 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
713 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
714 dev->touch = pkt[0] & 0x01;
Jim Perssonf7370692009-07-07 22:07:59 -0700715
716 return 1;
717}
718#endif
719
720/*****************************************************************************
721 * JASTEC Part
722 */
723#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
724static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
725{
726 dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
727 dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
728 dev->touch = (pkt[0] & 0x40) >> 6;
729
Jerrold Jones14e40202007-10-22 00:59:47 -0400730 return 1;
731}
732#endif
733
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800734/*****************************************************************************
735 * Zytronic Part
736 */
737#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
738static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
739{
740 switch (pkt[0]) {
741 case 0x3A: /* command response */
742 dbg("%s: Command response %d", __func__, pkt[1]);
743 break;
744
745 case 0xC0: /* down */
746 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
747 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
748 dev->touch = 1;
749 dbg("%s: down %d,%d", __func__, dev->x, dev->y);
750 return 1;
751
752 case 0x80: /* up */
753 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
754 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
755 dev->touch = 0;
756 dbg("%s: up %d,%d", __func__, dev->x, dev->y);
757 return 1;
758
759 default:
760 dbg("%s: Unknown return %d", __func__, pkt[0]);
761 break;
762 }
763
764 return 0;
765}
766#endif
Jerrold Jones14e40202007-10-22 00:59:47 -0400767
768/*****************************************************************************
Ondrej Zary51974242010-02-04 00:17:18 -0800769 * NEXIO Part
770 */
771#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
772
773#define NEXIO_TIMEOUT 5000
774#define NEXIO_BUFSIZE 1024
775#define NEXIO_THRESHOLD 50
776
777struct nexio_priv {
778 struct urb *ack;
779 unsigned char *ack_buf;
780};
781
782struct nexio_touch_packet {
783 u8 flags; /* 0xe1 = touch, 0xe1 = release */
784 __be16 data_len; /* total bytes of touch data */
785 __be16 x_len; /* bytes for X axis */
786 __be16 y_len; /* bytes for Y axis */
787 u8 data[];
788} __attribute__ ((packed));
789
790static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 };
791static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f };
792
793static void nexio_ack_complete(struct urb *urb)
794{
795}
796
Oliver Neukuma8aef622010-07-15 09:21:40 -0700797static int nexio_alloc(struct usbtouch_usb *usbtouch)
798{
799 struct nexio_priv *priv;
800 int ret = -ENOMEM;
801
802 usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
803 if (!usbtouch->priv)
804 goto out_buf;
805
806 priv = usbtouch->priv;
807
808 priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt),
809 GFP_KERNEL);
810 if (!priv->ack_buf)
811 goto err_priv;
812
813 priv->ack = usb_alloc_urb(0, GFP_KERNEL);
814 if (!priv->ack) {
815 dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
816 goto err_ack_buf;
817 }
818
819 return 0;
820
821err_ack_buf:
822 kfree(priv->ack_buf);
823err_priv:
824 kfree(priv);
825out_buf:
826 return ret;
827}
828
Ondrej Zary51974242010-02-04 00:17:18 -0800829static int nexio_init(struct usbtouch_usb *usbtouch)
830{
831 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
832 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
Oliver Neukuma8aef622010-07-15 09:21:40 -0700833 struct nexio_priv *priv = usbtouch->priv;
Ondrej Zary51974242010-02-04 00:17:18 -0800834 int ret = -ENOMEM;
835 int actual_len, i;
836 unsigned char *buf;
837 char *firmware_ver = NULL, *device_name = NULL;
838 int input_ep = 0, output_ep = 0;
839
840 /* find first input and output endpoint */
841 for (i = 0; i < interface->desc.bNumEndpoints; i++) {
842 if (!input_ep &&
843 usb_endpoint_dir_in(&interface->endpoint[i].desc))
844 input_ep = interface->endpoint[i].desc.bEndpointAddress;
845 if (!output_ep &&
846 usb_endpoint_dir_out(&interface->endpoint[i].desc))
847 output_ep = interface->endpoint[i].desc.bEndpointAddress;
848 }
849 if (!input_ep || !output_ep)
850 return -ENXIO;
851
Oliver Neukuma8aef622010-07-15 09:21:40 -0700852 buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
Ondrej Zary51974242010-02-04 00:17:18 -0800853 if (!buf)
854 goto out_buf;
855
856 /* two empty reads */
857 for (i = 0; i < 2; i++) {
858 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
859 buf, NEXIO_BUFSIZE, &actual_len,
860 NEXIO_TIMEOUT);
861 if (ret < 0)
862 goto out_buf;
863 }
864
865 /* send init command */
866 memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt));
867 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep),
868 buf, sizeof(nexio_init_pkt), &actual_len,
869 NEXIO_TIMEOUT);
870 if (ret < 0)
871 goto out_buf;
872
873 /* read replies */
874 for (i = 0; i < 3; i++) {
875 memset(buf, 0, NEXIO_BUFSIZE);
876 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
877 buf, NEXIO_BUFSIZE, &actual_len,
878 NEXIO_TIMEOUT);
879 if (ret < 0 || actual_len < 1 || buf[1] != actual_len)
880 continue;
881 switch (buf[0]) {
882 case 0x83: /* firmware version */
883 if (!firmware_ver)
Oliver Neukuma8aef622010-07-15 09:21:40 -0700884 firmware_ver = kstrdup(&buf[2], GFP_NOIO);
Ondrej Zary51974242010-02-04 00:17:18 -0800885 break;
886 case 0x84: /* device name */
887 if (!device_name)
Oliver Neukuma8aef622010-07-15 09:21:40 -0700888 device_name = kstrdup(&buf[2], GFP_NOIO);
Ondrej Zary51974242010-02-04 00:17:18 -0800889 break;
890 }
891 }
892
893 printk(KERN_INFO "Nexio device: %s, firmware version: %s\n",
894 device_name, firmware_ver);
895
896 kfree(firmware_ver);
897 kfree(device_name);
898
Ondrej Zary51974242010-02-04 00:17:18 -0800899 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep),
900 priv->ack_buf, sizeof(nexio_ack_pkt),
901 nexio_ack_complete, usbtouch);
902 ret = 0;
Ondrej Zary51974242010-02-04 00:17:18 -0800903
Ondrej Zary51974242010-02-04 00:17:18 -0800904out_buf:
905 kfree(buf);
906 return ret;
907}
908
909static void nexio_exit(struct usbtouch_usb *usbtouch)
910{
911 struct nexio_priv *priv = usbtouch->priv;
912
913 usb_kill_urb(priv->ack);
914 usb_free_urb(priv->ack);
915 kfree(priv->ack_buf);
916 kfree(priv);
917}
918
919static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
920{
Ondrej Zary51974242010-02-04 00:17:18 -0800921 struct nexio_touch_packet *packet = (void *) pkt;
922 struct nexio_priv *priv = usbtouch->priv;
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700923 unsigned int data_len = be16_to_cpu(packet->data_len);
924 unsigned int x_len = be16_to_cpu(packet->x_len);
925 unsigned int y_len = be16_to_cpu(packet->y_len);
926 int x, y, begin_x, begin_y, end_x, end_y, w, h, ret;
Ondrej Zary51974242010-02-04 00:17:18 -0800927
928 /* got touch data? */
929 if ((pkt[0] & 0xe0) != 0xe0)
930 return 0;
931
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700932 if (data_len > 0xff)
933 data_len -= 0x100;
934 if (x_len > 0xff)
935 x_len -= 0x80;
Ondrej Zary388bbca2010-05-26 23:30:54 -0700936
Ondrej Zary51974242010-02-04 00:17:18 -0800937 /* send ACK */
938 ret = usb_submit_urb(priv->ack, GFP_ATOMIC);
939
940 if (!usbtouch->type->max_xc) {
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700941 usbtouch->type->max_xc = 2 * x_len;
942 input_set_abs_params(usbtouch->input, ABS_X,
943 0, usbtouch->type->max_xc, 0, 0);
944 usbtouch->type->max_yc = 2 * y_len;
945 input_set_abs_params(usbtouch->input, ABS_Y,
946 0, usbtouch->type->max_yc, 0, 0);
Ondrej Zary51974242010-02-04 00:17:18 -0800947 }
948 /*
949 * The device reports state of IR sensors on X and Y axes.
950 * Each byte represents "darkness" percentage (0-100) of one element.
951 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
952 * This also means that there's a limited multi-touch capability but
953 * it's disabled (and untested) here as there's no X driver for that.
954 */
955 begin_x = end_x = begin_y = end_y = -1;
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700956 for (x = 0; x < x_len; x++) {
Ondrej Zary51974242010-02-04 00:17:18 -0800957 if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) {
958 begin_x = x;
959 continue;
960 }
961 if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) {
962 end_x = x - 1;
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700963 for (y = x_len; y < data_len; y++) {
Ondrej Zary51974242010-02-04 00:17:18 -0800964 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700965 begin_y = y - x_len;
Ondrej Zary51974242010-02-04 00:17:18 -0800966 continue;
967 }
968 if (end_y == -1 &&
969 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
Dmitry Torokhov4aa5bbe2010-06-08 01:01:46 -0700970 end_y = y - 1 - x_len;
Ondrej Zary51974242010-02-04 00:17:18 -0800971 w = end_x - begin_x;
972 h = end_y - begin_y;
973#if 0
974 /* multi-touch */
975 input_report_abs(usbtouch->input,
976 ABS_MT_TOUCH_MAJOR, max(w,h));
977 input_report_abs(usbtouch->input,
978 ABS_MT_TOUCH_MINOR, min(x,h));
979 input_report_abs(usbtouch->input,
980 ABS_MT_POSITION_X, 2*begin_x+w);
981 input_report_abs(usbtouch->input,
982 ABS_MT_POSITION_Y, 2*begin_y+h);
983 input_report_abs(usbtouch->input,
984 ABS_MT_ORIENTATION, w > h);
985 input_mt_sync(usbtouch->input);
986#endif
987 /* single touch */
988 usbtouch->x = 2 * begin_x + w;
989 usbtouch->y = 2 * begin_y + h;
990 usbtouch->touch = packet->flags & 0x01;
991 begin_y = end_y = -1;
992 return 1;
993 }
994 }
995 begin_x = end_x = -1;
996 }
997
998 }
999 return 0;
1000}
1001#endif
1002
1003
1004/*****************************************************************************
Michael Gebetsroitherd2cc817a2011-11-04 23:56:05 -07001005 * ELO part
1006 */
1007
1008#ifdef CONFIG_TOUCHSCREEN_USB_ELO
1009
1010static int elo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1011{
1012 dev->x = (pkt[3] << 8) | pkt[2];
1013 dev->y = (pkt[5] << 8) | pkt[4];
1014 dev->touch = pkt[6] > 0;
1015 dev->press = pkt[6];
1016
1017 return 1;
1018}
1019#endif
1020
1021
1022/*****************************************************************************
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001023 * the different device descriptors
1024 */
Daniel Ritz62aa3662008-01-17 12:01:18 -05001025#ifdef MULTI_PACKET
1026static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
1027 unsigned char *pkt, int len);
1028#endif
1029
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001030static struct usbtouch_device_info usbtouch_dev_info[] = {
Michael Gebetsroitherd2cc817a2011-11-04 23:56:05 -07001031#ifdef CONFIG_TOUCHSCREEN_USB_ELO
1032 [DEVTYPE_ELO] = {
1033 .min_xc = 0x0,
1034 .max_xc = 0x0fff,
1035 .min_yc = 0x0,
1036 .max_yc = 0x0fff,
1037 .max_press = 0xff,
1038 .rept_size = 8,
1039 .read_data = elo_read_data,
1040 },
1041#endif
1042
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001043#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001044 [DEVTYPE_EGALAX] = {
1045 .min_xc = 0x0,
1046 .max_xc = 0x07ff,
1047 .min_yc = 0x0,
1048 .max_yc = 0x07ff,
1049 .rept_size = 16,
Daniel Ritz5d892662006-07-31 21:43:24 +02001050 .process_pkt = usbtouch_process_multi,
1051 .get_pkt_len = egalax_get_pkt_len,
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001052 .read_data = egalax_read_data,
1053 },
1054#endif
1055
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001056#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001057 [DEVTYPE_PANJIT] = {
1058 .min_xc = 0x0,
1059 .max_xc = 0x0fff,
1060 .min_yc = 0x0,
1061 .max_yc = 0x0fff,
1062 .rept_size = 8,
1063 .read_data = panjit_read_data,
1064 },
1065#endif
1066
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001067#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001068 [DEVTYPE_3M] = {
1069 .min_xc = 0x0,
1070 .max_xc = 0x4000,
1071 .min_yc = 0x0,
1072 .max_yc = 0x4000,
1073 .rept_size = 11,
1074 .read_data = mtouch_read_data,
1075 .init = mtouch_init,
1076 },
1077#endif
1078
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001079#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001080 [DEVTYPE_ITM] = {
1081 .min_xc = 0x0,
1082 .max_xc = 0x0fff,
1083 .min_yc = 0x0,
1084 .max_yc = 0x0fff,
1085 .max_press = 0xff,
1086 .rept_size = 8,
1087 .read_data = itm_read_data,
1088 },
1089#endif
Daniel Ritz5d892662006-07-31 21:43:24 +02001090
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001091#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz5d892662006-07-31 21:43:24 +02001092 [DEVTYPE_ETURBO] = {
1093 .min_xc = 0x0,
1094 .max_xc = 0x07ff,
1095 .min_yc = 0x0,
1096 .max_yc = 0x07ff,
1097 .rept_size = 8,
Daniel Ritz5d892662006-07-31 21:43:24 +02001098 .process_pkt = usbtouch_process_multi,
1099 .get_pkt_len = eturbo_get_pkt_len,
1100 .read_data = eturbo_read_data,
1101 },
1102#endif
1103
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001104#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritz5d892662006-07-31 21:43:24 +02001105 [DEVTYPE_GUNZE] = {
1106 .min_xc = 0x0,
1107 .max_xc = 0x0fff,
1108 .min_yc = 0x0,
1109 .max_yc = 0x0fff,
1110 .rept_size = 4,
1111 .read_data = gunze_read_data,
1112 },
1113#endif
Holger Schurig24ced062006-11-17 22:50:15 +01001114
Ondrej Zaryc6f8d702007-06-12 00:33:13 -04001115#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +01001116 [DEVTYPE_DMC_TSC10] = {
1117 .min_xc = 0x0,
1118 .max_xc = 0x03ff,
1119 .min_yc = 0x0,
1120 .max_yc = 0x03ff,
1121 .rept_size = 5,
1122 .init = dmc_tsc10_init,
1123 .read_data = dmc_tsc10_read_data,
1124 },
1125#endif
Ondrej Zarydf561fc2007-07-03 01:55:03 -04001126
1127#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
1128 [DEVTYPE_IRTOUCH] = {
1129 .min_xc = 0x0,
1130 .max_xc = 0x0fff,
1131 .min_yc = 0x0,
1132 .max_yc = 0x0fff,
1133 .rept_size = 8,
1134 .read_data = irtouch_read_data,
1135 },
1136#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -04001137
1138#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
1139 [DEVTYPE_IDEALTEK] = {
1140 .min_xc = 0x0,
1141 .max_xc = 0x0fff,
1142 .min_yc = 0x0,
1143 .max_yc = 0x0fff,
1144 .rept_size = 8,
Ondrej Zarya14a8402007-09-04 23:45:01 -04001145 .process_pkt = usbtouch_process_multi,
1146 .get_pkt_len = idealtek_get_pkt_len,
1147 .read_data = idealtek_read_data,
1148 },
1149#endif
Ilya Frolov9d5657d2007-10-12 14:19:40 -04001150
1151#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1152 [DEVTYPE_GENERAL_TOUCH] = {
1153 .min_xc = 0x0,
Roy Yineb083ba2010-02-21 22:52:49 -08001154 .max_xc = 0x7fff,
Ilya Frolov9d5657d2007-10-12 14:19:40 -04001155 .min_yc = 0x0,
Roy Yineb083ba2010-02-21 22:52:49 -08001156 .max_yc = 0x7fff,
Ilya Frolov9d5657d2007-10-12 14:19:40 -04001157 .rept_size = 7,
1158 .read_data = general_touch_read_data,
Jerrold Jones14e40202007-10-22 00:59:47 -04001159 },
Ilya Frolov9d5657d2007-10-12 14:19:40 -04001160#endif
1161
Jerrold Jones14e40202007-10-22 00:59:47 -04001162#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
1163 [DEVTYPE_GOTOP] = {
1164 .min_xc = 0x0,
1165 .max_xc = 0x03ff,
1166 .min_yc = 0x0,
1167 .max_yc = 0x03ff,
1168 .rept_size = 4,
1169 .read_data = gotop_read_data,
1170 },
1171#endif
Jim Perssonf7370692009-07-07 22:07:59 -07001172
1173#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
1174 [DEVTYPE_JASTEC] = {
1175 .min_xc = 0x0,
1176 .max_xc = 0x0fff,
1177 .min_yc = 0x0,
1178 .max_yc = 0x0fff,
1179 .rept_size = 4,
1180 .read_data = jastec_read_data,
1181 },
1182#endif
Florian Echtler9e3b2582009-07-27 17:35:39 -07001183
1184#ifdef CONFIG_TOUCHSCREEN_USB_E2I
1185 [DEVTYPE_E2I] = {
1186 .min_xc = 0x0,
1187 .max_xc = 0x7fff,
1188 .min_yc = 0x0,
1189 .max_yc = 0x7fff,
1190 .rept_size = 6,
1191 .init = e2i_init,
1192 .read_data = e2i_read_data,
1193 },
1194#endif
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001195
1196#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1197 [DEVTYPE_ZYTRONIC] = {
1198 .min_xc = 0x0,
1199 .max_xc = 0x03ff,
1200 .min_yc = 0x0,
1201 .max_yc = 0x03ff,
1202 .rept_size = 5,
1203 .read_data = zytronic_read_data,
1204 .irq_always = true,
1205 },
1206#endif
Petr Å tetiardbe14202009-11-29 23:37:07 -08001207
Petr Å tetiar38771bb2010-06-28 09:38:48 -07001208#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1209 [DEVTYPE_TC45USB] = {
Petr Å tetiardbe14202009-11-29 23:37:07 -08001210 .min_xc = 0x0,
1211 .max_xc = 0x0fff,
1212 .min_yc = 0x0,
1213 .max_yc = 0x0fff,
1214 .rept_size = 5,
Petr Å tetiar38771bb2010-06-28 09:38:48 -07001215 .read_data = tc45usb_read_data,
Petr Å tetiardbe14202009-11-29 23:37:07 -08001216 },
1217#endif
Ondrej Zary51974242010-02-04 00:17:18 -08001218
1219#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1220 [DEVTYPE_NEXIO] = {
Ondrej Zary388bbca2010-05-26 23:30:54 -07001221 .rept_size = 1024,
Ondrej Zary51974242010-02-04 00:17:18 -08001222 .irq_always = true,
1223 .read_data = nexio_read_data,
Oliver Neukuma8aef622010-07-15 09:21:40 -07001224 .alloc = nexio_alloc,
Ondrej Zary51974242010-02-04 00:17:18 -08001225 .init = nexio_init,
1226 .exit = nexio_exit,
1227 },
1228#endif
Armando Viscontiaa875122012-03-04 10:41:36 -08001229#ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
1230 [DEVTYPE_ETOUCH] = {
1231 .min_xc = 0x0,
1232 .max_xc = 0x07ff,
1233 .min_yc = 0x0,
1234 .max_yc = 0x07ff,
1235 .rept_size = 16,
1236 .process_pkt = usbtouch_process_multi,
1237 .get_pkt_len = etouch_get_pkt_len,
1238 .read_data = etouch_read_data,
1239 },
1240#endif
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001241};
1242
1243
1244/*****************************************************************************
1245 * Generic Part
1246 */
1247static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
David Howells7d12e782006-10-05 14:55:46 +01001248 unsigned char *pkt, int len)
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001249{
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001250 struct usbtouch_device_info *type = usbtouch->type;
1251
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001252 if (!type->read_data(usbtouch, pkt))
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001253 return;
1254
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001255 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001256
1257 if (swap_xy) {
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001258 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
1259 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001260 } else {
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001261 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
1262 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001263 }
1264 if (type->max_press)
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +01001265 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001266 input_sync(usbtouch->input);
1267}
1268
1269
Daniel Ritz5d892662006-07-31 21:43:24 +02001270#ifdef MULTI_PACKET
1271static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
Daniel Ritz5d892662006-07-31 21:43:24 +02001272 unsigned char *pkt, int len)
1273{
1274 unsigned char *buffer;
1275 int pkt_len, pos, buf_len, tmp;
1276
1277 /* process buffer */
1278 if (unlikely(usbtouch->buf_len)) {
1279 /* try to get size */
1280 pkt_len = usbtouch->type->get_pkt_len(
1281 usbtouch->buffer, usbtouch->buf_len);
1282
1283 /* drop? */
1284 if (unlikely(!pkt_len))
1285 goto out_flush_buf;
1286
1287 /* need to append -pkt_len bytes before able to get size */
1288 if (unlikely(pkt_len < 0)) {
1289 int append = -pkt_len;
1290 if (unlikely(append > len))
1291 append = len;
1292 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
1293 goto out_flush_buf;
1294 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
1295 usbtouch->buf_len += append;
1296
1297 pkt_len = usbtouch->type->get_pkt_len(
1298 usbtouch->buffer, usbtouch->buf_len);
1299 if (pkt_len < 0)
1300 return;
1301 }
1302
1303 /* append */
1304 tmp = pkt_len - usbtouch->buf_len;
1305 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
1306 goto out_flush_buf;
1307 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
David Howells7d12e782006-10-05 14:55:46 +01001308 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
Daniel Ritz5d892662006-07-31 21:43:24 +02001309
1310 buffer = pkt + tmp;
1311 buf_len = len - tmp;
1312 } else {
1313 buffer = pkt;
1314 buf_len = len;
1315 }
1316
1317 /* loop over the received packet, process */
1318 pos = 0;
1319 while (pos < buf_len) {
1320 /* get packet len */
Daniel Ritz62aa3662008-01-17 12:01:18 -05001321 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
1322 buf_len - pos);
Daniel Ritz5d892662006-07-31 21:43:24 +02001323
Daniel Ritz62aa3662008-01-17 12:01:18 -05001324 /* unknown packet: skip one byte */
1325 if (unlikely(!pkt_len)) {
1326 pos++;
1327 continue;
1328 }
Daniel Ritz5d892662006-07-31 21:43:24 +02001329
1330 /* full packet: process */
1331 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
David Howells7d12e782006-10-05 14:55:46 +01001332 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
Daniel Ritz5d892662006-07-31 21:43:24 +02001333 } else {
1334 /* incomplete packet: save in buffer */
1335 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
1336 usbtouch->buf_len = buf_len - pos;
1337 return;
1338 }
1339 pos += pkt_len;
1340 }
1341
1342out_flush_buf:
1343 usbtouch->buf_len = 0;
1344 return;
1345}
1346#endif
1347
1348
David Howells7d12e782006-10-05 14:55:46 +01001349static void usbtouch_irq(struct urb *urb)
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001350{
1351 struct usbtouch_usb *usbtouch = urb->context;
1352 int retval;
1353
1354 switch (urb->status) {
1355 case 0:
1356 /* success */
1357 break;
Pete Zaitcev38e2bfc2006-09-18 22:49:02 -07001358 case -ETIME:
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001359 /* this urb is timing out */
1360 dbg("%s - urb timed out - was the device unplugged?",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001361 __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001362 return;
1363 case -ECONNRESET:
1364 case -ENOENT:
1365 case -ESHUTDOWN:
Ondrej Zary51974242010-02-04 00:17:18 -08001366 case -EPIPE:
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001367 /* this urb is terminated, clean up */
1368 dbg("%s - urb shutting down with status: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001369 __func__, urb->status);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001370 return;
1371 default:
1372 dbg("%s - nonzero urb status received: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001373 __func__, urb->status);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001374 goto exit;
1375 }
1376
David Howells7d12e782006-10-05 14:55:46 +01001377 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001378
1379exit:
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001380 usb_mark_last_busy(interface_to_usbdev(usbtouch->interface));
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001381 retval = usb_submit_urb(urb, GFP_ATOMIC);
1382 if (retval)
1383 err("%s - usb_submit_urb failed with result: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001384 __func__, retval);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001385}
1386
1387static int usbtouch_open(struct input_dev *input)
1388{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001389 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001390 int r;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001391
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001392 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001393
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001394 r = usb_autopm_get_interface(usbtouch->interface) ? -EIO : 0;
1395 if (r < 0)
1396 goto out;
1397
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001398 if (!usbtouch->type->irq_always) {
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001399 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) {
1400 r = -EIO;
1401 goto out_put;
1402 }
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001403 }
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001404
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001405 usbtouch->interface->needs_remote_wakeup = 1;
1406out_put:
1407 usb_autopm_put_interface(usbtouch->interface);
1408out:
1409 return r;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001410}
1411
1412static void usbtouch_close(struct input_dev *input)
1413{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001414 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001415 int r;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001416
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001417 if (!usbtouch->type->irq_always)
1418 usb_kill_urb(usbtouch->irq);
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001419 r = usb_autopm_get_interface(usbtouch->interface);
1420 usbtouch->interface->needs_remote_wakeup = 0;
1421 if (!r)
1422 usb_autopm_put_interface(usbtouch->interface);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001423}
1424
Oliver Neukumed4299e2010-07-15 09:16:39 -07001425static int usbtouch_suspend
1426(struct usb_interface *intf, pm_message_t message)
1427{
1428 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1429
1430 usb_kill_urb(usbtouch->irq);
1431
1432 return 0;
1433}
1434
1435static int usbtouch_resume(struct usb_interface *intf)
1436{
1437 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1438 struct input_dev *input = usbtouch->input;
1439 int result = 0;
1440
1441 mutex_lock(&input->mutex);
1442 if (input->users || usbtouch->type->irq_always)
1443 result = usb_submit_urb(usbtouch->irq, GFP_NOIO);
1444 mutex_unlock(&input->mutex);
1445
1446 return result;
1447}
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001448
Oliver Neukuma8aef622010-07-15 09:21:40 -07001449static int usbtouch_reset_resume(struct usb_interface *intf)
1450{
1451 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1452 struct input_dev *input = usbtouch->input;
1453 int err = 0;
1454
1455 /* reinit the device */
1456 if (usbtouch->type->init) {
1457 err = usbtouch->type->init(usbtouch);
1458 if (err) {
1459 dbg("%s - type->init() failed, err: %d",
1460 __func__, err);
1461 return err;
1462 }
1463 }
1464
1465 /* restart IO if needed */
1466 mutex_lock(&input->mutex);
1467 if (input->users)
1468 err = usb_submit_urb(usbtouch->irq, GFP_NOIO);
1469 mutex_unlock(&input->mutex);
1470
1471 return err;
1472}
1473
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001474static void usbtouch_free_buffers(struct usb_device *udev,
1475 struct usbtouch_usb *usbtouch)
1476{
Daniel Mack997ea582010-04-12 13:17:25 +02001477 usb_free_coherent(udev, usbtouch->type->rept_size,
1478 usbtouch->data, usbtouch->data_dma);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001479 kfree(usbtouch->buffer);
1480}
1481
Ondrej Zaryf4a5e352010-02-03 23:54:59 -08001482static struct usb_endpoint_descriptor *
1483usbtouch_get_input_endpoint(struct usb_host_interface *interface)
1484{
1485 int i;
1486
1487 for (i = 0; i < interface->desc.bNumEndpoints; i++)
1488 if (usb_endpoint_dir_in(&interface->endpoint[i].desc))
1489 return &interface->endpoint[i].desc;
1490
1491 return NULL;
1492}
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001493
1494static int usbtouch_probe(struct usb_interface *intf,
1495 const struct usb_device_id *id)
1496{
1497 struct usbtouch_usb *usbtouch;
1498 struct input_dev *input_dev;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001499 struct usb_endpoint_descriptor *endpoint;
1500 struct usb_device *udev = interface_to_usbdev(intf);
1501 struct usbtouch_device_info *type;
Daniel Ritz5d892662006-07-31 21:43:24 +02001502 int err = -ENOMEM;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001503
Daniel Ritzec42d442008-07-03 10:45:37 -04001504 /* some devices are ignored */
1505 if (id->driver_info == DEVTYPE_IGNORE)
1506 return -ENODEV;
1507
Ondrej Zaryf4a5e352010-02-03 23:54:59 -08001508 endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
1509 if (!endpoint)
1510 return -ENXIO;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001511
1512 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
1513 input_dev = input_allocate_device();
1514 if (!usbtouch || !input_dev)
1515 goto out_free;
1516
1517 type = &usbtouch_dev_info[id->driver_info];
1518 usbtouch->type = type;
1519 if (!type->process_pkt)
1520 type->process_pkt = usbtouch_process_pkt;
1521
Daniel Mack997ea582010-04-12 13:17:25 +02001522 usbtouch->data = usb_alloc_coherent(udev, type->rept_size,
1523 GFP_KERNEL, &usbtouch->data_dma);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001524 if (!usbtouch->data)
1525 goto out_free;
1526
Daniel Ritz62aa3662008-01-17 12:01:18 -05001527 if (type->get_pkt_len) {
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001528 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
1529 if (!usbtouch->buffer)
1530 goto out_free_buffers;
1531 }
1532
1533 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
1534 if (!usbtouch->irq) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001535 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001536 goto out_free_buffers;
1537 }
1538
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001539 usbtouch->interface = intf;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001540 usbtouch->input = input_dev;
1541
1542 if (udev->manufacturer)
1543 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
1544
1545 if (udev->product) {
1546 if (udev->manufacturer)
1547 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
1548 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
1549 }
1550
1551 if (!strlen(usbtouch->name))
1552 snprintf(usbtouch->name, sizeof(usbtouch->name),
1553 "USB Touchscreen %04x:%04x",
1554 le16_to_cpu(udev->descriptor.idVendor),
1555 le16_to_cpu(udev->descriptor.idProduct));
1556
1557 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
Vladimir Shebordaev7b6dff92007-09-06 21:32:16 -04001558 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001559
1560 input_dev->name = usbtouch->name;
1561 input_dev->phys = usbtouch->phys;
1562 usb_to_input_id(udev, &input_dev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -04001563 input_dev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001564
1565 input_set_drvdata(input_dev, usbtouch);
1566
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001567 input_dev->open = usbtouch_open;
1568 input_dev->close = usbtouch_close;
1569
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001570 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1571 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001572 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
1573 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
1574 if (type->max_press)
1575 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1576 type->max_press, 0, 0);
1577
Ondrej Zary51974242010-02-04 00:17:18 -08001578 if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT)
1579 usb_fill_int_urb(usbtouch->irq, udev,
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001580 usb_rcvintpipe(udev, endpoint->bEndpointAddress),
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001581 usbtouch->data, type->rept_size,
1582 usbtouch_irq, usbtouch, endpoint->bInterval);
Ondrej Zary51974242010-02-04 00:17:18 -08001583 else
1584 usb_fill_bulk_urb(usbtouch->irq, udev,
1585 usb_rcvbulkpipe(udev, endpoint->bEndpointAddress),
1586 usbtouch->data, type->rept_size,
1587 usbtouch_irq, usbtouch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001588
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001589 usbtouch->irq->dev = udev;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001590 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1591 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1592
Oliver Neukuma8aef622010-07-15 09:21:40 -07001593 /* device specific allocations */
1594 if (type->alloc) {
1595 err = type->alloc(usbtouch);
1596 if (err) {
1597 dbg("%s - type->alloc() failed, err: %d", __func__, err);
1598 goto out_free_urb;
1599 }
1600 }
1601
1602 /* device specific initialisation*/
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001603 if (type->init) {
1604 err = type->init(usbtouch);
1605 if (err) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001606 dbg("%s - type->init() failed, err: %d", __func__, err);
Oliver Neukuma8aef622010-07-15 09:21:40 -07001607 goto out_do_exit;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001608 }
1609 }
1610
1611 err = input_register_device(usbtouch->input);
1612 if (err) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001613 dbg("%s - input_register_device failed, err: %d", __func__, err);
Ondrej Zary51974242010-02-04 00:17:18 -08001614 goto out_do_exit;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001615 }
1616
1617 usb_set_intfdata(intf, usbtouch);
1618
Ondrej Zary1e87a432010-02-04 00:20:35 -08001619 if (usbtouch->type->irq_always) {
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001620 /* this can't fail */
1621 usb_autopm_get_interface(intf);
Ondrej Zary1e87a432010-02-04 00:20:35 -08001622 err = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1623 if (err) {
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001624 usb_autopm_put_interface(intf);
Ondrej Zary1e87a432010-02-04 00:20:35 -08001625 err("%s - usb_submit_urb failed with result: %d",
1626 __func__, err);
1627 goto out_unregister_input;
1628 }
1629 }
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001630
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001631 return 0;
1632
Ondrej Zary1e87a432010-02-04 00:20:35 -08001633out_unregister_input:
1634 input_unregister_device(input_dev);
1635 input_dev = NULL;
Ondrej Zary51974242010-02-04 00:17:18 -08001636out_do_exit:
1637 if (type->exit)
1638 type->exit(usbtouch);
Ondrej Zary1e87a432010-02-04 00:20:35 -08001639out_free_urb:
1640 usb_free_urb(usbtouch->irq);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001641out_free_buffers:
1642 usbtouch_free_buffers(udev, usbtouch);
1643out_free:
1644 input_free_device(input_dev);
1645 kfree(usbtouch);
Daniel Ritz5d892662006-07-31 21:43:24 +02001646 return err;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001647}
1648
1649static void usbtouch_disconnect(struct usb_interface *intf)
1650{
1651 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1652
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001653 dbg("%s - called", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001654
1655 if (!usbtouch)
1656 return;
1657
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001658 dbg("%s - usbtouch is initialized, cleaning up", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001659 usb_set_intfdata(intf, NULL);
Oliver Neukum722232b2009-11-23 08:10:50 -08001660 /* this will stop IO via close */
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001661 input_unregister_device(usbtouch->input);
1662 usb_free_urb(usbtouch->irq);
Ondrej Zary51974242010-02-04 00:17:18 -08001663 if (usbtouch->type->exit)
1664 usbtouch->type->exit(usbtouch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001665 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1666 kfree(usbtouch);
1667}
1668
1669MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1670
1671static struct usb_driver usbtouch_driver = {
1672 .name = "usbtouchscreen",
1673 .probe = usbtouch_probe,
1674 .disconnect = usbtouch_disconnect,
Oliver Neukumed4299e2010-07-15 09:16:39 -07001675 .suspend = usbtouch_suspend,
1676 .resume = usbtouch_resume,
Oliver Neukuma8aef622010-07-15 09:21:40 -07001677 .reset_resume = usbtouch_reset_resume,
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001678 .id_table = usbtouch_devices,
Oliver Neukum5d9efc52010-07-15 09:19:51 -07001679 .supports_autosuspend = 1,
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001680};
1681
Greg Kroah-Hartman08642e72011-11-18 09:48:31 -08001682module_usb_driver(usbtouch_driver);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001683
1684MODULE_AUTHOR(DRIVER_AUTHOR);
1685MODULE_DESCRIPTION(DRIVER_DESC);
1686MODULE_LICENSE("GPL");
1687
1688MODULE_ALIAS("touchkitusb");
1689MODULE_ALIAS("itmtouch");
1690MODULE_ALIAS("mtouchusb");