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 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
20 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License as
24 * published by the Free Software Foundation; either version 2 of the
25 * License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful, but
28 * WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 * Driver is based on touchkitusb.c
37 * - ITM parts are from itmtouch.c
38 * - 3M parts are from mtouchusb.c
39 * - PanJit parts are from an unmerged driver by Lanslott Gish
40 * - DMC TSC 10/25 are from Holger Schurig, with ideas from an unmerged
41 * driver from Marius Vollmer
43 *****************************************************************************/
47 #include <linux/kernel.h>
48 #include <linux/slab.h>
49 #include <linux/input.h>
50 #include <linux/module.h>
51 #include <linux/init.h>
52 #include <linux/usb.h>
53 #include <linux/usb/input.h>
54 #include <linux/hid.h>
57 #define DRIVER_VERSION "v0.6"
58 #define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
59 #define DRIVER_DESC "USB Touchscreen Driver"
62 module_param(swap_xy, bool, 0644);
63 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
65 static int hwcalib_xy;
66 module_param(hwcalib_xy, bool, 0644);
67 MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
69 /* device specifc data/functions */
71 struct usbtouch_device_info {
74 int min_press, max_press;
78 * Always service the USB devices irq not just when the input device is
79 * open. This is useful when devices have a watchdog which prevents us
80 * from periodically polling the device. Leave this unset unless your
81 * touchscreen device requires it, as it does consume more of the USB
86 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
89 * used to get the packet len. possible return values:
92 * < 0: -return value more bytes needed
94 int (*get_pkt_len) (unsigned char *pkt, int len);
96 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
97 int (*init) (struct usbtouch_usb *usbtouch);
100 /* a usbtouch device */
101 struct usbtouch_usb {
104 unsigned char *buffer;
107 struct usb_device *udev;
108 struct input_dev *input;
109 struct usbtouch_device_info *type;
130 DEVTYPE_GENERAL_TOUCH,
137 #define USB_DEVICE_HID_CLASS(vend, prod) \
138 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
139 | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
140 | USB_DEVICE_ID_MATCH_DEVICE, \
141 .idVendor = (vend), \
142 .idProduct = (prod), \
143 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
144 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
146 static struct usb_device_id usbtouch_devices[] = {
147 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
148 /* ignore the HID capable devices, handled by usbhid */
149 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
150 {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE},
152 /* normal device IDs */
153 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
154 {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX},
155 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
156 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
157 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
158 {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX},
159 {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX},
162 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
163 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
164 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
165 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
166 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
169 #ifdef CONFIG_TOUCHSCREEN_USB_3M
170 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
173 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
174 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
177 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
178 {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO},
181 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
182 {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE},
185 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
186 {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10},
189 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
190 {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
191 {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH},
194 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
195 {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK},
198 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
199 {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH},
202 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
203 {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP},
204 {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP},
205 {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP},
208 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
209 {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC},
212 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
213 {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I},
216 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
217 {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC},
224 /*****************************************************************************
228 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
229 static int e2i_init(struct usbtouch_usb *usbtouch)
233 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
234 0x01, 0x02, 0x0000, 0x0081,
235 NULL, 0, USB_CTRL_SET_TIMEOUT);
237 dbg("%s - usb_control_msg - E2I_RESET - bytes|err: %d",
242 static int e2i_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
244 int tmp = (pkt[0] << 8) | pkt[1];
245 dev->x = (pkt[2] << 8) | pkt[3];
246 dev->y = (pkt[4] << 8) | pkt[5];
249 dev->touch = (tmp > 0);
250 dev->press = (tmp > 0 ? tmp : 0);
257 /*****************************************************************************
261 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
267 #define EGALAX_PKT_TYPE_MASK 0xFE
268 #define EGALAX_PKT_TYPE_REPT 0x80
269 #define EGALAX_PKT_TYPE_DIAG 0x0A
271 static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
273 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
276 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
277 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
278 dev->touch = pkt[0] & 0x01;
283 static int egalax_get_pkt_len(unsigned char *buf, int len)
285 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
286 case EGALAX_PKT_TYPE_REPT:
289 case EGALAX_PKT_TYPE_DIAG:
301 /*****************************************************************************
304 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
305 static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
307 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
308 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
309 dev->touch = pkt[0] & 0x01;
316 /*****************************************************************************
319 #ifdef CONFIG_TOUCHSCREEN_USB_3M
321 #define MTOUCHUSB_ASYNC_REPORT 1
322 #define MTOUCHUSB_RESET 7
323 #define MTOUCHUSB_REQ_CTRLLR_ID 10
325 static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
328 dev->x = (pkt[4] << 8) | pkt[3];
329 dev->y = 0xffff - ((pkt[6] << 8) | pkt[5]);
331 dev->x = (pkt[8] << 8) | pkt[7];
332 dev->y = (pkt[10] << 8) | pkt[9];
334 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
339 static int mtouch_init(struct usbtouch_usb *usbtouch)
343 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
345 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
346 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
347 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
353 for (i = 0; i < 3; i++) {
354 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
355 MTOUCHUSB_ASYNC_REPORT,
356 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
357 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
358 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
366 /* Default min/max xy are the raw values, override if using hw-calib */
368 input_set_abs_params(usbtouch->input, ABS_X, 0, 0xffff, 0, 0);
369 input_set_abs_params(usbtouch->input, ABS_Y, 0, 0xffff, 0, 0);
377 /*****************************************************************************
380 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
381 static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
385 * ITM devices report invalid x/y data if not touched.
386 * if the screen was touched before but is not touched any more
387 * report touch as 0 with the last valid x/y data once. then stop
388 * reporting data until touched again.
390 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
392 touch = ~pkt[7] & 0x20;
402 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
403 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
411 /*****************************************************************************
414 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
418 static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
422 /* packets should start with sync */
423 if (!(pkt[0] & 0x80))
426 shift = (6 - (pkt[0] & 0x03));
427 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
428 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
429 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
434 static int eturbo_get_pkt_len(unsigned char *buf, int len)
445 /*****************************************************************************
448 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
449 static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
451 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
454 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
455 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
456 dev->touch = pkt[0] & 0x20;
462 /*****************************************************************************
465 * Documentation about the controller and it's protocol can be found at
466 * http://www.dmccoltd.com/files/controler/tsc10usb_pi_e.pdf
467 * http://www.dmccoltd.com/files/controler/tsc25_usb_e.pdf
469 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
471 /* supported data rates. currently using 130 */
472 #define TSC10_RATE_POINT 0x50
473 #define TSC10_RATE_30 0x40
474 #define TSC10_RATE_50 0x41
475 #define TSC10_RATE_80 0x42
476 #define TSC10_RATE_100 0x43
477 #define TSC10_RATE_130 0x44
478 #define TSC10_RATE_150 0x45
481 #define TSC10_CMD_RESET 0x55
482 #define TSC10_CMD_RATE 0x05
483 #define TSC10_CMD_DATA1 0x01
485 static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
487 struct usb_device *dev = usbtouch->udev;
491 buf = kmalloc(2, GFP_KERNEL);
495 buf[0] = buf[1] = 0xFF;
496 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
498 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
499 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
502 if (buf[0] != 0x06) {
507 /* set coordinate output rate */
508 buf[0] = buf[1] = 0xFF;
509 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
511 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
512 TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT);
515 if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) {
520 /* start sending data */
521 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0),
523 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
524 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
532 static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
534 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
535 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
536 dev->touch = pkt[0] & 0x01;
543 /*****************************************************************************
546 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
547 static int irtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
549 dev->x = (pkt[3] << 8) | pkt[2];
550 dev->y = (pkt[5] << 8) | pkt[4];
551 dev->touch = (pkt[1] & 0x03) ? 1 : 0;
558 /*****************************************************************************
559 * IdealTEK URTC1000 Part
561 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
565 static int idealtek_get_pkt_len(unsigned char *buf, int len)
574 static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
576 switch (pkt[0] & 0x98) {
578 /* touch data in IdealTEK mode */
579 dev->x = (pkt[1] << 5) | (pkt[2] >> 2);
580 dev->y = (pkt[3] << 5) | (pkt[4] >> 2);
581 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
585 /* touch data in MT emulation mode */
586 dev->x = (pkt[2] << 5) | (pkt[1] >> 2);
587 dev->y = (pkt[4] << 5) | (pkt[3] >> 2);
588 dev->touch = (pkt[0] & 0x40) ? 1 : 0;
597 /*****************************************************************************
600 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
601 static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
603 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ;
604 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ;
605 dev->press = pkt[5] & 0xff;
606 dev->touch = pkt[0] & 0x01;
612 /*****************************************************************************
615 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
616 static int gotop_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
618 dev->x = ((pkt[1] & 0x38) << 4) | pkt[2];
619 dev->y = ((pkt[1] & 0x07) << 7) | pkt[3];
620 dev->touch = pkt[0] & 0x01;
626 /*****************************************************************************
629 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
630 static int jastec_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
632 dev->x = ((pkt[0] & 0x3f) << 6) | (pkt[2] & 0x3f);
633 dev->y = ((pkt[1] & 0x3f) << 6) | (pkt[3] & 0x3f);
634 dev->touch = (pkt[0] & 0x40) >> 6;
640 /*****************************************************************************
643 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
644 static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
647 case 0x3A: /* command response */
648 dbg("%s: Command response %d", __func__, pkt[1]);
651 case 0xC0: /* down */
652 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
653 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
655 dbg("%s: down %d,%d", __func__, dev->x, dev->y);
659 dev->x = (pkt[1] & 0x7f) | ((pkt[2] & 0x07) << 7);
660 dev->y = (pkt[3] & 0x7f) | ((pkt[4] & 0x07) << 7);
662 dbg("%s: up %d,%d", __func__, dev->x, dev->y);
666 dbg("%s: Unknown return %d", __func__, pkt[0]);
674 /*****************************************************************************
675 * the different device descriptors
678 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
679 unsigned char *pkt, int len);
682 static struct usbtouch_device_info usbtouch_dev_info[] = {
683 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
690 .process_pkt = usbtouch_process_multi,
691 .get_pkt_len = egalax_get_pkt_len,
692 .read_data = egalax_read_data,
696 #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT
703 .read_data = panjit_read_data,
707 #ifdef CONFIG_TOUCHSCREEN_USB_3M
714 .read_data = mtouch_read_data,
719 #ifdef CONFIG_TOUCHSCREEN_USB_ITM
727 .read_data = itm_read_data,
731 #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO
738 .process_pkt = usbtouch_process_multi,
739 .get_pkt_len = eturbo_get_pkt_len,
740 .read_data = eturbo_read_data,
744 #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE
751 .read_data = gunze_read_data,
755 #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10
756 [DEVTYPE_DMC_TSC10] = {
762 .init = dmc_tsc10_init,
763 .read_data = dmc_tsc10_read_data,
767 #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH
768 [DEVTYPE_IRTOUCH] = {
774 .read_data = irtouch_read_data,
778 #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK
779 [DEVTYPE_IDEALTEK] = {
785 .process_pkt = usbtouch_process_multi,
786 .get_pkt_len = idealtek_get_pkt_len,
787 .read_data = idealtek_read_data,
791 #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
792 [DEVTYPE_GENERAL_TOUCH] = {
798 .read_data = general_touch_read_data,
802 #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP
809 .read_data = gotop_read_data,
813 #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC
820 .read_data = jastec_read_data,
824 #ifdef CONFIG_TOUCHSCREEN_USB_E2I
832 .read_data = e2i_read_data,
836 #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC
837 [DEVTYPE_ZYTRONIC] = {
843 .read_data = zytronic_read_data,
850 /*****************************************************************************
853 static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
854 unsigned char *pkt, int len)
856 struct usbtouch_device_info *type = usbtouch->type;
858 if (!type->read_data(usbtouch, pkt))
861 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
864 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
865 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
867 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
868 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
871 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
872 input_sync(usbtouch->input);
877 static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
878 unsigned char *pkt, int len)
880 unsigned char *buffer;
881 int pkt_len, pos, buf_len, tmp;
884 if (unlikely(usbtouch->buf_len)) {
885 /* try to get size */
886 pkt_len = usbtouch->type->get_pkt_len(
887 usbtouch->buffer, usbtouch->buf_len);
890 if (unlikely(!pkt_len))
893 /* need to append -pkt_len bytes before able to get size */
894 if (unlikely(pkt_len < 0)) {
895 int append = -pkt_len;
896 if (unlikely(append > len))
898 if (usbtouch->buf_len + append >= usbtouch->type->rept_size)
900 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, append);
901 usbtouch->buf_len += append;
903 pkt_len = usbtouch->type->get_pkt_len(
904 usbtouch->buffer, usbtouch->buf_len);
910 tmp = pkt_len - usbtouch->buf_len;
911 if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
913 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
914 usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
923 /* loop over the received packet, process */
925 while (pos < buf_len) {
927 pkt_len = usbtouch->type->get_pkt_len(buffer + pos,
930 /* unknown packet: skip one byte */
931 if (unlikely(!pkt_len)) {
936 /* full packet: process */
937 if (likely((pkt_len > 0) && (pkt_len <= buf_len - pos))) {
938 usbtouch_process_pkt(usbtouch, buffer + pos, pkt_len);
940 /* incomplete packet: save in buffer */
941 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
942 usbtouch->buf_len = buf_len - pos;
949 usbtouch->buf_len = 0;
955 static void usbtouch_irq(struct urb *urb)
957 struct usbtouch_usb *usbtouch = urb->context;
960 switch (urb->status) {
965 /* this urb is timing out */
966 dbg("%s - urb timed out - was the device unplugged?",
972 /* this urb is terminated, clean up */
973 dbg("%s - urb shutting down with status: %d",
974 __func__, urb->status);
977 dbg("%s - nonzero urb status received: %d",
978 __func__, urb->status);
982 usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length);
985 retval = usb_submit_urb(urb, GFP_ATOMIC);
987 err("%s - usb_submit_urb failed with result: %d",
991 static int usbtouch_open(struct input_dev *input)
993 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
995 usbtouch->irq->dev = usbtouch->udev;
997 if (!usbtouch->type->irq_always) {
998 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
1005 static void usbtouch_close(struct input_dev *input)
1007 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1009 if (!usbtouch->type->irq_always)
1010 usb_kill_urb(usbtouch->irq);
1014 static void usbtouch_free_buffers(struct usb_device *udev,
1015 struct usbtouch_usb *usbtouch)
1017 usb_buffer_free(udev, usbtouch->type->rept_size,
1018 usbtouch->data, usbtouch->data_dma);
1019 kfree(usbtouch->buffer);
1023 static int usbtouch_probe(struct usb_interface *intf,
1024 const struct usb_device_id *id)
1026 struct usbtouch_usb *usbtouch;
1027 struct input_dev *input_dev;
1028 struct usb_host_interface *interface;
1029 struct usb_endpoint_descriptor *endpoint;
1030 struct usb_device *udev = interface_to_usbdev(intf);
1031 struct usbtouch_device_info *type;
1034 /* some devices are ignored */
1035 if (id->driver_info == DEVTYPE_IGNORE)
1038 interface = intf->cur_altsetting;
1039 endpoint = &interface->endpoint[0].desc;
1041 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
1042 input_dev = input_allocate_device();
1043 if (!usbtouch || !input_dev)
1046 type = &usbtouch_dev_info[id->driver_info];
1047 usbtouch->type = type;
1048 if (!type->process_pkt)
1049 type->process_pkt = usbtouch_process_pkt;
1051 usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
1052 GFP_KERNEL, &usbtouch->data_dma);
1053 if (!usbtouch->data)
1056 if (type->get_pkt_len) {
1057 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
1058 if (!usbtouch->buffer)
1059 goto out_free_buffers;
1062 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
1063 if (!usbtouch->irq) {
1064 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __func__);
1065 goto out_free_buffers;
1068 usbtouch->udev = udev;
1069 usbtouch->input = input_dev;
1071 if (udev->manufacturer)
1072 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
1074 if (udev->product) {
1075 if (udev->manufacturer)
1076 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
1077 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
1080 if (!strlen(usbtouch->name))
1081 snprintf(usbtouch->name, sizeof(usbtouch->name),
1082 "USB Touchscreen %04x:%04x",
1083 le16_to_cpu(udev->descriptor.idVendor),
1084 le16_to_cpu(udev->descriptor.idProduct));
1086 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
1087 strlcat(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
1089 input_dev->name = usbtouch->name;
1090 input_dev->phys = usbtouch->phys;
1091 usb_to_input_id(udev, &input_dev->id);
1092 input_dev->dev.parent = &intf->dev;
1094 input_set_drvdata(input_dev, usbtouch);
1096 input_dev->open = usbtouch_open;
1097 input_dev->close = usbtouch_close;
1099 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1100 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1101 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
1102 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
1103 if (type->max_press)
1104 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1105 type->max_press, 0, 0);
1107 usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
1108 usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress),
1109 usbtouch->data, type->rept_size,
1110 usbtouch_irq, usbtouch, endpoint->bInterval);
1112 usbtouch->irq->dev = usbtouch->udev;
1113 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1114 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1116 /* device specific init */
1118 err = type->init(usbtouch);
1120 dbg("%s - type->init() failed, err: %d", __func__, err);
1121 goto out_free_buffers;
1125 err = input_register_device(usbtouch->input);
1127 dbg("%s - input_register_device failed, err: %d", __func__, err);
1128 goto out_free_buffers;
1131 usb_set_intfdata(intf, usbtouch);
1133 if (usbtouch->type->irq_always)
1134 usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1139 usbtouch_free_buffers(udev, usbtouch);
1141 input_free_device(input_dev);
1146 static void usbtouch_disconnect(struct usb_interface *intf)
1148 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
1150 dbg("%s - called", __func__);
1155 dbg("%s - usbtouch is initialized, cleaning up", __func__);
1156 usb_set_intfdata(intf, NULL);
1157 /* this will stop IO via close */
1158 input_unregister_device(usbtouch->input);
1159 usb_free_urb(usbtouch->irq);
1160 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1164 MODULE_DEVICE_TABLE(usb, usbtouch_devices);
1166 static struct usb_driver usbtouch_driver = {
1167 .name = "usbtouchscreen",
1168 .probe = usbtouch_probe,
1169 .disconnect = usbtouch_disconnect,
1170 .id_table = usbtouch_devices,
1173 static int __init usbtouch_init(void)
1175 return usb_register(&usbtouch_driver);
1178 static void __exit usbtouch_cleanup(void)
1180 usb_deregister(&usbtouch_driver);
1183 module_init(usbtouch_init);
1184 module_exit(usbtouch_cleanup);
1186 MODULE_AUTHOR(DRIVER_AUTHOR);
1187 MODULE_DESCRIPTION(DRIVER_DESC);
1188 MODULE_LICENSE("GPL");
1190 MODULE_ALIAS("touchkitusb");
1191 MODULE_ALIAS("itmtouch");
1192 MODULE_ALIAS("mtouchusb");