blob: 69be77118884b04f96a542de5961c758d4ed7fb1 [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
Daniel Ritz1d3e2022006-03-29 22:41:07 +020018 *
Jerrold Jones14e40202007-10-22 00:59:47 -040019 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
Daniel Ritz1d3e2022006-03-29 22:41:07 +020020 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
21 *
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License as
24 * published by the Free Software Foundation; either version 2 of the
25 * License, or (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful, but
28 * WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *
36 * Driver is based on touchkitusb.c
37 * - ITM parts are from itmtouch.c
38 * - 3M parts are from mtouchusb.c
39 * - PanJit parts are from an unmerged driver by Lanslott Gish
Holger Schurig24ced062006-11-17 22:50:15 +010040 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
41 * driver from Marius Vollmer
Daniel Ritz1d3e2022006-03-29 22:41:07 +020042 *
43 *****************************************************************************/
44
45//#define DEBUG
46
Daniel Ritz1d3e2022006-03-29 22:41:07 +020047#include <linux/kernel.h>
48#include <linux/slab.h>
49#include <linux/input.h>
50#include <linux/module.h>
51#include <linux/init.h>
52#include <linux/usb.h>
David Brownellae0dadc2006-06-13 10:04:34 -070053#include <linux/usb/input.h>
Daniel Ritzec42d442008-07-03 10:45:37 -040054#include <linux/hid.h>
Daniel Ritz1d3e2022006-03-29 22:41:07 +020055
56
Daniel Ritz62aa3662008-01-17 12:01:18 -050057#define DRIVER_VERSION "v0.6"
Daniel Ritz1d3e2022006-03-29 22:41:07 +020058#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
59#define DRIVER_DESC "USB Touchscreen Driver"
60
61static int swap_xy;
62module_param(swap_xy, bool, 0644);
63MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
64
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -080065static int hwcalib_xy;
66module_param(hwcalib_xy, bool, 0644);
67MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
68
Daniel Ritz1d3e2022006-03-29 22:41:07 +020069/* device specifc data/functions */
70struct usbtouch_usb;
71struct usbtouch_device_info {
72 int min_xc, max_xc;
73 int min_yc, max_yc;
74 int min_press, max_press;
75 int rept_size;
Daniel Ritz1d3e2022006-03-29 22:41:07 +020076
Daniel Silverstone2330ed12009-11-23 08:38:16 -080077 /*
78 * Always service the USB devices irq not just when the input device is
79 * open. This is useful when devices have a watchdog which prevents us
80 * from periodically polling the device. Leave this unset unless your
81 * touchscreen device requires it, as it does consume more of the USB
82 * bandwidth.
83 */
84 bool irq_always;
85
David Howells7d12e782006-10-05 14:55:46 +010086 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
Daniel Ritz62aa3662008-01-17 12:01:18 -050087
88 /*
89 * used to get the packet len. possible return values:
90 * > 0: packet len
91 * = 0: skip one byte
92 * < 0: -return value more bytes needed
93 */
Daniel Ritz5d892662006-07-31 21:43:24 +020094 int (*get_pkt_len) (unsigned char *pkt, int len);
Daniel Ritz62aa3662008-01-17 12:01:18 -050095
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +010096 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
Daniel Ritz1d3e2022006-03-29 22:41:07 +020097 int (*init) (struct usbtouch_usb *usbtouch);
98};
99
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200100/* a usbtouch device */
101struct usbtouch_usb {
102 unsigned char *data;
103 dma_addr_t data_dma;
104 unsigned char *buffer;
105 int buf_len;
106 struct urb *irq;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800107 struct usb_interface *interface;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200108 struct input_dev *input;
109 struct usbtouch_device_info *type;
110 char name[128];
111 char phys[64];
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100112
113 int x, y;
114 int touch, press;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200115};
116
Daniel Ritz5d892662006-07-31 21:43:24 +0200117
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200118/* device types */
119enum {
Daniel Ritzec42d442008-07-03 10:45:37 -0400120 DEVTYPE_IGNORE = -1,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200121 DEVTYPE_EGALAX,
122 DEVTYPE_PANJIT,
123 DEVTYPE_3M,
124 DEVTYPE_ITM,
Daniel Ritz5d892662006-07-31 21:43:24 +0200125 DEVTYPE_ETURBO,
126 DEVTYPE_GUNZE,
Holger Schurig24ced062006-11-17 22:50:15 +0100127 DEVTYPE_DMC_TSC10,
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400128 DEVTYPE_IRTOUCH,
Ondrej Zarya14a8402007-09-04 23:45:01 -0400129 DEVTYPE_IDEALTEK,
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400130 DEVTYPE_GENERAL_TOUCH,
Jerrold Jones14e40202007-10-22 00:59:47 -0400131 DEVTYPE_GOTOP,
Jim Perssonf7370692009-07-07 22:07:59 -0700132 DEVTYPE_JASTEC,
Florian Echtler9e3b2582009-07-27 17:35:39 -0700133 DEVTYPE_E2I,
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800134 DEVTYPE_ZYTRONIC,
Petr Å tetiardbe14202009-11-29 23:37:07 -0800135 DEVTYPE_TC5UH,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200136};
137
Daniel Ritzec42d442008-07-03 10:45:37 -0400138#define USB_DEVICE_HID_CLASS(vend, prod) \
139 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
Daniel Ritz139ebe82009-02-28 12:50:54 -0800140 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
Daniel Ritzec42d442008-07-03 10:45:37 -0400141 | USB_DEVICE_ID_MATCH_DEVICE, \
142 .idVendor = (vend), \
143 .idProduct = (prod), \
144 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
145 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
146
Márton Németh9cb3ce52010-01-10 23:59:05 -0800147static const struct usb_device_id usbtouch_devices[] = {
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400148#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritzec42d442008-07-03 10:45:37 -0400149 /* ignore the HID capable devices, handled by usbhid */
150 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
151 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
152
153 /* normal device IDs */
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200154 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz5d892662006-07-31 21:43:24 +0200155 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200156 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
157 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
158 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz5d892662006-07-31 21:43:24 +0200159 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
160 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200161#endif
162
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400163#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200164 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
165 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
166 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
167 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
168#endif
169
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400170#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200171 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
172#endif
173
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400174#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200175 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
176#endif
177
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400178#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz5d892662006-07-31 21:43:24 +0200179 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
180#endif
181
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400182#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritz5d892662006-07-31 21:43:24 +0200183 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
184#endif
185
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400186#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100187 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
188#endif
189
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400190#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
191 {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
192 {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
193#endif
194
Ondrej Zarya14a8402007-09-04 23:45:01 -0400195#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
196 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
197#endif
198
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400199#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
200 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
201#endif
202
Jerrold Jones14e40202007-10-22 00:59:47 -0400203#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
204 {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP},
205 {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP},
206 {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP},
207#endif
208
Jim Perssonf7370692009-07-07 22:07:59 -0700209#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
210 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
211#endif
212
Florian Echtler9e3b2582009-07-27 17:35:39 -0700213#ifdef CONFIG_TOUCHSCREEN_USB_E2I
214 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
215#endif
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800216
217#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
218 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
219#endif
220
Petr Å tetiardbe14202009-11-29 23:37:07 -0800221#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
222 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH},
223#endif
224
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200225 {}
226};
227
228
229/*****************************************************************************
Florian Echtler9e3b2582009-07-27 17:35:39 -0700230 * e2i Part
231 */
232
233#ifdef CONFIG_TOUCHSCREEN_USB_E2I
234static int e2i_init(struct usbtouch_usb *usbtouch)
235{
236 int ret;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800237 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
Florian Echtler9e3b2582009-07-27 17:35:39 -0700238
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800239 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Florian Echtler9e3b2582009-07-27 17:35:39 -0700240 0x01, 0x02, 0x0000, 0x0081,
241 NULL, 0, USB_CTRL_SET_TIMEOUT);
242
243 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
244 __func__, ret);
245 return ret;
246}
247
248static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
249{
250 int tmp = (pkt[0] << 8) | pkt[1];
251 dev->x = (pkt[2] << 8) | pkt[3];
252 dev->y = (pkt[4] << 8) | pkt[5];
253
254 tmp = tmp - 0xA000;
255 dev->touch = (tmp > 0);
256 dev->press = (tmp > 0 ? tmp : 0);
257
258 return 1;
259}
260#endif
261
262
263/*****************************************************************************
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200264 * eGalax part
265 */
266
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400267#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200268
Daniel Ritz62aa3662008-01-17 12:01:18 -0500269#ifndef MULTI_PACKET
270#define MULTI_PACKET
271#endif
272
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200273#define EGALAX_PKT_TYPE_MASK 0xFE
274#define EGALAX_PKT_TYPE_REPT 0x80
275#define EGALAX_PKT_TYPE_DIAG 0x0A
276
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100277static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200278{
279 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
280 return 0;
281
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100282 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
283 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
284 dev->touch = pkt[0] & 0x01;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200285
286 return 1;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200287}
288
Daniel Ritz5d892662006-07-31 21:43:24 +0200289static int egalax_get_pkt_len(unsigned char *buf, int len)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200290{
291 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
292 case EGALAX_PKT_TYPE_REPT:
293 return 5;
294
295 case EGALAX_PKT_TYPE_DIAG:
Daniel Ritz5d892662006-07-31 21:43:24 +0200296 if (len < 2)
297 return -1;
298
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200299 return buf[1] + 2;
300 }
301
302 return 0;
303}
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200304#endif
305
306
307/*****************************************************************************
308 * PanJit Part
309 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400310#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100311static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200312{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100313 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
314 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
315 dev->touch = pkt[0] & 0x01;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200316
317 return 1;
318}
319#endif
320
321
322/*****************************************************************************
323 * 3M/Microtouch Part
324 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400325#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200326
327#define MTOUCHUSB_ASYNC_REPORT 1
328#define MTOUCHUSB_RESET 7
329#define MTOUCHUSB_REQ_CTRLLR_ID 10
330
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100331static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200332{
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -0800333 if (hwcalib_xy) {
334 dev->x = (pkt[4] << 8) | pkt[3];
335 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
336 } else {
337 dev->x = (pkt[8] << 8) | pkt[7];
338 dev->y = (pkt[10] << 8) | pkt[9];
339 }
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100340 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200341
342 return 1;
343}
344
345static int mtouch_init(struct usbtouch_usb *usbtouch)
346{
Daniel Ritz5d892662006-07-31 21:43:24 +0200347 int ret, i;
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800348 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200349
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800350 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200351 MTOUCHUSB_RESET,
352 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
353 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
354 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400355 __func__, ret);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200356 if (ret < 0)
357 return ret;
Daniel Ritz5d892662006-07-31 21:43:24 +0200358 msleep(150);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200359
Daniel Ritz5d892662006-07-31 21:43:24 +0200360 for (i = 0; i < 3; i++) {
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800361 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Daniel Ritz5d892662006-07-31 21:43:24 +0200362 MTOUCHUSB_ASYNC_REPORT,
363 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
364 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
365 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400366 __func__, ret);
Daniel Ritz5d892662006-07-31 21:43:24 +0200367 if (ret >= 0)
368 break;
369 if (ret != -EPIPE)
370 return ret;
371 }
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200372
Dan Streetmanc9cbf3d2009-01-10 23:44:22 -0800373 /* Default min/max xy are the raw values, override if using hw-calib */
374 if (hwcalib_xy) {
375 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
376 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
377 }
378
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200379 return 0;
380}
381#endif
382
383
384/*****************************************************************************
385 * ITM Part
386 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400387#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100388static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200389{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100390 int touch;
391 /*
392 * ITM devices report invalid x/y data if not touched.
393 * if the screen was touched before but is not touched any more
394 * report touch as 0 with the last valid x/y data once. then stop
395 * reporting data until touched again.
396 */
397 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200398
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100399 touch = ~pkt[7] & 0x20;
400 if (!touch) {
401 if (dev->touch) {
402 dev->touch = 0;
403 return 1;
404 }
405
406 return 0;
407 }
408
409 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
410 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
411 dev->touch = touch;
412
413 return 1;
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200414}
415#endif
416
417
418/*****************************************************************************
Daniel Ritz5d892662006-07-31 21:43:24 +0200419 * eTurboTouch part
420 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400421#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz62aa3662008-01-17 12:01:18 -0500422#ifndef MULTI_PACKET
423#define MULTI_PACKET
424#endif
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100425static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz5d892662006-07-31 21:43:24 +0200426{
427 unsigned int shift;
428
429 /* packets should start with sync */
430 if (!(pkt[0] & 0x80))
431 return 0;
432
433 shift = (6 - (pkt[0] & 0x03));
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100434 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
435 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
436 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
Daniel Ritz5d892662006-07-31 21:43:24 +0200437
438 return 1;
439}
440
441static int eturbo_get_pkt_len(unsigned char *buf, int len)
442{
443 if (buf[0] & 0x80)
444 return 5;
445 if (buf[0] == 0x01)
446 return 3;
447 return 0;
448}
449#endif
450
451
452/*****************************************************************************
453 * Gunze part
454 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400455#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100456static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Daniel Ritz5d892662006-07-31 21:43:24 +0200457{
458 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
459 return 0;
460
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100461 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
462 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
463 dev->touch = pkt[0] & 0x20;
Daniel Ritz5d892662006-07-31 21:43:24 +0200464
465 return 1;
466}
467#endif
468
469/*****************************************************************************
Holger Schurig24ced062006-11-17 22:50:15 +0100470 * DMC TSC-10/25 Part
471 *
472 * Documentation about the controller and it's protocol can be found at
473 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
474 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
475 */
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400476#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100477
478/* supported data rates. currently using 130 */
479#define TSC10_RATE_POINT 0x50
480#define TSC10_RATE_30 0x40
481#define TSC10_RATE_50 0x41
482#define TSC10_RATE_80 0x42
483#define TSC10_RATE_100 0x43
484#define TSC10_RATE_130 0x44
485#define TSC10_RATE_150 0x45
486
487/* commands */
488#define TSC10_CMD_RESET 0x55
489#define TSC10_CMD_RATE 0x05
490#define TSC10_CMD_DATA1 0x01
491
492static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
493{
Ondrej Zaryfea4d142010-02-03 23:46:48 -0800494 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
Oliver Neukum76d057c2008-04-04 15:31:47 -0400495 int ret = -ENOMEM;
496 unsigned char *buf;
Holger Schurig24ced062006-11-17 22:50:15 +0100497
Oliver Neukum76d057c2008-04-04 15:31:47 -0400498 buf = kmalloc(2, GFP_KERNEL);
499 if (!buf)
500 goto err_nobuf;
Holger Schurig24ced062006-11-17 22:50:15 +0100501 /* reset */
502 buf[0] = buf[1] = 0xFF;
503 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
504 TSC10_CMD_RESET,
505 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
506 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
507 if (ret < 0)
Oliver Neukum76d057c2008-04-04 15:31:47 -0400508 goto err_out;
Nuno Lucas2ec6f242008-11-11 16:48:04 -0500509 if (buf[0] != 0x06) {
Oliver Neukum76d057c2008-04-04 15:31:47 -0400510 ret = -ENODEV;
511 goto err_out;
512 }
Holger Schurig24ced062006-11-17 22:50:15 +0100513
514 /* set coordinate output rate */
515 buf[0] = buf[1] = 0xFF;
516 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
517 TSC10_CMD_RATE,
518 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
519 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
520 if (ret < 0)
Oliver Neukum76d057c2008-04-04 15:31:47 -0400521 goto err_out;
Nuno Lucas2ec6f242008-11-11 16:48:04 -0500522 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
Oliver Neukum76d057c2008-04-04 15:31:47 -0400523 ret = -ENODEV;
524 goto err_out;
525 }
Holger Schurig24ced062006-11-17 22:50:15 +0100526
527 /* start sending data */
528 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
529 TSC10_CMD_DATA1,
530 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
531 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
Oliver Neukum76d057c2008-04-04 15:31:47 -0400532err_out:
533 kfree(buf);
534err_nobuf:
535 return ret;
Holger Schurig24ced062006-11-17 22:50:15 +0100536}
537
538
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100539static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
Holger Schurig24ced062006-11-17 22:50:15 +0100540{
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100541 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
542 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
543 dev->touch = pkt[0] & 0x01;
Holger Schurig24ced062006-11-17 22:50:15 +0100544
545 return 1;
546}
547#endif
548
549
550/*****************************************************************************
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400551 * IRTOUCH Part
552 */
553#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
554static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
555{
556 dev->x = (pkt[3] << 8) | pkt[2];
557 dev->y = (pkt[5] << 8) | pkt[4];
558 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
559
560 return 1;
561}
562#endif
563
Petr Å tetiardbe14202009-11-29 23:37:07 -0800564/*****************************************************************************
565 * ET&T TC5UH part
566 */
567#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
568static int tc5uh_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
569{
570 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
571 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
572 dev->touch = pkt[0] & 0x01;
573
574 return 1;
575}
576#endif
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400577
578/*****************************************************************************
Ondrej Zarya14a8402007-09-04 23:45:01 -0400579 * IdealTEK URTC1000 Part
580 */
581#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
Daniel Ritz62aa3662008-01-17 12:01:18 -0500582#ifndef MULTI_PACKET
583#define MULTI_PACKET
584#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400585static int idealtek_get_pkt_len(unsigned char *buf, int len)
586{
587 if (buf[0] & 0x80)
588 return 5;
589 if (buf[0] == 0x01)
590 return len;
591 return 0;
592}
593
594static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
595{
596 switch (pkt[0] & 0x98) {
597 case 0x88:
598 /* touch data in IdealTEK mode */
599 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
600 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
601 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
602 return 1;
603
604 case 0x98:
605 /* touch data in MT emulation mode */
606 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
607 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
608 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
609 return 1;
610
611 default:
612 return 0;
613 }
614}
615#endif
616
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400617/*****************************************************************************
618 * General Touch Part
619 */
620#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
621static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
622{
623 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ;
624 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ;
625 dev->press = pkt[5] & 0xff;
626 dev->touch = pkt[0] & 0x01;
627
628 return 1;
629}
630#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400631
632/*****************************************************************************
Jerrold Jones14e40202007-10-22 00:59:47 -0400633 * GoTop Part
634 */
635#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
636static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
637{
638 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
639 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
640 dev->touch = pkt[0] & 0x01;
Jim Perssonf7370692009-07-07 22:07:59 -0700641
642 return 1;
643}
644#endif
645
646/*****************************************************************************
647 * JASTEC Part
648 */
649#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
650static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
651{
652 dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
653 dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
654 dev->touch = (pkt[0] & 0x40) >> 6;
655
Jerrold Jones14e40202007-10-22 00:59:47 -0400656 return 1;
657}
658#endif
659
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800660/*****************************************************************************
661 * Zytronic Part
662 */
663#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
664static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
665{
666 switch (pkt[0]) {
667 case 0x3A: /* command response */
668 dbg("%s: Command response %d", __func__, pkt[1]);
669 break;
670
671 case 0xC0: /* down */
672 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
673 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
674 dev->touch = 1;
675 dbg("%s: down %d,%d", __func__, dev->x, dev->y);
676 return 1;
677
678 case 0x80: /* up */
679 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
680 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
681 dev->touch = 0;
682 dbg("%s: up %d,%d", __func__, dev->x, dev->y);
683 return 1;
684
685 default:
686 dbg("%s: Unknown return %d", __func__, pkt[0]);
687 break;
688 }
689
690 return 0;
691}
692#endif
Jerrold Jones14e40202007-10-22 00:59:47 -0400693
694/*****************************************************************************
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200695 * the different device descriptors
696 */
Daniel Ritz62aa3662008-01-17 12:01:18 -0500697#ifdef MULTI_PACKET
698static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
699 unsigned char *pkt, int len);
700#endif
701
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200702static struct usbtouch_device_info usbtouch_dev_info[] = {
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400703#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200704 [DEVTYPE_EGALAX] = {
705 .min_xc = 0x0,
706 .max_xc = 0x07ff,
707 .min_yc = 0x0,
708 .max_yc = 0x07ff,
709 .rept_size = 16,
Daniel Ritz5d892662006-07-31 21:43:24 +0200710 .process_pkt = usbtouch_process_multi,
711 .get_pkt_len = egalax_get_pkt_len,
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200712 .read_data = egalax_read_data,
713 },
714#endif
715
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400716#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200717 [DEVTYPE_PANJIT] = {
718 .min_xc = 0x0,
719 .max_xc = 0x0fff,
720 .min_yc = 0x0,
721 .max_yc = 0x0fff,
722 .rept_size = 8,
723 .read_data = panjit_read_data,
724 },
725#endif
726
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400727#ifdef CONFIG_TOUCHSCREEN_USB_3M
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200728 [DEVTYPE_3M] = {
729 .min_xc = 0x0,
730 .max_xc = 0x4000,
731 .min_yc = 0x0,
732 .max_yc = 0x4000,
733 .rept_size = 11,
734 .read_data = mtouch_read_data,
735 .init = mtouch_init,
736 },
737#endif
738
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400739#ifdef CONFIG_TOUCHSCREEN_USB_ITM
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200740 [DEVTYPE_ITM] = {
741 .min_xc = 0x0,
742 .max_xc = 0x0fff,
743 .min_yc = 0x0,
744 .max_yc = 0x0fff,
745 .max_press = 0xff,
746 .rept_size = 8,
747 .read_data = itm_read_data,
748 },
749#endif
Daniel Ritz5d892662006-07-31 21:43:24 +0200750
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400751#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
Daniel Ritz5d892662006-07-31 21:43:24 +0200752 [DEVTYPE_ETURBO] = {
753 .min_xc = 0x0,
754 .max_xc = 0x07ff,
755 .min_yc = 0x0,
756 .max_yc = 0x07ff,
757 .rept_size = 8,
Daniel Ritz5d892662006-07-31 21:43:24 +0200758 .process_pkt = usbtouch_process_multi,
759 .get_pkt_len = eturbo_get_pkt_len,
760 .read_data = eturbo_read_data,
761 },
762#endif
763
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400764#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
Daniel Ritz5d892662006-07-31 21:43:24 +0200765 [DEVTYPE_GUNZE] = {
766 .min_xc = 0x0,
767 .max_xc = 0x0fff,
768 .min_yc = 0x0,
769 .max_yc = 0x0fff,
770 .rept_size = 4,
771 .read_data = gunze_read_data,
772 },
773#endif
Holger Schurig24ced062006-11-17 22:50:15 +0100774
Ondrej Zaryc6f8d702007-06-12 00:33:13 -0400775#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
Holger Schurig24ced062006-11-17 22:50:15 +0100776 [DEVTYPE_DMC_TSC10] = {
777 .min_xc = 0x0,
778 .max_xc = 0x03ff,
779 .min_yc = 0x0,
780 .max_yc = 0x03ff,
781 .rept_size = 5,
782 .init = dmc_tsc10_init,
783 .read_data = dmc_tsc10_read_data,
784 },
785#endif
Ondrej Zarydf561fc2007-07-03 01:55:03 -0400786
787#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
788 [DEVTYPE_IRTOUCH] = {
789 .min_xc = 0x0,
790 .max_xc = 0x0fff,
791 .min_yc = 0x0,
792 .max_yc = 0x0fff,
793 .rept_size = 8,
794 .read_data = irtouch_read_data,
795 },
796#endif
Ondrej Zarya14a8402007-09-04 23:45:01 -0400797
798#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
799 [DEVTYPE_IDEALTEK] = {
800 .min_xc = 0x0,
801 .max_xc = 0x0fff,
802 .min_yc = 0x0,
803 .max_yc = 0x0fff,
804 .rept_size = 8,
Ondrej Zarya14a8402007-09-04 23:45:01 -0400805 .process_pkt = usbtouch_process_multi,
806 .get_pkt_len = idealtek_get_pkt_len,
807 .read_data = idealtek_read_data,
808 },
809#endif
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400810
811#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
812 [DEVTYPE_GENERAL_TOUCH] = {
813 .min_xc = 0x0,
814 .max_xc = 0x0500,
815 .min_yc = 0x0,
816 .max_yc = 0x0500,
817 .rept_size = 7,
818 .read_data = general_touch_read_data,
Jerrold Jones14e40202007-10-22 00:59:47 -0400819 },
Ilya Frolov9d5657d2007-10-12 14:19:40 -0400820#endif
821
Jerrold Jones14e40202007-10-22 00:59:47 -0400822#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
823 [DEVTYPE_GOTOP] = {
824 .min_xc = 0x0,
825 .max_xc = 0x03ff,
826 .min_yc = 0x0,
827 .max_yc = 0x03ff,
828 .rept_size = 4,
829 .read_data = gotop_read_data,
830 },
831#endif
Jim Perssonf7370692009-07-07 22:07:59 -0700832
833#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
834 [DEVTYPE_JASTEC] = {
835 .min_xc = 0x0,
836 .max_xc = 0x0fff,
837 .min_yc = 0x0,
838 .max_yc = 0x0fff,
839 .rept_size = 4,
840 .read_data = jastec_read_data,
841 },
842#endif
Florian Echtler9e3b2582009-07-27 17:35:39 -0700843
844#ifdef CONFIG_TOUCHSCREEN_USB_E2I
845 [DEVTYPE_E2I] = {
846 .min_xc = 0x0,
847 .max_xc = 0x7fff,
848 .min_yc = 0x0,
849 .max_yc = 0x7fff,
850 .rept_size = 6,
851 .init = e2i_init,
852 .read_data = e2i_read_data,
853 },
854#endif
Daniel Silverstone2330ed12009-11-23 08:38:16 -0800855
856#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
857 [DEVTYPE_ZYTRONIC] = {
858 .min_xc = 0x0,
859 .max_xc = 0x03ff,
860 .min_yc = 0x0,
861 .max_yc = 0x03ff,
862 .rept_size = 5,
863 .read_data = zytronic_read_data,
864 .irq_always = true,
865 },
866#endif
Petr Å tetiardbe14202009-11-29 23:37:07 -0800867
868#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
869 [DEVTYPE_TC5UH] = {
870 .min_xc = 0x0,
871 .max_xc = 0x0fff,
872 .min_yc = 0x0,
873 .max_yc = 0x0fff,
874 .rept_size = 5,
875 .read_data = tc5uh_read_data,
876 },
877#endif
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200878};
879
880
881/*****************************************************************************
882 * Generic Part
883 */
884static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
David Howells7d12e782006-10-05 14:55:46 +0100885 unsigned char *pkt, int len)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200886{
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200887 struct usbtouch_device_info *type = usbtouch->type;
888
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100889 if (!type->read_data(usbtouch, pkt))
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200890 return;
891
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100892 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200893
894 if (swap_xy) {
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100895 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
896 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200897 } else {
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100898 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
899 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200900 }
901 if (type->max_press)
Daniel Ritzc9d8c2b2006-12-11 18:17:45 +0100902 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200903 input_sync(usbtouch->input);
904}
905
906
Daniel Ritz5d892662006-07-31 21:43:24 +0200907#ifdef MULTI_PACKET
908static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
Daniel Ritz5d892662006-07-31 21:43:24 +0200909 unsigned char *pkt, int len)
910{
911 unsigned char *buffer;
912 int pkt_len, pos, buf_len, tmp;
913
914 /* process buffer */
915 if (unlikely(usbtouch->buf_len)) {
916 /* try to get size */
917 pkt_len = usbtouch->type->get_pkt_len(
918 usbtouch->buffer, usbtouch->buf_len);
919
920 /* drop? */
921 if (unlikely(!pkt_len))
922 goto out_flush_buf;
923
924 /* need to append -pkt_len bytes before able to get size */
925 if (unlikely(pkt_len < 0)) {
926 int append = -pkt_len;
927 if (unlikely(append > len))
928 append = len;
929 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
930 goto out_flush_buf;
931 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
932 usbtouch->buf_len += append;
933
934 pkt_len = usbtouch->type->get_pkt_len(
935 usbtouch->buffer, usbtouch->buf_len);
936 if (pkt_len < 0)
937 return;
938 }
939
940 /* append */
941 tmp = pkt_len - usbtouch->buf_len;
942 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
943 goto out_flush_buf;
944 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
David Howells7d12e782006-10-05 14:55:46 +0100945 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
Daniel Ritz5d892662006-07-31 21:43:24 +0200946
947 buffer = pkt + tmp;
948 buf_len = len - tmp;
949 } else {
950 buffer = pkt;
951 buf_len = len;
952 }
953
954 /* loop over the received packet, process */
955 pos = 0;
956 while (pos < buf_len) {
957 /* get packet len */
Daniel Ritz62aa3662008-01-17 12:01:18 -0500958 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
959 buf_len - pos);
Daniel Ritz5d892662006-07-31 21:43:24 +0200960
Daniel Ritz62aa3662008-01-17 12:01:18 -0500961 /* unknown packet: skip one byte */
962 if (unlikely(!pkt_len)) {
963 pos++;
964 continue;
965 }
Daniel Ritz5d892662006-07-31 21:43:24 +0200966
967 /* full packet: process */
968 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
David Howells7d12e782006-10-05 14:55:46 +0100969 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
Daniel Ritz5d892662006-07-31 21:43:24 +0200970 } else {
971 /* incomplete packet: save in buffer */
972 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
973 usbtouch->buf_len = buf_len - pos;
974 return;
975 }
976 pos += pkt_len;
977 }
978
979out_flush_buf:
980 usbtouch->buf_len = 0;
981 return;
982}
983#endif
984
985
David Howells7d12e782006-10-05 14:55:46 +0100986static void usbtouch_irq(struct urb *urb)
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200987{
988 struct usbtouch_usb *usbtouch = urb->context;
989 int retval;
990
991 switch (urb->status) {
992 case 0:
993 /* success */
994 break;
Pete Zaitcev38e2bfc2006-09-18 22:49:02 -0700995 case -ETIME:
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200996 /* this urb is timing out */
997 dbg("%s - urb timed out - was the device unplugged?",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400998 __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +0200999 return;
1000 case -ECONNRESET:
1001 case -ENOENT:
1002 case -ESHUTDOWN:
1003 /* this urb is terminated, clean up */
1004 dbg("%s - urb shutting down with status: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001005 __func__, urb->status);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001006 return;
1007 default:
1008 dbg("%s - nonzero urb status received: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001009 __func__, urb->status);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001010 goto exit;
1011 }
1012
David Howells7d12e782006-10-05 14:55:46 +01001013 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001014
1015exit:
1016 retval = usb_submit_urb(urb, GFP_ATOMIC);
1017 if (retval)
1018 err("%s - usb_submit_urb failed with result: %d",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001019 __func__, retval);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001020}
1021
1022static int usbtouch_open(struct input_dev *input)
1023{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001024 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001025
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001026 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001027
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001028 if (!usbtouch->type->irq_always) {
1029 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
1030 return -EIO;
1031 }
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001032
1033 return 0;
1034}
1035
1036static void usbtouch_close(struct input_dev *input)
1037{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001038 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001039
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001040 if (!usbtouch->type->irq_always)
1041 usb_kill_urb(usbtouch->irq);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001042}
1043
1044
1045static void usbtouch_free_buffers(struct usb_device *udev,
1046 struct usbtouch_usb *usbtouch)
1047{
Dmitry Torokhove37a97d2007-05-03 00:57:29 -04001048 usb_buffer_free(udev, usbtouch->type->rept_size,
1049 usbtouch->data, usbtouch->data_dma);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001050 kfree(usbtouch->buffer);
1051}
1052
1053
1054static int usbtouch_probe(struct usb_interface *intf,
1055 const struct usb_device_id *id)
1056{
1057 struct usbtouch_usb *usbtouch;
1058 struct input_dev *input_dev;
1059 struct usb_host_interface *interface;
1060 struct usb_endpoint_descriptor *endpoint;
1061 struct usb_device *udev = interface_to_usbdev(intf);
1062 struct usbtouch_device_info *type;
Daniel Ritz5d892662006-07-31 21:43:24 +02001063 int err = -ENOMEM;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001064
Daniel Ritzec42d442008-07-03 10:45:37 -04001065 /* some devices are ignored */
1066 if (id->driver_info == DEVTYPE_IGNORE)
1067 return -ENODEV;
1068
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001069 interface = intf->cur_altsetting;
1070 endpoint = &interface->endpoint[0].desc;
1071
1072 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
1073 input_dev = input_allocate_device();
1074 if (!usbtouch || !input_dev)
1075 goto out_free;
1076
1077 type = &usbtouch_dev_info[id->driver_info];
1078 usbtouch->type = type;
1079 if (!type->process_pkt)
1080 type->process_pkt = usbtouch_process_pkt;
1081
1082 usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
Christoph Lametere94b1762006-12-06 20:33:17 -08001083 GFP_KERNEL, &usbtouch->data_dma);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001084 if (!usbtouch->data)
1085 goto out_free;
1086
Daniel Ritz62aa3662008-01-17 12:01:18 -05001087 if (type->get_pkt_len) {
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001088 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
1089 if (!usbtouch->buffer)
1090 goto out_free_buffers;
1091 }
1092
1093 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
1094 if (!usbtouch->irq) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001095 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001096 goto out_free_buffers;
1097 }
1098
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001099 usbtouch->interface = intf;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001100 usbtouch->input = input_dev;
1101
1102 if (udev->manufacturer)
1103 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
1104
1105 if (udev->product) {
1106 if (udev->manufacturer)
1107 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
1108 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
1109 }
1110
1111 if (!strlen(usbtouch->name))
1112 snprintf(usbtouch->name, sizeof(usbtouch->name),
1113 "USB Touchscreen %04x:%04x",
1114 le16_to_cpu(udev->descriptor.idVendor),
1115 le16_to_cpu(udev->descriptor.idProduct));
1116
1117 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
Vladimir Shebordaev7b6dff92007-09-06 21:32:16 -04001118 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001119
1120 input_dev->name = usbtouch->name;
1121 input_dev->phys = usbtouch->phys;
1122 usb_to_input_id(udev, &input_dev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -04001123 input_dev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -04001124
1125 input_set_drvdata(input_dev, usbtouch);
1126
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001127 input_dev->open = usbtouch_open;
1128 input_dev->close = usbtouch_close;
1129
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001130 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1131 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001132 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
1133 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
1134 if (type->max_press)
1135 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1136 type->max_press, 0, 0);
1137
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001138 usb_fill_int_urb(usbtouch->irq, udev,
1139 usb_rcvintpipe(udev, endpoint->bEndpointAddress),
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001140 usbtouch->data, type->rept_size,
1141 usbtouch_irq, usbtouch, endpoint->bInterval);
1142
Ondrej Zaryfea4d142010-02-03 23:46:48 -08001143 usbtouch->irq->dev = udev;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001144 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1145 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1146
1147 /* device specific init */
1148 if (type->init) {
1149 err = type->init(usbtouch);
1150 if (err) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001151 dbg("%s - type->init() failed, err: %d", __func__, err);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001152 goto out_free_buffers;
1153 }
1154 }
1155
1156 err = input_register_device(usbtouch->input);
1157 if (err) {
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001158 dbg("%s - input_register_device failed, err: %d", __func__, err);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001159 goto out_free_buffers;
1160 }
1161
1162 usb_set_intfdata(intf, usbtouch);
1163
Daniel Silverstone2330ed12009-11-23 08:38:16 -08001164 if (usbtouch->type->irq_always)
1165 usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1166
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001167 return 0;
1168
1169out_free_buffers:
1170 usbtouch_free_buffers(udev, usbtouch);
1171out_free:
1172 input_free_device(input_dev);
1173 kfree(usbtouch);
Daniel Ritz5d892662006-07-31 21:43:24 +02001174 return err;
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001175}
1176
1177static void usbtouch_disconnect(struct usb_interface *intf)
1178{
1179 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1180
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001181 dbg("%s - called", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001182
1183 if (!usbtouch)
1184 return;
1185
Harvey Harrisonea3e6c52008-05-05 11:36:18 -04001186 dbg("%s - usbtouch is initialized, cleaning up", __func__);
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001187 usb_set_intfdata(intf, NULL);
Oliver Neukum722232bc2009-11-23 08:10:50 -08001188 /* this will stop IO via close */
Daniel Ritz1d3e2022006-03-29 22:41:07 +02001189 input_unregister_device(usbtouch->input);
1190 usb_free_urb(usbtouch->irq);
1191 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1192 kfree(usbtouch);
1193}
1194
1195MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1196
1197static struct usb_driver usbtouch_driver = {
1198 .name = "usbtouchscreen",
1199 .probe = usbtouch_probe,
1200 .disconnect = usbtouch_disconnect,
1201 .id_table = usbtouch_devices,
1202};
1203
1204static int __init usbtouch_init(void)
1205{
1206 return usb_register(&usbtouch_driver);
1207}
1208
1209static void __exit usbtouch_cleanup(void)
1210{
1211 usb_deregister(&usbtouch_driver);
1212}
1213
1214module_init(usbtouch_init);
1215module_exit(usbtouch_cleanup);
1216
1217MODULE_AUTHOR(DRIVER_AUTHOR);
1218MODULE_DESCRIPTION(DRIVER_DESC);
1219MODULE_LICENSE("GPL");
1220
1221MODULE_ALIAS("touchkitusb");
1222MODULE_ALIAS("itmtouch");
1223MODULE_ALIAS("mtouchusb");