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 (*alloc) (struct usbtouch_usb *usbtouch);
99 int (*init) (struct usbtouch_usb *usbtouch);
100 void (*exit) (struct usbtouch_usb *usbtouch);
103 /* a usbtouch device */
104 struct usbtouch_usb {
107 unsigned char *buffer;
110 struct usb_interface *interface;
111 struct input_dev *input;
112 struct usbtouch_device_info *type;
134 DEVTYPE_GENERAL_TOUCH,
143 #define USB_DEVICE_HID_CLASS(vend, prod) \
144 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
145 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
146 | USB_DEVICE_ID_MATCH_DEVICE, \
147 .idVendor = (vend), \
148 .idProduct = (prod), \
149 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
150 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
152 static const struct usb_device_id usbtouch_devices[] = {
153 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
154 /* ignore the HID capable devices, handled by usbhid */
155 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
156 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
158 /* normal device IDs */
159 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
160 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
161 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
162 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
163 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
164 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
165 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
168 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
169 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
170 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
171 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
172 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
175 #ifdef CONFIG_TOUCHSCREEN_USB_3M
176 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
179 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
180 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
183 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
184 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
187 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
188 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
191 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
192 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
195 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
196 {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
197 {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
200 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
201 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
204 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
205 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
208 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
209 {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP},
210 {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP},
211 {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP},
214 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
215 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
218 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
219 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
222 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
223 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
226 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
228 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC45USB},
230 {USB_DEVICE(0x0664, 0x0306), .driver_info = DEVTYPE_TC45USB},
233 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
234 /* data interface only */
235 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
236 .driver_info = DEVTYPE_NEXIO},
237 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
238 .driver_info = DEVTYPE_NEXIO},
245 /*****************************************************************************
249 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
250 static int e2i_init(struct usbtouch_usb *usbtouch)
253 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
255 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
256 0x01, 0x02, 0x0000, 0x0081,
257 NULL, 0, USB_CTRL_SET_TIMEOUT);
259 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
264 static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
266 int tmp = (pkt[0] << 8) | pkt[1];
267 dev->x = (pkt[2] << 8) | pkt[3];
268 dev->y = (pkt[4] << 8) | pkt[5];
271 dev->touch = (tmp > 0);
272 dev->press = (tmp > 0 ? tmp : 0);
279 /*****************************************************************************
283 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
289 #define EGALAX_PKT_TYPE_MASK 0xFE
290 #define EGALAX_PKT_TYPE_REPT 0x80
291 #define EGALAX_PKT_TYPE_DIAG 0x0A
293 static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
295 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
298 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
299 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
300 dev->touch = pkt[0] & 0x01;
305 static int egalax_get_pkt_len(unsigned char *buf, int len)
307 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
308 case EGALAX_PKT_TYPE_REPT:
311 case EGALAX_PKT_TYPE_DIAG:
323 /*****************************************************************************
326 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
327 static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
329 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
330 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
331 dev->touch = pkt[0] & 0x01;
338 /*****************************************************************************
341 #ifdef CONFIG_TOUCHSCREEN_USB_3M
343 #define MTOUCHUSB_ASYNC_REPORT 1
344 #define MTOUCHUSB_RESET 7
345 #define MTOUCHUSB_REQ_CTRLLR_ID 10
347 static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
350 dev->x = (pkt[4] << 8) | pkt[3];
351 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
353 dev->x = (pkt[8] << 8) | pkt[7];
354 dev->y = (pkt[10] << 8) | pkt[9];
356 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
361 static int mtouch_init(struct usbtouch_usb *usbtouch)
364 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
366 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
368 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
369 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
370 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
376 for (i = 0; i < 3; i++) {
377 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
378 MTOUCHUSB_ASYNC_REPORT,
379 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
380 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
381 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
389 /* Default min/max xy are the raw values, override if using hw-calib */
391 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
392 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
400 /*****************************************************************************
403 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
404 static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
408 * ITM devices report invalid x/y data if not touched.
409 * if the screen was touched before but is not touched any more
410 * report touch as 0 with the last valid x/y data once. then stop
411 * reporting data until touched again.
413 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
415 touch = ~pkt[7] & 0x20;
425 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
426 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
434 /*****************************************************************************
437 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
441 static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
445 /* packets should start with sync */
446 if (!(pkt[0] & 0x80))
449 shift = (6 - (pkt[0] & 0x03));
450 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
451 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
452 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
457 static int eturbo_get_pkt_len(unsigned char *buf, int len)
468 /*****************************************************************************
471 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
472 static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
474 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
477 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
478 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
479 dev->touch = pkt[0] & 0x20;
485 /*****************************************************************************
488 * Documentation about the controller and it's protocol can be found at
489 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
490 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
492 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
494 /* supported data rates. currently using 130 */
495 #define TSC10_RATE_POINT 0x50
496 #define TSC10_RATE_30 0x40
497 #define TSC10_RATE_50 0x41
498 #define TSC10_RATE_80 0x42
499 #define TSC10_RATE_100 0x43
500 #define TSC10_RATE_130 0x44
501 #define TSC10_RATE_150 0x45
504 #define TSC10_CMD_RESET 0x55
505 #define TSC10_CMD_RATE 0x05
506 #define TSC10_CMD_DATA1 0x01
508 static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
510 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
514 buf = kmalloc(2, GFP_NOIO);
518 buf[0] = buf[1] = 0xFF;
519 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
521 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
522 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
525 if (buf[0] != 0x06) {
530 /* set coordinate output rate */
531 buf[0] = buf[1] = 0xFF;
532 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
534 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
535 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
538 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
543 /* start sending data */
544 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
546 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
547 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
555 static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
557 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
558 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
559 dev->touch = pkt[0] & 0x01;
566 /*****************************************************************************
569 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
570 static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
572 dev->x = (pkt[3] << 8) | pkt[2];
573 dev->y = (pkt[5] << 8) | pkt[4];
574 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
580 /*****************************************************************************
581 * ET&T TC5UH/TC4UM part
583 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
584 static int tc45usb_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
586 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
587 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
588 dev->touch = pkt[0] & 0x01;
594 /*****************************************************************************
595 * IdealTEK URTC1000 Part
597 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
601 static int idealtek_get_pkt_len(unsigned char *buf, int len)
610 static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
612 switch (pkt[0] & 0x98) {
614 /* touch data in IdealTEK mode */
615 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
616 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
617 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
621 /* touch data in MT emulation mode */
622 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
623 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
624 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
633 /*****************************************************************************
636 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
637 static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
639 dev->x = (pkt[2] << 8) | pkt[1];
640 dev->y = (pkt[4] << 8) | pkt[3];
641 dev->press = pkt[5] & 0xff;
642 dev->touch = pkt[0] & 0x01;
648 /*****************************************************************************
651 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
652 static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
654 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
655 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
656 dev->touch = pkt[0] & 0x01;
662 /*****************************************************************************
665 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
666 static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
668 dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
669 dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
670 dev->touch = (pkt[0] & 0x40) >> 6;
676 /*****************************************************************************
679 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
680 static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
683 case 0x3A: /* command response */
684 dbg("%s: Command response %d", __func__, pkt[1]);
687 case 0xC0: /* down */
688 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
689 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
691 dbg("%s: down %d,%d", __func__, dev->x, dev->y);
695 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
696 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
698 dbg("%s: up %d,%d", __func__, dev->x, dev->y);
702 dbg("%s: Unknown return %d", __func__, pkt[0]);
710 /*****************************************************************************
713 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
715 #define NEXIO_TIMEOUT 5000
716 #define NEXIO_BUFSIZE 1024
717 #define NEXIO_THRESHOLD 50
721 unsigned char *ack_buf;
724 struct nexio_touch_packet {
725 u8 flags; /* 0xe1 = touch, 0xe1 = release */
726 __be16 data_len; /* total bytes of touch data */
727 __be16 x_len; /* bytes for X axis */
728 __be16 y_len; /* bytes for Y axis */
730 } __attribute__ ((packed));
732 static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 };
733 static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f };
735 static void nexio_ack_complete(struct urb *urb)
739 static int nexio_alloc(struct usbtouch_usb *usbtouch)
741 struct nexio_priv *priv;
744 usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
748 priv = usbtouch->priv;
750 priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt),
755 priv->ack = usb_alloc_urb(0, GFP_KERNEL);
757 dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
764 kfree(priv->ack_buf);
771 static int nexio_init(struct usbtouch_usb *usbtouch)
773 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
774 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
775 struct nexio_priv *priv = usbtouch->priv;
779 char *firmware_ver = NULL, *device_name = NULL;
780 int input_ep = 0, output_ep = 0;
782 /* find first input and output endpoint */
783 for (i = 0; i < interface->desc.bNumEndpoints; i++) {
785 usb_endpoint_dir_in(&interface->endpoint[i].desc))
786 input_ep = interface->endpoint[i].desc.bEndpointAddress;
788 usb_endpoint_dir_out(&interface->endpoint[i].desc))
789 output_ep = interface->endpoint[i].desc.bEndpointAddress;
791 if (!input_ep || !output_ep)
794 buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
798 /* two empty reads */
799 for (i = 0; i < 2; i++) {
800 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
801 buf, NEXIO_BUFSIZE, &actual_len,
807 /* send init command */
808 memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt));
809 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep),
810 buf, sizeof(nexio_init_pkt), &actual_len,
816 for (i = 0; i < 3; i++) {
817 memset(buf, 0, NEXIO_BUFSIZE);
818 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
819 buf, NEXIO_BUFSIZE, &actual_len,
821 if (ret < 0 || actual_len < 1 || buf[1] != actual_len)
824 case 0x83: /* firmware version */
826 firmware_ver = kstrdup(&buf[2], GFP_NOIO);
828 case 0x84: /* device name */
830 device_name = kstrdup(&buf[2], GFP_NOIO);
835 printk(KERN_INFO "Nexio device: %s, firmware version: %s\n",
836 device_name, firmware_ver);
841 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep),
842 priv->ack_buf, sizeof(nexio_ack_pkt),
843 nexio_ack_complete, usbtouch);
851 static void nexio_exit(struct usbtouch_usb *usbtouch)
853 struct nexio_priv *priv = usbtouch->priv;
855 usb_kill_urb(priv->ack);
856 usb_free_urb(priv->ack);
857 kfree(priv->ack_buf);
861 static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
863 struct nexio_touch_packet *packet = (void *) pkt;
864 struct nexio_priv *priv = usbtouch->priv;
865 unsigned int data_len = be16_to_cpu(packet->data_len);
866 unsigned int x_len = be16_to_cpu(packet->x_len);
867 unsigned int y_len = be16_to_cpu(packet->y_len);
868 int x, y, begin_x, begin_y, end_x, end_y, w, h, ret;
870 /* got touch data? */
871 if ((pkt[0] & 0xe0) != 0xe0)
880 ret = usb_submit_urb(priv->ack, GFP_ATOMIC);
882 if (!usbtouch->type->max_xc) {
883 usbtouch->type->max_xc = 2 * x_len;
884 input_set_abs_params(usbtouch->input, ABS_X,
885 0, usbtouch->type->max_xc, 0, 0);
886 usbtouch->type->max_yc = 2 * y_len;
887 input_set_abs_params(usbtouch->input, ABS_Y,
888 0, usbtouch->type->max_yc, 0, 0);
891 * The device reports state of IR sensors on X and Y axes.
892 * Each byte represents "darkness" percentage (0-100) of one element.
893 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
894 * This also means that there's a limited multi-touch capability but
895 * it's disabled (and untested) here as there's no X driver for that.
897 begin_x = end_x = begin_y = end_y = -1;
898 for (x = 0; x < x_len; x++) {
899 if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) {
903 if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) {
905 for (y = x_len; y < data_len; y++) {
906 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
911 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
912 end_y = y - 1 - x_len;
917 input_report_abs(usbtouch->input,
918 ABS_MT_TOUCH_MAJOR, max(w,h));
919 input_report_abs(usbtouch->input,
920 ABS_MT_TOUCH_MINOR, min(x,h));
921 input_report_abs(usbtouch->input,
922 ABS_MT_POSITION_X, 2*begin_x+w);
923 input_report_abs(usbtouch->input,
924 ABS_MT_POSITION_Y, 2*begin_y+h);
925 input_report_abs(usbtouch->input,
926 ABS_MT_ORIENTATION, w > h);
927 input_mt_sync(usbtouch->input);
930 usbtouch->x = 2 * begin_x + w;
931 usbtouch->y = 2 * begin_y + h;
932 usbtouch->touch = packet->flags & 0x01;
933 begin_y = end_y = -1;
937 begin_x = end_x = -1;
946 /*****************************************************************************
947 * the different device descriptors
950 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
951 unsigned char *pkt, int len);
954 static struct usbtouch_device_info usbtouch_dev_info[] = {
955 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
962 .process_pkt = usbtouch_process_multi,
963 .get_pkt_len = egalax_get_pkt_len,
964 .read_data = egalax_read_data,
968 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
975 .read_data = panjit_read_data,
979 #ifdef CONFIG_TOUCHSCREEN_USB_3M
986 .read_data = mtouch_read_data,
991 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
999 .read_data = itm_read_data,
1003 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
1004 [DEVTYPE_ETURBO] = {
1010 .process_pkt = usbtouch_process_multi,
1011 .get_pkt_len = eturbo_get_pkt_len,
1012 .read_data = eturbo_read_data,
1016 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
1023 .read_data = gunze_read_data,
1027 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
1028 [DEVTYPE_DMC_TSC10] = {
1034 .init = dmc_tsc10_init,
1035 .read_data = dmc_tsc10_read_data,
1039 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
1040 [DEVTYPE_IRTOUCH] = {
1046 .read_data = irtouch_read_data,
1050 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
1051 [DEVTYPE_IDEALTEK] = {
1057 .process_pkt = usbtouch_process_multi,
1058 .get_pkt_len = idealtek_get_pkt_len,
1059 .read_data = idealtek_read_data,
1063 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
1064 [DEVTYPE_GENERAL_TOUCH] = {
1070 .read_data = general_touch_read_data,
1074 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
1081 .read_data = gotop_read_data,
1085 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
1086 [DEVTYPE_JASTEC] = {
1092 .read_data = jastec_read_data,
1096 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
1104 .read_data = e2i_read_data,
1108 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
1109 [DEVTYPE_ZYTRONIC] = {
1115 .read_data = zytronic_read_data,
1120 #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB
1121 [DEVTYPE_TC45USB] = {
1127 .read_data = tc45usb_read_data,
1131 #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1135 .read_data = nexio_read_data,
1136 .alloc = nexio_alloc,
1144 /*****************************************************************************
1147 static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
1148 unsigned char *pkt, int len)
1150 struct usbtouch_device_info *type = usbtouch->type;
1152 if (!type->read_data(usbtouch, pkt))
1155 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
1158 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
1159 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
1161 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
1162 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
1164 if (type->max_press)
1165 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
1166 input_sync(usbtouch->input);
1171 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
1172 unsigned char *pkt, int len)
1174 unsigned char *buffer;
1175 int pkt_len, pos, buf_len, tmp;
1177 /* process buffer */
1178 if (unlikely(usbtouch->buf_len)) {
1179 /* try to get size */
1180 pkt_len = usbtouch->type->get_pkt_len(
1181 usbtouch->buffer, usbtouch->buf_len);
1184 if (unlikely(!pkt_len))
1187 /* need to append -pkt_len bytes before able to get size */
1188 if (unlikely(pkt_len < 0)) {
1189 int append = -pkt_len;
1190 if (unlikely(append > len))
1192 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
1194 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
1195 usbtouch->buf_len += append;
1197 pkt_len = usbtouch->type->get_pkt_len(
1198 usbtouch->buffer, usbtouch->buf_len);
1204 tmp = pkt_len - usbtouch->buf_len;
1205 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
1207 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
1208 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
1211 buf_len = len - tmp;
1217 /* loop over the received packet, process */
1219 while (pos < buf_len) {
1220 /* get packet len */
1221 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
1224 /* unknown packet: skip one byte */
1225 if (unlikely(!pkt_len)) {
1230 /* full packet: process */
1231 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
1232 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
1234 /* incomplete packet: save in buffer */
1235 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
1236 usbtouch->buf_len = buf_len - pos;
1243 usbtouch->buf_len = 0;
1249 static void usbtouch_irq(struct urb *urb)
1251 struct usbtouch_usb *usbtouch = urb->context;
1254 switch (urb->status) {
1259 /* this urb is timing out */
1260 dbg("%s - urb timed out - was the device unplugged?",
1267 /* this urb is terminated, clean up */
1268 dbg("%s - urb shutting down with status: %d",
1269 __func__, urb->status);
1272 dbg("%s - nonzero urb status received: %d",
1273 __func__, urb->status);
1277 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
1280 usb_mark_last_busy(interface_to_usbdev(usbtouch->interface));
1281 retval = usb_submit_urb(urb, GFP_ATOMIC);
1283 err("%s - usb_submit_urb failed with result: %d",
1287 static int usbtouch_open(struct input_dev *input)
1289 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1292 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
1294 r = usb_autopm_get_interface(usbtouch->interface) ? -EIO : 0;
1298 if (!usbtouch->type->irq_always) {
1299 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) {
1305 usbtouch->interface->needs_remote_wakeup = 1;
1307 usb_autopm_put_interface(usbtouch->interface);
1312 static void usbtouch_close(struct input_dev *input)
1314 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1317 if (!usbtouch->type->irq_always)
1318 usb_kill_urb(usbtouch->irq);
1319 r = usb_autopm_get_interface(usbtouch->interface);
1320 usbtouch->interface->needs_remote_wakeup = 0;
1322 usb_autopm_put_interface(usbtouch->interface);
1325 static int usbtouch_suspend
1326 (struct usb_interface *intf, pm_message_t message)
1328 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1330 usb_kill_urb(usbtouch->irq);
1335 static int usbtouch_resume(struct usb_interface *intf)
1337 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1338 struct input_dev *input = usbtouch->input;
1341 mutex_lock(&input->mutex);
1342 if (input->users || usbtouch->type->irq_always)
1343 result = usb_submit_urb(usbtouch->irq, GFP_NOIO);
1344 mutex_unlock(&input->mutex);
1349 static int usbtouch_reset_resume(struct usb_interface *intf)
1351 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1352 struct input_dev *input = usbtouch->input;
1355 /* reinit the device */
1356 if (usbtouch->type->init) {
1357 err = usbtouch->type->init(usbtouch);
1359 dbg("%s - type->init() failed, err: %d",
1365 /* restart IO if needed */
1366 mutex_lock(&input->mutex);
1368 err = usb_submit_urb(usbtouch->irq, GFP_NOIO);
1369 mutex_unlock(&input->mutex);
1374 static void usbtouch_free_buffers(struct usb_device *udev,
1375 struct usbtouch_usb *usbtouch)
1377 usb_free_coherent(udev, usbtouch->type->rept_size,
1378 usbtouch->data, usbtouch->data_dma);
1379 kfree(usbtouch->buffer);
1382 static struct usb_endpoint_descriptor *
1383 usbtouch_get_input_endpoint(struct usb_host_interface *interface)
1387 for (i = 0; i < interface->desc.bNumEndpoints; i++)
1388 if (usb_endpoint_dir_in(&interface->endpoint[i].desc))
1389 return &interface->endpoint[i].desc;
1394 static int usbtouch_probe(struct usb_interface *intf,
1395 const struct usb_device_id *id)
1397 struct usbtouch_usb *usbtouch;
1398 struct input_dev *input_dev;
1399 struct usb_endpoint_descriptor *endpoint;
1400 struct usb_device *udev = interface_to_usbdev(intf);
1401 struct usbtouch_device_info *type;
1404 /* some devices are ignored */
1405 if (id->driver_info == DEVTYPE_IGNORE)
1408 endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
1412 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
1413 input_dev = input_allocate_device();
1414 if (!usbtouch || !input_dev)
1417 type = &usbtouch_dev_info[id->driver_info];
1418 usbtouch->type = type;
1419 if (!type->process_pkt)
1420 type->process_pkt = usbtouch_process_pkt;
1422 usbtouch->data = usb_alloc_coherent(udev, type->rept_size,
1423 GFP_KERNEL, &usbtouch->data_dma);
1424 if (!usbtouch->data)
1427 if (type->get_pkt_len) {
1428 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
1429 if (!usbtouch->buffer)
1430 goto out_free_buffers;
1433 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
1434 if (!usbtouch->irq) {
1435 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
1436 goto out_free_buffers;
1439 usbtouch->interface = intf;
1440 usbtouch->input = input_dev;
1442 if (udev->manufacturer)
1443 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
1445 if (udev->product) {
1446 if (udev->manufacturer)
1447 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
1448 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
1451 if (!strlen(usbtouch->name))
1452 snprintf(usbtouch->name, sizeof(usbtouch->name),
1453 "USB Touchscreen %04x:%04x",
1454 le16_to_cpu(udev->descriptor.idVendor),
1455 le16_to_cpu(udev->descriptor.idProduct));
1457 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
1458 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
1460 input_dev->name = usbtouch->name;
1461 input_dev->phys = usbtouch->phys;
1462 usb_to_input_id(udev, &input_dev->id);
1463 input_dev->dev.parent = &intf->dev;
1465 input_set_drvdata(input_dev, usbtouch);
1467 input_dev->open = usbtouch_open;
1468 input_dev->close = usbtouch_close;
1470 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1471 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1472 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
1473 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
1474 if (type->max_press)
1475 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1476 type->max_press, 0, 0);
1478 if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT)
1479 usb_fill_int_urb(usbtouch->irq, udev,
1480 usb_rcvintpipe(udev, endpoint->bEndpointAddress),
1481 usbtouch->data, type->rept_size,
1482 usbtouch_irq, usbtouch, endpoint->bInterval);
1484 usb_fill_bulk_urb(usbtouch->irq, udev,
1485 usb_rcvbulkpipe(udev, endpoint->bEndpointAddress),
1486 usbtouch->data, type->rept_size,
1487 usbtouch_irq, usbtouch);
1489 usbtouch->irq->dev = udev;
1490 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1491 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1493 /* device specific allocations */
1495 err = type->alloc(usbtouch);
1497 dbg("%s - type->alloc() failed, err: %d", __func__, err);
1502 /* device specific initialisation*/
1504 err = type->init(usbtouch);
1506 dbg("%s - type->init() failed, err: %d", __func__, err);
1511 err = input_register_device(usbtouch->input);
1513 dbg("%s - input_register_device failed, err: %d", __func__, err);
1517 usb_set_intfdata(intf, usbtouch);
1519 if (usbtouch->type->irq_always) {
1520 /* this can't fail */
1521 usb_autopm_get_interface(intf);
1522 err = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1524 usb_autopm_put_interface(intf);
1525 err("%s - usb_submit_urb failed with result: %d",
1527 goto out_unregister_input;
1533 out_unregister_input:
1534 input_unregister_device(input_dev);
1538 type->exit(usbtouch);
1540 usb_free_urb(usbtouch->irq);
1542 usbtouch_free_buffers(udev, usbtouch);
1544 input_free_device(input_dev);
1549 static void usbtouch_disconnect(struct usb_interface *intf)
1551 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1553 dbg("%s - called", __func__);
1558 dbg("%s - usbtouch is initialized, cleaning up", __func__);
1559 usb_set_intfdata(intf, NULL);
1560 /* this will stop IO via close */
1561 input_unregister_device(usbtouch->input);
1562 usb_free_urb(usbtouch->irq);
1563 if (usbtouch->type->exit)
1564 usbtouch->type->exit(usbtouch);
1565 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1569 MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1571 static struct usb_driver usbtouch_driver = {
1572 .name = "usbtouchscreen",
1573 .probe = usbtouch_probe,
1574 .disconnect = usbtouch_disconnect,
1575 .suspend = usbtouch_suspend,
1576 .resume = usbtouch_resume,
1577 .reset_resume = usbtouch_reset_resume,
1578 .id_table = usbtouch_devices,
1579 .supports_autosuspend = 1,
1582 static int __init usbtouch_init(void)
1584 return usb_register(&usbtouch_driver);
1587 static void __exit usbtouch_cleanup(void)
1589 usb_deregister(&usbtouch_driver);
1592 module_init(usbtouch_init);
1593 module_exit(usbtouch_cleanup);
1595 MODULE_AUTHOR(DRIVER_AUTHOR);
1596 MODULE_DESCRIPTION(DRIVER_DESC);
1597 MODULE_LICENSE("GPL");
1599 MODULE_ALIAS("touchkitusb");
1600 MODULE_ALIAS("itmtouch");
1601 MODULE_ALIAS("mtouchusb");