1 /******************************************************************************
3 * Driver for USB Touchscreens, supporting those devices:
5 * includes eTurboTouch CT-410/510/700
6 * - 3M/Microtouch EX II series
12 * - IRTOUCHSYSTEMS/UNITOP
15 * - GoTop Super_Q2/GogoPen/PenPower tablets
16 * - JASTEC USB touch controller/DigiTech DTR-02U
17 * - Zytronic capacitive touchscreen
19 * - Elo TouchSystems 2700 IntelliTouch
20 * - EasyTouch USB Dual/Multi touch controller from Data Modul
22 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
23 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
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.
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.
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.
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
43 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
44 * driver from Marius Vollmer
46 *****************************************************************************/
50 #include <linux/kernel.h>
51 #include <linux/slab.h>
52 #include <linux/input.h>
53 #include <linux/module.h>
54 #include <linux/usb.h>
55 #include <linux/usb/input.h>
56 #include <linux/hid.h>
59 #define DRIVER_VERSION "v0.6"
60 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
61 #define DRIVER_DESC "USB Touchscreen Driver"
64 module_param(swap_xy
, bool, 0644);
65 MODULE_PARM_DESC(swap_xy
, "If set X and Y axes are swapped.");
67 static bool hwcalib_xy
;
68 module_param(hwcalib_xy
, bool, 0644);
69 MODULE_PARM_DESC(hwcalib_xy
, "If set hw-calibrated X/Y are used if available");
71 /* device specifc data/functions */
73 struct usbtouch_device_info
{
76 int min_press
, max_press
;
80 * Always service the USB devices irq not just when the input device is
81 * open. This is useful when devices have a watchdog which prevents us
82 * from periodically polling the device. Leave this unset unless your
83 * touchscreen device requires it, as it does consume more of the USB
88 void (*process_pkt
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
, int len
);
91 * used to get the packet len. possible return values:
94 * < 0: -return value more bytes needed
96 int (*get_pkt_len
) (unsigned char *pkt
, int len
);
98 int (*read_data
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
);
99 int (*alloc
) (struct usbtouch_usb
*usbtouch
);
100 int (*init
) (struct usbtouch_usb
*usbtouch
);
101 void (*exit
) (struct usbtouch_usb
*usbtouch
);
104 /* a usbtouch device */
105 struct usbtouch_usb
{
109 unsigned char *buffer
;
112 struct usb_interface
*interface
;
113 struct input_dev
*input
;
114 struct usbtouch_device_info
*type
;
135 DEVTYPE_IRTOUCH_HIRES
,
137 DEVTYPE_GENERAL_TOUCH
,
148 #define USB_DEVICE_HID_CLASS(vend, prod) \
149 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
150 | USB_DEVICE_ID_MATCH_DEVICE, \
151 .idVendor = (vend), \
152 .idProduct = (prod), \
153 .bInterfaceClass = USB_INTERFACE_CLASS_HID
155 static const struct usb_device_id usbtouch_devices
[] = {
156 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
157 /* ignore the HID capable devices, handled by usbhid */
158 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info
= DEVTYPE_IGNORE
},
159 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info
= DEVTYPE_IGNORE
},
161 /* normal device IDs */
162 {USB_DEVICE(0x3823, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
163 {USB_DEVICE(0x3823, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
164 {USB_DEVICE(0x0123, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
165 {USB_DEVICE(0x0eef, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
166 {USB_DEVICE(0x0eef, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
167 {USB_DEVICE(0x1234, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
168 {USB_DEVICE(0x1234, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
171 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
172 {USB_DEVICE(0x134c, 0x0001), .driver_info
= DEVTYPE_PANJIT
},
173 {USB_DEVICE(0x134c, 0x0002), .driver_info
= DEVTYPE_PANJIT
},
174 {USB_DEVICE(0x134c, 0x0003), .driver_info
= DEVTYPE_PANJIT
},
175 {USB_DEVICE(0x134c, 0x0004), .driver_info
= DEVTYPE_PANJIT
},
178 #ifdef CONFIG_TOUCHSCREEN_USB_3M
179 {USB_DEVICE(0x0596, 0x0001), .driver_info
= DEVTYPE_3M
},
182 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
183 {USB_DEVICE(0x0403, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
184 {USB_DEVICE(0x16e3, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
187 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
188 {USB_DEVICE(0x1234, 0x5678), .driver_info
= DEVTYPE_ETURBO
},
191 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
192 {USB_DEVICE(0x0637, 0x0001), .driver_info
= DEVTYPE_GUNZE
},
195 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
196 {USB_DEVICE(0x0afa, 0x03e8), .driver_info
= DEVTYPE_DMC_TSC10
},
199 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
200 {USB_DEVICE(0x595a, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
201 {USB_DEVICE(0x6615, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
202 {USB_DEVICE(0x6615, 0x0012), .driver_info
= DEVTYPE_IRTOUCH_HIRES
},
205 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
206 {USB_DEVICE(0x1391, 0x1000), .driver_info
= DEVTYPE_IDEALTEK
},
209 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
210 {USB_DEVICE(0x0dfc, 0x0001), .driver_info
= DEVTYPE_GENERAL_TOUCH
},
213 #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
},
219 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
220 {USB_DEVICE(0x0f92, 0x0001), .driver_info
= DEVTYPE_JASTEC
},
223 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
224 {USB_DEVICE(0x1ac7, 0x0001), .driver_info
= DEVTYPE_E2I
},
227 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
228 {USB_DEVICE(0x14c8, 0x0003), .driver_info
= DEVTYPE_ZYTRONIC
},
231 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
233 {USB_DEVICE(0x0664, 0x0309), .driver_info
= DEVTYPE_TC45USB
},
235 {USB_DEVICE(0x0664, 0x0306), .driver_info
= DEVTYPE_TC45USB
},
238 #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
},
246 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
247 {USB_DEVICE(0x04e7, 0x0020), .driver_info
= DEVTYPE_ELO
},
250 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
251 {USB_DEVICE(0x7374, 0x0001), .driver_info
= DEVTYPE_ETOUCH
},
258 /*****************************************************************************
262 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
263 static int e2i_init(struct usbtouch_usb
*usbtouch
)
266 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
268 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
269 0x01, 0x02, 0x0000, 0x0081,
270 NULL
, 0, USB_CTRL_SET_TIMEOUT
);
272 dev_dbg(&usbtouch
->interface
->dev
,
273 "%s - usb_control_msg - E2I_RESET - bytes|err: %d\n",
278 static int e2i_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
280 int tmp
= (pkt
[0] << 8) | pkt
[1];
281 dev
->x
= (pkt
[2] << 8) | pkt
[3];
282 dev
->y
= (pkt
[4] << 8) | pkt
[5];
285 dev
->touch
= (tmp
> 0);
286 dev
->press
= (tmp
> 0 ? tmp
: 0);
293 /*****************************************************************************
297 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
303 #define EGALAX_PKT_TYPE_MASK 0xFE
304 #define EGALAX_PKT_TYPE_REPT 0x80
305 #define EGALAX_PKT_TYPE_DIAG 0x0A
307 static int egalax_init(struct usbtouch_usb
*usbtouch
)
311 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
314 * An eGalax diagnostic packet kicks the device into using the right
315 * protocol. We send a "check active" packet. The response will be
316 * read later and ignored.
319 buf
= kmalloc(3, GFP_KERNEL
);
323 buf
[0] = EGALAX_PKT_TYPE_DIAG
;
324 buf
[1] = 1; /* length */
325 buf
[2] = 'A'; /* command - check active */
327 for (i
= 0; i
< 3; i
++) {
328 ret
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
330 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
332 USB_CTRL_SET_TIMEOUT
);
346 static int egalax_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
348 if ((pkt
[0] & EGALAX_PKT_TYPE_MASK
) != EGALAX_PKT_TYPE_REPT
)
351 dev
->x
= ((pkt
[3] & 0x0F) << 7) | (pkt
[4] & 0x7F);
352 dev
->y
= ((pkt
[1] & 0x0F) << 7) | (pkt
[2] & 0x7F);
353 dev
->touch
= pkt
[0] & 0x01;
358 static int egalax_get_pkt_len(unsigned char *buf
, int len
)
360 switch (buf
[0] & EGALAX_PKT_TYPE_MASK
) {
361 case EGALAX_PKT_TYPE_REPT
:
364 case EGALAX_PKT_TYPE_DIAG
:
375 /*****************************************************************************
379 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
385 #define ETOUCH_PKT_TYPE_MASK 0xFE
386 #define ETOUCH_PKT_TYPE_REPT 0x80
387 #define ETOUCH_PKT_TYPE_REPT2 0xB0
388 #define ETOUCH_PKT_TYPE_DIAG 0x0A
390 static int etouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
392 if ((pkt
[0] & ETOUCH_PKT_TYPE_MASK
) != ETOUCH_PKT_TYPE_REPT
&&
393 (pkt
[0] & ETOUCH_PKT_TYPE_MASK
) != ETOUCH_PKT_TYPE_REPT2
)
396 dev
->x
= ((pkt
[1] & 0x1F) << 7) | (pkt
[2] & 0x7F);
397 dev
->y
= ((pkt
[3] & 0x1F) << 7) | (pkt
[4] & 0x7F);
398 dev
->touch
= pkt
[0] & 0x01;
403 static int etouch_get_pkt_len(unsigned char *buf
, int len
)
405 switch (buf
[0] & ETOUCH_PKT_TYPE_MASK
) {
406 case ETOUCH_PKT_TYPE_REPT
:
407 case ETOUCH_PKT_TYPE_REPT2
:
410 case ETOUCH_PKT_TYPE_DIAG
:
421 /*****************************************************************************
424 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
425 static int panjit_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
427 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
428 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
429 dev
->touch
= pkt
[0] & 0x01;
436 /*****************************************************************************
439 #ifdef CONFIG_TOUCHSCREEN_USB_3M
441 #define MTOUCHUSB_ASYNC_REPORT 1
442 #define MTOUCHUSB_RESET 7
443 #define MTOUCHUSB_REQ_CTRLLR_ID 10
445 static int mtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
448 dev
->x
= (pkt
[4] << 8) | pkt
[3];
449 dev
->y
= 0xffff - ((pkt
[6] << 8) | pkt
[5]);
451 dev
->x
= (pkt
[8] << 8) | pkt
[7];
452 dev
->y
= (pkt
[10] << 8) | pkt
[9];
454 dev
->touch
= (pkt
[2] & 0x40) ? 1 : 0;
459 static int mtouch_init(struct usbtouch_usb
*usbtouch
)
462 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
464 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
466 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
467 1, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
468 dev_dbg(&usbtouch
->interface
->dev
,
469 "%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d\n",
475 for (i
= 0; i
< 3; i
++) {
476 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
477 MTOUCHUSB_ASYNC_REPORT
,
478 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
479 1, 1, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
480 dev_dbg(&usbtouch
->interface
->dev
,
481 "%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d\n",
489 /* Default min/max xy are the raw values, override if using hw-calib */
491 input_set_abs_params(usbtouch
->input
, ABS_X
, 0, 0xffff, 0, 0);
492 input_set_abs_params(usbtouch
->input
, ABS_Y
, 0, 0xffff, 0, 0);
500 /*****************************************************************************
503 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
504 static int itm_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
508 * ITM devices report invalid x/y data if not touched.
509 * if the screen was touched before but is not touched any more
510 * report touch as 0 with the last valid x/y data once. then stop
511 * reporting data until touched again.
513 dev
->press
= ((pkt
[2] & 0x01) << 7) | (pkt
[5] & 0x7F);
515 touch
= ~pkt
[7] & 0x20;
525 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[3] & 0x7F);
526 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[4] & 0x7F);
534 /*****************************************************************************
537 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
541 static int eturbo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
545 /* packets should start with sync */
546 if (!(pkt
[0] & 0x80))
549 shift
= (6 - (pkt
[0] & 0x03));
550 dev
->x
= ((pkt
[3] << 7) | pkt
[4]) >> shift
;
551 dev
->y
= ((pkt
[1] << 7) | pkt
[2]) >> shift
;
552 dev
->touch
= (pkt
[0] & 0x10) ? 1 : 0;
557 static int eturbo_get_pkt_len(unsigned char *buf
, int len
)
568 /*****************************************************************************
571 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
572 static int gunze_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
574 if (!(pkt
[0] & 0x80) || ((pkt
[1] | pkt
[2] | pkt
[3]) & 0x80))
577 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[2] & 0x7F);
578 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[3] & 0x7F);
579 dev
->touch
= pkt
[0] & 0x20;
585 /*****************************************************************************
588 * Documentation about the controller and it's protocol can be found at
589 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
590 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
592 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
594 /* supported data rates. currently using 130 */
595 #define TSC10_RATE_POINT 0x50
596 #define TSC10_RATE_30 0x40
597 #define TSC10_RATE_50 0x41
598 #define TSC10_RATE_80 0x42
599 #define TSC10_RATE_100 0x43
600 #define TSC10_RATE_130 0x44
601 #define TSC10_RATE_150 0x45
604 #define TSC10_CMD_RESET 0x55
605 #define TSC10_CMD_RATE 0x05
606 #define TSC10_CMD_DATA1 0x01
608 static int dmc_tsc10_init(struct usbtouch_usb
*usbtouch
)
610 struct usb_device
*dev
= interface_to_usbdev(usbtouch
->interface
);
614 buf
= kmalloc(2, GFP_NOIO
);
618 buf
[0] = buf
[1] = 0xFF;
619 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
621 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
622 0, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
625 if (buf
[0] != 0x06) {
630 /* TSC-25 data sheet specifies a delay after the RESET command */
633 /* set coordinate output rate */
634 buf
[0] = buf
[1] = 0xFF;
635 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
637 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
638 TSC10_RATE_150
, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
641 if ((buf
[0] != 0x06) && (buf
[0] != 0x15 || buf
[1] != 0x01)) {
646 /* start sending data */
647 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
649 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
650 0, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
658 static int dmc_tsc10_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
660 dev
->x
= ((pkt
[2] & 0x03) << 8) | pkt
[1];
661 dev
->y
= ((pkt
[4] & 0x03) << 8) | pkt
[3];
662 dev
->touch
= pkt
[0] & 0x01;
669 /*****************************************************************************
672 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
673 static int irtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
675 dev
->x
= (pkt
[3] << 8) | pkt
[2];
676 dev
->y
= (pkt
[5] << 8) | pkt
[4];
677 dev
->touch
= (pkt
[1] & 0x03) ? 1 : 0;
683 /*****************************************************************************
684 * ET&T TC5UH/TC4UM part
686 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
687 static int tc45usb_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
689 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
690 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
691 dev
->touch
= pkt
[0] & 0x01;
697 /*****************************************************************************
698 * IdealTEK URTC1000 Part
700 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
704 static int idealtek_get_pkt_len(unsigned char *buf
, int len
)
713 static int idealtek_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
715 switch (pkt
[0] & 0x98) {
717 /* touch data in IdealTEK mode */
718 dev
->x
= (pkt
[1] << 5) | (pkt
[2] >> 2);
719 dev
->y
= (pkt
[3] << 5) | (pkt
[4] >> 2);
720 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
724 /* touch data in MT emulation mode */
725 dev
->x
= (pkt
[2] << 5) | (pkt
[1] >> 2);
726 dev
->y
= (pkt
[4] << 5) | (pkt
[3] >> 2);
727 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
736 /*****************************************************************************
739 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
740 static int general_touch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
742 dev
->x
= (pkt
[2] << 8) | pkt
[1];
743 dev
->y
= (pkt
[4] << 8) | pkt
[3];
744 dev
->press
= pkt
[5] & 0xff;
745 dev
->touch
= pkt
[0] & 0x01;
751 /*****************************************************************************
754 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
755 static int gotop_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
757 dev
->x
= ((pkt
[1] & 0x38) << 4) | pkt
[2];
758 dev
->y
= ((pkt
[1] & 0x07) << 7) | pkt
[3];
759 dev
->touch
= pkt
[0] & 0x01;
765 /*****************************************************************************
768 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
769 static int jastec_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
771 dev
->x
= ((pkt
[0] & 0x3f) << 6) | (pkt
[2] & 0x3f);
772 dev
->y
= ((pkt
[1] & 0x3f) << 6) | (pkt
[3] & 0x3f);
773 dev
->touch
= (pkt
[0] & 0x40) >> 6;
779 /*****************************************************************************
782 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
783 static int zytronic_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
785 struct usb_interface
*intf
= dev
->interface
;
788 case 0x3A: /* command response */
789 dev_dbg(&intf
->dev
, "%s: Command response %d\n", __func__
, pkt
[1]);
792 case 0xC0: /* down */
793 dev
->x
= (pkt
[1] & 0x7f) | ((pkt
[2] & 0x07) << 7);
794 dev
->y
= (pkt
[3] & 0x7f) | ((pkt
[4] & 0x07) << 7);
796 dev_dbg(&intf
->dev
, "%s: down %d,%d\n", __func__
, dev
->x
, dev
->y
);
800 dev
->x
= (pkt
[1] & 0x7f) | ((pkt
[2] & 0x07) << 7);
801 dev
->y
= (pkt
[3] & 0x7f) | ((pkt
[4] & 0x07) << 7);
803 dev_dbg(&intf
->dev
, "%s: up %d,%d\n", __func__
, dev
->x
, dev
->y
);
807 dev_dbg(&intf
->dev
, "%s: Unknown return %d\n", __func__
, pkt
[0]);
815 /*****************************************************************************
818 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
820 #define NEXIO_TIMEOUT 5000
821 #define NEXIO_BUFSIZE 1024
822 #define NEXIO_THRESHOLD 50
826 unsigned char *ack_buf
;
829 struct nexio_touch_packet
{
830 u8 flags
; /* 0xe1 = touch, 0xe1 = release */
831 __be16 data_len
; /* total bytes of touch data */
832 __be16 x_len
; /* bytes for X axis */
833 __be16 y_len
; /* bytes for Y axis */
835 } __attribute__ ((packed
));
837 static unsigned char nexio_ack_pkt
[2] = { 0xaa, 0x02 };
838 static unsigned char nexio_init_pkt
[4] = { 0x82, 0x04, 0x0a, 0x0f };
840 static void nexio_ack_complete(struct urb
*urb
)
844 static int nexio_alloc(struct usbtouch_usb
*usbtouch
)
846 struct nexio_priv
*priv
;
849 usbtouch
->priv
= kmalloc(sizeof(struct nexio_priv
), GFP_KERNEL
);
853 priv
= usbtouch
->priv
;
855 priv
->ack_buf
= kmemdup(nexio_ack_pkt
, sizeof(nexio_ack_pkt
),
860 priv
->ack
= usb_alloc_urb(0, GFP_KERNEL
);
862 dev_dbg(&usbtouch
->interface
->dev
,
863 "%s - usb_alloc_urb failed: usbtouch->ack\n", __func__
);
870 kfree(priv
->ack_buf
);
877 static int nexio_init(struct usbtouch_usb
*usbtouch
)
879 struct usb_device
*dev
= interface_to_usbdev(usbtouch
->interface
);
880 struct usb_host_interface
*interface
= usbtouch
->interface
->cur_altsetting
;
881 struct nexio_priv
*priv
= usbtouch
->priv
;
885 char *firmware_ver
= NULL
, *device_name
= NULL
;
886 int input_ep
= 0, output_ep
= 0;
888 /* find first input and output endpoint */
889 for (i
= 0; i
< interface
->desc
.bNumEndpoints
; i
++) {
891 usb_endpoint_dir_in(&interface
->endpoint
[i
].desc
))
892 input_ep
= interface
->endpoint
[i
].desc
.bEndpointAddress
;
894 usb_endpoint_dir_out(&interface
->endpoint
[i
].desc
))
895 output_ep
= interface
->endpoint
[i
].desc
.bEndpointAddress
;
897 if (!input_ep
|| !output_ep
)
900 buf
= kmalloc(NEXIO_BUFSIZE
, GFP_NOIO
);
904 /* two empty reads */
905 for (i
= 0; i
< 2; i
++) {
906 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, input_ep
),
907 buf
, NEXIO_BUFSIZE
, &actual_len
,
913 /* send init command */
914 memcpy(buf
, nexio_init_pkt
, sizeof(nexio_init_pkt
));
915 ret
= usb_bulk_msg(dev
, usb_sndbulkpipe(dev
, output_ep
),
916 buf
, sizeof(nexio_init_pkt
), &actual_len
,
922 for (i
= 0; i
< 3; i
++) {
923 memset(buf
, 0, NEXIO_BUFSIZE
);
924 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, input_ep
),
925 buf
, NEXIO_BUFSIZE
, &actual_len
,
927 if (ret
< 0 || actual_len
< 1 || buf
[1] != actual_len
)
930 case 0x83: /* firmware version */
932 firmware_ver
= kstrdup(&buf
[2], GFP_NOIO
);
934 case 0x84: /* device name */
936 device_name
= kstrdup(&buf
[2], GFP_NOIO
);
941 printk(KERN_INFO
"Nexio device: %s, firmware version: %s\n",
942 device_name
, firmware_ver
);
947 usb_fill_bulk_urb(priv
->ack
, dev
, usb_sndbulkpipe(dev
, output_ep
),
948 priv
->ack_buf
, sizeof(nexio_ack_pkt
),
949 nexio_ack_complete
, usbtouch
);
957 static void nexio_exit(struct usbtouch_usb
*usbtouch
)
959 struct nexio_priv
*priv
= usbtouch
->priv
;
961 usb_kill_urb(priv
->ack
);
962 usb_free_urb(priv
->ack
);
963 kfree(priv
->ack_buf
);
967 static int nexio_read_data(struct usbtouch_usb
*usbtouch
, unsigned char *pkt
)
969 struct nexio_touch_packet
*packet
= (void *) pkt
;
970 struct nexio_priv
*priv
= usbtouch
->priv
;
971 unsigned int data_len
= be16_to_cpu(packet
->data_len
);
972 unsigned int x_len
= be16_to_cpu(packet
->x_len
);
973 unsigned int y_len
= be16_to_cpu(packet
->y_len
);
974 int x
, y
, begin_x
, begin_y
, end_x
, end_y
, w
, h
, ret
;
976 /* got touch data? */
977 if ((pkt
[0] & 0xe0) != 0xe0)
986 ret
= usb_submit_urb(priv
->ack
, GFP_ATOMIC
);
988 if (!usbtouch
->type
->max_xc
) {
989 usbtouch
->type
->max_xc
= 2 * x_len
;
990 input_set_abs_params(usbtouch
->input
, ABS_X
,
991 0, usbtouch
->type
->max_xc
, 0, 0);
992 usbtouch
->type
->max_yc
= 2 * y_len
;
993 input_set_abs_params(usbtouch
->input
, ABS_Y
,
994 0, usbtouch
->type
->max_yc
, 0, 0);
997 * The device reports state of IR sensors on X and Y axes.
998 * Each byte represents "darkness" percentage (0-100) of one element.
999 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
1000 * This also means that there's a limited multi-touch capability but
1001 * it's disabled (and untested) here as there's no X driver for that.
1003 begin_x
= end_x
= begin_y
= end_y
= -1;
1004 for (x
= 0; x
< x_len
; x
++) {
1005 if (begin_x
== -1 && packet
->data
[x
] > NEXIO_THRESHOLD
) {
1009 if (end_x
== -1 && begin_x
!= -1 && packet
->data
[x
] < NEXIO_THRESHOLD
) {
1011 for (y
= x_len
; y
< data_len
; y
++) {
1012 if (begin_y
== -1 && packet
->data
[y
] > NEXIO_THRESHOLD
) {
1013 begin_y
= y
- x_len
;
1017 begin_y
!= -1 && packet
->data
[y
] < NEXIO_THRESHOLD
) {
1018 end_y
= y
- 1 - x_len
;
1019 w
= end_x
- begin_x
;
1020 h
= end_y
- begin_y
;
1023 input_report_abs(usbtouch
->input
,
1024 ABS_MT_TOUCH_MAJOR
, max(w
,h
));
1025 input_report_abs(usbtouch
->input
,
1026 ABS_MT_TOUCH_MINOR
, min(x
,h
));
1027 input_report_abs(usbtouch
->input
,
1028 ABS_MT_POSITION_X
, 2*begin_x
+w
);
1029 input_report_abs(usbtouch
->input
,
1030 ABS_MT_POSITION_Y
, 2*begin_y
+h
);
1031 input_report_abs(usbtouch
->input
,
1032 ABS_MT_ORIENTATION
, w
> h
);
1033 input_mt_sync(usbtouch
->input
);
1036 usbtouch
->x
= 2 * begin_x
+ w
;
1037 usbtouch
->y
= 2 * begin_y
+ h
;
1038 usbtouch
->touch
= packet
->flags
& 0x01;
1039 begin_y
= end_y
= -1;
1043 begin_x
= end_x
= -1;
1052 /*****************************************************************************
1056 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
1058 static int elo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
1060 dev
->x
= (pkt
[3] << 8) | pkt
[2];
1061 dev
->y
= (pkt
[5] << 8) | pkt
[4];
1062 dev
->touch
= pkt
[6] > 0;
1063 dev
->press
= pkt
[6];
1070 /*****************************************************************************
1071 * the different device descriptors
1074 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
1075 unsigned char *pkt
, int len
);
1078 static struct usbtouch_device_info usbtouch_dev_info
[] = {
1079 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
1087 .read_data
= elo_read_data
,
1091 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
1092 [DEVTYPE_EGALAX
] = {
1098 .process_pkt
= usbtouch_process_multi
,
1099 .get_pkt_len
= egalax_get_pkt_len
,
1100 .read_data
= egalax_read_data
,
1101 .init
= egalax_init
,
1105 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
1106 [DEVTYPE_PANJIT
] = {
1112 .read_data
= panjit_read_data
,
1116 #ifdef CONFIG_TOUCHSCREEN_USB_3M
1123 .read_data
= mtouch_read_data
,
1124 .init
= mtouch_init
,
1128 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
1136 .read_data
= itm_read_data
,
1140 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
1141 [DEVTYPE_ETURBO
] = {
1147 .process_pkt
= usbtouch_process_multi
,
1148 .get_pkt_len
= eturbo_get_pkt_len
,
1149 .read_data
= eturbo_read_data
,
1153 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
1160 .read_data
= gunze_read_data
,
1164 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
1165 [DEVTYPE_DMC_TSC10
] = {
1171 .init
= dmc_tsc10_init
,
1172 .read_data
= dmc_tsc10_read_data
,
1176 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
1177 [DEVTYPE_IRTOUCH
] = {
1183 .read_data
= irtouch_read_data
,
1186 [DEVTYPE_IRTOUCH_HIRES
] = {
1192 .read_data
= irtouch_read_data
,
1196 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
1197 [DEVTYPE_IDEALTEK
] = {
1203 .process_pkt
= usbtouch_process_multi
,
1204 .get_pkt_len
= idealtek_get_pkt_len
,
1205 .read_data
= idealtek_read_data
,
1209 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1210 [DEVTYPE_GENERAL_TOUCH
] = {
1216 .read_data
= general_touch_read_data
,
1220 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
1227 .read_data
= gotop_read_data
,
1231 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
1232 [DEVTYPE_JASTEC
] = {
1238 .read_data
= jastec_read_data
,
1242 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
1250 .read_data
= e2i_read_data
,
1254 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1255 [DEVTYPE_ZYTRONIC
] = {
1261 .read_data
= zytronic_read_data
,
1266 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1267 [DEVTYPE_TC45USB
] = {
1273 .read_data
= tc45usb_read_data
,
1277 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1281 .read_data
= nexio_read_data
,
1282 .alloc
= nexio_alloc
,
1287 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
1288 [DEVTYPE_ETOUCH
] = {
1294 .process_pkt
= usbtouch_process_multi
,
1295 .get_pkt_len
= etouch_get_pkt_len
,
1296 .read_data
= etouch_read_data
,
1302 /*****************************************************************************
1305 static void usbtouch_process_pkt(struct usbtouch_usb
*usbtouch
,
1306 unsigned char *pkt
, int len
)
1308 struct usbtouch_device_info
*type
= usbtouch
->type
;
1310 if (!type
->read_data(usbtouch
, pkt
))
1313 input_report_key(usbtouch
->input
, BTN_TOUCH
, usbtouch
->touch
);
1316 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->y
);
1317 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->x
);
1319 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->x
);
1320 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->y
);
1322 if (type
->max_press
)
1323 input_report_abs(usbtouch
->input
, ABS_PRESSURE
, usbtouch
->press
);
1324 input_sync(usbtouch
->input
);
1329 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
1330 unsigned char *pkt
, int len
)
1332 unsigned char *buffer
;
1333 int pkt_len
, pos
, buf_len
, tmp
;
1335 /* process buffer */
1336 if (unlikely(usbtouch
->buf_len
)) {
1337 /* try to get size */
1338 pkt_len
= usbtouch
->type
->get_pkt_len(
1339 usbtouch
->buffer
, usbtouch
->buf_len
);
1342 if (unlikely(!pkt_len
))
1345 /* need to append -pkt_len bytes before able to get size */
1346 if (unlikely(pkt_len
< 0)) {
1347 int append
= -pkt_len
;
1348 if (unlikely(append
> len
))
1350 if (usbtouch
->buf_len
+ append
>= usbtouch
->type
->rept_size
)
1352 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, append
);
1353 usbtouch
->buf_len
+= append
;
1355 pkt_len
= usbtouch
->type
->get_pkt_len(
1356 usbtouch
->buffer
, usbtouch
->buf_len
);
1362 tmp
= pkt_len
- usbtouch
->buf_len
;
1363 if (usbtouch
->buf_len
+ tmp
>= usbtouch
->type
->rept_size
)
1365 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, tmp
);
1366 usbtouch_process_pkt(usbtouch
, usbtouch
->buffer
, pkt_len
);
1369 buf_len
= len
- tmp
;
1375 /* loop over the received packet, process */
1377 while (pos
< buf_len
) {
1378 /* get packet len */
1379 pkt_len
= usbtouch
->type
->get_pkt_len(buffer
+ pos
,
1382 /* unknown packet: skip one byte */
1383 if (unlikely(!pkt_len
)) {
1388 /* full packet: process */
1389 if (likely((pkt_len
> 0) && (pkt_len
<= buf_len
- pos
))) {
1390 usbtouch_process_pkt(usbtouch
, buffer
+ pos
, pkt_len
);
1392 /* incomplete packet: save in buffer */
1393 memcpy(usbtouch
->buffer
, buffer
+ pos
, buf_len
- pos
);
1394 usbtouch
->buf_len
= buf_len
- pos
;
1401 usbtouch
->buf_len
= 0;
1407 static void usbtouch_irq(struct urb
*urb
)
1409 struct usbtouch_usb
*usbtouch
= urb
->context
;
1410 struct device
*dev
= &usbtouch
->interface
->dev
;
1413 switch (urb
->status
) {
1418 /* this urb is timing out */
1420 "%s - urb timed out - was the device unplugged?\n",
1427 /* this urb is terminated, clean up */
1428 dev_dbg(dev
, "%s - urb shutting down with status: %d\n",
1429 __func__
, urb
->status
);
1432 dev_dbg(dev
, "%s - nonzero urb status received: %d\n",
1433 __func__
, urb
->status
);
1437 usbtouch
->type
->process_pkt(usbtouch
, usbtouch
->data
, urb
->actual_length
);
1440 usb_mark_last_busy(interface_to_usbdev(usbtouch
->interface
));
1441 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
1443 dev_err(dev
, "%s - usb_submit_urb failed with result: %d\n",
1447 static int usbtouch_open(struct input_dev
*input
)
1449 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
1452 usbtouch
->irq
->dev
= interface_to_usbdev(usbtouch
->interface
);
1454 r
= usb_autopm_get_interface(usbtouch
->interface
) ? -EIO
: 0;
1458 if (!usbtouch
->type
->irq_always
) {
1459 if (usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
)) {
1465 usbtouch
->interface
->needs_remote_wakeup
= 1;
1467 usb_autopm_put_interface(usbtouch
->interface
);
1472 static void usbtouch_close(struct input_dev
*input
)
1474 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
1477 if (!usbtouch
->type
->irq_always
)
1478 usb_kill_urb(usbtouch
->irq
);
1479 r
= usb_autopm_get_interface(usbtouch
->interface
);
1480 usbtouch
->interface
->needs_remote_wakeup
= 0;
1482 usb_autopm_put_interface(usbtouch
->interface
);
1485 static int usbtouch_suspend
1486 (struct usb_interface
*intf
, pm_message_t message
)
1488 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1490 usb_kill_urb(usbtouch
->irq
);
1495 static int usbtouch_resume(struct usb_interface
*intf
)
1497 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1498 struct input_dev
*input
= usbtouch
->input
;
1501 mutex_lock(&input
->mutex
);
1502 if (input
->users
|| usbtouch
->type
->irq_always
)
1503 result
= usb_submit_urb(usbtouch
->irq
, GFP_NOIO
);
1504 mutex_unlock(&input
->mutex
);
1509 static int usbtouch_reset_resume(struct usb_interface
*intf
)
1511 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1512 struct input_dev
*input
= usbtouch
->input
;
1515 /* reinit the device */
1516 if (usbtouch
->type
->init
) {
1517 err
= usbtouch
->type
->init(usbtouch
);
1520 "%s - type->init() failed, err: %d\n",
1526 /* restart IO if needed */
1527 mutex_lock(&input
->mutex
);
1529 err
= usb_submit_urb(usbtouch
->irq
, GFP_NOIO
);
1530 mutex_unlock(&input
->mutex
);
1535 static void usbtouch_free_buffers(struct usb_device
*udev
,
1536 struct usbtouch_usb
*usbtouch
)
1538 usb_free_coherent(udev
, usbtouch
->data_size
,
1539 usbtouch
->data
, usbtouch
->data_dma
);
1540 kfree(usbtouch
->buffer
);
1543 static struct usb_endpoint_descriptor
*
1544 usbtouch_get_input_endpoint(struct usb_host_interface
*interface
)
1548 for (i
= 0; i
< interface
->desc
.bNumEndpoints
; i
++)
1549 if (usb_endpoint_dir_in(&interface
->endpoint
[i
].desc
))
1550 return &interface
->endpoint
[i
].desc
;
1555 static int usbtouch_probe(struct usb_interface
*intf
,
1556 const struct usb_device_id
*id
)
1558 struct usbtouch_usb
*usbtouch
;
1559 struct input_dev
*input_dev
;
1560 struct usb_endpoint_descriptor
*endpoint
;
1561 struct usb_device
*udev
= interface_to_usbdev(intf
);
1562 struct usbtouch_device_info
*type
;
1565 /* some devices are ignored */
1566 if (id
->driver_info
== DEVTYPE_IGNORE
)
1569 endpoint
= usbtouch_get_input_endpoint(intf
->cur_altsetting
);
1573 usbtouch
= kzalloc(sizeof(struct usbtouch_usb
), GFP_KERNEL
);
1574 input_dev
= input_allocate_device();
1575 if (!usbtouch
|| !input_dev
)
1578 type
= &usbtouch_dev_info
[id
->driver_info
];
1579 usbtouch
->type
= type
;
1580 if (!type
->process_pkt
)
1581 type
->process_pkt
= usbtouch_process_pkt
;
1583 usbtouch
->data_size
= type
->rept_size
;
1584 if (type
->get_pkt_len
) {
1586 * When dealing with variable-length packets we should
1587 * not request more than wMaxPacketSize bytes at once
1588 * as we do not know if there is more data coming or
1589 * we filled exactly wMaxPacketSize bytes and there is
1592 usbtouch
->data_size
= min(usbtouch
->data_size
,
1593 usb_endpoint_maxp(endpoint
));
1596 usbtouch
->data
= usb_alloc_coherent(udev
, usbtouch
->data_size
,
1597 GFP_KERNEL
, &usbtouch
->data_dma
);
1598 if (!usbtouch
->data
)
1601 if (type
->get_pkt_len
) {
1602 usbtouch
->buffer
= kmalloc(type
->rept_size
, GFP_KERNEL
);
1603 if (!usbtouch
->buffer
)
1604 goto out_free_buffers
;
1607 usbtouch
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
1608 if (!usbtouch
->irq
) {
1610 "%s - usb_alloc_urb failed: usbtouch->irq\n", __func__
);
1611 goto out_free_buffers
;
1614 usbtouch
->interface
= intf
;
1615 usbtouch
->input
= input_dev
;
1617 if (udev
->manufacturer
)
1618 strlcpy(usbtouch
->name
, udev
->manufacturer
, sizeof(usbtouch
->name
));
1620 if (udev
->product
) {
1621 if (udev
->manufacturer
)
1622 strlcat(usbtouch
->name
, " ", sizeof(usbtouch
->name
));
1623 strlcat(usbtouch
->name
, udev
->product
, sizeof(usbtouch
->name
));
1626 if (!strlen(usbtouch
->name
))
1627 snprintf(usbtouch
->name
, sizeof(usbtouch
->name
),
1628 "USB Touchscreen %04x:%04x",
1629 le16_to_cpu(udev
->descriptor
.idVendor
),
1630 le16_to_cpu(udev
->descriptor
.idProduct
));
1632 usb_make_path(udev
, usbtouch
->phys
, sizeof(usbtouch
->phys
));
1633 strlcat(usbtouch
->phys
, "/input0", sizeof(usbtouch
->phys
));
1635 input_dev
->name
= usbtouch
->name
;
1636 input_dev
->phys
= usbtouch
->phys
;
1637 usb_to_input_id(udev
, &input_dev
->id
);
1638 input_dev
->dev
.parent
= &intf
->dev
;
1640 input_set_drvdata(input_dev
, usbtouch
);
1642 input_dev
->open
= usbtouch_open
;
1643 input_dev
->close
= usbtouch_close
;
1645 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
1646 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
1647 input_set_abs_params(input_dev
, ABS_X
, type
->min_xc
, type
->max_xc
, 0, 0);
1648 input_set_abs_params(input_dev
, ABS_Y
, type
->min_yc
, type
->max_yc
, 0, 0);
1649 if (type
->max_press
)
1650 input_set_abs_params(input_dev
, ABS_PRESSURE
, type
->min_press
,
1651 type
->max_press
, 0, 0);
1653 if (usb_endpoint_type(endpoint
) == USB_ENDPOINT_XFER_INT
)
1654 usb_fill_int_urb(usbtouch
->irq
, udev
,
1655 usb_rcvintpipe(udev
, endpoint
->bEndpointAddress
),
1656 usbtouch
->data
, usbtouch
->data_size
,
1657 usbtouch_irq
, usbtouch
, endpoint
->bInterval
);
1659 usb_fill_bulk_urb(usbtouch
->irq
, udev
,
1660 usb_rcvbulkpipe(udev
, endpoint
->bEndpointAddress
),
1661 usbtouch
->data
, usbtouch
->data_size
,
1662 usbtouch_irq
, usbtouch
);
1664 usbtouch
->irq
->dev
= udev
;
1665 usbtouch
->irq
->transfer_dma
= usbtouch
->data_dma
;
1666 usbtouch
->irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1668 /* device specific allocations */
1670 err
= type
->alloc(usbtouch
);
1673 "%s - type->alloc() failed, err: %d\n",
1679 /* device specific initialisation*/
1681 err
= type
->init(usbtouch
);
1684 "%s - type->init() failed, err: %d\n",
1690 err
= input_register_device(usbtouch
->input
);
1693 "%s - input_register_device failed, err: %d\n",
1698 usb_set_intfdata(intf
, usbtouch
);
1700 if (usbtouch
->type
->irq_always
) {
1701 /* this can't fail */
1702 usb_autopm_get_interface(intf
);
1703 err
= usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
);
1705 usb_autopm_put_interface(intf
);
1707 "%s - usb_submit_urb failed with result: %d\n",
1709 goto out_unregister_input
;
1715 out_unregister_input
:
1716 input_unregister_device(input_dev
);
1720 type
->exit(usbtouch
);
1722 usb_free_urb(usbtouch
->irq
);
1724 usbtouch_free_buffers(udev
, usbtouch
);
1726 input_free_device(input_dev
);
1731 static void usbtouch_disconnect(struct usb_interface
*intf
)
1733 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1739 "%s - usbtouch is initialized, cleaning up\n", __func__
);
1741 usb_set_intfdata(intf
, NULL
);
1742 /* this will stop IO via close */
1743 input_unregister_device(usbtouch
->input
);
1744 usb_free_urb(usbtouch
->irq
);
1745 if (usbtouch
->type
->exit
)
1746 usbtouch
->type
->exit(usbtouch
);
1747 usbtouch_free_buffers(interface_to_usbdev(intf
), usbtouch
);
1751 MODULE_DEVICE_TABLE(usb
, usbtouch_devices
);
1753 static struct usb_driver usbtouch_driver
= {
1754 .name
= "usbtouchscreen",
1755 .probe
= usbtouch_probe
,
1756 .disconnect
= usbtouch_disconnect
,
1757 .suspend
= usbtouch_suspend
,
1758 .resume
= usbtouch_resume
,
1759 .reset_resume
= usbtouch_reset_resume
,
1760 .id_table
= usbtouch_devices
,
1761 .supports_autosuspend
= 1,
1764 module_usb_driver(usbtouch_driver
);
1766 MODULE_AUTHOR(DRIVER_AUTHOR
);
1767 MODULE_DESCRIPTION(DRIVER_DESC
);
1768 MODULE_LICENSE("GPL");
1770 MODULE_ALIAS("touchkitusb");
1771 MODULE_ALIAS("itmtouch");
1772 MODULE_ALIAS("mtouchusb");