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
20 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
21 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License as
25 * published by the Free Software Foundation; either version 2 of the
26 * License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 * Driver is based on touchkitusb.c
38 * - ITM parts are from itmtouch.c
39 * - 3M parts are from mtouchusb.c
40 * - PanJit parts are from an unmerged driver by Lanslott Gish
41 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
42 * driver from Marius Vollmer
44 *****************************************************************************/
48 #include <linux/kernel.h>
49 #include <linux/slab.h>
50 #include <linux/input.h>
51 #include <linux/module.h>
52 #include <linux/init.h>
53 #include <linux/usb.h>
54 #include <linux/usb/input.h>
55 #include <linux/hid.h>
58 #define DRIVER_VERSION "v0.6"
59 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
60 #define DRIVER_DESC "USB Touchscreen Driver"
63 module_param(swap_xy
, bool, 0644);
64 MODULE_PARM_DESC(swap_xy
, "If set X and Y axes are swapped.");
66 static int hwcalib_xy
;
67 module_param(hwcalib_xy
, bool, 0644);
68 MODULE_PARM_DESC(hwcalib_xy
, "If set hw-calibrated X/Y are used if available");
70 /* device specifc data/functions */
72 struct usbtouch_device_info
{
75 int min_press
, max_press
;
79 * Always service the USB devices irq not just when the input device is
80 * open. This is useful when devices have a watchdog which prevents us
81 * from periodically polling the device. Leave this unset unless your
82 * touchscreen device requires it, as it does consume more of the USB
87 void (*process_pkt
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
, int len
);
90 * used to get the packet len. possible return values:
93 * < 0: -return value more bytes needed
95 int (*get_pkt_len
) (unsigned char *pkt
, int len
);
97 int (*read_data
) (struct usbtouch_usb
*usbtouch
, unsigned char *pkt
);
98 int (*init
) (struct usbtouch_usb
*usbtouch
);
99 void (*exit
) (struct usbtouch_usb
*usbtouch
);
102 /* a usbtouch device */
103 struct usbtouch_usb
{
106 unsigned char *buffer
;
109 struct usb_interface
*interface
;
110 struct input_dev
*input
;
111 struct usbtouch_device_info
*type
;
133 DEVTYPE_GENERAL_TOUCH
,
142 #define USB_DEVICE_HID_CLASS(vend, prod) \
143 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
144 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
145 | USB_DEVICE_ID_MATCH_DEVICE, \
146 .idVendor = (vend), \
147 .idProduct = (prod), \
148 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
149 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
151 static const struct usb_device_id usbtouch_devices
[] = {
152 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
153 /* ignore the HID capable devices, handled by usbhid */
154 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info
= DEVTYPE_IGNORE
},
155 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info
= DEVTYPE_IGNORE
},
157 /* normal device IDs */
158 {USB_DEVICE(0x3823, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
159 {USB_DEVICE(0x3823, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
160 {USB_DEVICE(0x0123, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
161 {USB_DEVICE(0x0eef, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
162 {USB_DEVICE(0x0eef, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
163 {USB_DEVICE(0x1234, 0x0001), .driver_info
= DEVTYPE_EGALAX
},
164 {USB_DEVICE(0x1234, 0x0002), .driver_info
= DEVTYPE_EGALAX
},
167 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
168 {USB_DEVICE(0x134c, 0x0001), .driver_info
= DEVTYPE_PANJIT
},
169 {USB_DEVICE(0x134c, 0x0002), .driver_info
= DEVTYPE_PANJIT
},
170 {USB_DEVICE(0x134c, 0x0003), .driver_info
= DEVTYPE_PANJIT
},
171 {USB_DEVICE(0x134c, 0x0004), .driver_info
= DEVTYPE_PANJIT
},
174 #ifdef CONFIG_TOUCHSCREEN_USB_3M
175 {USB_DEVICE(0x0596, 0x0001), .driver_info
= DEVTYPE_3M
},
178 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
179 {USB_DEVICE(0x0403, 0xf9e9), .driver_info
= DEVTYPE_ITM
},
182 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
183 {USB_DEVICE(0x1234, 0x5678), .driver_info
= DEVTYPE_ETURBO
},
186 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
187 {USB_DEVICE(0x0637, 0x0001), .driver_info
= DEVTYPE_GUNZE
},
190 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
191 {USB_DEVICE(0x0afa, 0x03e8), .driver_info
= DEVTYPE_DMC_TSC10
},
194 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
195 {USB_DEVICE(0x595a, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
196 {USB_DEVICE(0x6615, 0x0001), .driver_info
= DEVTYPE_IRTOUCH
},
199 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
200 {USB_DEVICE(0x1391, 0x1000), .driver_info
= DEVTYPE_IDEALTEK
},
203 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
204 {USB_DEVICE(0x0dfc, 0x0001), .driver_info
= DEVTYPE_GENERAL_TOUCH
},
207 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
208 {USB_DEVICE(0x08f2, 0x007f), .driver_info
= DEVTYPE_GOTOP
},
209 {USB_DEVICE(0x08f2, 0x00ce), .driver_info
= DEVTYPE_GOTOP
},
210 {USB_DEVICE(0x08f2, 0x00f4), .driver_info
= DEVTYPE_GOTOP
},
213 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
214 {USB_DEVICE(0x0f92, 0x0001), .driver_info
= DEVTYPE_JASTEC
},
217 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
218 {USB_DEVICE(0x1ac7, 0x0001), .driver_info
= DEVTYPE_E2I
},
221 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
222 {USB_DEVICE(0x14c8, 0x0003), .driver_info
= DEVTYPE_ZYTRONIC
},
225 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
227 {USB_DEVICE(0x0664, 0x0309), .driver_info
= DEVTYPE_TC45USB
},
229 {USB_DEVICE(0x0664, 0x0306), .driver_info
= DEVTYPE_TC45USB
},
232 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
233 /* data interface only */
234 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
235 .driver_info
= DEVTYPE_NEXIO
},
236 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
237 .driver_info
= DEVTYPE_NEXIO
},
244 /*****************************************************************************
248 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
249 static int e2i_init(struct usbtouch_usb
*usbtouch
)
252 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
254 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
255 0x01, 0x02, 0x0000, 0x0081,
256 NULL
, 0, USB_CTRL_SET_TIMEOUT
);
258 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
263 static int e2i_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
265 int tmp
= (pkt
[0] << 8) | pkt
[1];
266 dev
->x
= (pkt
[2] << 8) | pkt
[3];
267 dev
->y
= (pkt
[4] << 8) | pkt
[5];
270 dev
->touch
= (tmp
> 0);
271 dev
->press
= (tmp
> 0 ? tmp
: 0);
278 /*****************************************************************************
282 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
288 #define EGALAX_PKT_TYPE_MASK 0xFE
289 #define EGALAX_PKT_TYPE_REPT 0x80
290 #define EGALAX_PKT_TYPE_DIAG 0x0A
292 static int egalax_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
294 if ((pkt
[0] & EGALAX_PKT_TYPE_MASK
) != EGALAX_PKT_TYPE_REPT
)
297 dev
->x
= ((pkt
[3] & 0x0F) << 7) | (pkt
[4] & 0x7F);
298 dev
->y
= ((pkt
[1] & 0x0F) << 7) | (pkt
[2] & 0x7F);
299 dev
->touch
= pkt
[0] & 0x01;
304 static int egalax_get_pkt_len(unsigned char *buf
, int len
)
306 switch (buf
[0] & EGALAX_PKT_TYPE_MASK
) {
307 case EGALAX_PKT_TYPE_REPT
:
310 case EGALAX_PKT_TYPE_DIAG
:
322 /*****************************************************************************
325 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
326 static int panjit_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
328 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
329 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
330 dev
->touch
= pkt
[0] & 0x01;
337 /*****************************************************************************
340 #ifdef CONFIG_TOUCHSCREEN_USB_3M
342 #define MTOUCHUSB_ASYNC_REPORT 1
343 #define MTOUCHUSB_RESET 7
344 #define MTOUCHUSB_REQ_CTRLLR_ID 10
346 static int mtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
349 dev
->x
= (pkt
[4] << 8) | pkt
[3];
350 dev
->y
= 0xffff - ((pkt
[6] << 8) | pkt
[5]);
352 dev
->x
= (pkt
[8] << 8) | pkt
[7];
353 dev
->y
= (pkt
[10] << 8) | pkt
[9];
355 dev
->touch
= (pkt
[2] & 0x40) ? 1 : 0;
360 static int mtouch_init(struct usbtouch_usb
*usbtouch
)
363 struct usb_device
*udev
= interface_to_usbdev(usbtouch
->interface
);
365 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
367 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
368 1, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
369 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
375 for (i
= 0; i
< 3; i
++) {
376 ret
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
377 MTOUCHUSB_ASYNC_REPORT
,
378 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
379 1, 1, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
380 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
388 /* Default min/max xy are the raw values, override if using hw-calib */
390 input_set_abs_params(usbtouch
->input
, ABS_X
, 0, 0xffff, 0, 0);
391 input_set_abs_params(usbtouch
->input
, ABS_Y
, 0, 0xffff, 0, 0);
399 /*****************************************************************************
402 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
403 static int itm_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
407 * ITM devices report invalid x/y data if not touched.
408 * if the screen was touched before but is not touched any more
409 * report touch as 0 with the last valid x/y data once. then stop
410 * reporting data until touched again.
412 dev
->press
= ((pkt
[2] & 0x01) << 7) | (pkt
[5] & 0x7F);
414 touch
= ~pkt
[7] & 0x20;
424 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[3] & 0x7F);
425 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[4] & 0x7F);
433 /*****************************************************************************
436 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
440 static int eturbo_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
444 /* packets should start with sync */
445 if (!(pkt
[0] & 0x80))
448 shift
= (6 - (pkt
[0] & 0x03));
449 dev
->x
= ((pkt
[3] << 7) | pkt
[4]) >> shift
;
450 dev
->y
= ((pkt
[1] << 7) | pkt
[2]) >> shift
;
451 dev
->touch
= (pkt
[0] & 0x10) ? 1 : 0;
456 static int eturbo_get_pkt_len(unsigned char *buf
, int len
)
467 /*****************************************************************************
470 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
471 static int gunze_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
473 if (!(pkt
[0] & 0x80) || ((pkt
[1] | pkt
[2] | pkt
[3]) & 0x80))
476 dev
->x
= ((pkt
[0] & 0x1F) << 7) | (pkt
[2] & 0x7F);
477 dev
->y
= ((pkt
[1] & 0x1F) << 7) | (pkt
[3] & 0x7F);
478 dev
->touch
= pkt
[0] & 0x20;
484 /*****************************************************************************
487 * Documentation about the controller and it's protocol can be found at
488 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
489 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
491 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
493 /* supported data rates. currently using 130 */
494 #define TSC10_RATE_POINT 0x50
495 #define TSC10_RATE_30 0x40
496 #define TSC10_RATE_50 0x41
497 #define TSC10_RATE_80 0x42
498 #define TSC10_RATE_100 0x43
499 #define TSC10_RATE_130 0x44
500 #define TSC10_RATE_150 0x45
503 #define TSC10_CMD_RESET 0x55
504 #define TSC10_CMD_RATE 0x05
505 #define TSC10_CMD_DATA1 0x01
507 static int dmc_tsc10_init(struct usbtouch_usb
*usbtouch
)
509 struct usb_device
*dev
= interface_to_usbdev(usbtouch
->interface
);
513 buf
= kmalloc(2, GFP_KERNEL
);
517 buf
[0] = buf
[1] = 0xFF;
518 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
520 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
521 0, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
524 if (buf
[0] != 0x06) {
529 /* set coordinate output rate */
530 buf
[0] = buf
[1] = 0xFF;
531 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
533 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
534 TSC10_RATE_150
, 0, buf
, 2, USB_CTRL_SET_TIMEOUT
);
537 if ((buf
[0] != 0x06) && (buf
[0] != 0x15 || buf
[1] != 0x01)) {
542 /* start sending data */
543 ret
= usb_control_msg(dev
, usb_rcvctrlpipe (dev
, 0),
545 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
546 0, 0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
554 static int dmc_tsc10_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
556 dev
->x
= ((pkt
[2] & 0x03) << 8) | pkt
[1];
557 dev
->y
= ((pkt
[4] & 0x03) << 8) | pkt
[3];
558 dev
->touch
= pkt
[0] & 0x01;
565 /*****************************************************************************
568 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
569 static int irtouch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
571 dev
->x
= (pkt
[3] << 8) | pkt
[2];
572 dev
->y
= (pkt
[5] << 8) | pkt
[4];
573 dev
->touch
= (pkt
[1] & 0x03) ? 1 : 0;
579 /*****************************************************************************
580 * ET&T TC5UH/TC4UM part
582 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
583 static int tc45usb_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
585 dev
->x
= ((pkt
[2] & 0x0F) << 8) | pkt
[1];
586 dev
->y
= ((pkt
[4] & 0x0F) << 8) | pkt
[3];
587 dev
->touch
= pkt
[0] & 0x01;
593 /*****************************************************************************
594 * IdealTEK URTC1000 Part
596 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
600 static int idealtek_get_pkt_len(unsigned char *buf
, int len
)
609 static int idealtek_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
611 switch (pkt
[0] & 0x98) {
613 /* touch data in IdealTEK mode */
614 dev
->x
= (pkt
[1] << 5) | (pkt
[2] >> 2);
615 dev
->y
= (pkt
[3] << 5) | (pkt
[4] >> 2);
616 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
620 /* touch data in MT emulation mode */
621 dev
->x
= (pkt
[2] << 5) | (pkt
[1] >> 2);
622 dev
->y
= (pkt
[4] << 5) | (pkt
[3] >> 2);
623 dev
->touch
= (pkt
[0] & 0x40) ? 1 : 0;
632 /*****************************************************************************
635 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
636 static int general_touch_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
638 dev
->x
= (pkt
[2] << 8) | pkt
[1];
639 dev
->y
= (pkt
[4] << 8) | pkt
[3];
640 dev
->press
= pkt
[5] & 0xff;
641 dev
->touch
= pkt
[0] & 0x01;
647 /*****************************************************************************
650 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
651 static int gotop_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
653 dev
->x
= ((pkt
[1] & 0x38) << 4) | pkt
[2];
654 dev
->y
= ((pkt
[1] & 0x07) << 7) | pkt
[3];
655 dev
->touch
= pkt
[0] & 0x01;
661 /*****************************************************************************
664 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
665 static int jastec_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
667 dev
->x
= ((pkt
[0] & 0x3f) << 6) | (pkt
[2] & 0x3f);
668 dev
->y
= ((pkt
[1] & 0x3f) << 6) | (pkt
[3] & 0x3f);
669 dev
->touch
= (pkt
[0] & 0x40) >> 6;
675 /*****************************************************************************
678 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
679 static int zytronic_read_data(struct usbtouch_usb
*dev
, unsigned char *pkt
)
682 case 0x3A: /* command response */
683 dbg("%s: Command response %d", __func__
, pkt
[1]);
686 case 0xC0: /* down */
687 dev
->x
= (pkt
[1] & 0x7f) | ((pkt
[2] & 0x07) << 7);
688 dev
->y
= (pkt
[3] & 0x7f) | ((pkt
[4] & 0x07) << 7);
690 dbg("%s: down %d,%d", __func__
, dev
->x
, dev
->y
);
694 dev
->x
= (pkt
[1] & 0x7f) | ((pkt
[2] & 0x07) << 7);
695 dev
->y
= (pkt
[3] & 0x7f) | ((pkt
[4] & 0x07) << 7);
697 dbg("%s: up %d,%d", __func__
, dev
->x
, dev
->y
);
701 dbg("%s: Unknown return %d", __func__
, pkt
[0]);
709 /*****************************************************************************
712 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
714 #define NEXIO_TIMEOUT 5000
715 #define NEXIO_BUFSIZE 1024
716 #define NEXIO_THRESHOLD 50
720 unsigned char *ack_buf
;
723 struct nexio_touch_packet
{
724 u8 flags
; /* 0xe1 = touch, 0xe1 = release */
725 __be16 data_len
; /* total bytes of touch data */
726 __be16 x_len
; /* bytes for X axis */
727 __be16 y_len
; /* bytes for Y axis */
729 } __attribute__ ((packed
));
731 static unsigned char nexio_ack_pkt
[2] = { 0xaa, 0x02 };
732 static unsigned char nexio_init_pkt
[4] = { 0x82, 0x04, 0x0a, 0x0f };
734 static void nexio_ack_complete(struct urb
*urb
)
738 static int nexio_init(struct usbtouch_usb
*usbtouch
)
740 struct usb_device
*dev
= interface_to_usbdev(usbtouch
->interface
);
741 struct usb_host_interface
*interface
= usbtouch
->interface
->cur_altsetting
;
742 struct nexio_priv
*priv
;
746 char *firmware_ver
= NULL
, *device_name
= NULL
;
747 int input_ep
= 0, output_ep
= 0;
749 /* find first input and output endpoint */
750 for (i
= 0; i
< interface
->desc
.bNumEndpoints
; i
++) {
752 usb_endpoint_dir_in(&interface
->endpoint
[i
].desc
))
753 input_ep
= interface
->endpoint
[i
].desc
.bEndpointAddress
;
755 usb_endpoint_dir_out(&interface
->endpoint
[i
].desc
))
756 output_ep
= interface
->endpoint
[i
].desc
.bEndpointAddress
;
758 if (!input_ep
|| !output_ep
)
761 buf
= kmalloc(NEXIO_BUFSIZE
, GFP_KERNEL
);
765 /* two empty reads */
766 for (i
= 0; i
< 2; i
++) {
767 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, input_ep
),
768 buf
, NEXIO_BUFSIZE
, &actual_len
,
774 /* send init command */
775 memcpy(buf
, nexio_init_pkt
, sizeof(nexio_init_pkt
));
776 ret
= usb_bulk_msg(dev
, usb_sndbulkpipe(dev
, output_ep
),
777 buf
, sizeof(nexio_init_pkt
), &actual_len
,
783 for (i
= 0; i
< 3; i
++) {
784 memset(buf
, 0, NEXIO_BUFSIZE
);
785 ret
= usb_bulk_msg(dev
, usb_rcvbulkpipe(dev
, input_ep
),
786 buf
, NEXIO_BUFSIZE
, &actual_len
,
788 if (ret
< 0 || actual_len
< 1 || buf
[1] != actual_len
)
791 case 0x83: /* firmware version */
793 firmware_ver
= kstrdup(&buf
[2], GFP_KERNEL
);
795 case 0x84: /* device name */
797 device_name
= kstrdup(&buf
[2], GFP_KERNEL
);
802 printk(KERN_INFO
"Nexio device: %s, firmware version: %s\n",
803 device_name
, firmware_ver
);
808 /* prepare ACK URB */
811 usbtouch
->priv
= kmalloc(sizeof(struct nexio_priv
), GFP_KERNEL
);
815 priv
= usbtouch
->priv
;
817 priv
->ack_buf
= kmemdup(nexio_ack_pkt
, sizeof(nexio_ack_pkt
),
822 priv
->ack
= usb_alloc_urb(0, GFP_KERNEL
);
824 dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__
);
828 usb_fill_bulk_urb(priv
->ack
, dev
, usb_sndbulkpipe(dev
, output_ep
),
829 priv
->ack_buf
, sizeof(nexio_ack_pkt
),
830 nexio_ack_complete
, usbtouch
);
835 kfree(priv
->ack_buf
);
843 static void nexio_exit(struct usbtouch_usb
*usbtouch
)
845 struct nexio_priv
*priv
= usbtouch
->priv
;
847 usb_kill_urb(priv
->ack
);
848 usb_free_urb(priv
->ack
);
849 kfree(priv
->ack_buf
);
853 static int nexio_read_data(struct usbtouch_usb
*usbtouch
, unsigned char *pkt
)
855 struct nexio_touch_packet
*packet
= (void *) pkt
;
856 struct nexio_priv
*priv
= usbtouch
->priv
;
857 unsigned int data_len
= be16_to_cpu(packet
->data_len
);
858 unsigned int x_len
= be16_to_cpu(packet
->x_len
);
859 unsigned int y_len
= be16_to_cpu(packet
->y_len
);
860 int x
, y
, begin_x
, begin_y
, end_x
, end_y
, w
, h
, ret
;
862 /* got touch data? */
863 if ((pkt
[0] & 0xe0) != 0xe0)
872 ret
= usb_submit_urb(priv
->ack
, GFP_ATOMIC
);
874 if (!usbtouch
->type
->max_xc
) {
875 usbtouch
->type
->max_xc
= 2 * x_len
;
876 input_set_abs_params(usbtouch
->input
, ABS_X
,
877 0, usbtouch
->type
->max_xc
, 0, 0);
878 usbtouch
->type
->max_yc
= 2 * y_len
;
879 input_set_abs_params(usbtouch
->input
, ABS_Y
,
880 0, usbtouch
->type
->max_yc
, 0, 0);
883 * The device reports state of IR sensors on X and Y axes.
884 * Each byte represents "darkness" percentage (0-100) of one element.
885 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
886 * This also means that there's a limited multi-touch capability but
887 * it's disabled (and untested) here as there's no X driver for that.
889 begin_x
= end_x
= begin_y
= end_y
= -1;
890 for (x
= 0; x
< x_len
; x
++) {
891 if (begin_x
== -1 && packet
->data
[x
] > NEXIO_THRESHOLD
) {
895 if (end_x
== -1 && begin_x
!= -1 && packet
->data
[x
] < NEXIO_THRESHOLD
) {
897 for (y
= x_len
; y
< data_len
; y
++) {
898 if (begin_y
== -1 && packet
->data
[y
] > NEXIO_THRESHOLD
) {
903 begin_y
!= -1 && packet
->data
[y
] < NEXIO_THRESHOLD
) {
904 end_y
= y
- 1 - x_len
;
909 input_report_abs(usbtouch
->input
,
910 ABS_MT_TOUCH_MAJOR
, max(w
,h
));
911 input_report_abs(usbtouch
->input
,
912 ABS_MT_TOUCH_MINOR
, min(x
,h
));
913 input_report_abs(usbtouch
->input
,
914 ABS_MT_POSITION_X
, 2*begin_x
+w
);
915 input_report_abs(usbtouch
->input
,
916 ABS_MT_POSITION_Y
, 2*begin_y
+h
);
917 input_report_abs(usbtouch
->input
,
918 ABS_MT_ORIENTATION
, w
> h
);
919 input_mt_sync(usbtouch
->input
);
922 usbtouch
->x
= 2 * begin_x
+ w
;
923 usbtouch
->y
= 2 * begin_y
+ h
;
924 usbtouch
->touch
= packet
->flags
& 0x01;
925 begin_y
= end_y
= -1;
929 begin_x
= end_x
= -1;
938 /*****************************************************************************
939 * the different device descriptors
942 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
943 unsigned char *pkt
, int len
);
946 static struct usbtouch_device_info usbtouch_dev_info
[] = {
947 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
954 .process_pkt
= usbtouch_process_multi
,
955 .get_pkt_len
= egalax_get_pkt_len
,
956 .read_data
= egalax_read_data
,
960 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
967 .read_data
= panjit_read_data
,
971 #ifdef CONFIG_TOUCHSCREEN_USB_3M
978 .read_data
= mtouch_read_data
,
983 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
991 .read_data
= itm_read_data
,
995 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
1002 .process_pkt
= usbtouch_process_multi
,
1003 .get_pkt_len
= eturbo_get_pkt_len
,
1004 .read_data
= eturbo_read_data
,
1008 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
1015 .read_data
= gunze_read_data
,
1019 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
1020 [DEVTYPE_DMC_TSC10
] = {
1026 .init
= dmc_tsc10_init
,
1027 .read_data
= dmc_tsc10_read_data
,
1031 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
1032 [DEVTYPE_IRTOUCH
] = {
1038 .read_data
= irtouch_read_data
,
1042 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
1043 [DEVTYPE_IDEALTEK
] = {
1049 .process_pkt
= usbtouch_process_multi
,
1050 .get_pkt_len
= idealtek_get_pkt_len
,
1051 .read_data
= idealtek_read_data
,
1055 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1056 [DEVTYPE_GENERAL_TOUCH
] = {
1062 .read_data
= general_touch_read_data
,
1066 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
1073 .read_data
= gotop_read_data
,
1077 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
1078 [DEVTYPE_JASTEC
] = {
1084 .read_data
= jastec_read_data
,
1088 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
1096 .read_data
= e2i_read_data
,
1100 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1101 [DEVTYPE_ZYTRONIC
] = {
1107 .read_data
= zytronic_read_data
,
1112 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1113 [DEVTYPE_TC45USB
] = {
1119 .read_data
= tc45usb_read_data
,
1123 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1127 .read_data
= nexio_read_data
,
1135 /*****************************************************************************
1138 static void usbtouch_process_pkt(struct usbtouch_usb
*usbtouch
,
1139 unsigned char *pkt
, int len
)
1141 struct usbtouch_device_info
*type
= usbtouch
->type
;
1143 if (!type
->read_data(usbtouch
, pkt
))
1146 input_report_key(usbtouch
->input
, BTN_TOUCH
, usbtouch
->touch
);
1149 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->y
);
1150 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->x
);
1152 input_report_abs(usbtouch
->input
, ABS_X
, usbtouch
->x
);
1153 input_report_abs(usbtouch
->input
, ABS_Y
, usbtouch
->y
);
1155 if (type
->max_press
)
1156 input_report_abs(usbtouch
->input
, ABS_PRESSURE
, usbtouch
->press
);
1157 input_sync(usbtouch
->input
);
1162 static void usbtouch_process_multi(struct usbtouch_usb
*usbtouch
,
1163 unsigned char *pkt
, int len
)
1165 unsigned char *buffer
;
1166 int pkt_len
, pos
, buf_len
, tmp
;
1168 /* process buffer */
1169 if (unlikely(usbtouch
->buf_len
)) {
1170 /* try to get size */
1171 pkt_len
= usbtouch
->type
->get_pkt_len(
1172 usbtouch
->buffer
, usbtouch
->buf_len
);
1175 if (unlikely(!pkt_len
))
1178 /* need to append -pkt_len bytes before able to get size */
1179 if (unlikely(pkt_len
< 0)) {
1180 int append
= -pkt_len
;
1181 if (unlikely(append
> len
))
1183 if (usbtouch
->buf_len
+ append
>= usbtouch
->type
->rept_size
)
1185 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, append
);
1186 usbtouch
->buf_len
+= append
;
1188 pkt_len
= usbtouch
->type
->get_pkt_len(
1189 usbtouch
->buffer
, usbtouch
->buf_len
);
1195 tmp
= pkt_len
- usbtouch
->buf_len
;
1196 if (usbtouch
->buf_len
+ tmp
>= usbtouch
->type
->rept_size
)
1198 memcpy(usbtouch
->buffer
+ usbtouch
->buf_len
, pkt
, tmp
);
1199 usbtouch_process_pkt(usbtouch
, usbtouch
->buffer
, pkt_len
);
1202 buf_len
= len
- tmp
;
1208 /* loop over the received packet, process */
1210 while (pos
< buf_len
) {
1211 /* get packet len */
1212 pkt_len
= usbtouch
->type
->get_pkt_len(buffer
+ pos
,
1215 /* unknown packet: skip one byte */
1216 if (unlikely(!pkt_len
)) {
1221 /* full packet: process */
1222 if (likely((pkt_len
> 0) && (pkt_len
<= buf_len
- pos
))) {
1223 usbtouch_process_pkt(usbtouch
, buffer
+ pos
, pkt_len
);
1225 /* incomplete packet: save in buffer */
1226 memcpy(usbtouch
->buffer
, buffer
+ pos
, buf_len
- pos
);
1227 usbtouch
->buf_len
= buf_len
- pos
;
1234 usbtouch
->buf_len
= 0;
1240 static void usbtouch_irq(struct urb
*urb
)
1242 struct usbtouch_usb
*usbtouch
= urb
->context
;
1245 switch (urb
->status
) {
1250 /* this urb is timing out */
1251 dbg("%s - urb timed out - was the device unplugged?",
1258 /* this urb is terminated, clean up */
1259 dbg("%s - urb shutting down with status: %d",
1260 __func__
, urb
->status
);
1263 dbg("%s - nonzero urb status received: %d",
1264 __func__
, urb
->status
);
1268 usbtouch
->type
->process_pkt(usbtouch
, usbtouch
->data
, urb
->actual_length
);
1271 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
1273 err("%s - usb_submit_urb failed with result: %d",
1277 static int usbtouch_open(struct input_dev
*input
)
1279 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
1281 usbtouch
->irq
->dev
= interface_to_usbdev(usbtouch
->interface
);
1283 if (!usbtouch
->type
->irq_always
) {
1284 if (usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
))
1291 static void usbtouch_close(struct input_dev
*input
)
1293 struct usbtouch_usb
*usbtouch
= input_get_drvdata(input
);
1295 if (!usbtouch
->type
->irq_always
)
1296 usb_kill_urb(usbtouch
->irq
);
1300 static void usbtouch_free_buffers(struct usb_device
*udev
,
1301 struct usbtouch_usb
*usbtouch
)
1303 usb_free_coherent(udev
, usbtouch
->type
->rept_size
,
1304 usbtouch
->data
, usbtouch
->data_dma
);
1305 kfree(usbtouch
->buffer
);
1308 static struct usb_endpoint_descriptor
*
1309 usbtouch_get_input_endpoint(struct usb_host_interface
*interface
)
1313 for (i
= 0; i
< interface
->desc
.bNumEndpoints
; i
++)
1314 if (usb_endpoint_dir_in(&interface
->endpoint
[i
].desc
))
1315 return &interface
->endpoint
[i
].desc
;
1320 static int usbtouch_probe(struct usb_interface
*intf
,
1321 const struct usb_device_id
*id
)
1323 struct usbtouch_usb
*usbtouch
;
1324 struct input_dev
*input_dev
;
1325 struct usb_endpoint_descriptor
*endpoint
;
1326 struct usb_device
*udev
= interface_to_usbdev(intf
);
1327 struct usbtouch_device_info
*type
;
1330 /* some devices are ignored */
1331 if (id
->driver_info
== DEVTYPE_IGNORE
)
1334 endpoint
= usbtouch_get_input_endpoint(intf
->cur_altsetting
);
1338 usbtouch
= kzalloc(sizeof(struct usbtouch_usb
), GFP_KERNEL
);
1339 input_dev
= input_allocate_device();
1340 if (!usbtouch
|| !input_dev
)
1343 type
= &usbtouch_dev_info
[id
->driver_info
];
1344 usbtouch
->type
= type
;
1345 if (!type
->process_pkt
)
1346 type
->process_pkt
= usbtouch_process_pkt
;
1348 usbtouch
->data
= usb_alloc_coherent(udev
, type
->rept_size
,
1349 GFP_KERNEL
, &usbtouch
->data_dma
);
1350 if (!usbtouch
->data
)
1353 if (type
->get_pkt_len
) {
1354 usbtouch
->buffer
= kmalloc(type
->rept_size
, GFP_KERNEL
);
1355 if (!usbtouch
->buffer
)
1356 goto out_free_buffers
;
1359 usbtouch
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
1360 if (!usbtouch
->irq
) {
1361 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__
);
1362 goto out_free_buffers
;
1365 usbtouch
->interface
= intf
;
1366 usbtouch
->input
= input_dev
;
1368 if (udev
->manufacturer
)
1369 strlcpy(usbtouch
->name
, udev
->manufacturer
, sizeof(usbtouch
->name
));
1371 if (udev
->product
) {
1372 if (udev
->manufacturer
)
1373 strlcat(usbtouch
->name
, " ", sizeof(usbtouch
->name
));
1374 strlcat(usbtouch
->name
, udev
->product
, sizeof(usbtouch
->name
));
1377 if (!strlen(usbtouch
->name
))
1378 snprintf(usbtouch
->name
, sizeof(usbtouch
->name
),
1379 "USB Touchscreen %04x:%04x",
1380 le16_to_cpu(udev
->descriptor
.idVendor
),
1381 le16_to_cpu(udev
->descriptor
.idProduct
));
1383 usb_make_path(udev
, usbtouch
->phys
, sizeof(usbtouch
->phys
));
1384 strlcat(usbtouch
->phys
, "/input0", sizeof(usbtouch
->phys
));
1386 input_dev
->name
= usbtouch
->name
;
1387 input_dev
->phys
= usbtouch
->phys
;
1388 usb_to_input_id(udev
, &input_dev
->id
);
1389 input_dev
->dev
.parent
= &intf
->dev
;
1391 input_set_drvdata(input_dev
, usbtouch
);
1393 input_dev
->open
= usbtouch_open
;
1394 input_dev
->close
= usbtouch_close
;
1396 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
1397 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
1398 input_set_abs_params(input_dev
, ABS_X
, type
->min_xc
, type
->max_xc
, 0, 0);
1399 input_set_abs_params(input_dev
, ABS_Y
, type
->min_yc
, type
->max_yc
, 0, 0);
1400 if (type
->max_press
)
1401 input_set_abs_params(input_dev
, ABS_PRESSURE
, type
->min_press
,
1402 type
->max_press
, 0, 0);
1404 if (usb_endpoint_type(endpoint
) == USB_ENDPOINT_XFER_INT
)
1405 usb_fill_int_urb(usbtouch
->irq
, udev
,
1406 usb_rcvintpipe(udev
, endpoint
->bEndpointAddress
),
1407 usbtouch
->data
, type
->rept_size
,
1408 usbtouch_irq
, usbtouch
, endpoint
->bInterval
);
1410 usb_fill_bulk_urb(usbtouch
->irq
, udev
,
1411 usb_rcvbulkpipe(udev
, endpoint
->bEndpointAddress
),
1412 usbtouch
->data
, type
->rept_size
,
1413 usbtouch_irq
, usbtouch
);
1415 usbtouch
->irq
->dev
= udev
;
1416 usbtouch
->irq
->transfer_dma
= usbtouch
->data_dma
;
1417 usbtouch
->irq
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1419 /* device specific init */
1421 err
= type
->init(usbtouch
);
1423 dbg("%s - type->init() failed, err: %d", __func__
, err
);
1428 err
= input_register_device(usbtouch
->input
);
1430 dbg("%s - input_register_device failed, err: %d", __func__
, err
);
1434 usb_set_intfdata(intf
, usbtouch
);
1436 if (usbtouch
->type
->irq_always
) {
1437 err
= usb_submit_urb(usbtouch
->irq
, GFP_KERNEL
);
1439 err("%s - usb_submit_urb failed with result: %d",
1441 goto out_unregister_input
;
1447 out_unregister_input
:
1448 input_unregister_device(input_dev
);
1452 type
->exit(usbtouch
);
1454 usb_free_urb(usbtouch
->irq
);
1456 usbtouch_free_buffers(udev
, usbtouch
);
1458 input_free_device(input_dev
);
1463 static void usbtouch_disconnect(struct usb_interface
*intf
)
1465 struct usbtouch_usb
*usbtouch
= usb_get_intfdata(intf
);
1467 dbg("%s - called", __func__
);
1472 dbg("%s - usbtouch is initialized, cleaning up", __func__
);
1473 usb_set_intfdata(intf
, NULL
);
1474 /* this will stop IO via close */
1475 input_unregister_device(usbtouch
->input
);
1476 usb_free_urb(usbtouch
->irq
);
1477 if (usbtouch
->type
->exit
)
1478 usbtouch
->type
->exit(usbtouch
);
1479 usbtouch_free_buffers(interface_to_usbdev(intf
), usbtouch
);
1483 MODULE_DEVICE_TABLE(usb
, usbtouch_devices
);
1485 static struct usb_driver usbtouch_driver
= {
1486 .name
= "usbtouchscreen",
1487 .probe
= usbtouch_probe
,
1488 .disconnect
= usbtouch_disconnect
,
1489 .id_table
= usbtouch_devices
,
1492 static int __init
usbtouch_init(void)
1494 return usb_register(&usbtouch_driver
);
1497 static void __exit
usbtouch_cleanup(void)
1499 usb_deregister(&usbtouch_driver
);
1502 module_init(usbtouch_init
);
1503 module_exit(usbtouch_cleanup
);
1505 MODULE_AUTHOR(DRIVER_AUTHOR
);
1506 MODULE_DESCRIPTION(DRIVER_DESC
);
1507 MODULE_LICENSE("GPL");
1509 MODULE_ALIAS("touchkitusb");
1510 MODULE_ALIAS("itmtouch");
1511 MODULE_ALIAS("mtouchusb");