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/init.h>
55 #include <linux/usb.h>
56 #include <linux/usb/input.h>
57 #include <linux/hid.h>
60 #define DRIVER_VERSION "v0.6"
61 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
62 #define DRIVER_DESC "USB Touchscreen Driver"
65 module_param(swap_xy
, bool, 0644);
66 MODULE_PARM_DESC(swap_xy
, "If set X and Y axes are swapped.");
68 static bool hwcalib_xy
;
69 module_param(hwcalib_xy
, bool, 0644);
70 MODULE_PARM_DESC(hwcalib_xy
, "If set hw-calibrated X/Y are used if available");
72 /* device specifc data/functions */
74 struct usbtouch_device_info
{
77 int min_press
, max_press
;
81 * Always service the USB devices irq not just when the input device is
82 * open. This is useful when devices have a watchdog which prevents us
83 * from periodically polling the device. Leave this unset unless your
84 * touchscreen device requires it, as it does consume more of the USB
89 void (*process_pkt
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
, int len
);
92 * used to get the packet len. possible return values:
95 * < 0: -return value more bytes needed
97 int (*get_pkt_len
) (unsigned char *pkt
, int len
);
99 int (*read_data
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
);
100 int (*alloc
) (struct usbtouch_usb
*usbtouch
);
101 int (*init
) (struct usbtouch_usb
*usbtouch
);
102 void (*exit
) (struct usbtouch_usb
*usbtouch
);
105 /* a usbtouch device */
106 struct usbtouch_usb
{
110 unsigned char *buffer
;
113 struct usb_interface
*interface
;
114 struct input_dev
*input
;
115 struct usbtouch_device_info
*type
;
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
},
204 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
205 {USB_DEVICE(0x1391, 0x1000), .driver_info
= DEVTYPE_IDEALTEK
},
208 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
209 {USB_DEVICE(0x0dfc, 0x0001), .driver_info
= DEVTYPE_GENERAL_TOUCH
},
212 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
213 {USB_DEVICE(0x08f2, 0x007f), .driver_info
= DEVTYPE_GOTOP
},
214 {USB_DEVICE(0x08f2, 0x00ce), .driver_info
= DEVTYPE_GOTOP
},
215 {USB_DEVICE(0x08f2, 0x00f4), .driver_info
= DEVTYPE_GOTOP
},
218 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
219 {USB_DEVICE(0x0f92, 0x0001), .driver_info
= DEVTYPE_JASTEC
},
222 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
223 {USB_DEVICE(0x1ac7, 0x0001), .driver_info
= DEVTYPE_E2I
},
226 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
227 {USB_DEVICE(0x14c8, 0x0003), .driver_info
= DEVTYPE_ZYTRONIC
},
230 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
232 {USB_DEVICE(0x0664, 0x0309), .driver_info
= DEVTYPE_TC45USB
},
234 {USB_DEVICE(0x0664, 0x0306), .driver_info
= DEVTYPE_TC45USB
},
237 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
238 /* data interface only */
239 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
240 .driver_info
= DEVTYPE_NEXIO
},
241 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
242 .driver_info
= DEVTYPE_NEXIO
},
245 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
246 {USB_DEVICE(0x04e7, 0x0020), .driver_info
= DEVTYPE_ELO
},
249 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
250 {USB_DEVICE(0x7374, 0x0001), .driver_info
= DEVTYPE_ETOUCH
},
257 /*****************************************************************************
261 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
262 static int e2i_init(struct usbtouch_usb
*usbtouch
)
265 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
267 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
268 0x01, 0x02, 0x0000, 0x0081,
269 NULL
, 0, USB_CTRL_SET_TIMEOUT
);
271 dev_dbg(&usbtouch
->interface
->dev
,
272 "%s - usb_control_msg - E2I_RESET - bytes|err: %d\n",
277 static int e2i_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
279 int tmp
= (pkt
[0] << 8) | pkt
[1];
280 dev
->x
= (pkt
[2] << 8) | pkt
[3];
281 dev
->y
= (pkt
[4] << 8) | pkt
[5];
284 dev
->touch
= (tmp
> 0);
285 dev
->press
= (tmp
> 0 ? tmp
: 0);
292 /*****************************************************************************
296 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
302 #define EGALAX_PKT_TYPE_MASK 0xFE
303 #define EGALAX_PKT_TYPE_REPT 0x80
304 #define EGALAX_PKT_TYPE_DIAG 0x0A
306 static int egalax_init(struct usbtouch_usb
*usbtouch
)
310 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
313 * An eGalax diagnostic packet kicks the device into using the right
314 * protocol. We send a "check active" packet. The response will be
315 * read later and ignored.
318 buf
= kmalloc(3, GFP_KERNEL
);
322 buf
[0] = EGALAX_PKT_TYPE_DIAG
;
323 buf
[1] = 1; /* length */
324 buf
[2] = 'A'; /* command - check active */
326 for (i
= 0; i
< 3; i
++) {
327 ret
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
329 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
331 USB_CTRL_SET_TIMEOUT
);
345 static int egalax_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
347 if ((pkt
[0] & EGALAX_PKT_TYPE_MASK
) != EGALAX_PKT_TYPE_REPT
)
350 dev
->x
= ((pkt
[3] & 0x0F) << 7) | (pkt
[4] & 0x7F);
351 dev
->y
= ((pkt
[1] & 0x0F) << 7) | (pkt
[2] & 0x7F);
352 dev
->touch
= pkt
[0] & 0x01;
357 static int egalax_get_pkt_len(unsigned char *buf
, int len
)
359 switch (buf
[0] & EGALAX_PKT_TYPE_MASK
) {
360 case EGALAX_PKT_TYPE_REPT
:
363 case EGALAX_PKT_TYPE_DIAG
:
374 /*****************************************************************************
378 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
384 #define ETOUCH_PKT_TYPE_MASK 0xFE
385 #define ETOUCH_PKT_TYPE_REPT 0x80
386 #define ETOUCH_PKT_TYPE_REPT2 0xB0
387 #define ETOUCH_PKT_TYPE_DIAG 0x0A
389 static int etouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
391 if ((pkt
[0] & ETOUCH_PKT_TYPE_MASK
) != ETOUCH_PKT_TYPE_REPT
&&
392 (pkt
[0] & ETOUCH_PKT_TYPE_MASK
) != ETOUCH_PKT_TYPE_REPT2
)
395 dev
->x
= ((pkt
[1] & 0x1F) << 7) | (pkt
[2] & 0x7F);
396 dev
->y
= ((pkt
[3] & 0x1F) << 7) | (pkt
[4] & 0x7F);
397 dev
->touch
= pkt
[0] & 0x01;
402 static int etouch_get_pkt_len(unsigned char *buf
, int len
)
404 switch (buf
[0] & ETOUCH_PKT_TYPE_MASK
) {
405 case ETOUCH_PKT_TYPE_REPT
:
406 case ETOUCH_PKT_TYPE_REPT2
:
409 case ETOUCH_PKT_TYPE_DIAG
:
420 /*****************************************************************************
423 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
424 static int panjit_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
426 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
427 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
428 dev
->touch
= pkt
[0] & 0x01;
435 /*****************************************************************************
438 #ifdef CONFIG_TOUCHSCREEN_USB_3M
440 #define MTOUCHUSB_ASYNC_REPORT 1
441 #define MTOUCHUSB_RESET 7
442 #define MTOUCHUSB_REQ_CTRLLR_ID 10
444 static int mtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
447 dev
->x
= (pkt
[4] << 8) | pkt
[3];
448 dev
->y
= 0xffff - ((pkt
[6] << 8) | pkt
[5]);
450 dev
->x
= (pkt
[8] << 8) | pkt
[7];
451 dev
->y
= (pkt
[10] << 8) | pkt
[9];
453 dev
->touch
= (pkt
[2] & 0x40) ? 1 : 0;
458 static int mtouch_init(struct usbtouch_usb
*usbtouch
)
461 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
463 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
465 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
466 1, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
467 dev_dbg(&usbtouch
->interface
->dev
,
468 "%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d\n",
474 for (i
= 0; i
< 3; i
++) {
475 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
476 MTOUCHUSB_ASYNC_REPORT
,
477 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
478 1, 1, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
479 dev_dbg(&usbtouch
->interface
->dev
,
480 "%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d\n",
488 /* Default min/max xy are the raw values, override if using hw-calib */
490 input_set_abs_params(usbtouch
->input
, ABS_X
, 0, 0xffff, 0, 0);
491 input_set_abs_params(usbtouch
->input
, ABS_Y
, 0, 0xffff, 0, 0);
499 /*****************************************************************************
502 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
503 static int itm_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
507 * ITM devices report invalid x/y data if not touched.
508 * if the screen was touched before but is not touched any more
509 * report touch as 0 with the last valid x/y data once. then stop
510 * reporting data until touched again.
512 dev
->press
= ((pkt
[2] & 0x01) << 7) | (pkt
[5] & 0x7F);
514 touch
= ~pkt
[7] & 0x20;
524 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[3] & 0x7F);
525 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[4] & 0x7F);
533 /*****************************************************************************
536 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
540 static int eturbo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
544 /* packets should start with sync */
545 if (!(pkt
[0] & 0x80))
548 shift
= (6 - (pkt
[0] & 0x03));
549 dev
->x
= ((pkt
[3] << 7) | pkt
[4]) >> shift
;
550 dev
->y
= ((pkt
[1] << 7) | pkt
[2]) >> shift
;
551 dev
->touch
= (pkt
[0] & 0x10) ? 1 : 0;
556 static int eturbo_get_pkt_len(unsigned char *buf
, int len
)
567 /*****************************************************************************
570 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
571 static int gunze_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
573 if (!(pkt
[0] & 0x80) || ((pkt
[1] | pkt
[2] | pkt
[3]) & 0x80))
576 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[2] & 0x7F);
577 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[3] & 0x7F);
578 dev
->touch
= pkt
[0] & 0x20;
584 /*****************************************************************************
587 * Documentation about the controller and it's protocol can be found at
588 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
589 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
591 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
593 /* supported data rates. currently using 130 */
594 #define TSC10_RATE_POINT 0x50
595 #define TSC10_RATE_30 0x40
596 #define TSC10_RATE_50 0x41
597 #define TSC10_RATE_80 0x42
598 #define TSC10_RATE_100 0x43
599 #define TSC10_RATE_130 0x44
600 #define TSC10_RATE_150 0x45
603 #define TSC10_CMD_RESET 0x55
604 #define TSC10_CMD_RATE 0x05
605 #define TSC10_CMD_DATA1 0x01
607 static int dmc_tsc10_init(struct usbtouch_usb
*usbtouch
)
609 struct usb_device
*dev
= interface_to_usbdev(usbtouch
->interface
);
613 buf
= kmalloc(2, GFP_NOIO
);
617 buf
[0] = buf
[1] = 0xFF;
618 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
620 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
621 0, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
624 if (buf
[0] != 0x06) {
629 /* set coordinate output rate */
630 buf
[0] = buf
[1] = 0xFF;
631 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
633 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
634 TSC10_RATE_150
, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
637 if ((buf
[0] != 0x06) && (buf
[0] != 0x15 || buf
[1] != 0x01)) {
642 /* start sending data */
643 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
645 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
646 0, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
654 static int dmc_tsc10_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
656 dev
->x
= ((pkt
[2] & 0x03) << 8) | pkt
[1];
657 dev
->y
= ((pkt
[4] & 0x03) << 8) | pkt
[3];
658 dev
->touch
= pkt
[0] & 0x01;
665 /*****************************************************************************
668 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
669 static int irtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
671 dev
->x
= (pkt
[3] << 8) | pkt
[2];
672 dev
->y
= (pkt
[5] << 8) | pkt
[4];
673 dev
->touch
= (pkt
[1] & 0x03) ? 1 : 0;
679 /*****************************************************************************
680 * ET&T TC5UH/TC4UM part
682 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
683 static int tc45usb_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
685 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
686 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
687 dev
->touch
= pkt
[0] & 0x01;
693 /*****************************************************************************
694 * IdealTEK URTC1000 Part
696 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
700 static int idealtek_get_pkt_len(unsigned char *buf
, int len
)
709 static int idealtek_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
711 switch (pkt
[0] & 0x98) {
713 /* touch data in IdealTEK mode */
714 dev
->x
= (pkt
[1] << 5) | (pkt
[2] >> 2);
715 dev
->y
= (pkt
[3] << 5) | (pkt
[4] >> 2);
716 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
720 /* touch data in MT emulation mode */
721 dev
->x
= (pkt
[2] << 5) | (pkt
[1] >> 2);
722 dev
->y
= (pkt
[4] << 5) | (pkt
[3] >> 2);
723 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
732 /*****************************************************************************
735 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
736 static int general_touch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
738 dev
->x
= (pkt
[2] << 8) | pkt
[1];
739 dev
->y
= (pkt
[4] << 8) | pkt
[3];
740 dev
->press
= pkt
[5] & 0xff;
741 dev
->touch
= pkt
[0] & 0x01;
747 /*****************************************************************************
750 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
751 static int gotop_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
753 dev
->x
= ((pkt
[1] & 0x38) << 4) | pkt
[2];
754 dev
->y
= ((pkt
[1] & 0x07) << 7) | pkt
[3];
755 dev
->touch
= pkt
[0] & 0x01;
761 /*****************************************************************************
764 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
765 static int jastec_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
767 dev
->x
= ((pkt
[0] & 0x3f) << 6) | (pkt
[2] & 0x3f);
768 dev
->y
= ((pkt
[1] & 0x3f) << 6) | (pkt
[3] & 0x3f);
769 dev
->touch
= (pkt
[0] & 0x40) >> 6;
775 /*****************************************************************************
778 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
779 static int zytronic_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
781 struct usb_interface
*intf
= dev
->interface
;
784 case 0x3A: /* command response */
785 dev_dbg(&intf
->dev
, "%s: Command response %d\n", __func__
, pkt
[1]);
788 case 0xC0: /* down */
789 dev
->x
= (pkt
[1] & 0x7f) | ((pkt
[2] & 0x07) << 7);
790 dev
->y
= (pkt
[3] & 0x7f) | ((pkt
[4] & 0x07) << 7);
792 dev_dbg(&intf
->dev
, "%s: down %d,%d\n", __func__
, dev
->x
, dev
->y
);
796 dev
->x
= (pkt
[1] & 0x7f) | ((pkt
[2] & 0x07) << 7);
797 dev
->y
= (pkt
[3] & 0x7f) | ((pkt
[4] & 0x07) << 7);
799 dev_dbg(&intf
->dev
, "%s: up %d,%d\n", __func__
, dev
->x
, dev
->y
);
803 dev_dbg(&intf
->dev
, "%s: Unknown return %d\n", __func__
, pkt
[0]);
811 /*****************************************************************************
814 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
816 #define NEXIO_TIMEOUT 5000
817 #define NEXIO_BUFSIZE 1024
818 #define NEXIO_THRESHOLD 50
822 unsigned char *ack_buf
;
825 struct nexio_touch_packet
{
826 u8 flags
; /* 0xe1 = touch, 0xe1 = release */
827 __be16 data_len
; /* total bytes of touch data */
828 __be16 x_len
; /* bytes for X axis */
829 __be16 y_len
; /* bytes for Y axis */
831 } __attribute__ ((packed
));
833 static unsigned char nexio_ack_pkt
[2] = { 0xaa, 0x02 };
834 static unsigned char nexio_init_pkt
[4] = { 0x82, 0x04, 0x0a, 0x0f };
836 static void nexio_ack_complete(struct urb
*urb
)
840 static int nexio_alloc(struct usbtouch_usb
*usbtouch
)
842 struct nexio_priv
*priv
;
845 usbtouch
->priv
= kmalloc(sizeof(struct nexio_priv
), GFP_KERNEL
);
849 priv
= usbtouch
->priv
;
851 priv
->ack_buf
= kmemdup(nexio_ack_pkt
, sizeof(nexio_ack_pkt
),
856 priv
->ack
= usb_alloc_urb(0, GFP_KERNEL
);
858 dev_dbg(&usbtouch
->interface
->dev
,
859 "%s - usb_alloc_urb failed: usbtouch->ack\n", __func__
);
866 kfree(priv
->ack_buf
);
873 static int nexio_init(struct usbtouch_usb
*usbtouch
)
875 struct usb_device
*dev
= interface_to_usbdev(usbtouch
->interface
);
876 struct usb_host_interface
*interface
= usbtouch
->interface
->cur_altsetting
;
877 struct nexio_priv
*priv
= usbtouch
->priv
;
881 char *firmware_ver
= NULL
, *device_name
= NULL
;
882 int input_ep
= 0, output_ep
= 0;
884 /* find first input and output endpoint */
885 for (i
= 0; i
< interface
->desc
.bNumEndpoints
; i
++) {
887 usb_endpoint_dir_in(&interface
->endpoint
[i
].desc
))
888 input_ep
= interface
->endpoint
[i
].desc
.bEndpointAddress
;
890 usb_endpoint_dir_out(&interface
->endpoint
[i
].desc
))
891 output_ep
= interface
->endpoint
[i
].desc
.bEndpointAddress
;
893 if (!input_ep
|| !output_ep
)
896 buf
= kmalloc(NEXIO_BUFSIZE
, GFP_NOIO
);
900 /* two empty reads */
901 for (i
= 0; i
< 2; i
++) {
902 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, input_ep
),
903 buf
, NEXIO_BUFSIZE
, &actual_len
,
909 /* send init command */
910 memcpy(buf
, nexio_init_pkt
, sizeof(nexio_init_pkt
));
911 ret
= usb_bulk_msg(dev
, usb_sndbulkpipe(dev
, output_ep
),
912 buf
, sizeof(nexio_init_pkt
), &actual_len
,
918 for (i
= 0; i
< 3; i
++) {
919 memset(buf
, 0, NEXIO_BUFSIZE
);
920 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, input_ep
),
921 buf
, NEXIO_BUFSIZE
, &actual_len
,
923 if (ret
< 0 || actual_len
< 1 || buf
[1] != actual_len
)
926 case 0x83: /* firmware version */
928 firmware_ver
= kstrdup(&buf
[2], GFP_NOIO
);
930 case 0x84: /* device name */
932 device_name
= kstrdup(&buf
[2], GFP_NOIO
);
937 printk(KERN_INFO
"Nexio device: %s, firmware version: %s\n",
938 device_name
, firmware_ver
);
943 usb_fill_bulk_urb(priv
->ack
, dev
, usb_sndbulkpipe(dev
, output_ep
),
944 priv
->ack_buf
, sizeof(nexio_ack_pkt
),
945 nexio_ack_complete
, usbtouch
);
953 static void nexio_exit(struct usbtouch_usb
*usbtouch
)
955 struct nexio_priv
*priv
= usbtouch
->priv
;
957 usb_kill_urb(priv
->ack
);
958 usb_free_urb(priv
->ack
);
959 kfree(priv
->ack_buf
);
963 static int nexio_read_data(struct usbtouch_usb
*usbtouch
, unsigned char *pkt
)
965 struct nexio_touch_packet
*packet
= (void *) pkt
;
966 struct nexio_priv
*priv
= usbtouch
->priv
;
967 unsigned int data_len
= be16_to_cpu(packet
->data_len
);
968 unsigned int x_len
= be16_to_cpu(packet
->x_len
);
969 unsigned int y_len
= be16_to_cpu(packet
->y_len
);
970 int x
, y
, begin_x
, begin_y
, end_x
, end_y
, w
, h
, ret
;
972 /* got touch data? */
973 if ((pkt
[0] & 0xe0) != 0xe0)
982 ret
= usb_submit_urb(priv
->ack
, GFP_ATOMIC
);
984 if (!usbtouch
->type
->max_xc
) {
985 usbtouch
->type
->max_xc
= 2 * x_len
;
986 input_set_abs_params(usbtouch
->input
, ABS_X
,
987 0, usbtouch
->type
->max_xc
, 0, 0);
988 usbtouch
->type
->max_yc
= 2 * y_len
;
989 input_set_abs_params(usbtouch
->input
, ABS_Y
,
990 0, usbtouch
->type
->max_yc
, 0, 0);
993 * The device reports state of IR sensors on X and Y axes.
994 * Each byte represents "darkness" percentage (0-100) of one element.
995 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
996 * This also means that there's a limited multi-touch capability but
997 * it's disabled (and untested) here as there's no X driver for that.
999 begin_x
= end_x
= begin_y
= end_y
= -1;
1000 for (x
= 0; x
< x_len
; x
++) {
1001 if (begin_x
== -1 && packet
->data
[x
] > NEXIO_THRESHOLD
) {
1005 if (end_x
== -1 && begin_x
!= -1 && packet
->data
[x
] < NEXIO_THRESHOLD
) {
1007 for (y
= x_len
; y
< data_len
; y
++) {
1008 if (begin_y
== -1 && packet
->data
[y
] > NEXIO_THRESHOLD
) {
1009 begin_y
= y
- x_len
;
1013 begin_y
!= -1 && packet
->data
[y
] < NEXIO_THRESHOLD
) {
1014 end_y
= y
- 1 - x_len
;
1015 w
= end_x
- begin_x
;
1016 h
= end_y
- begin_y
;
1019 input_report_abs(usbtouch
->input
,
1020 ABS_MT_TOUCH_MAJOR
, max(w
,h
));
1021 input_report_abs(usbtouch
->input
,
1022 ABS_MT_TOUCH_MINOR
, min(x
,h
));
1023 input_report_abs(usbtouch
->input
,
1024 ABS_MT_POSITION_X
, 2*begin_x
+w
);
1025 input_report_abs(usbtouch
->input
,
1026 ABS_MT_POSITION_Y
, 2*begin_y
+h
);
1027 input_report_abs(usbtouch
->input
,
1028 ABS_MT_ORIENTATION
, w
> h
);
1029 input_mt_sync(usbtouch
->input
);
1032 usbtouch
->x
= 2 * begin_x
+ w
;
1033 usbtouch
->y
= 2 * begin_y
+ h
;
1034 usbtouch
->touch
= packet
->flags
& 0x01;
1035 begin_y
= end_y
= -1;
1039 begin_x
= end_x
= -1;
1048 /*****************************************************************************
1052 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
1054 static int elo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
1056 dev
->x
= (pkt
[3] << 8) | pkt
[2];
1057 dev
->y
= (pkt
[5] << 8) | pkt
[4];
1058 dev
->touch
= pkt
[6] > 0;
1059 dev
->press
= pkt
[6];
1066 /*****************************************************************************
1067 * the different device descriptors
1070 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
1071 unsigned char *pkt
, int len
);
1074 static struct usbtouch_device_info usbtouch_dev_info
[] = {
1075 #ifdef CONFIG_TOUCHSCREEN_USB_ELO
1083 .read_data
= elo_read_data
,
1087 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
1088 [DEVTYPE_EGALAX
] = {
1094 .process_pkt
= usbtouch_process_multi
,
1095 .get_pkt_len
= egalax_get_pkt_len
,
1096 .read_data
= egalax_read_data
,
1097 .init
= egalax_init
,
1101 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
1102 [DEVTYPE_PANJIT
] = {
1108 .read_data
= panjit_read_data
,
1112 #ifdef CONFIG_TOUCHSCREEN_USB_3M
1119 .read_data
= mtouch_read_data
,
1120 .init
= mtouch_init
,
1124 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
1132 .read_data
= itm_read_data
,
1136 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
1137 [DEVTYPE_ETURBO
] = {
1143 .process_pkt
= usbtouch_process_multi
,
1144 .get_pkt_len
= eturbo_get_pkt_len
,
1145 .read_data
= eturbo_read_data
,
1149 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
1156 .read_data
= gunze_read_data
,
1160 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
1161 [DEVTYPE_DMC_TSC10
] = {
1167 .init
= dmc_tsc10_init
,
1168 .read_data
= dmc_tsc10_read_data
,
1172 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
1173 [DEVTYPE_IRTOUCH
] = {
1179 .read_data
= irtouch_read_data
,
1183 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
1184 [DEVTYPE_IDEALTEK
] = {
1190 .process_pkt
= usbtouch_process_multi
,
1191 .get_pkt_len
= idealtek_get_pkt_len
,
1192 .read_data
= idealtek_read_data
,
1196 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1197 [DEVTYPE_GENERAL_TOUCH
] = {
1203 .read_data
= general_touch_read_data
,
1207 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
1214 .read_data
= gotop_read_data
,
1218 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
1219 [DEVTYPE_JASTEC
] = {
1225 .read_data
= jastec_read_data
,
1229 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
1237 .read_data
= e2i_read_data
,
1241 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1242 [DEVTYPE_ZYTRONIC
] = {
1248 .read_data
= zytronic_read_data
,
1253 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1254 [DEVTYPE_TC45USB
] = {
1260 .read_data
= tc45usb_read_data
,
1264 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1268 .read_data
= nexio_read_data
,
1269 .alloc
= nexio_alloc
,
1274 #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH
1275 [DEVTYPE_ETOUCH
] = {
1281 .process_pkt
= usbtouch_process_multi
,
1282 .get_pkt_len
= etouch_get_pkt_len
,
1283 .read_data
= etouch_read_data
,
1289 /*****************************************************************************
1292 static void usbtouch_process_pkt(struct usbtouch_usb
*usbtouch
,
1293 unsigned char *pkt
, int len
)
1295 struct usbtouch_device_info
*type
= usbtouch
->type
;
1297 if (!type
->read_data(usbtouch
, pkt
))
1300 input_report_key(usbtouch
->input
, BTN_TOUCH
, usbtouch
->touch
);
1303 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->y
);
1304 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->x
);
1306 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->x
);
1307 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->y
);
1309 if (type
->max_press
)
1310 input_report_abs(usbtouch
->input
, ABS_PRESSURE
, usbtouch
->press
);
1311 input_sync(usbtouch
->input
);
1316 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
1317 unsigned char *pkt
, int len
)
1319 unsigned char *buffer
;
1320 int pkt_len
, pos
, buf_len
, tmp
;
1322 /* process buffer */
1323 if (unlikely(usbtouch
->buf_len
)) {
1324 /* try to get size */
1325 pkt_len
= usbtouch
->type
->get_pkt_len(
1326 usbtouch
->buffer
, usbtouch
->buf_len
);
1329 if (unlikely(!pkt_len
))
1332 /* need to append -pkt_len bytes before able to get size */
1333 if (unlikely(pkt_len
< 0)) {
1334 int append
= -pkt_len
;
1335 if (unlikely(append
> len
))
1337 if (usbtouch
->buf_len
+ append
>= usbtouch
->type
->rept_size
)
1339 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, append
);
1340 usbtouch
->buf_len
+= append
;
1342 pkt_len
= usbtouch
->type
->get_pkt_len(
1343 usbtouch
->buffer
, usbtouch
->buf_len
);
1349 tmp
= pkt_len
- usbtouch
->buf_len
;
1350 if (usbtouch
->buf_len
+ tmp
>= usbtouch
->type
->rept_size
)
1352 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, tmp
);
1353 usbtouch_process_pkt(usbtouch
, usbtouch
->buffer
, pkt_len
);
1356 buf_len
= len
- tmp
;
1362 /* loop over the received packet, process */
1364 while (pos
< buf_len
) {
1365 /* get packet len */
1366 pkt_len
= usbtouch
->type
->get_pkt_len(buffer
+ pos
,
1369 /* unknown packet: skip one byte */
1370 if (unlikely(!pkt_len
)) {
1375 /* full packet: process */
1376 if (likely((pkt_len
> 0) && (pkt_len
<= buf_len
- pos
))) {
1377 usbtouch_process_pkt(usbtouch
, buffer
+ pos
, pkt_len
);
1379 /* incomplete packet: save in buffer */
1380 memcpy(usbtouch
->buffer
, buffer
+ pos
, buf_len
- pos
);
1381 usbtouch
->buf_len
= buf_len
- pos
;
1388 usbtouch
->buf_len
= 0;
1394 static void usbtouch_irq(struct urb
*urb
)
1396 struct usbtouch_usb
*usbtouch
= urb
->context
;
1397 struct device
*dev
= &usbtouch
->interface
->dev
;
1400 switch (urb
->status
) {
1405 /* this urb is timing out */
1407 "%s - urb timed out - was the device unplugged?\n",
1414 /* this urb is terminated, clean up */
1415 dev_dbg(dev
, "%s - urb shutting down with status: %d\n",
1416 __func__
, urb
->status
);
1419 dev_dbg(dev
, "%s - nonzero urb status received: %d\n",
1420 __func__
, urb
->status
);
1424 usbtouch
->type
->process_pkt(usbtouch
, usbtouch
->data
, urb
->actual_length
);
1427 usb_mark_last_busy(interface_to_usbdev(usbtouch
->interface
));
1428 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
1430 dev_err(dev
, "%s - usb_submit_urb failed with result: %d\n",
1434 static int usbtouch_open(struct input_dev
*input
)
1436 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
1439 usbtouch
->irq
->dev
= interface_to_usbdev(usbtouch
->interface
);
1441 r
= usb_autopm_get_interface(usbtouch
->interface
) ? -EIO
: 0;
1445 if (!usbtouch
->type
->irq_always
) {
1446 if (usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
)) {
1452 usbtouch
->interface
->needs_remote_wakeup
= 1;
1454 usb_autopm_put_interface(usbtouch
->interface
);
1459 static void usbtouch_close(struct input_dev
*input
)
1461 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
1464 if (!usbtouch
->type
->irq_always
)
1465 usb_kill_urb(usbtouch
->irq
);
1466 r
= usb_autopm_get_interface(usbtouch
->interface
);
1467 usbtouch
->interface
->needs_remote_wakeup
= 0;
1469 usb_autopm_put_interface(usbtouch
->interface
);
1472 static int usbtouch_suspend
1473 (struct usb_interface
*intf
, pm_message_t message
)
1475 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1477 usb_kill_urb(usbtouch
->irq
);
1482 static int usbtouch_resume(struct usb_interface
*intf
)
1484 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1485 struct input_dev
*input
= usbtouch
->input
;
1488 mutex_lock(&input
->mutex
);
1489 if (input
->users
|| usbtouch
->type
->irq_always
)
1490 result
= usb_submit_urb(usbtouch
->irq
, GFP_NOIO
);
1491 mutex_unlock(&input
->mutex
);
1496 static int usbtouch_reset_resume(struct usb_interface
*intf
)
1498 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1499 struct input_dev
*input
= usbtouch
->input
;
1502 /* reinit the device */
1503 if (usbtouch
->type
->init
) {
1504 err
= usbtouch
->type
->init(usbtouch
);
1507 "%s - type->init() failed, err: %d\n",
1513 /* restart IO if needed */
1514 mutex_lock(&input
->mutex
);
1516 err
= usb_submit_urb(usbtouch
->irq
, GFP_NOIO
);
1517 mutex_unlock(&input
->mutex
);
1522 static void usbtouch_free_buffers(struct usb_device
*udev
,
1523 struct usbtouch_usb
*usbtouch
)
1525 usb_free_coherent(udev
, usbtouch
->data_size
,
1526 usbtouch
->data
, usbtouch
->data_dma
);
1527 kfree(usbtouch
->buffer
);
1530 static struct usb_endpoint_descriptor
*
1531 usbtouch_get_input_endpoint(struct usb_host_interface
*interface
)
1535 for (i
= 0; i
< interface
->desc
.bNumEndpoints
; i
++)
1536 if (usb_endpoint_dir_in(&interface
->endpoint
[i
].desc
))
1537 return &interface
->endpoint
[i
].desc
;
1542 static int usbtouch_probe(struct usb_interface
*intf
,
1543 const struct usb_device_id
*id
)
1545 struct usbtouch_usb
*usbtouch
;
1546 struct input_dev
*input_dev
;
1547 struct usb_endpoint_descriptor
*endpoint
;
1548 struct usb_device
*udev
= interface_to_usbdev(intf
);
1549 struct usbtouch_device_info
*type
;
1552 /* some devices are ignored */
1553 if (id
->driver_info
== DEVTYPE_IGNORE
)
1556 endpoint
= usbtouch_get_input_endpoint(intf
->cur_altsetting
);
1560 usbtouch
= kzalloc(sizeof(struct usbtouch_usb
), GFP_KERNEL
);
1561 input_dev
= input_allocate_device();
1562 if (!usbtouch
|| !input_dev
)
1565 type
= &usbtouch_dev_info
[id
->driver_info
];
1566 usbtouch
->type
= type
;
1567 if (!type
->process_pkt
)
1568 type
->process_pkt
= usbtouch_process_pkt
;
1570 usbtouch
->data_size
= type
->rept_size
;
1571 if (type
->get_pkt_len
) {
1573 * When dealing with variable-length packets we should
1574 * not request more than wMaxPacketSize bytes at once
1575 * as we do not know if there is more data coming or
1576 * we filled exactly wMaxPacketSize bytes and there is
1579 usbtouch
->data_size
= min(usbtouch
->data_size
,
1580 usb_endpoint_maxp(endpoint
));
1583 usbtouch
->data
= usb_alloc_coherent(udev
, usbtouch
->data_size
,
1584 GFP_KERNEL
, &usbtouch
->data_dma
);
1585 if (!usbtouch
->data
)
1588 if (type
->get_pkt_len
) {
1589 usbtouch
->buffer
= kmalloc(type
->rept_size
, GFP_KERNEL
);
1590 if (!usbtouch
->buffer
)
1591 goto out_free_buffers
;
1594 usbtouch
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
1595 if (!usbtouch
->irq
) {
1597 "%s - usb_alloc_urb failed: usbtouch->irq\n", __func__
);
1598 goto out_free_buffers
;
1601 usbtouch
->interface
= intf
;
1602 usbtouch
->input
= input_dev
;
1604 if (udev
->manufacturer
)
1605 strlcpy(usbtouch
->name
, udev
->manufacturer
, sizeof(usbtouch
->name
));
1607 if (udev
->product
) {
1608 if (udev
->manufacturer
)
1609 strlcat(usbtouch
->name
, " ", sizeof(usbtouch
->name
));
1610 strlcat(usbtouch
->name
, udev
->product
, sizeof(usbtouch
->name
));
1613 if (!strlen(usbtouch
->name
))
1614 snprintf(usbtouch
->name
, sizeof(usbtouch
->name
),
1615 "USB Touchscreen %04x:%04x",
1616 le16_to_cpu(udev
->descriptor
.idVendor
),
1617 le16_to_cpu(udev
->descriptor
.idProduct
));
1619 usb_make_path(udev
, usbtouch
->phys
, sizeof(usbtouch
->phys
));
1620 strlcat(usbtouch
->phys
, "/input0", sizeof(usbtouch
->phys
));
1622 input_dev
->name
= usbtouch
->name
;
1623 input_dev
->phys
= usbtouch
->phys
;
1624 usb_to_input_id(udev
, &input_dev
->id
);
1625 input_dev
->dev
.parent
= &intf
->dev
;
1627 input_set_drvdata(input_dev
, usbtouch
);
1629 input_dev
->open
= usbtouch_open
;
1630 input_dev
->close
= usbtouch_close
;
1632 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
1633 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
1634 input_set_abs_params(input_dev
, ABS_X
, type
->min_xc
, type
->max_xc
, 0, 0);
1635 input_set_abs_params(input_dev
, ABS_Y
, type
->min_yc
, type
->max_yc
, 0, 0);
1636 if (type
->max_press
)
1637 input_set_abs_params(input_dev
, ABS_PRESSURE
, type
->min_press
,
1638 type
->max_press
, 0, 0);
1640 if (usb_endpoint_type(endpoint
) == USB_ENDPOINT_XFER_INT
)
1641 usb_fill_int_urb(usbtouch
->irq
, udev
,
1642 usb_rcvintpipe(udev
, endpoint
->bEndpointAddress
),
1643 usbtouch
->data
, usbtouch
->data_size
,
1644 usbtouch_irq
, usbtouch
, endpoint
->bInterval
);
1646 usb_fill_bulk_urb(usbtouch
->irq
, udev
,
1647 usb_rcvbulkpipe(udev
, endpoint
->bEndpointAddress
),
1648 usbtouch
->data
, usbtouch
->data_size
,
1649 usbtouch_irq
, usbtouch
);
1651 usbtouch
->irq
->dev
= udev
;
1652 usbtouch
->irq
->transfer_dma
= usbtouch
->data_dma
;
1653 usbtouch
->irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1655 /* device specific allocations */
1657 err
= type
->alloc(usbtouch
);
1660 "%s - type->alloc() failed, err: %d\n",
1666 /* device specific initialisation*/
1668 err
= type
->init(usbtouch
);
1671 "%s - type->init() failed, err: %d\n",
1677 err
= input_register_device(usbtouch
->input
);
1680 "%s - input_register_device failed, err: %d\n",
1685 usb_set_intfdata(intf
, usbtouch
);
1687 if (usbtouch
->type
->irq_always
) {
1688 /* this can't fail */
1689 usb_autopm_get_interface(intf
);
1690 err
= usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
);
1692 usb_autopm_put_interface(intf
);
1694 "%s - usb_submit_urb failed with result: %d\n",
1696 goto out_unregister_input
;
1702 out_unregister_input
:
1703 input_unregister_device(input_dev
);
1707 type
->exit(usbtouch
);
1709 usb_free_urb(usbtouch
->irq
);
1711 usbtouch_free_buffers(udev
, usbtouch
);
1713 input_free_device(input_dev
);
1718 static void usbtouch_disconnect(struct usb_interface
*intf
)
1720 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1726 "%s - usbtouch is initialized, cleaning up\n", __func__
);
1728 usb_set_intfdata(intf
, NULL
);
1729 /* this will stop IO via close */
1730 input_unregister_device(usbtouch
->input
);
1731 usb_free_urb(usbtouch
->irq
);
1732 if (usbtouch
->type
->exit
)
1733 usbtouch
->type
->exit(usbtouch
);
1734 usbtouch_free_buffers(interface_to_usbdev(intf
), usbtouch
);
1738 MODULE_DEVICE_TABLE(usb
, usbtouch_devices
);
1740 static struct usb_driver usbtouch_driver
= {
1741 .name
= "usbtouchscreen",
1742 .probe
= usbtouch_probe
,
1743 .disconnect
= usbtouch_disconnect
,
1744 .suspend
= usbtouch_suspend
,
1745 .resume
= usbtouch_resume
,
1746 .reset_resume
= usbtouch_reset_resume
,
1747 .id_table
= usbtouch_devices
,
1748 .supports_autosuspend
= 1,
1751 module_usb_driver(usbtouch_driver
);
1753 MODULE_AUTHOR(DRIVER_AUTHOR
);
1754 MODULE_DESCRIPTION(DRIVER_DESC
);
1755 MODULE_LICENSE("GPL");
1757 MODULE_ALIAS("touchkitusb");
1758 MODULE_ALIAS("itmtouch");
1759 MODULE_ALIAS("mtouchusb");