Merge branch 'tracing/core' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic...
[linux-2.6-block.git] / drivers / input / touchscreen / usbtouchscreen.c
CommitLineData
1d3e2023
DR
1/******************************************************************************
2 * usbtouchscreen.c
3 * Driver for USB Touchscreens, supporting those devices:
4 * - eGalax Touchkit
5d892665
DR
5 * includes eTurboTouch CT-410/510/700
6 * - 3M/Microtouch EX II series
1d3e2023
DR
7 * - ITM
8 * - PanJit TouchSet
5d892665
DR
9 * - eTurboTouch
10 * - Gunze AHL61
24ced062 11 * - DMC TSC-10/25
df561fcd 12 * - IRTOUCHSYSTEMS/UNITOP
a14a8401 13 * - IdealTEK URTC1000
62aa366d 14 * - General Touch
14e40206 15 * - GoTop Super_Q2/GogoPen/PenPower tablets
f7370699 16 * - JASTEC USB touch controller/DigiTech DTR-02U
2330ed18 17 * - Zytronic capacitive touchscreen
1d3e2023 18 *
14e40206 19 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
1d3e2023
DR
20 * 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
24ced062
HS
40 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
41 * driver from Marius Vollmer
1d3e2023
DR
42 *
43 *****************************************************************************/
44
45//#define DEBUG
46
1d3e2023
DR
47#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>
ae0dadcf 53#include <linux/usb/input.h>
ec42d448 54#include <linux/hid.h>
1d3e2023
DR
55
56
62aa366d 57#define DRIVER_VERSION "v0.6"
1d3e2023
DR
58#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
c9cbf3d3
DS
65static 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
1d3e2023
DR
69/* 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;
1d3e2023 76
2330ed18
DS
77 /*
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
7d12e780 86 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
62aa366d
DR
87
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 */
5d892665 94 int (*get_pkt_len) (unsigned char *pkt, int len);
62aa366d 95
c9d8c2b3 96 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
1d3e2023
DR
97 int (*init) (struct usbtouch_usb *usbtouch);
98};
99
1d3e2023
DR
100/* 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;
107 struct usb_device *udev;
108 struct input_dev *input;
109 struct usbtouch_device_info *type;
110 char name[128];
111 char phys[64];
c9d8c2b3
DR
112
113 int x, y;
114 int touch, press;
1d3e2023
DR
115};
116
5d892665 117
1d3e2023
DR
118/* device types */
119enum {
ec42d448 120 DEVTYPE_IGNORE = -1,
1d3e2023
DR
121 DEVTYPE_EGALAX,
122 DEVTYPE_PANJIT,
123 DEVTYPE_3M,
124 DEVTYPE_ITM,
5d892665
DR
125 DEVTYPE_ETURBO,
126 DEVTYPE_GUNZE,
24ced062 127 DEVTYPE_DMC_TSC10,
df561fcd 128 DEVTYPE_IRTOUCH,
a14a8401 129 DEVTYPE_IDEALTEK,
9d5657db 130 DEVTYPE_GENERAL_TOUCH,
14e40206 131 DEVTYPE_GOTOP,
f7370699 132 DEVTYPE_JASTEC,
9e3b2583 133 DEVTYPE_E2I,
2330ed18 134 DEVTYPE_ZYTRONIC,
dbe1420b 135 DEVTYPE_TC5UH,
1d3e2023
DR
136};
137
ec42d448
DR
138#define USB_DEVICE_HID_CLASS(vend, prod) \
139 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
139ebe8d 140 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
ec42d448
DR
141 | USB_DEVICE_ID_MATCH_DEVICE, \
142 .idVendor = (vend), \
143 .idProduct = (prod), \
144 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
145 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
146
1d3e2023 147static struct usb_device_id usbtouch_devices[] = {
c6f8d706 148#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
ec42d448
DR
149 /* 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 */
1d3e2023 154 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
5d892665 155 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
1d3e2023
DR
156 {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},
5d892665
DR
159 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
160 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
1d3e2023
DR
161#endif
162
c6f8d706 163#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
1d3e2023
DR
164 {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
c6f8d706 170#ifdef CONFIG_TOUCHSCREEN_USB_3M
1d3e2023
DR
171 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
172#endif
173
c6f8d706 174#ifdef CONFIG_TOUCHSCREEN_USB_ITM
1d3e2023
DR
175 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
176#endif
177
c6f8d706 178#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
5d892665
DR
179 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
180#endif
181
c6f8d706 182#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
5d892665
DR
183 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
184#endif
185
c6f8d706 186#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
24ced062
HS
187 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
188#endif
189
df561fcd
OZ
190#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
a14a8401
OZ
195#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
196 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
197#endif
198
9d5657db
IF
199#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
200 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
201#endif
202
14e40206
JJ
203#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
f7370699
JP
209#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
210 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
211#endif
212
9e3b2583
FE
213#ifdef CONFIG_TOUCHSCREEN_USB_E2I
214 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
215#endif
2330ed18
DS
216
217#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
218 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
219#endif
220
dbe1420b
221#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
222 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH},
223#endif
224
1d3e2023
DR
225 {}
226};
227
228
9e3b2583
FE
229/*****************************************************************************
230 * e2i Part
231 */
232
233#ifdef CONFIG_TOUCHSCREEN_USB_E2I
234static int e2i_init(struct usbtouch_usb *usbtouch)
235{
236 int ret;
237
238 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
239 0x01, 0x02, 0x0000, 0x0081,
240 NULL, 0, USB_CTRL_SET_TIMEOUT);
241
242 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
243 __func__, ret);
244 return ret;
245}
246
247static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
248{
249 int tmp = (pkt[0] << 8) | pkt[1];
250 dev->x = (pkt[2] << 8) | pkt[3];
251 dev->y = (pkt[4] << 8) | pkt[5];
252
253 tmp = tmp - 0xA000;
254 dev->touch = (tmp > 0);
255 dev->press = (tmp > 0 ? tmp : 0);
256
257 return 1;
258}
259#endif
260
261
1d3e2023
DR
262/*****************************************************************************
263 * eGalax part
264 */
265
c6f8d706 266#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
1d3e2023 267
62aa366d
DR
268#ifndef MULTI_PACKET
269#define MULTI_PACKET
270#endif
271
1d3e2023
DR
272#define EGALAX_PKT_TYPE_MASK 0xFE
273#define EGALAX_PKT_TYPE_REPT 0x80
274#define EGALAX_PKT_TYPE_DIAG 0x0A
275
c9d8c2b3 276static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1d3e2023
DR
277{
278 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
279 return 0;
280
c9d8c2b3
DR
281 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
282 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
283 dev->touch = pkt[0] & 0x01;
1d3e2023
DR
284
285 return 1;
1d3e2023
DR
286}
287
5d892665 288static int egalax_get_pkt_len(unsigned char *buf, int len)
1d3e2023
DR
289{
290 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
291 case EGALAX_PKT_TYPE_REPT:
292 return 5;
293
294 case EGALAX_PKT_TYPE_DIAG:
5d892665
DR
295 if (len < 2)
296 return -1;
297
1d3e2023
DR
298 return buf[1] + 2;
299 }
300
301 return 0;
302}
1d3e2023
DR
303#endif
304
305
306/*****************************************************************************
307 * PanJit Part
308 */
c6f8d706 309#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
c9d8c2b3 310static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1d3e2023 311{
c9d8c2b3
DR
312 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
313 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
314 dev->touch = pkt[0] & 0x01;
1d3e2023
DR
315
316 return 1;
317}
318#endif
319
320
321/*****************************************************************************
322 * 3M/Microtouch Part
323 */
c6f8d706 324#ifdef CONFIG_TOUCHSCREEN_USB_3M
1d3e2023
DR
325
326#define MTOUCHUSB_ASYNC_REPORT 1
327#define MTOUCHUSB_RESET 7
328#define MTOUCHUSB_REQ_CTRLLR_ID 10
329
c9d8c2b3 330static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1d3e2023 331{
c9cbf3d3
DS
332 if (hwcalib_xy) {
333 dev->x = (pkt[4] << 8) | pkt[3];
334 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
335 } else {
336 dev->x = (pkt[8] << 8) | pkt[7];
337 dev->y = (pkt[10] << 8) | pkt[9];
338 }
c9d8c2b3 339 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
1d3e2023
DR
340
341 return 1;
342}
343
344static int mtouch_init(struct usbtouch_usb *usbtouch)
345{
5d892665 346 int ret, i;
1d3e2023
DR
347
348 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
349 MTOUCHUSB_RESET,
350 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
351 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
352 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
ea3e6c59 353 __func__, ret);
1d3e2023
DR
354 if (ret < 0)
355 return ret;
5d892665
DR
356 msleep(150);
357
358 for (i = 0; i < 3; i++) {
359 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
360 MTOUCHUSB_ASYNC_REPORT,
361 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
362 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
363 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
ea3e6c59 364 __func__, ret);
5d892665
DR
365 if (ret >= 0)
366 break;
367 if (ret != -EPIPE)
368 return ret;
369 }
1d3e2023 370
c9cbf3d3
DS
371 /* Default min/max xy are the raw values, override if using hw-calib */
372 if (hwcalib_xy) {
373 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
374 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
375 }
376
1d3e2023
DR
377 return 0;
378}
379#endif
380
381
382/*****************************************************************************
383 * ITM Part
384 */
c6f8d706 385#ifdef CONFIG_TOUCHSCREEN_USB_ITM
c9d8c2b3 386static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
1d3e2023 387{
c9d8c2b3
DR
388 int touch;
389 /*
390 * ITM devices report invalid x/y data if not touched.
391 * if the screen was touched before but is not touched any more
392 * report touch as 0 with the last valid x/y data once. then stop
393 * reporting data until touched again.
394 */
395 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
396
397 touch = ~pkt[7] & 0x20;
398 if (!touch) {
399 if (dev->touch) {
400 dev->touch = 0;
401 return 1;
402 }
403
404 return 0;
405 }
406
407 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
408 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
409 dev->touch = touch;
1d3e2023 410
c9d8c2b3 411 return 1;
1d3e2023
DR
412}
413#endif
414
415
5d892665
DR
416/*****************************************************************************
417 * eTurboTouch part
418 */
c6f8d706 419#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
62aa366d
DR
420#ifndef MULTI_PACKET
421#define MULTI_PACKET
422#endif
c9d8c2b3 423static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
5d892665
DR
424{
425 unsigned int shift;
426
427 /* packets should start with sync */
428 if (!(pkt[0] & 0x80))
429 return 0;
430
431 shift = (6 - (pkt[0] & 0x03));
c9d8c2b3
DR
432 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
433 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
434 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
5d892665
DR
435
436 return 1;
437}
438
439static int eturbo_get_pkt_len(unsigned char *buf, int len)
440{
441 if (buf[0] & 0x80)
442 return 5;
443 if (buf[0] == 0x01)
444 return 3;
445 return 0;
446}
447#endif
448
449
450/*****************************************************************************
451 * Gunze part
452 */
c6f8d706 453#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
c9d8c2b3 454static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
5d892665
DR
455{
456 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
457 return 0;
458
c9d8c2b3
DR
459 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
460 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
461 dev->touch = pkt[0] & 0x20;
5d892665
DR
462
463 return 1;
464}
465#endif
466
24ced062
HS
467/*****************************************************************************
468 * DMC TSC-10/25 Part
469 *
470 * Documentation about the controller and it's protocol can be found at
471 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
472 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
473 */
c6f8d706 474#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
24ced062
HS
475
476/* supported data rates. currently using 130 */
477#define TSC10_RATE_POINT 0x50
478#define TSC10_RATE_30 0x40
479#define TSC10_RATE_50 0x41
480#define TSC10_RATE_80 0x42
481#define TSC10_RATE_100 0x43
482#define TSC10_RATE_130 0x44
483#define TSC10_RATE_150 0x45
484
485/* commands */
486#define TSC10_CMD_RESET 0x55
487#define TSC10_CMD_RATE 0x05
488#define TSC10_CMD_DATA1 0x01
489
490static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
491{
492 struct usb_device *dev = usbtouch->udev;
76d057ce
ON
493 int ret = -ENOMEM;
494 unsigned char *buf;
24ced062 495
76d057ce
ON
496 buf = kmalloc(2, GFP_KERNEL);
497 if (!buf)
498 goto err_nobuf;
24ced062
HS
499 /* reset */
500 buf[0] = buf[1] = 0xFF;
501 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
502 TSC10_CMD_RESET,
503 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
504 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
505 if (ret < 0)
76d057ce 506 goto err_out;
2ec6f246 507 if (buf[0] != 0x06) {
76d057ce
ON
508 ret = -ENODEV;
509 goto err_out;
510 }
24ced062
HS
511
512 /* set coordinate output rate */
513 buf[0] = buf[1] = 0xFF;
514 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
515 TSC10_CMD_RATE,
516 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
517 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
518 if (ret < 0)
76d057ce 519 goto err_out;
2ec6f246 520 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
76d057ce
ON
521 ret = -ENODEV;
522 goto err_out;
523 }
24ced062
HS
524
525 /* start sending data */
526 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
527 TSC10_CMD_DATA1,
528 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
529 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
76d057ce
ON
530err_out:
531 kfree(buf);
532err_nobuf:
533 return ret;
24ced062
HS
534}
535
536
c9d8c2b3 537static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
24ced062 538{
c9d8c2b3
DR
539 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
540 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
541 dev->touch = pkt[0] & 0x01;
24ced062
HS
542
543 return 1;
544}
545#endif
546
547
df561fcd
OZ
548/*****************************************************************************
549 * IRTOUCH Part
550 */
551#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
552static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
553{
554 dev->x = (pkt[3] << 8) | pkt[2];
555 dev->y = (pkt[5] << 8) | pkt[4];
556 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
557
558 return 1;
559}
560#endif
561
dbe1420b
562/*****************************************************************************
563 * ET&T TC5UH part
564 */
565#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
566static int tc5uh_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
567{
568 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
569 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
570 dev->touch = pkt[0] & 0x01;
571
572 return 1;
573}
574#endif
df561fcd 575
a14a8401
OZ
576/*****************************************************************************
577 * IdealTEK URTC1000 Part
578 */
579#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
62aa366d
DR
580#ifndef MULTI_PACKET
581#define MULTI_PACKET
582#endif
a14a8401
OZ
583static int idealtek_get_pkt_len(unsigned char *buf, int len)
584{
585 if (buf[0] & 0x80)
586 return 5;
587 if (buf[0] == 0x01)
588 return len;
589 return 0;
590}
591
592static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
593{
594 switch (pkt[0] & 0x98) {
595 case 0x88:
596 /* touch data in IdealTEK mode */
597 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
598 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
599 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
600 return 1;
601
602 case 0x98:
603 /* touch data in MT emulation mode */
604 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
605 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
606 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
607 return 1;
608
609 default:
610 return 0;
611 }
612}
613#endif
614
9d5657db
IF
615/*****************************************************************************
616 * General Touch Part
617 */
618#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
619static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
620{
eb083ba2
RY
621 dev->x = (pkt[2] << 8) | pkt[1];
622 dev->y = (pkt[4] << 8) | pkt[3];
9d5657db
IF
623 dev->press = pkt[5] & 0xff;
624 dev->touch = pkt[0] & 0x01;
625
626 return 1;
627}
628#endif
a14a8401 629
14e40206
JJ
630/*****************************************************************************
631 * GoTop Part
632 */
633#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
634static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
635{
636 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
637 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
638 dev->touch = pkt[0] & 0x01;
f7370699
JP
639
640 return 1;
641}
642#endif
643
644/*****************************************************************************
645 * JASTEC Part
646 */
647#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
648static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
649{
650 dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
651 dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
652 dev->touch = (pkt[0] & 0x40) >> 6;
653
14e40206
JJ
654 return 1;
655}
656#endif
657
2330ed18
DS
658/*****************************************************************************
659 * Zytronic Part
660 */
661#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
662static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
663{
664 switch (pkt[0]) {
665 case 0x3A: /* command response */
666 dbg("%s: Command response %d", __func__, pkt[1]);
667 break;
668
669 case 0xC0: /* down */
670 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
671 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
672 dev->touch = 1;
673 dbg("%s: down %d,%d", __func__, dev->x, dev->y);
674 return 1;
675
676 case 0x80: /* up */
677 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
678 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
679 dev->touch = 0;
680 dbg("%s: up %d,%d", __func__, dev->x, dev->y);
681 return 1;
682
683 default:
684 dbg("%s: Unknown return %d", __func__, pkt[0]);
685 break;
686 }
687
688 return 0;
689}
690#endif
14e40206 691
1d3e2023
DR
692/*****************************************************************************
693 * the different device descriptors
694 */
62aa366d
DR
695#ifdef MULTI_PACKET
696static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
697 unsigned char *pkt, int len);
698#endif
699
1d3e2023 700static struct usbtouch_device_info usbtouch_dev_info[] = {
c6f8d706 701#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
1d3e2023
DR
702 [DEVTYPE_EGALAX] = {
703 .min_xc = 0x0,
704 .max_xc = 0x07ff,
705 .min_yc = 0x0,
706 .max_yc = 0x07ff,
707 .rept_size = 16,
5d892665
DR
708 .process_pkt = usbtouch_process_multi,
709 .get_pkt_len = egalax_get_pkt_len,
1d3e2023
DR
710 .read_data = egalax_read_data,
711 },
712#endif
713
c6f8d706 714#ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
1d3e2023
DR
715 [DEVTYPE_PANJIT] = {
716 .min_xc = 0x0,
717 .max_xc = 0x0fff,
718 .min_yc = 0x0,
719 .max_yc = 0x0fff,
720 .rept_size = 8,
721 .read_data = panjit_read_data,
722 },
723#endif
724
c6f8d706 725#ifdef CONFIG_TOUCHSCREEN_USB_3M
1d3e2023
DR
726 [DEVTYPE_3M] = {
727 .min_xc = 0x0,
728 .max_xc = 0x4000,
729 .min_yc = 0x0,
730 .max_yc = 0x4000,
731 .rept_size = 11,
732 .read_data = mtouch_read_data,
733 .init = mtouch_init,
734 },
735#endif
736
c6f8d706 737#ifdef CONFIG_TOUCHSCREEN_USB_ITM
1d3e2023
DR
738 [DEVTYPE_ITM] = {
739 .min_xc = 0x0,
740 .max_xc = 0x0fff,
741 .min_yc = 0x0,
742 .max_yc = 0x0fff,
743 .max_press = 0xff,
744 .rept_size = 8,
745 .read_data = itm_read_data,
746 },
747#endif
5d892665 748
c6f8d706 749#ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
5d892665
DR
750 [DEVTYPE_ETURBO] = {
751 .min_xc = 0x0,
752 .max_xc = 0x07ff,
753 .min_yc = 0x0,
754 .max_yc = 0x07ff,
755 .rept_size = 8,
5d892665
DR
756 .process_pkt = usbtouch_process_multi,
757 .get_pkt_len = eturbo_get_pkt_len,
758 .read_data = eturbo_read_data,
759 },
760#endif
761
c6f8d706 762#ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
5d892665
DR
763 [DEVTYPE_GUNZE] = {
764 .min_xc = 0x0,
765 .max_xc = 0x0fff,
766 .min_yc = 0x0,
767 .max_yc = 0x0fff,
768 .rept_size = 4,
769 .read_data = gunze_read_data,
770 },
771#endif
24ced062 772
c6f8d706 773#ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
24ced062
HS
774 [DEVTYPE_DMC_TSC10] = {
775 .min_xc = 0x0,
776 .max_xc = 0x03ff,
777 .min_yc = 0x0,
778 .max_yc = 0x03ff,
779 .rept_size = 5,
780 .init = dmc_tsc10_init,
781 .read_data = dmc_tsc10_read_data,
782 },
783#endif
df561fcd
OZ
784
785#ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
786 [DEVTYPE_IRTOUCH] = {
787 .min_xc = 0x0,
788 .max_xc = 0x0fff,
789 .min_yc = 0x0,
790 .max_yc = 0x0fff,
791 .rept_size = 8,
792 .read_data = irtouch_read_data,
793 },
794#endif
a14a8401
OZ
795
796#ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
797 [DEVTYPE_IDEALTEK] = {
798 .min_xc = 0x0,
799 .max_xc = 0x0fff,
800 .min_yc = 0x0,
801 .max_yc = 0x0fff,
802 .rept_size = 8,
a14a8401
OZ
803 .process_pkt = usbtouch_process_multi,
804 .get_pkt_len = idealtek_get_pkt_len,
805 .read_data = idealtek_read_data,
806 },
807#endif
9d5657db
IF
808
809#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
810 [DEVTYPE_GENERAL_TOUCH] = {
811 .min_xc = 0x0,
eb083ba2 812 .max_xc = 0x7fff,
9d5657db 813 .min_yc = 0x0,
eb083ba2 814 .max_yc = 0x7fff,
9d5657db
IF
815 .rept_size = 7,
816 .read_data = general_touch_read_data,
14e40206 817 },
9d5657db
IF
818#endif
819
14e40206
JJ
820#ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
821 [DEVTYPE_GOTOP] = {
822 .min_xc = 0x0,
823 .max_xc = 0x03ff,
824 .min_yc = 0x0,
825 .max_yc = 0x03ff,
826 .rept_size = 4,
827 .read_data = gotop_read_data,
828 },
829#endif
f7370699
JP
830
831#ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
832 [DEVTYPE_JASTEC] = {
833 .min_xc = 0x0,
834 .max_xc = 0x0fff,
835 .min_yc = 0x0,
836 .max_yc = 0x0fff,
837 .rept_size = 4,
838 .read_data = jastec_read_data,
839 },
840#endif
9e3b2583
FE
841
842#ifdef CONFIG_TOUCHSCREEN_USB_E2I
843 [DEVTYPE_E2I] = {
844 .min_xc = 0x0,
845 .max_xc = 0x7fff,
846 .min_yc = 0x0,
847 .max_yc = 0x7fff,
848 .rept_size = 6,
849 .init = e2i_init,
850 .read_data = e2i_read_data,
851 },
852#endif
2330ed18
DS
853
854#ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
855 [DEVTYPE_ZYTRONIC] = {
856 .min_xc = 0x0,
857 .max_xc = 0x03ff,
858 .min_yc = 0x0,
859 .max_yc = 0x03ff,
860 .rept_size = 5,
861 .read_data = zytronic_read_data,
862 .irq_always = true,
863 },
864#endif
dbe1420b
865
866#ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC5UH
867 [DEVTYPE_TC5UH] = {
868 .min_xc = 0x0,
869 .max_xc = 0x0fff,
870 .min_yc = 0x0,
871 .max_yc = 0x0fff,
872 .rept_size = 5,
873 .read_data = tc5uh_read_data,
874 },
875#endif
1d3e2023
DR
876};
877
878
879/*****************************************************************************
880 * Generic Part
881 */
882static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
7d12e780 883 unsigned char *pkt, int len)
1d3e2023 884{
1d3e2023
DR
885 struct usbtouch_device_info *type = usbtouch->type;
886
c9d8c2b3 887 if (!type->read_data(usbtouch, pkt))
1d3e2023
DR
888 return;
889
c9d8c2b3 890 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
1d3e2023
DR
891
892 if (swap_xy) {
c9d8c2b3
DR
893 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
894 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
1d3e2023 895 } else {
c9d8c2b3
DR
896 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
897 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
1d3e2023
DR
898 }
899 if (type->max_press)
c9d8c2b3 900 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
1d3e2023
DR
901 input_sync(usbtouch->input);
902}
903
904
5d892665
DR
905#ifdef MULTI_PACKET
906static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
5d892665
DR
907 unsigned char *pkt, int len)
908{
909 unsigned char *buffer;
910 int pkt_len, pos, buf_len, tmp;
911
912 /* process buffer */
913 if (unlikely(usbtouch->buf_len)) {
914 /* try to get size */
915 pkt_len = usbtouch->type->get_pkt_len(
916 usbtouch->buffer, usbtouch->buf_len);
917
918 /* drop? */
919 if (unlikely(!pkt_len))
920 goto out_flush_buf;
921
922 /* need to append -pkt_len bytes before able to get size */
923 if (unlikely(pkt_len < 0)) {
924 int append = -pkt_len;
925 if (unlikely(append > len))
926 append = len;
927 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
928 goto out_flush_buf;
929 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
930 usbtouch->buf_len += append;
931
932 pkt_len = usbtouch->type->get_pkt_len(
933 usbtouch->buffer, usbtouch->buf_len);
934 if (pkt_len < 0)
935 return;
936 }
937
938 /* append */
939 tmp = pkt_len - usbtouch->buf_len;
940 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
941 goto out_flush_buf;
942 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
7d12e780 943 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
5d892665
DR
944
945 buffer = pkt + tmp;
946 buf_len = len - tmp;
947 } else {
948 buffer = pkt;
949 buf_len = len;
950 }
951
952 /* loop over the received packet, process */
953 pos = 0;
954 while (pos < buf_len) {
955 /* get packet len */
62aa366d
DR
956 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
957 buf_len - pos);
5d892665 958
62aa366d
DR
959 /* unknown packet: skip one byte */
960 if (unlikely(!pkt_len)) {
961 pos++;
962 continue;
963 }
5d892665
DR
964
965 /* full packet: process */
966 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
7d12e780 967 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
5d892665
DR
968 } else {
969 /* incomplete packet: save in buffer */
970 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
971 usbtouch->buf_len = buf_len - pos;
972 return;
973 }
974 pos += pkt_len;
975 }
976
977out_flush_buf:
978 usbtouch->buf_len = 0;
979 return;
980}
981#endif
982
983
7d12e780 984static void usbtouch_irq(struct urb *urb)
1d3e2023
DR
985{
986 struct usbtouch_usb *usbtouch = urb->context;
987 int retval;
988
989 switch (urb->status) {
990 case 0:
991 /* success */
992 break;
38e2bfc9 993 case -ETIME:
1d3e2023
DR
994 /* this urb is timing out */
995 dbg("%s - urb timed out - was the device unplugged?",
ea3e6c59 996 __func__);
1d3e2023
DR
997 return;
998 case -ECONNRESET:
999 case -ENOENT:
1000 case -ESHUTDOWN:
1001 /* this urb is terminated, clean up */
1002 dbg("%s - urb shutting down with status: %d",
ea3e6c59 1003 __func__, urb->status);
1d3e2023
DR
1004 return;
1005 default:
1006 dbg("%s - nonzero urb status received: %d",
ea3e6c59 1007 __func__, urb->status);
1d3e2023
DR
1008 goto exit;
1009 }
1010
7d12e780 1011 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
1d3e2023
DR
1012
1013exit:
1014 retval = usb_submit_urb(urb, GFP_ATOMIC);
1015 if (retval)
1016 err("%s - usb_submit_urb failed with result: %d",
ea3e6c59 1017 __func__, retval);
1d3e2023
DR
1018}
1019
1020static int usbtouch_open(struct input_dev *input)
1021{
7791bdae 1022 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1d3e2023
DR
1023
1024 usbtouch->irq->dev = usbtouch->udev;
1025
2330ed18
DS
1026 if (!usbtouch->type->irq_always) {
1027 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
1028 return -EIO;
1029 }
1d3e2023
DR
1030
1031 return 0;
1032}
1033
1034static void usbtouch_close(struct input_dev *input)
1035{
7791bdae 1036 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1d3e2023 1037
2330ed18
DS
1038 if (!usbtouch->type->irq_always)
1039 usb_kill_urb(usbtouch->irq);
1d3e2023
DR
1040}
1041
1042
1043static void usbtouch_free_buffers(struct usb_device *udev,
1044 struct usbtouch_usb *usbtouch)
1045{
e37a97d4
DT
1046 usb_buffer_free(udev, usbtouch->type->rept_size,
1047 usbtouch->data, usbtouch->data_dma);
1d3e2023
DR
1048 kfree(usbtouch->buffer);
1049}
1050
1051
1052static int usbtouch_probe(struct usb_interface *intf,
1053 const struct usb_device_id *id)
1054{
1055 struct usbtouch_usb *usbtouch;
1056 struct input_dev *input_dev;
1057 struct usb_host_interface *interface;
1058 struct usb_endpoint_descriptor *endpoint;
1059 struct usb_device *udev = interface_to_usbdev(intf);
1060 struct usbtouch_device_info *type;
5d892665 1061 int err = -ENOMEM;
ec42d448
DR
1062
1063 /* some devices are ignored */
1064 if (id->driver_info == DEVTYPE_IGNORE)
1065 return -ENODEV;
1d3e2023
DR
1066
1067 interface = intf->cur_altsetting;
1068 endpoint = &interface->endpoint[0].desc;
1069
1070 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
1071 input_dev = input_allocate_device();
1072 if (!usbtouch || !input_dev)
1073 goto out_free;
1074
1075 type = &usbtouch_dev_info[id->driver_info];
1076 usbtouch->type = type;
1077 if (!type->process_pkt)
1078 type->process_pkt = usbtouch_process_pkt;
1079
1080 usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
e94b1766 1081 GFP_KERNEL, &usbtouch->data_dma);
1d3e2023
DR
1082 if (!usbtouch->data)
1083 goto out_free;
1084
62aa366d 1085 if (type->get_pkt_len) {
1d3e2023
DR
1086 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
1087 if (!usbtouch->buffer)
1088 goto out_free_buffers;
1089 }
1090
1091 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
1092 if (!usbtouch->irq) {
ea3e6c59 1093 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
1d3e2023
DR
1094 goto out_free_buffers;
1095 }
1096
1097 usbtouch->udev = udev;
1098 usbtouch->input = input_dev;
1099
1100 if (udev->manufacturer)
1101 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
1102
1103 if (udev->product) {
1104 if (udev->manufacturer)
1105 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
1106 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
1107 }
1108
1109 if (!strlen(usbtouch->name))
1110 snprintf(usbtouch->name, sizeof(usbtouch->name),
1111 "USB Touchscreen %04x:%04x",
1112 le16_to_cpu(udev->descriptor.idVendor),
1113 le16_to_cpu(udev->descriptor.idProduct));
1114
1115 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
7b6dff98 1116 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
1d3e2023
DR
1117
1118 input_dev->name = usbtouch->name;
1119 input_dev->phys = usbtouch->phys;
1120 usb_to_input_id(udev, &input_dev->id);
c0f82d57 1121 input_dev->dev.parent = &intf->dev;
7791bdae
DT
1122
1123 input_set_drvdata(input_dev, usbtouch);
1124
1d3e2023
DR
1125 input_dev->open = usbtouch_open;
1126 input_dev->close = usbtouch_close;
1127
7b19ada2
JS
1128 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1129 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1d3e2023
DR
1130 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
1131 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
1132 if (type->max_press)
1133 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1134 type->max_press, 0, 0);
1135
1136 usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
d8fa59a8 1137 usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress),
1d3e2023
DR
1138 usbtouch->data, type->rept_size,
1139 usbtouch_irq, usbtouch, endpoint->bInterval);
1140
5d892665 1141 usbtouch->irq->dev = usbtouch->udev;
1d3e2023
DR
1142 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1143 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1144
1145 /* device specific init */
1146 if (type->init) {
1147 err = type->init(usbtouch);
1148 if (err) {
ea3e6c59 1149 dbg("%s - type->init() failed, err: %d", __func__, err);
1d3e2023
DR
1150 goto out_free_buffers;
1151 }
1152 }
1153
1154 err = input_register_device(usbtouch->input);
1155 if (err) {
ea3e6c59 1156 dbg("%s - input_register_device failed, err: %d", __func__, err);
1d3e2023
DR
1157 goto out_free_buffers;
1158 }
1159
1160 usb_set_intfdata(intf, usbtouch);
1161
2330ed18
DS
1162 if (usbtouch->type->irq_always)
1163 usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1164
1d3e2023
DR
1165 return 0;
1166
1167out_free_buffers:
1168 usbtouch_free_buffers(udev, usbtouch);
1169out_free:
1170 input_free_device(input_dev);
1171 kfree(usbtouch);
5d892665 1172 return err;
1d3e2023
DR
1173}
1174
1175static void usbtouch_disconnect(struct usb_interface *intf)
1176{
1177 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1178
ea3e6c59 1179 dbg("%s - called", __func__);
1d3e2023
DR
1180
1181 if (!usbtouch)
1182 return;
1183
ea3e6c59 1184 dbg("%s - usbtouch is initialized, cleaning up", __func__);
1d3e2023 1185 usb_set_intfdata(intf, NULL);
722232bc 1186 /* this will stop IO via close */
1d3e2023
DR
1187 input_unregister_device(usbtouch->input);
1188 usb_free_urb(usbtouch->irq);
1189 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1190 kfree(usbtouch);
1191}
1192
1193MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1194
1195static struct usb_driver usbtouch_driver = {
1196 .name = "usbtouchscreen",
1197 .probe = usbtouch_probe,
1198 .disconnect = usbtouch_disconnect,
1199 .id_table = usbtouch_devices,
1200};
1201
1202static int __init usbtouch_init(void)
1203{
1204 return usb_register(&usbtouch_driver);
1205}
1206
1207static void __exit usbtouch_cleanup(void)
1208{
1209 usb_deregister(&usbtouch_driver);
1210}
1211
1212module_init(usbtouch_init);
1213module_exit(usbtouch_cleanup);
1214
1215MODULE_AUTHOR(DRIVER_AUTHOR);
1216MODULE_DESCRIPTION(DRIVER_DESC);
1217MODULE_LICENSE("GPL");
1218
1219MODULE_ALIAS("touchkitusb");
1220MODULE_ALIAS("itmtouch");
1221MODULE_ALIAS("mtouchusb");